Created
February 12, 2022 15:55
-
-
Save nyxkrage/797fb55f48dcecfb728d9c883e5a17c0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class InGameConsole { | |
// The constructor is run when initiating the mods, everything in the game is not expected to be initialized | |
constructor(game_instance, game_config, api) { | |
// this.name is required | |
this.name = "InGame Console" | |
// this.id is required and should be unique to your mod | |
// for instance "yourname.modname" | |
this.id = "nyxkrage.igconsole" | |
// this.XXX can be used to save things for use in start or in your hooks | |
this.api = api | |
this.game_instance = game_instance | |
this.game_config = game_config | |
this.console = null; | |
// functions called from pre and post are called hooks | |
// Pre-hooks are called before the normal function is called | |
this.pre = { | |
"window.console.log": this.onConsoleLog, | |
} | |
// Post-hooks are called after the normal function is called | |
this.post = { | |
// Scene.XXXX hooks look at the XXXX scene for a function | |
"Scene.MainScene.create": this.postMainSceneCreate, | |
} | |
} | |
// Start is called before the `pre` and `post` hooks are applied, but after most things in the game have loaded | |
start() {} | |
// This function will be called before the normal console.log code | |
onConsoleLog(self, ...args) { | |
if (self.console) | |
self.console.setText(args.join(" ")) | |
} | |
// This function will be called after the normal MainScene creation code | |
postMainSceneCreate(self) { | |
self.console = this.add.text(10, this.game.renderer.height - 20, "Welcome from a Mod!", { color: "white", fontSize: "12px"}).setScrollFactor(0).setDepth(Number.MAX_SAFE_INTEGER) | |
} | |
} | |
module.exports = InGameConsole |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment