-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6133dc5
Showing
4 changed files
with
347 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,310 @@ | ||
/* ================================================================ | ||
main.js | ||
================================================================ */ | ||
|
||
// escape regex | ||
const escapeRe = /\\(?:u[0-9a-fA-F]{4}|x[0-9a-fA-F]{2}|u{[0-9a-fA-F]{1,6}}|[0-2][0-7]{0,2}|3[0-7][0-7]?|[4-7][0-7]?|.)/; | ||
|
||
/** | ||
* Main plugin instance | ||
*/ | ||
class AcodePlugin { | ||
/** | ||
* Init function | ||
*/ | ||
async init() { | ||
this.addModes(); | ||
} | ||
/** | ||
* Register minecraft files | ||
*/ | ||
addModes() { | ||
// register minecraft files | ||
ace.require("ace/ext/modelist").modes.push({ | ||
caption: "Minecraft Language", | ||
extRe: /\.lang$/, | ||
extensions: "lang", | ||
mode: "ace/mode/lang", | ||
name: "Lang" | ||
}, { | ||
caption: "Minecraft Function", | ||
extRe: /\.mcfunction$/, | ||
extensions: "mcfunction", | ||
mode: "ace/mode/mcfunction", | ||
name: "Mcfunction" | ||
}); | ||
|
||
// dot-lang highlighter | ||
define("ace/mode/lang_highlight_rules",[ | ||
"require","exports","module", | ||
"ace/lib/oop", | ||
"ace/mode/text_highlight_rules" | ||
],function(require, exports, module){ | ||
"use strict"; | ||
const oop = require("../lib/oop"); | ||
const { TextHighlightRules } = require("./text_highlight_rules"); | ||
function LangHighlightRules() { | ||
// add highlighting rules | ||
this.$rules = { | ||
start: [ | ||
{ | ||
// a comment | ||
token: "comment", | ||
regex: /(^\s*##.*|\s+##.*)$/ | ||
}, | ||
{ | ||
// "=" character | ||
token: "keyword", | ||
regex: /=/ | ||
}, | ||
{ | ||
// translation value | ||
token: "string", | ||
regex: /(?<==)/, | ||
push: [ | ||
{ | ||
// parameters | ||
token: "identifier", | ||
regex: /%(%|[a-z]|[1-9]\d*(?:\$[a-z])?|\.\d+[df\$])/ | ||
}, | ||
{ | ||
// icons | ||
token: "storage", | ||
regex: /:[_a-zA-Z0-9.]+:/ | ||
}, | ||
{ | ||
defaultToken: "string" | ||
}, | ||
{ | ||
// end | ||
token: "string", | ||
regex: /((?=\t+##)|$)/, | ||
next: "pop" | ||
} | ||
] | ||
}, | ||
{ | ||
// translation key | ||
token: "variable", | ||
regex: /^[^=]+/ | ||
} | ||
] | ||
}; | ||
this.normalizeRules(); | ||
} | ||
LangHighlightRules.metaData = { | ||
fileTypes: ["lang"], | ||
name: "Lang" | ||
}; | ||
oop.inherits(LangHighlightRules, TextHighlightRules); | ||
exports.LangHighlightRules = LangHighlightRules; | ||
}); | ||
// dot-lang mode | ||
define("ace/mode/lang",[ | ||
"require","exports","module", | ||
"ace/lib/oop", | ||
"ace/mode/text", | ||
"ace/mode/lang_highlight_rules" | ||
],function(require,exports,module){ | ||
"use strict"; | ||
const oop = require("../lib/oop"); | ||
const { Mode: TextMode } = require("./text"); | ||
const { LangHighlightRules } = require("./lang_highlight_rules"); | ||
function LangMode() { | ||
this.HighlightRules = LangHighlightRules; | ||
this.$behaviour = this.$defaultBehaviour; | ||
}; | ||
oop.inherits(LangMode, TextMode); | ||
LangMode.prototype.$id = "ace/mode/lang"; | ||
exports.Mode = LangMode; | ||
}); | ||
|
||
// mcfunction highlighter | ||
define("ace/mode/mcfunction_highlight_rules",[ | ||
"require","exports","module", | ||
"ace/lib/oop", | ||
"ace/mode/text_highlight_rules" | ||
],function(require, exports, module){ | ||
"use strict"; | ||
const oop = require("../lib/oop"); | ||
const { TextHighlightRules } = require("./text_highlight_rules"); | ||
// commands and sub-commands, as of 1.20.12 | ||
// commands | ||
const cmds = [ | ||
"\\?", "ability", "alwaysday", "camerashake", "clear", "clearspawnpoint", | ||
"clone", "connect", "damage", "daylock", "deop", "dialogue", "difficulty", | ||
"effect", "enchant", "event", "execute", "fill", "fog", "function", | ||
"gamemode", "gamerule", "gametest", "give", "help", "immutableworld", | ||
"inputpermission", "kick", "kill", "list", "locate", "loot", "me", | ||
"mobevent", "msg", "music", "op", "particle", "playanimation", "playsound", | ||
"reload", "replaceitem", "ride", "say", "schedule", "scoreboard", | ||
"script", "scriptevent", "setblock", "setmaxplayers", "setworldspawn", | ||
"spawnpoint", "spreadplayers", "stopsound", "structure", "summon", | ||
"tag", "teleport", "tell", "tellraw", "testfor", "testforblock", | ||
"testforblocks", "tickingarea", "time", "title", "titleraw", "toggledownfall", | ||
"tp", "w", "wb", "weather", "worldbuilder", "wsserver", "xp" | ||
]; | ||
// sub-commands | ||
const subCmds = [ | ||
"actionbar", "add", "align", "all", "anchored", "as", "ascending", "at", | ||
"belowname", "biome", "block", "circle", "structure", "block", "blocks", | ||
"change", "clear", "clearall", "close", "connect", "create", "debugger", | ||
"delete", "descending", "destroy", "dummy", "entity", "evict_riders", | ||
"exportstats", "eyes", "facing", "feet", "fill", "filtered", "fog", "give", | ||
"if", "in", "insert", "keep", "kill", "list", "listen", "load", "loot", | ||
"mainhand", "masked", "matches", "objectives", "offhand", "on_area_loaded", | ||
"open", "operation", "play", "pos", "positioned", "preload", "profiler", | ||
"push", "queue", "query", "rain", "random", "remove", "remove_all", "replace", | ||
"reset", "rotated", "run", "runset", "runsetuntilfail", "runthese", "runthis", | ||
"save", "score", "set", "setdisplay", "sidebar", "spawn", "start", | ||
"start_riding", "stop", "stop_riding", "stopall", "subtitle", "summon_ride", | ||
"summon_rider", "test", "thunder", "tickingarea", "times", "title", "unless", | ||
"volume", "watchdog" | ||
]; | ||
// dimensions, used in some commands | ||
const dims = [ | ||
"overworld", "nether", "the_end" | ||
]; | ||
function McfunctionHighlightRules() { | ||
// add keywords | ||
this.createKeywordMapper({ | ||
keyword: [...cmds, ...subCmds, ...dims].join("|") | ||
}); | ||
// add highlighting rules | ||
this.$rules = { | ||
start: [ | ||
{ | ||
// a comment | ||
token: "comment", | ||
regex: /\s*#.*/ | ||
}, | ||
{ | ||
// a string (text within double quotes) | ||
token: "string", | ||
regex: /"/, | ||
push: [ | ||
{ | ||
// escape characters | ||
token: "constant.language.escape", | ||
regex: escapeRe | ||
}, | ||
{ | ||
// back to parent rules | ||
token: "string", | ||
regex: /"/, | ||
next: "pop" | ||
}, | ||
{ | ||
// part of the string | ||
defaultToken: "string" | ||
} | ||
] | ||
}, | ||
{ | ||
// numbers | ||
token: "constant.numeric", | ||
regex: /[-+]?(0|[1-9]\d*)(\.\d+)?/ | ||
}, | ||
{ | ||
// boolean | ||
token: "constant.language.boolean", | ||
regex: /(true|false)/ | ||
}, | ||
{ | ||
// punctuation operators | ||
token: "punctuation.operator", | ||
regex: /[!,.:]/ | ||
}, | ||
{ | ||
// keyword operators | ||
token: "keyword.operator", | ||
regex: /[-+*/=^~]/ | ||
}, | ||
{ | ||
// selector | ||
token: "storage", | ||
regex: /@[aerpsv]/ | ||
}, | ||
{ | ||
// bracket | ||
token: "paren", | ||
regex: /[\[\]\{\}]/ | ||
}, | ||
{ | ||
// minecraft namespace | ||
token: "identifier.class", | ||
regex: /\bminecraft\b/ | ||
}, | ||
{ | ||
// commands | ||
token: "keyword", | ||
regex: "\\b(" + cmds.join("|") + ")\\b" | ||
}, | ||
{ | ||
// sub-commands | ||
token: "identifier", | ||
regex: "\\b(" + subCmds.join("|") + ")\\b" | ||
}, | ||
{ | ||
// dimensions | ||
token: "constant.language", | ||
regex: "\\b(" + dims.join("|") + ")\\b" | ||
}, | ||
{ | ||
// variable (like in shell script), for target selectors | ||
token: "variable", | ||
regex: /[a-zA-Z0-9_]+(?==)/ | ||
} | ||
] | ||
}; | ||
this.normalizeRules(); | ||
} | ||
McfunctionHighlightRules.metaData = { | ||
fileTypes: ["mcfunction"], | ||
name: "Mcfunction" | ||
}; | ||
oop.inherits(McfunctionHighlightRules, TextHighlightRules); | ||
exports.McfunctionHighlightRules = McfunctionHighlightRules; | ||
}); | ||
// mcfunction mode | ||
define("ace/mode/mcfunction",[ | ||
"require","exports","module", | ||
"ace/lib/oop", | ||
"ace/mode/text", | ||
"ace/mode/mcfunction_highlight_rules" | ||
],function(require,exports,module){ | ||
"use strict"; | ||
const oop = require("../lib/oop"); | ||
const { Mode: TextMode } = require("./text"); | ||
const { McfunctionHighlightRules } = require("./mcfunction_highlight_rules"); | ||
function McfunctionMode() { | ||
this.HighlightRules = McfunctionHighlightRules; | ||
this.$behaviour = this.$defaultBehaviour; | ||
}; | ||
oop.inherits(McfunctionMode, TextMode); | ||
McfunctionMode.prototype.$id = "ace/mode/mcfunction"; | ||
exports.Mode = McfunctionMode; | ||
}); | ||
} | ||
/** | ||
* Unmount function | ||
*/ | ||
async destroy() { | ||
// no-op | ||
} | ||
} | ||
|
||
if (window.acode) { | ||
const acodePlugin = new AcodePlugin(); | ||
const pluginId = "vytdev.minecraft.util"; | ||
acode.setPluginInit(pluginId, async (baseUrl, $page, { cacheFileUrl, cacheFile }) => { | ||
if (!baseUrl.endsWith('/')) { | ||
baseUrl += '/'; | ||
} | ||
acodePlugin.baseUrl = baseUrl; | ||
await acodePlugin.init($page, cacheFile, cacheFileUrl); | ||
}); | ||
acode.setPluginUnmount(pluginId, () => { | ||
acodePlugin.destroy(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"id": "vytdev.minecraft.util", | ||
"name": "Minecraft Utility", | ||
"main": "main.js", | ||
"version": "1.0.0", | ||
"readme": "readme.md", | ||
"icon": "icon.png", | ||
"files": [], | ||
"minVersionCode": 304, | ||
"price": 0, | ||
"author": { | ||
"name": "VYT", | ||
"email": "[email protected]", | ||
"github": "vytdev" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Minecraft Utils | ||
|
||
> *For Minecraft add-on devs only =)* | ||
This plugin will help you to make your Minecraft add-ons. | ||
|
||
This can highlight the following Minecraft files: | ||
|
||
- `.mcfunction` | ||
- `.lang` | ||
|
||
*More features coming soon...* | ||
|
||
## Contributing | ||
|
||
You are welcome to contribute with this plugin development. See the GitHub repo: | ||
https://github.com/vytdev/minecraft-acode-plugin | ||
|
||
*Fun fact: I wrote this plugin with Acode* 😁 | ||
|
||
**Thanks for using this plugin. Hope you like it 🥰** |