diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/README.md b/README.md new file mode 100644 index 0000000..27745bb --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# cc-speedrun-utilities + CrossCode mod containing various utilities and features for speedrunning and debugging the game. diff --git a/Utilities/freeSP.js b/Utilities/freeSP.js new file mode 100644 index 0000000..559917b --- /dev/null +++ b/Utilities/freeSP.js @@ -0,0 +1,48 @@ +/** + * CrossCode Speedrun Utilities - freeSP.js + * + * Hotkey for giving SP, gives points past the regular cap. + */ + +sc.OPTIONS_DEFINITION["keys-free-sp"] = { + type: "CONTROLS", + init: { + key1: ig.KEY.U, + key2: undefined + }, + cat: sc.OPTION_CATEGORY.CONTROLS, + hasDivider: true, + header: "cc-speedrun-utilities", +}; + +let giveSPAmount = 12; + +/** + * @inject + * Detect when Save and Load Position/Map binds are pressed + */ +sc.Control.inject({ + freeSPPress: function () { + return ig.input.pressed("free-sp"); + } +}); + +/** + * @inject + * Handle execution of Save and Load Position/Map keybinds + */ +ig.ENTITY.Player.inject({ + gatherInput(...args) { + if (ig.game.isControlBlocked()) { + return this.parent(...args); + } + + if (!ig.interact.isBlocked()) { + if (sc.control.freeSPPress()) { + this.params.currentSp += giveSPAmount; + } + } + + return this.parent(...args); + } +}); \ No newline at end of file diff --git a/Utilities/saveHotkeys.js b/Utilities/saveHotkeys.js new file mode 100644 index 0000000..eadeb3f --- /dev/null +++ b/Utilities/saveHotkeys.js @@ -0,0 +1,91 @@ +/** + * CrossCode Speedrun Utilities - saveHotkeys.js + * + * Hotkeys for loading your latest autosave and making quicksaves + * for quickly practicing segments repeatedly + */ + + sc.OPTIONS_DEFINITION["keys-autosave-load"] = { + type: "CONTROLS", + init: { + key1: ig.KEY.I, + key2: undefined + }, + cat: sc.OPTION_CATEGORY.CONTROLS, + hasDivider: false, + header: "cc-speedrun-utilities", +}; + +sc.OPTIONS_DEFINITION["keys-quick-save"] = { + type: "CONTROLS", + init: { + key1: ig.KEY.O, + key2: undefined + }, + cat: sc.OPTION_CATEGORY.CONTROLS, + hasDivider: false, + header: "cc-speedrun-utilities", +}; + +sc.OPTIONS_DEFINITION["keys-quick-load"] = { + type: "CONTROLS", + init: { + key1: ig.KEY.P, + key2: undefined + }, + cat: sc.OPTION_CATEGORY.CONTROLS, + hasDivider: false, + header: "cc-speedrun-utilities", +}; + +let currQuickSave = null; + +/** + * @inject + * Inject hotkeys. + */ +sc.Control.inject({ + autosaveLoadPress: function () { + return ig.input.pressed("autosave-load"); + }, + + quickSavePress: function() { + return ig.input.pressed("quick-save"); + }, + + quickLoadPress: function() { + return ig.input.pressed("quick-load"); + } +}); + +/** + * @inject + * Handle execution of hotkeys. + */ +ig.ENTITY.Player.inject({ + gatherInput(...args) { + if (ig.game.isControlBlocked()) { + return this.parent(...args); + } + + if (!ig.interact.isBlocked()) { + if (sc.control.autosaveLoadPress()) { + ig.storage.loadSlot(-1); + } + + if (sc.control.quickSavePress()) { + currQuickSave = {}; + ig.storage._saveState(currQuickSave); + currQuickSave = new ig.SaveSlot(currQuickSave); + } + + if (sc.control.quickLoadPress()) { + if(currQuickSave) { + ig.storage.loadSlot(currQuickSave); + } + } + } + + return this.parent(...args); + } +}); \ No newline at end of file diff --git a/assets/data/lang/sc/gui.en_US.json.patch b/assets/data/lang/sc/gui.en_US.json.patch new file mode 100644 index 0000000..573fd18 --- /dev/null +++ b/assets/data/lang/sc/gui.en_US.json.patch @@ -0,0 +1,18 @@ +{ + "labels": { + "options": { + "headers": { + "cc-speedrun-utilities": "Speedrun Utilities" + }, + + "controls": { + "keys": { + "free-sp": "Give SP", + "autosave-load": "Load Autosave", + "quick-save": "Quick Save", + "quick-load": "Quick Load" + } + } + } + } +} \ No newline at end of file diff --git a/ccmod.json b/ccmod.json new file mode 100644 index 0000000..c42618b --- /dev/null +++ b/ccmod.json @@ -0,0 +1,14 @@ +{ + "id": "yoshi-speedrun-utilities", + "version": "1.0.0", + "module": true, + "title": "Speedrun Utilities", + "description": "Various useful features for speedrunning and debugging.", + "prestart": "prestart.js", + "dependencies": { + "input-api": "^1.0.0" + }, + "icons": { + "24": "icon.png" + } +} \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..5b7d3d4 Binary files /dev/null and b/icon.png differ diff --git a/prestart.js b/prestart.js new file mode 100644 index 0000000..886e51b --- /dev/null +++ b/prestart.js @@ -0,0 +1,8 @@ +/** + * CrossCode Speedrun Utilities + * + * A growing collection of useful features for speedrunning and debugging the game. + */ + +import './Utilities/freeSP.js' +import './Utilities/saveHotkeys.js' \ No newline at end of file