Skip to content

Commit

Permalink
initial scripting stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Dec 3, 2024
1 parent 60b1fb2 commit fe45a48
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
}
],
"resources": {
"files": [
"scripts/*.swipe"
],
"spritesheets": {
"UISheet": [
"resources/*.png"
Expand Down
Binary file added resources/script.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions scripts/Circle.swipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

@version 1.0
@name "Circle Tool"
@by "HJfod"
@input r 5.0 "Radius"
@input id 1 "Object ID"
@input count 40 "Object count"

r *= 30.0
pos = getViewCenter()
a = 0
for i in count {
create(id, x = pos.x + cos(a) * r, y = pos.y + sin(a) * r, rotation = 360 - a)
a += 360 / count
}
10 changes: 10 additions & 0 deletions scripts/SelectRandom.swipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@version 1.0
@name "Deselect Random"
@by "HJfod"

objs = getSelectedObjects()
for obj in objs {
if random() > 0.5 {
obj.deselect()
}
}
11 changes: 11 additions & 0 deletions scripts/Test.swipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

@version 1.0
@name "Swipe test"
@by "HJfod"

function vararg(named, x, y, args...) {
// todo: why tf is this not just args[0], args[1]??? why is args not just an array???
print("named: {}, x: {}, y: {}, argument0: {}, argument1: {}", argument0, argument1)
}

vararg("hi", 5, true, "six", y = 6, ball)
29 changes: 29 additions & 0 deletions swipe-vscode/language-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"comments": {
"lineComment": "//",
"blockComment": [ "/*", "*/" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
"autoClosingPairs": [
{ "open": "{", "close": "}", "autoCloseBefore": ";:.,=}])>` \n\t" },
["[", "]"],
["(", ")"],
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
{ "open": "\"", "close": "\"", "notIn": ["string"] },
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
{ "open": "/**", "close": " */", "notIn": ["string"] }
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["<", ">"],
["\"", "\""],
["'", "'"],
["`", "`"]
]
}
37 changes: 37 additions & 0 deletions swipe-vscode/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "swipelang-support",
"displayName": "Swipe Language Support",
"description": "Support for the Swipe language for scripting in BetterEdit",
"author": {
"name": "HJfod",
"url": "https://github.com/hjfod"
},
"repository": {
"url": "https://github.com/hjfod/BetterEdit"
},
"publisher": "HJfod",
"version": "0.0.1",
"engines": {
"vscode": "^1.67.0"
},
"categories": [
"Programming Languages"
],
"contributes": {
"languages": [{
"id": "swipe",
"aliases": ["Swipe"],
"extensions": [".swipe"],
"configuration": "./language-configuration.json",
"icon": {
"dark": "./swipe.png",
"light": "./swipe.png"
}
}],
"grammars": [{
"language": "swipe",
"scopeName": "source.swipe",
"path": "./syntaxes/swipe.tmLanguage.json"
}]
}
}
Binary file added swipe-vscode/swipe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
181 changes: 181 additions & 0 deletions swipe-vscode/syntaxes/swipe.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "swipe",
"patterns": [
{
"include": "#language"
}
],
"repository": {
"language": {
"patterns": [
{
"include": "#comments"
},
{
"include": "#constants"
},
{
"include": "#keywords"
},
{
"include": "#strings"
},
{
"include": "#declarations"
},
{
"include": "#parenthesis"
},
{
"include": "#operators"
},
{
"include": "#expression"
}
]
},
"declarations": {
"patterns": [
{
"match": "(?<=const\\s+)[a-zA-Z]+",
"name": "variable.other.constant.swipe"
},
{
"match": "(?<=new\\s*)[a-zA-Z0-9_]+",
"name": "entity.name.type.swipe"
},
{
"match": "\\b(\\w+\\!?)(?=\\s*\\()",
"captures": {
"1": {
"name": "entity.name.function.swipe"
}
}
}
]
},
"keywords": {
"patterns": [
{
"name": "keyword.control.swipe",
"match": "\\b(for|while|if|else|try|return|break|continue|new)\\b"
},
{
"name": "keyword.control.meta.swipe",
"match": "(@([a-zA-Z]+))\\b"
},
{
"name": "storage.type.swipe",
"match": "(?<=@input\\s+)(number|string|boolean)\\b"
},
{
"name": "keyword.other.swipe",
"match": "\\b(in)\\b"
},
{
"name": "storage.type.swipe",
"match": "\\b(const|function)\\b"
},
{
"name": "punctuation.swipe",
"match": "(->)|\\.|;|,|:|\\?|#"
}
]
},
"operators": {
"name": "keyword.operator.swipe",
"match": "[\\+\\-\\*\\/=<>\\^\\|\\&\\!%~@]"
},
"strings": {
"patterns": [
{
"name": "string.quoted.double.swipe",
"begin": "\"",
"end": "\"",
"patterns": [
{
"name": "constant.character.escape.swipe",
"match": "\\\\."
}
]
}
]
},
"constants": {
"patterns": [
{
"name": "constant.numeric.swipe",
"match": "\\b(([0-9]*\\.[0-9]+)|([0-9]+))\\b"
},
{
"name": "constant.numeric.swipe",
"match": "0x[0-9A-Fa-f]+"
},
{
"name": "constant.language.swipe",
"match": "\\b((argument[0-9]*)|arguments|namedArguments|this)\\b"
},
{
"name": "constant.language.swipe",
"match": "\\b(true|false|null)\\b"
}
]
},
"comments": {
"patterns": [
{
"name": "comment.block",
"begin": "/\\*",
"end": "\\*/"
},
{
"name": "comment.line",
"begin": "//",
"end": "\n"
}
]
},
"parenthesis": {
"patterns": [
{
"begin": "\\(",
"end": "\\)",
"beginCaptures": {
"0": { "name": "punctuation.paren.open" }
},
"endCaptures": {
"0": { "name": "punctuation.paren.close" }
},
"name": "expression.group",
"patterns": [{ "include": "#language" }]
},
{
"begin": "\\{",
"end": "\\}",
"beginCaptures": {
"0": { "name": "punctuation.paren.open" }
},
"endCaptures": {
"0": { "name": "punctuation.paren.close" }
},
"name": "expression.group",
"patterns": [{ "include": "#language" }]
},
{
"begin": "\\[",
"end": "\\]",
"beginCaptures": {
"0": { "name": "punctuation.paren.open" }
},
"endCaptures": {
"0": { "name": "punctuation.paren.close" }
},
"name": "expression.group",
"patterns": [{ "include": "#language" }]
}
]
}
},
"scopeName": "source.swipe"
}

0 comments on commit fe45a48

Please sign in to comment.