diff --git a/mod.json b/mod.json index bff52495..690b6f6f 100644 --- a/mod.json +++ b/mod.json @@ -63,6 +63,9 @@ } ], "resources": { + "files": [ + "scripts/*.swipe" + ], "spritesheets": { "UISheet": [ "resources/*.png" diff --git a/resources/script.png b/resources/script.png new file mode 100644 index 00000000..818c77ff Binary files /dev/null and b/resources/script.png differ diff --git a/scripts/Circle.swipe b/scripts/Circle.swipe new file mode 100644 index 00000000..aa4c8e93 --- /dev/null +++ b/scripts/Circle.swipe @@ -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 +} diff --git a/scripts/SelectRandom.swipe b/scripts/SelectRandom.swipe new file mode 100644 index 00000000..edd31456 --- /dev/null +++ b/scripts/SelectRandom.swipe @@ -0,0 +1,10 @@ +@version 1.0 +@name "Deselect Random" +@by "HJfod" + +objs = getSelectedObjects() +for obj in objs { + if random() > 0.5 { + obj.deselect() + } +} diff --git a/scripts/Test.swipe b/scripts/Test.swipe new file mode 100644 index 00000000..ceb7af25 --- /dev/null +++ b/scripts/Test.swipe @@ -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) diff --git a/swipe-vscode/language-configuration.json b/swipe-vscode/language-configuration.json new file mode 100644 index 00000000..e4a0c760 --- /dev/null +++ b/swipe-vscode/language-configuration.json @@ -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": [ + ["{", "}"], + ["[", "]"], + ["(", ")"], + ["<", ">"], + ["\"", "\""], + ["'", "'"], + ["`", "`"] + ] +} \ No newline at end of file diff --git a/swipe-vscode/package.json b/swipe-vscode/package.json new file mode 100644 index 00000000..c1fc6744 --- /dev/null +++ b/swipe-vscode/package.json @@ -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" + }] + } +} \ No newline at end of file diff --git a/swipe-vscode/swipe.png b/swipe-vscode/swipe.png new file mode 100644 index 00000000..2ba9772b Binary files /dev/null and b/swipe-vscode/swipe.png differ diff --git a/swipe-vscode/syntaxes/swipe.tmLanguage.json b/swipe-vscode/syntaxes/swipe.tmLanguage.json new file mode 100644 index 00000000..aa532ab9 --- /dev/null +++ b/swipe-vscode/syntaxes/swipe.tmLanguage.json @@ -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" +}