From 7fd95709098709c09cc2272f165b9cf510de9340 Mon Sep 17 00:00:00 2001 From: inc0der Date: Thu, 20 Aug 2020 00:08:43 -0300 Subject: [PATCH 01/18] Add the chapter scene --- src/scenes/Scene_Chapters.hx | 179 +++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 src/scenes/Scene_Chapters.hx diff --git a/src/scenes/Scene_Chapters.hx b/src/scenes/Scene_Chapters.hx new file mode 100644 index 0000000..c7055f0 --- /dev/null +++ b/src/scenes/Scene_Chapters.hx @@ -0,0 +1,179 @@ +import js.html.Console; +import utils.Fn; +import rm.core.Sprite; +import types.Chapter; +import rm.Globals.GameSwitches; +import rm.Globals.GameVariables; +import rm.Globals.GamePlayer; +import rm.core.Graphics; +import rm.windows.Window_SavefileList; +import rm.scenes.Scene_MenuBase; +import rm.scenes.Scene_Map; +import rm.managers.DataManager; +import rm.managers.SoundManager; +import rm.managers.SceneManager; +import Chapters.Params; +import windows.Window_ChapterList; +import windows.Window_ChapterSummary; +import windows.Window_ChapterThumbnail; + +class Scene_Chapters extends Scene_MenuBase { + private var _scelectedChapter: Int = 0; + private var _loadSuccess: Bool = false; + private var _saveFileList: Window_SavefileList; + private var _thumbnailWindow: Window_ChapterThumbnail; + private var _chapterSelectWindow: Window_ChapterList; + private var _summaryWindow: Window_ChapterSummary; + private var _selectedChapterIndex: Int; + private var _chapterBackground: Sprite; + + public function new() { + super(); + super.initialize(); + } + + public override function create() { + DataManager.loadAllSavefileImages(); + createChapterBackground(); + createWindowLayer(); + createHelpWindow(); + createSaveFileList(); + createChapterSelect(); + createChapterThumbnail(); + createChapterSummary(); + } + + public override function start() { + super.start(); + _saveFileList.refresh(); + } + + public override function update() { + super.update(); + if (!_saveFileList.isClosing() && _saveFileList.isClosed() && !_chapterSelectWindow.isOpen()) { + _thumbnailWindow.open(); + _summaryWindow.open(); + _chapterSelectWindow.open(); + _chapterSelectWindow.activate(); + } + if (_selectedChapterIndex != _chapterSelectWindow.index()) { + _selectedChapterIndex = _chapterSelectWindow.index(); + _thumbnailWindow.setChapter(selectedChapter()); + _summaryWindow.setChapter(selectedChapter()); + } + } + + public function createChapterBackground() { + _chapterBackground = new Sprite(); + addChild(_chapterBackground); + } + + public function createChapterSelect() { + var width = _tryEval(Params.chapterWindow.width); + var height = _tryEval(Params.chapterWindow.height); + var y: Int = Math.round(_tryEval(Params.chapterWindow.y)); + + _chapterSelectWindow = new Window_ChapterList(0, y, width, height); + _chapterSelectWindow.setHandler('ok', onChapterSelect); + _chapterSelectWindow.setHandler('cancel', popScene); + _chapterSelectWindow.close(); + addWindow(_chapterSelectWindow); + } + + public function createChapterThumbnail() { + var options = Params.thumbnailWindow; + var width = _tryEval(options.width); + var height = _tryEval(options.height); + var y = _tryEval(options.y); + var x = _tryEval(options.x); + + _thumbnailWindow = new Window_ChapterThumbnail(x, y, width, height); + _thumbnailWindow.close(); + addWindow(_thumbnailWindow); + } + + public function createChapterSummary() { + var options = Params.summaryWindow; + var width = _tryEval(options.width); + var height = _tryEval(options.height); + var y = _tryEval(options.y); + var x = _tryEval(options.x); + + _summaryWindow = new Window_ChapterSummary(x, y, width, height); + _summaryWindow.close(); + addWindow(_summaryWindow); + } + + public function createSaveFileList() { + var width = Math.round(Graphics.width); + var height = Math.round(Graphics.height - _helpWindow.height); + var y = Math.round(_helpWindow.height); + + _saveFileList = new Window_SavefileList(0, y, width, height); + _saveFileList.setHandler('ok', onSaveFileLoad); + _saveFileList.setHandler('cancel', popScene); + _saveFileList.select(0); + _saveFileList.setTopRow(0 - 2); + _helpWindow.setText('Load a save file'); + addWindow(_saveFileList); + } + + public function selectedChapter(): Chapter { + return _chapterSelectWindow.item(); + } + + public function setupSwitches(switchData: Array) { + if (switchData != null && switchData.length > 0) { + for (data in switchData) { + GameSwitches.setValue(data.id, data.value); + } + } + } + + public function setupVariables(variableData: Array) { + if (variableData != null && variableData.length > 0) { + for (data in variableData) { + GameVariables.setValue(data.id, data.value); + } + } + } + + public function onSaveFileLoad() { + var savefileId = _saveFileList.index(); + if (DataManager.loadGame(savefileId)) { + SoundManager.playLoad(); + _loadSuccess = true; + _saveFileList.deactivate(); + _saveFileList.close(); + _helpWindow.setText(Params.helpWindowTerm); + _chapterSelectWindow.refresh(); + } else { + _saveFileList.activate(); + SoundManager.playBuzzer(); + } + } + + public function onChapterSelect() { + var chapter: Chapter = selectedChapter(); + _chapterSelectWindow.close(); + fadeOutAll(); + if (chapter.requiredVariables != null) { + setupVariables(chapter.requiredVariables); + } + if (chapter.requiredSwitches != null) { + setupSwitches(chapter.requiredSwitches); + } + GamePlayer.reserveTransfer(chapter.startMapId, chapter.playerX, chapter.playerY); + GamePlayer.requestMapReload(); + SceneManager.goto(Scene_Map); + } + + private function _tryEval(expression): Dynamic { + try { + return Fn.eval(expression); + } catch (error) { + Console.error('Unable to evaluate the following expression ${expression}'); + return null; + } + } +} From 2838098eae3c61bce1e23740c9f70c894d29c81f Mon Sep 17 00:00:00 2001 From: inc0der Date: Thu, 20 Aug 2020 00:11:49 -0300 Subject: [PATCH 02/18] Fix scene missing package declaration --- src/scenes/Scene_Chapters.hx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/scenes/Scene_Chapters.hx b/src/scenes/Scene_Chapters.hx index c7055f0..84330f7 100644 --- a/src/scenes/Scene_Chapters.hx +++ b/src/scenes/Scene_Chapters.hx @@ -1,3 +1,5 @@ +package scenes; + import js.html.Console; import utils.Fn; import rm.core.Sprite; From 43574bcbc87766b834456791573aff07992437c0 Mon Sep 17 00:00:00 2001 From: inc0der Date: Thu, 20 Aug 2020 08:15:09 -0300 Subject: [PATCH 03/18] Add title scene --- src/overrides/SceneTitle.hx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/overrides/SceneTitle.hx diff --git a/src/overrides/SceneTitle.hx b/src/overrides/SceneTitle.hx new file mode 100644 index 0000000..e14ffb6 --- /dev/null +++ b/src/overrides/SceneTitle.hx @@ -0,0 +1,24 @@ +package overrides; + +import rm.managers.SceneManager; +import rm.scenes.Scene_Title; +import Chapters.Params; +import scenes.Scene_Chapters; + +class SceneTitle extends Scene_Title { + public function new() { + super(); + } + + public override function createCommandWindow() { + super.createCommandWindow(); + if (Params.isChapterCommandEnabled) { + _commandWindow.setHandler('chapterSelect', commandChapterSelect); + } + } + + public function commandChapterSelect() { + _commandWindow.close(); + SceneManager.push(Scene_Chapters); + } +} From ac9ca48ad8e1fa0a1da813f974f923d7098a9910 Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Sep 2020 11:26:03 -0300 Subject: [PATCH 04/18] Move and rename Scene_Title --- src/overrides/SceneTitle.hx | 24 ------------------------ src/scenes/SceneTitle.hx | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 24 deletions(-) delete mode 100644 src/overrides/SceneTitle.hx create mode 100644 src/scenes/SceneTitle.hx diff --git a/src/overrides/SceneTitle.hx b/src/overrides/SceneTitle.hx deleted file mode 100644 index e14ffb6..0000000 --- a/src/overrides/SceneTitle.hx +++ /dev/null @@ -1,24 +0,0 @@ -package overrides; - -import rm.managers.SceneManager; -import rm.scenes.Scene_Title; -import Chapters.Params; -import scenes.Scene_Chapters; - -class SceneTitle extends Scene_Title { - public function new() { - super(); - } - - public override function createCommandWindow() { - super.createCommandWindow(); - if (Params.isChapterCommandEnabled) { - _commandWindow.setHandler('chapterSelect', commandChapterSelect); - } - } - - public function commandChapterSelect() { - _commandWindow.close(); - SceneManager.push(Scene_Chapters); - } -} diff --git a/src/scenes/SceneTitle.hx b/src/scenes/SceneTitle.hx new file mode 100644 index 0000000..c07bfc6 --- /dev/null +++ b/src/scenes/SceneTitle.hx @@ -0,0 +1,33 @@ +package scenes; + +import core.Types.JsFn; +import utils.Comment; +import rm.managers.SceneManager; +// import core.Types.JsFn; +import rm.scenes.Scene_Title; +import utils.Fn; +import Chapters.Params; + +class SceneTitle { + public static inline function patch() { + var oldCreateCommandWindow: JsFn = Fn.getPrProp(Scene_Title, 'createCommandWindow'); + Fn.setPrProp(Scene_Title, 'createCommandWindow', () -> { + Comment.title('Scene_Title'); + var self: Scene_Title = Fn.self; + oldCreateCommandWindow.call(self); + if (Params.isChapterCommandEnabled) { + self.__commandWindow.setHandler('chapterSelect', untyped self.commandChapter.bind(self)); + } + }); + + commandChapter(); + } + + public static inline function commandChapter() { + Fn.setPrProp(Scene_Title, 'commandChapter', () -> { + var self: Scene_Title = Fn.self; + self.__commandWindow.close(); + SceneManager.push(Scene_Chapters); + }); + } +} From 2d4f19f328b551131ad198ce41ac4e41cc690ff0 Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Sep 2020 15:27:06 -0300 Subject: [PATCH 05/18] Add an event triggered on game saved --- src/overrides/DataManager.hx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/overrides/DataManager.hx diff --git a/src/overrides/DataManager.hx b/src/overrides/DataManager.hx new file mode 100644 index 0000000..6caed65 --- /dev/null +++ b/src/overrides/DataManager.hx @@ -0,0 +1,22 @@ +package overrides; + +import utils.Comment; +import core.Types.JsFn; +import utils.Fn; +import rm.managers.DataManager as RmDataManager; + +class DataManager { + public static inline function patch() { + Comment.title('DataManager'); + saveGame(); + } + + public static inline function saveGame() { + var oldSaveGame: JsFn = Fn.getField(RmDataManager, 'saveGame'); + Fn.setField(RmDataManager, 'saveGame', (savefileId) -> { + var saveName = RmDataManager.makeSavename(savefileId); + Chapters.Emitter.emit('game-saved', saveName); + oldSaveGame.call(Fn.self); + }); + } +} From eea78a968c7612ddacd398a1ff8811b99058be0b Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Sep 2020 15:28:23 -0300 Subject: [PATCH 06/18] Add command to title command window --- src/windows/TitleCommand.hx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/windows/TitleCommand.hx diff --git a/src/windows/TitleCommand.hx b/src/windows/TitleCommand.hx new file mode 100644 index 0000000..a3dfe2a --- /dev/null +++ b/src/windows/TitleCommand.hx @@ -0,0 +1,24 @@ +package windows; + +import utils.Comment; +import rm.managers.TextManager; +import rm.windows.Window_TitleCommand; +import utils.Fn; +import Chapters.Params; + +class TitleCommand { + public static inline function patch() { + Comment.title('Window_TitleCommand'); + makeCommandList(); + } + + public static inline function makeCommandList() { + Fn.setPrProp(Window_TitleCommand, 'makeCommandList', () -> { + var self: Window_TitleCommand = Fn.self; + self.addCommand(TextManager.newGame, 'newGame', true); + self.addCommand(TextManager.continue_, 'continue', self.isContinueEnabled()); + self.addCommand(Params.chapterCommandText, 'chapterSelect', self.isContinueEnabled()); + self.addCommand(TextManager.options, 'options', true); + }); + } +} From 2fd57c1849e40d77f10d4717ac4b2ed522046f2f Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Sep 2020 15:29:38 -0300 Subject: [PATCH 07/18] Add debug launch and task config --- .vscode/launch.json | 21 +++++++++++++++++++++ .vscode/tasks.json | 12 ++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b816f04 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "nwjs", + "request": "launch", + "name": "Debug Game", + "runtimeExecutable": "C:\\Program Files (x86)\\Steam\\steamapps\\common\\RPG Maker MZ\\nwjs-win\\nw.exe", + "runtimeArgs": [ + "--remote-debugging-port=9222" + ], + // "preLaunchTask": "lix: compile.hxml", + "webRoot": "${workspaceRoot}/game/", + "port": 9222, + // "sourceMaps": true + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..43d63c5 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,12 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "shell", + "group": "build", + "label": "lix: compile.hxml", + "command": "lix", + "args": ["compile.hxml"] + } + ] +} \ No newline at end of file From 5136a0c581dc7e7fad440163c180a2a914efeab5 Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Sep 2020 15:30:08 -0300 Subject: [PATCH 08/18] Update LunaTea dependency --- haxe_libraries/LunaTea.hxml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/haxe_libraries/LunaTea.hxml b/haxe_libraries/LunaTea.hxml index d6d8ceb..4c51524 100644 --- a/haxe_libraries/LunaTea.hxml +++ b/haxe_libraries/LunaTea.hxml @@ -1,6 +1,6 @@ -# @install: lix --silent download "gh://github.com/LunaTechsDev/LunaTea#15389955e5769766b8ab65c273168102a8c521e0" into LunaTea/0.7.9/github/15389955e5769766b8ab65c273168102a8c521e0 +# @install: lix --silent download "gh://github.com/LunaTechsDev/LunaTea#e715f4f6c1dd805236da2d12087ddce2c31ce900" into LunaTea/0.9.3/github/e715f4f6c1dd805236da2d12087ddce2c31ce900 -lib hxnodejs -lib jsfps -lib pixijs --cp ${HAXE_LIBCACHE}/LunaTea/0.7.9/github/15389955e5769766b8ab65c273168102a8c521e0/src/ --D LunaTea=0.7.9 \ No newline at end of file +-cp ${HAXE_LIBCACHE}/LunaTea/0.9.3/github/e715f4f6c1dd805236da2d12087ddce2c31ce900/src/ +-D LunaTea=0.9.3 \ No newline at end of file From 4ea384c93c72382bf47f0743c4b0b8a5685830dd Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Sep 2020 15:34:47 -0300 Subject: [PATCH 09/18] Add plugin parameters --- src/Parameters.js | 305 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 src/Parameters.js diff --git a/src/Parameters.js b/src/Parameters.js new file mode 100644 index 0000000..6c6782d --- /dev/null +++ b/src/Parameters.js @@ -0,0 +1,305 @@ +/*: + * @plugindesc A chapter selection system for your games + * + * + * @author LunaTechs | inc0der + * @url https://lunatechs.dev/plugins/luna-chapters/ + * + * @param chapters + * @text Chapters + * @type struct[] + * @desc A list of all your chapters + * @default ["{\"name\":\"01 That Dream\",\"description\":\"\\\"One day it all made sense, the next, well, the next day,\\\\nlets just say everything started \\\\nto change.\\\"\",\"summary\":\"\\\"\\\\\\\\C[3]Harold\\\\\\\\C[0] fell ill and \\\\\\\\C[3]Thersea\\\\\\\\C[0] set out\\\\non an adventure for a rare herb.\\\"\",\"thumbnail\":\"pictures/snowy_winter\",\"lockState\":\"true\",\"startMapId\":\"1\",\"playerX\":\"18\",\"playerY\":\"9\",\"requiredVariables\":\"[\\\"{\\\\\\\"id\\\\\\\":\\\\\\\"2\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"1\\\\\\\"}\\\"]\",\"requiredSwitches\":\"[\\\"{\\\\\\\"id\\\\\\\":\\\\\\\"2\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\"}\\\",\\\"{\\\\\\\"id\\\\\\\":\\\\\\\"3\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\"}\\\"]\"}","{\"name\":\"02 Once Upon A Star\",\"description\":\"\\\"There it was, I gazed upon the starry\\\\nnight's sky and then it all made\\\\nsense. \\\\\\\\i[10]\\\"\",\"summary\":\"\\\"Travel the \\\\\\\\C[1] Dark Woods \\\\\\\\C[0] and\\\\nfind the \\\\\\\\C[4]Golden Stone.\\\"\",\"thumbnail\":\"pictures/starry_night\",\"lockState\":\"false\",\"startMapId\":\"2\",\"playerX\":\"14\",\"playerY\":\"7\",\"requiredVariables\":\"[\\\"{\\\\\\\"id\\\\\\\":\\\\\\\"11\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"1\\\\\\\"}\\\"]\",\"requiredSwitches\":\"[\\\"{\\\\\\\"id\\\\\\\":\\\\\\\"10\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\"}\\\",\\\"{\\\\\\\"id\\\\\\\":\\\\\\\"11\\\\\\\",\\\\\\\"value\\\\\\\":\\\\\\\"true\\\\\\\"}\\\"]\"}","{\"name\":\"03 The Supernatural\",\"description\":\"\\\"This is when it all starts to get\\\\nreally weird. Are you ready for it\\\\nall?\\\"\",\"summary\":\"\\\"\\\"\",\"thumbnail\":\"\",\"lockState\":\"false\",\"startMapId\":\"3\",\"playerX\":\"5\",\"playerY\":\"2\",\"requiredVariables\":\"[]\",\"requiredSwitches\":\"[]\"}"] + * + * @param chapterWindow + * @text Chapter Window Options + * @type struct + * @desc The customizations for the chapter selection window + * @default {"x":"0","y":"this._helpWindow.height","width":"Graphics.width / 2","height":"Graphics.height - this._helpWindow.height","itemHeight":"160","maxItems":"4","fontSize":"18"} + * + * @param thumbnailWindow + * @text Thumbnail Window Options + * @type struct + * @desc The customizations for the thumbnail window + * @default {"x":"this._chapterSelectWindow.width","y":"this._helpWindow.height","width":"Graphics.width / 2","height":"Graphics.height / 2"} + * + * @param summaryWindow + * @text Summary Window Options + * @type struct + * @desc The customizations for the summary window + * @default {"x":"this._thumbnailWindow.x","y":"this._thumbnailWindow.y + this._thumbnailWindow.height","width":"Graphics.width / 2","height":"Graphics.height - (this._thumbnailWindow.height + this._helpWindow.height)"} + * + * + * @param horizontalLineColor + * @text Horizontal Line Color + * @type string + * @desc The horizontal line color. This line is drawn under chapter titles + * @default #fcefb3 + * + * @param helpWindowTerm + * @text Help Window Term + * @type string + * @desc The term used in the help window when selecting a chapter + * @default Select a chapter to continue + * + * @param summaryTitle + * @text Summary Title + * @type string + * @desc The term used as the title to th summary window + * @default Summary + * + * @param isChapterCommandEnabled + * @text Chapter Command Enabled + * @type boolean + * @desc Should the chapter command be included in the title scene's command window + * @default true + * + * @param chapterCommandText + * @text Chapter Command Text + * @type string + * @desc The text to use as the command's name on the title scene's command window + * @default Chapter Select + * + * @help +-------------------------------------------------------------------------------- + # TERMS OF USE + + MIT License - + + * Free for use in any RPG Maker MV game project, commercial or otherwise + + * Credit may go to FeniXEngine Contributors or FeniXEngine + + * Though not required, you may provide a link back to the original source code, + repository or website. + ------------------------------------------------------------------------------- + # INSTALLATION + + Place the plugin file directly in your game project's `/js/plugins/` + directory + + ------------------------------------------------------------------------------- + # INFORMATION + + This plugin provides the user the option of creating chapters for their game. + Each chapter will allow you to reset and setup switches and variables which + will be required for the player to play through the chapter again. + + ------------------------------------------------------------------------------- + # Parameters + The plugin's parameters provide many options for you to customize the way the + chapter is presented in the chapter selection scene. + + What is Required switches and variables? + + These are the switches and variables that you know are required to be setup + in a way that the chapter can correctly proceed. For example if you did a + full play-through of your game, then some switches and variables will be + incorrectly set. Starting a chapter without resetting the switch and variable + values would probably cause unexpected behavior and the chapter would be + unplayable. + + ------------------------------------------------------------------------------- + # Script Calls + + $gameSystem.chapters() + This script call return an array of all chapters + + $gameSystem.getChapterById(chapterId) + Returns the chapter object by its ID + + $gameSystem.getChapterDescription() + Returns the chapters description + + $gameSystem.isChapterLocked() + Returns true is the chapter is locked + + $gameSystem.lockChapter() + Locks the chapter + + $gameSystem.unlockChapter() + Unlocks the chapter + + ------------------------------------------------------------------------------- + # Plugin Commands + + The Plugin command keyword is: Chapter + + ## Open Chapter Select Scene + Chapter Open + + ## Lock a chapter + Chapter Lock chapterId + + ## Unlock a chapter + Chapter Unlock chapterId + +*/ + +/*~struct~Chapter: + * @param name + * @text Name + * @type string + * @desc The name of this chapter + * @default + * + * @param description + * @text Description + * @type note + * @desc A description or small summary of this chapter + * @default + * + * @param summary + * @text Summary + * @type note + * @desc A small summary of the events which occurred during this chapter + * @default + * + * @param thumbnail + * @text Thumbnail + * @type file + * @dir /img/ + * @desc A picture or screenshot to represent this chapter + * @default + * + * @param lockState + * @text Lock State + * @type boolean + * @on Unlock + * @off Lock + * @desc The default state of this chapter's lock. Enable to allow access on a new game + * @default false + * + * @param startMapId + * @text Start Map ID + * @type number + * @desc The map this chapter should load and set the player location to. + * @default + * + * @param playerX + * @text Player X + * @type number + * @desc The player's x axis starting position + * @default + * + * @param playerY + * @text Player Y + * @type number + * @desc The player's y axis starting position + * @default + * + * @param requiredVariables + * @text Required Variables + * @type struct[] + * @desc This will be a list of variables that you need to set up for the chapter to proceed correctly + * @default + * + * @param requiredSwitches + * @text Required Switches + * @type struct[] + * @desc This will be a list of switches that you need to set up for the chapter to proceed correctly + * @default + * + */ + +/*~struct~VariableChange: + * @param id + * @text Variable ID + * @type variable + * @desc The variable you want to set/change value of + * @default + * + * @param value + * @text Value + * @type string + * @desc The value you want to change the variable to + * @default + * + */ + +/*~struct~SwitchChange: + * @param id + * @text Switch ID + * @type switch + * @desc The switch you want to set/change value of + * @default + * + * @param value + * @text Value + * @type boolean + * @desc The value you want to change the switch to + * @default + * + */ + +/*~struct~ItemWindow: + * @param x + * @text X Position + * @type text + * @desc The position of the window on the x axis (Eval allowed) + * @default 0 + * + * @param y + * @text Y Position + * @type text + * @desc The position of the window on the y axis (Eval allowed) + * @default 0 + * + * @param width + * @text Width + * @type text + * @desc The width of the window (Eval allowed) + * @default 400 + * + * @param height + * @text Height + * @type text + * @desc The height of the window (Eval allowed) + * @default 400 + * + * @param itemHeight + * @text Item Height + * @type number + * @desc The height of each chapter rectangle in the window + * @default 145 + * + * @param maxItems + * @text Max Items + * @type number + * @desc The max amount of items to display in the window. + * @default 4 + * + * @param fontSize + * @text Font Size + * @type number + * @desc The default font size for the content in the window + * @default 18 + * + */ + +/*~struct~BasicWindow: + * @param x + * @text X Position + * @type text + * @desc The position of the window on the x axis (Eval allowed) + * @default 0 + * + * @param y + * @text Y Position + * @type text + * @desc The position of the window on the y axis (Eval allowed) + * @default 0 + * + * @param width + * @text Width + * @type text + * @desc The width of the window (Eval allowed) + * @default 400 + * + * @param height + * @text Height + * @type text + * @desc The height of the window (Eval allowed) + * @default 400 + * + */ From a3f4cd755b99b15fec91be8dca7bcc0723deeb73 Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Sep 2020 15:34:59 -0300 Subject: [PATCH 10/18] Remove redundant tool --- CleanJs.hx | 77 ------------------------------------------------------ 1 file changed, 77 deletions(-) delete mode 100644 CleanJs.hx diff --git a/CleanJs.hx b/CleanJs.hx deleted file mode 100644 index fd9baaf..0000000 --- a/CleanJs.hx +++ /dev/null @@ -1,77 +0,0 @@ -import sys.io.File; -import sys.FileSystem; -import haxe.macro.Expr; -import haxe.macro.Context; - -using StringTools; -using Lambda; - -class CleanJs { - static macro function pipe(exprs: Array): Expr { - var exprs = [for (expr in exprs) macro var _ = $expr]; - exprs.push(macro _); - return macro $b{exprs}; - } - - static macro function generateBuildDate(): ExprOf { - var date = Date.now(); - return macro $v{"Build Date: " + date.toString()} - } - - static macro function generatePluginGamePath(): ExprOf { - var gamePath = Context.definedValue("gamePath"); - return macro $v{gamePath + "/js/plugins/"} - } - - public static function main() { - final attributionStr = File.read("Attribution.txt").readAll().toString(); - final distDir = "dist"; - final madeWith = "Made with LunaTea -- Haxe"; - final allFiles = FileSystem.readDirectory(distDir); - allFiles.filter((file) -> !file.contains(".map")).iter((file) -> { - final fileNameStr = '//============================================================================= -// $file -//=============================================================================\n'; - - final madeWithStr = '//============================================================================= -// $madeWith -//=============================================================================\n'; - - var buildStr = generateBuildDate(); - final buildDate = '//============================================================================= -// $buildStr -//=============================================================================\n'; - final filePath = '$distDir/$file'; - final contents = File.read(filePath).readAll().toString(); - final cleanContents = contents.split("\n").map((lineContent) -> { - if (lineContent.contains("+=") - || (lineContent.contains("if(") && !lineContent.contains("_$LTGlobals_$")) - || lineContent.contains("#haxeui") - || lineContent.contains("haxe_ui") - || lineContent.contains("return")) { - return lineContent; - } else { - pipe( // Below Removes Semi Colons Per Lin - ~/(\*\/);/g.replace(lineContent, "$1"), ~/(==);/g.replace(_, "$1"), - ~/(\/\/.+\s*);/g.replace(_, - "$1"), // Below Removes New Line Characters from the output file - ~/(? Date: Mon, 14 Sep 2020 15:35:41 -0300 Subject: [PATCH 11/18] Change GameSystem chapter methods to their own class --- src/ChapterStore.hx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/ChapterStore.hx diff --git a/src/ChapterStore.hx b/src/ChapterStore.hx new file mode 100644 index 0000000..5cc5c29 --- /dev/null +++ b/src/ChapterStore.hx @@ -0,0 +1,36 @@ +package; + +import types.Chapter; +import Chapters.Params; + +class ChapterStore { + public var chapters(default, null): Array = []; + + public function new() { + chapters = Params.chapters; + } + + public function get_chapters() { + return chapters; + } + + public function getChapterById(chapterId: Int): Chapter { + return chapters[chapterId - 1]; + } + + public function getChapterDescription(chapterId: Int): String { + return chapters[chapterId - 1].description; + } + + public function isChapterLocked(chapterId: Int): Bool { + return chapters[chapterId - 1].lockState; + } + + public function lockChapter(chapterId: Int): Bool { + return chapters[chapterId - 1].lockState = true; + } + + public function unlockChapter(chapterId: Int): Bool { + return chapters[chapterId - 1].lockState = false; + } +} From d7280a1a23eb3e444f352af4dd250672f289c363 Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Sep 2020 15:37:06 -0300 Subject: [PATCH 12/18] Update main entry --- src/Chapters.hx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Chapters.hx b/src/Chapters.hx index 9a1cd75..6172f41 100644 --- a/src/Chapters.hx +++ b/src/Chapters.hx @@ -1,14 +1,28 @@ package; -import utils.Comment; +import rm.managers.StorageManager; +import overrides.DataManager; +import pixi.interaction.EventEmitter; +import windows.TitleCommand; +import rm.managers.PluginManager; +import scenes.SceneTitle; class Chapters { public static var Params: Dynamic; + public static var Emitter: EventEmitter; + public static var Store: ChapterStore; public static function main() { - Comment.pluginParams(" - @author inc0der | LunaTechsDev - @plugindesc Add a chapter selection system to your game . - "); + var rawParams = PluginManager.parameters('Luna_Chapters'); + Params = utils.Parse.parseParameters(rawParams); + Emitter = new EventEmitter(); + Store = new ChapterStore(); + + Emitter.on('game-saved', (savename: String) -> { + StorageManager.saveObject(savename, Store); + }); + DataManager.patch(); + SceneTitle.patch(); + TitleCommand.patch(); } } From 42e7781c2bd49b35408214ea00dba579d5e2e447 Mon Sep 17 00:00:00 2001 From: inc0der Date: Mon, 14 Sep 2020 16:27:32 -0300 Subject: [PATCH 13/18] Fix save bug caused by not calling function with original args --- src/overrides/DataManager.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overrides/DataManager.hx b/src/overrides/DataManager.hx index 6caed65..0de030b 100644 --- a/src/overrides/DataManager.hx +++ b/src/overrides/DataManager.hx @@ -16,7 +16,7 @@ class DataManager { Fn.setField(RmDataManager, 'saveGame', (savefileId) -> { var saveName = RmDataManager.makeSavename(savefileId); Chapters.Emitter.emit('game-saved', saveName); - oldSaveGame.call(Fn.self); + oldSaveGame.call(Fn.self, savefileId); }); } } From a45e08c26a7355c115d20d5c5812179e0474bf46 Mon Sep 17 00:00:00 2001 From: inc0der Date: Tue, 15 Sep 2020 10:25:56 -0300 Subject: [PATCH 14/18] Update LunaTea dependency --- haxe_libraries/LunaTea.hxml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haxe_libraries/LunaTea.hxml b/haxe_libraries/LunaTea.hxml index 4c51524..3f0a184 100644 --- a/haxe_libraries/LunaTea.hxml +++ b/haxe_libraries/LunaTea.hxml @@ -1,6 +1,6 @@ -# @install: lix --silent download "gh://github.com/LunaTechsDev/LunaTea#e715f4f6c1dd805236da2d12087ddce2c31ce900" into LunaTea/0.9.3/github/e715f4f6c1dd805236da2d12087ddce2c31ce900 +# @install: lix --silent download "gh://github.com/LunaTechsDev/LunaTea#e25fda16191479445ea86c9361d2fd43019ede09" into LunaTea/0.9.3/github/e25fda16191479445ea86c9361d2fd43019ede09 -lib hxnodejs -lib jsfps -lib pixijs --cp ${HAXE_LIBCACHE}/LunaTea/0.9.3/github/e715f4f6c1dd805236da2d12087ddce2c31ce900/src/ +-cp ${HAXE_LIBCACHE}/LunaTea/0.9.3/github/e25fda16191479445ea86c9361d2fd43019ede09/src/ -D LunaTea=0.9.3 \ No newline at end of file From 7636650df63a7d59eae0333a8d4065ffae780b1f Mon Sep 17 00:00:00 2001 From: inc0der Date: Tue, 15 Sep 2020 10:26:33 -0300 Subject: [PATCH 15/18] Update compile steps --- compile.hxml | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/compile.hxml b/compile.hxml index 527a4e8..e122b33 100644 --- a/compile.hxml +++ b/compile.hxml @@ -4,12 +4,6 @@ # JS Version -D js-es=6 -# Static Code Analysis For Removing Unnecessary Code --D analyzer-optimize -# -D js_source_map -# Haxe Source Map -# -D source-map-content - # Enable/Disable console.log -- tracing with the below line # --no-traces @@ -18,16 +12,27 @@ # -D js_classic -dce full +--macro macros.MacroTools.includeJsLib("./src/Parameters.js") + +# Static Code Analysis For Removing Unnecessary Code +# -D analyzer-optimize + +# Haxe Source Map +--debug +# --no-inline +# --no-opt + +-D keep_inline_positions + +-D source-map-content +-D js_source_map # RM Version for Conditional Compilation --D compileMV +# -D compileMV # Note you can call an hxml file inside an hxml file for build purposes. # For Compiling Separate JavaScript Files - --each --next --js dist/Luna_Chapters.js --main Chapters - ---cmd haxe -D gamePath=game/ --run CleanJs +-js game/js/plugins/Luna_Chapters.js +-main Chapters \ No newline at end of file From b02f83715003a99e850d2f8ca656a7a8b7bfed33 Mon Sep 17 00:00:00 2001 From: inc0der Date: Tue, 15 Sep 2020 10:27:09 -0300 Subject: [PATCH 16/18] Change all parameters with eval allowed to a note type --- src/Parameters.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Parameters.js b/src/Parameters.js index 6c6782d..27a874a 100644 --- a/src/Parameters.js +++ b/src/Parameters.js @@ -235,25 +235,25 @@ /*~struct~ItemWindow: * @param x * @text X Position - * @type text + * @type note * @desc The position of the window on the x axis (Eval allowed) * @default 0 * * @param y * @text Y Position - * @type text + * @type note * @desc The position of the window on the y axis (Eval allowed) * @default 0 * * @param width * @text Width - * @type text + * @type note * @desc The width of the window (Eval allowed) * @default 400 * * @param height * @text Height - * @type text + * @type note * @desc The height of the window (Eval allowed) * @default 400 * @@ -280,25 +280,25 @@ /*~struct~BasicWindow: * @param x * @text X Position - * @type text + * @type note * @desc The position of the window on the x axis (Eval allowed) * @default 0 * * @param y * @text Y Position - * @type text + * @type note * @desc The position of the window on the y axis (Eval allowed) * @default 0 * * @param width * @text Width - * @type text + * @type note * @desc The width of the window (Eval allowed) * @default 400 * * @param height * @text Height - * @type text + * @type note * @desc The height of the window (Eval allowed) * @default 400 * From 3960dd219aa5d56ad626c76fab4aa5437eccd8b0 Mon Sep 17 00:00:00 2001 From: inc0der Date: Tue, 15 Sep 2020 10:31:05 -0300 Subject: [PATCH 17/18] Add neccesary changes for MZ port --- src/scenes/Scene_Chapters.hx | 54 ++++++++++++++++++-------- src/windows/Window_ChapterList.hx | 24 ++++++------ src/windows/Window_ChapterSummary.hx | 15 ++++--- src/windows/Window_ChapterThumbnail.hx | 29 +++++++------- 4 files changed, 74 insertions(+), 48 deletions(-) diff --git a/src/scenes/Scene_Chapters.hx b/src/scenes/Scene_Chapters.hx index 84330f7..cdf19d1 100644 --- a/src/scenes/Scene_Chapters.hx +++ b/src/scenes/Scene_Chapters.hx @@ -1,13 +1,15 @@ package scenes; +import rm.core.Rectangle; import js.html.Console; import utils.Fn; import rm.core.Sprite; import types.Chapter; +import rm.Globals.GameSystem; import rm.Globals.GameSwitches; import rm.Globals.GameVariables; import rm.Globals.GamePlayer; -import rm.core.Graphics; +import rm.Globals.DataSystem; import rm.windows.Window_SavefileList; import rm.scenes.Scene_MenuBase; import rm.scenes.Scene_Map; @@ -19,9 +21,10 @@ import windows.Window_ChapterList; import windows.Window_ChapterSummary; import windows.Window_ChapterThumbnail; +@:keep() class Scene_Chapters extends Scene_MenuBase { - private var _scelectedChapter: Int = 0; - private var _loadSuccess: Bool = false; + private var _scelectedChapter: Int; + private var _loadSuccess: Bool; private var _saveFileList: Window_SavefileList; private var _thumbnailWindow: Window_ChapterThumbnail; private var _chapterSelectWindow: Window_ChapterList; @@ -31,6 +34,8 @@ class Scene_Chapters extends Scene_MenuBase { public function new() { super(); + _scelectedChapter = 0; + _loadSuccess = false; super.initialize(); } @@ -39,10 +44,10 @@ class Scene_Chapters extends Scene_MenuBase { createChapterBackground(); createWindowLayer(); createHelpWindow(); - createSaveFileList(); createChapterSelect(); createChapterThumbnail(); createChapterSummary(); + createSaveFileList(); } public override function start() { @@ -65,6 +70,14 @@ class Scene_Chapters extends Scene_MenuBase { } } + public override function isBottomHelpMode() { + return false; + }; + + public override function isBottomButtonMode() { + return true; + }; + public function createChapterBackground() { _chapterBackground = new Sprite(); addChild(_chapterBackground); @@ -73,9 +86,10 @@ class Scene_Chapters extends Scene_MenuBase { public function createChapterSelect() { var width = _tryEval(Params.chapterWindow.width); var height = _tryEval(Params.chapterWindow.height); - var y: Int = Math.round(_tryEval(Params.chapterWindow.y)); + var y = _tryEval(Params.chapterWindow.y); + var rect = new Rectangle(0, y, width, height); - _chapterSelectWindow = new Window_ChapterList(0, y, width, height); + _chapterSelectWindow = new Window_ChapterList(rect); _chapterSelectWindow.setHandler('ok', onChapterSelect); _chapterSelectWindow.setHandler('cancel', popScene); _chapterSelectWindow.close(); @@ -89,7 +103,9 @@ class Scene_Chapters extends Scene_MenuBase { var y = _tryEval(options.y); var x = _tryEval(options.x); - _thumbnailWindow = new Window_ChapterThumbnail(x, y, width, height); + var rect = new Rectangle(x, y, width, height); + + _thumbnailWindow = new Window_ChapterThumbnail(rect); _thumbnailWindow.close(); addWindow(_thumbnailWindow); } @@ -101,20 +117,25 @@ class Scene_Chapters extends Scene_MenuBase { var y = _tryEval(options.y); var x = _tryEval(options.x); - _summaryWindow = new Window_ChapterSummary(x, y, width, height); + var rect = new Rectangle(x, y, width, height); + + _summaryWindow = new Window_ChapterSummary(rect); _summaryWindow.close(); addWindow(_summaryWindow); } public function createSaveFileList() { - var width = Math.round(Graphics.width); - var height = Math.round(Graphics.height - _helpWindow.height); - var y = Math.round(_helpWindow.height); + var uiAreaWidth = DataSystem.advanced.uiAreaWidth; + var uiAreaHeight = DataSystem.advanced.uiAreaHeight; + var height = uiAreaHeight - _helpWindow.height; + // var y = mainAreaTop(); + var rect = new Rectangle(0, 0, uiAreaWidth, height); - _saveFileList = new Window_SavefileList(0, y, width, height); + _saveFileList = new Window_SavefileList(rect); _saveFileList.setHandler('ok', onSaveFileLoad); _saveFileList.setHandler('cancel', popScene); - _saveFileList.select(0); + _saveFileList.setMode('load', GameSystem.isAutosaveEnabled()); + _saveFileList.selectSavefile(DataManager.latestSavefileId()); _saveFileList.setTopRow(0 - 2); _helpWindow.setText('Load a save file'); addWindow(_saveFileList); @@ -142,17 +163,18 @@ class Scene_Chapters extends Scene_MenuBase { public function onSaveFileLoad() { var savefileId = _saveFileList.index(); - if (DataManager.loadGame(savefileId)) { + + DataManager.loadGame(savefileId).then(d -> { SoundManager.playLoad(); _loadSuccess = true; _saveFileList.deactivate(); _saveFileList.close(); _helpWindow.setText(Params.helpWindowTerm); _chapterSelectWindow.refresh(); - } else { + }).catchError(err -> { _saveFileList.activate(); SoundManager.playBuzzer(); - } + }); } public function onChapterSelect() { diff --git a/src/windows/Window_ChapterList.hx b/src/windows/Window_ChapterList.hx index f05421b..e46d558 100644 --- a/src/windows/Window_ChapterList.hx +++ b/src/windows/Window_ChapterList.hx @@ -11,25 +11,25 @@ import Chapters.Params; * I think its best to use the new StoragManager in MZ to store and load */ class Window_ChapterList extends Window_Selectable { - private var _page: Int = 0; - private var _data: Array = []; - private var _thumbnails: Array = []; + private var _page: Int; + private var _data: Array; + private var _thumbnails: Array; - public function new(x: Int, y: Int, width: Int, height: Int) { - super(x, y, width, height); - // contents.fontSize = Params.chapterWindow.fontSize + public function new(rect: Rectangle) { + super(rect); + contents.fontSize = Params.chapterWindow.fontSize; refresh(); } public override function refresh() { + makeItemList(); super.refresh(); contents.clear(); - makeItemList(); drawAllItems(); } public override function itemHeight(): Float { - return 10; // @todo replace with Params.chapterWindow.itemHeight + return Params.chapterWindow.itemHeight; } public function item(): Dynamic { @@ -41,11 +41,11 @@ class Window_ChapterList extends Window_Selectable { } public override function isOkEnabled(): Bool { - return item().lockState; + return item() && item().lockState; } public function makeItemList() { - // this._data = GameSystem.chapters; + this._data = Chapters.Store.chapters; } public override function maxItems() { @@ -62,13 +62,13 @@ class Window_ChapterList extends Window_Selectable { var chapter: Chapter = this._data[index]; if (chapter != null) { var rect: Rectangle = this.itemRect(index); - rect.width -= this.textPadding(); + rect.width -= 8; changePaintOpacity(this.isOkEnabled()); makeFontBigger(); drawText(chapter.name, Math.round(rect.x), Math.round(rect.y), Math.round(rect.width), 'left'); drawTextRect(chapter.name, rect); makeFontSmaller(); - drawTextEx(chapter.description, Math.round(rect.x), Math.round(rect.y + 50)); + drawTextEx(chapter.description, Math.round(rect.x), Math.round(rect.y + 50), contents.width); } } } diff --git a/src/windows/Window_ChapterSummary.hx b/src/windows/Window_ChapterSummary.hx index 44866eb..d341d7c 100644 --- a/src/windows/Window_ChapterSummary.hx +++ b/src/windows/Window_ChapterSummary.hx @@ -1,15 +1,17 @@ package windows; +import rm.Globals.GameSystem; +import rm.core.Rectangle; import rm.windows.Window_Base; import types.Chapter; import Chapters.Params; class Window_ChapterSummary extends Window_Base { - private var _chapter: Chapter = null; + private var _chapter: Chapter; - public function new(x: Int, y: Int, width: Int, height: Int) { - super(x, y, width, height); - super.initialize(x, y, width, height); + public function new(rect: Rectangle) { + super(rect); + super.initialize(rect); } public function setChapter(chapter) { @@ -36,15 +38,16 @@ class Window_ChapterSummary extends Window_Base { } public function drawTitle() { + var padding = GameSystem.windowPadding(); var width: Int = Std.int(width); - var textWidth = Std.int(width - standardPadding()); + var textWidth = Std.int(width - padding); this.drawText(Params.summaryTitle, 0, 0, textWidth, 'center'); this.contents.fillRect(0, 35, width, 5, Params.horizontalLineColor); } public function drawChapterSummary() { - drawTextEx(_chapter.summary, 0, 45); + drawTextEx(_chapter.summary, 0, 45, contents.width); this.resetFontSettings(); } } diff --git a/src/windows/Window_ChapterThumbnail.hx b/src/windows/Window_ChapterThumbnail.hx index c13f6b6..e7266e4 100644 --- a/src/windows/Window_ChapterThumbnail.hx +++ b/src/windows/Window_ChapterThumbnail.hx @@ -1,28 +1,31 @@ package windows; +import rm.core.Rectangle; import rm.core.Sprite; import rm.windows.Window_Base; -// import rm.managers.ImageManager; +import rm.managers.ImageManager; +import rm.Globals.GameSystem; import types.Chapter; /** * @TODO - Load image data using the new MZ codebase */ class Window_ChapterThumbnail extends Window_Base { - private var _chapter: Chapter = null; - private var _thumbnail: Sprite = null; + private var _chapter: Chapter; + private var _thumbnail: Sprite; - public function new(x: Int, y: Int, width: Int, height: Int) { - super(x, y, width, height); - super.initialize(x, y, width, height); + public function new(rect: Rectangle) { + super(rect); + super.initialize(rect); _chapter = null; createThumbnail(); } public function createThumbnail() { + var padding = GameSystem.windowPadding(); _thumbnail = new Sprite(); - _thumbnail.x = 0 + standardPadding(); - _thumbnail.y = 0 + standardPadding(); + _thumbnail.x = 0 + padding; + _thumbnail.y = 0 + padding; _thumbnail.width = width / 2; _thumbnail.height = height / 2; addChild(_thumbnail); @@ -45,13 +48,11 @@ class Window_ChapterThumbnail extends Window_Base { public function refresh() { if (_chapter != null && _chapter.thumbnail != null) { - /** - * @TODO Use loadBitmapFromUrl when LunaTea is ready - * - * _thumbnail.bitmap = ImageManager.loadBitmapFromUrl(_chapter.thumbnail); - */ + var path = 'img/${_chapter.thumbnail}.png'; + _thumbnail.bitmap = ImageManager.loadBitmapFromUrl(path); _thumbnail.bitmap.addLoadListener((bitmap) -> { - _thumbnail.width = (width - standardPadding() * 2); + var padding = GameSystem.windowPadding(); + _thumbnail.width = (width - padding * 2); }); } } From 21a53f30e932965d2dfc8a78d0a95f659e4be312 Mon Sep 17 00:00:00 2001 From: inc0der Date: Fri, 29 Sep 2023 13:02:48 -0300 Subject: [PATCH 18/18] long haitus commit --- .vscode/launch.json | 6 ++ Macros.hx | 102 +++++++++++++++++++++++++++ README.md | 8 ++- haxe_libraries/LunaTea.hxml | 6 +- src/Chapters.hx | 22 ++++++ src/Parameters.js | 25 +++++++ src/types/LockCommand.hx | 5 ++ src/windows/Window_ChapterList.hx | 7 +- src/windows/Window_ChapterSummary.hx | 2 +- 9 files changed, 176 insertions(+), 7 deletions(-) create mode 100644 Macros.hx create mode 100644 src/types/LockCommand.hx diff --git a/.vscode/launch.json b/.vscode/launch.json index b816f04..19ae5bf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,6 +16,12 @@ "webRoot": "${workspaceRoot}/game/", "port": 9222, // "sourceMaps": true + }, + { + "name": "Haxe Interpreter", + "type": "haxe-eval", + "request": "launch", + "args": ["compile.hxml", "--interp"] } ] } \ No newline at end of file diff --git a/Macros.hx b/Macros.hx new file mode 100644 index 0000000..2fa703d --- /dev/null +++ b/Macros.hx @@ -0,0 +1,102 @@ +import haxe.macro.Expr; +import haxe.macro.Context; +import haxe.macro.TypeTools; +import haxe.macro.Type.ClassType; + +// import haxe.macro; +using Lambda; + +typedef FieldData = { + name: String, + fields: Array, + types: Array +} + +typedef ClassData = { + externs: ClassType, + local: FieldData +} + +class Macros { + public static var rmClasses: Map = new Map(); + + private static function allInheritedFields(cType: ClassType): Array { + var fields: Array = cast cType.fields.get(); + var superClass = cType.superClass; + if (superClass != null) { + return allInheritedFields(superClass.t.get()).concat(fields); + } else { + return fields; + } + return fields; + } + + private static function isInherhitedBy(cType: ClassType, className: String): Bool { + var superClass = cType.superClass; + + if (cType.name == className) { + return true; + } + + if (superClass != null) { + return isInherhitedBy(superClass.t.get(), className); + } + return false; + } + + #if macro + @:nullSafety + private static function _getClassFromConstExpr(e: Expr): ClassType { + return switch (e.expr) { + case EConst(CIdent(identifier)): + return TypeTools.getClass(Context.getType(identifier)); + case _: + return null; + } + } + #end + macro public static function rmClass(): Array { + var localFields = Context.getBuildFields(); + var localClass = Context.getLocalClass().get(); + var localSuperClass = localClass.superClass.t.get(); + var localImports = Context.getLocalImports(); + + for (index => key in rmClasses) { + if (key.local.name != localClass.name && isInherhitedBy(localSuperClass, key.externs.name)) { + for (field in key.local.fields) { + var allSuperFields = allInheritedFields(localSuperClass); + if (!localFields.exists(f -> f.name == field.name) && !allSuperFields.exists(f -> f.name == field.name)) { + var newType = TAnonymous([ + { + name: field.name, + pos: Context.currentPos(), + kind: FVar(macro : String) + } + ]); + var newField: Field = { + name: '__${key.local.name}_${field.name}', + pos: Context.currentPos(), + kind: FVar(newType) + }; + localFields.push(newField); + } + } + } + + for (localImport in localImports) { + if (localImport.path.exists(i -> i.name == key.local.name)) { + trace('found import to assign fields for'); + } + } + } + + if (!rmClasses.exists(localSuperClass.name)) { + rmClasses.set(localSuperClass.name, { + externs: localSuperClass, + local: { name: localClass.name, fields: localFields, types: Context.getModule(localClass.module) } + }); + } + + return localFields; + } +} diff --git a/README.md b/README.md index ec76a69..286e9a9 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,10 @@ This plugin provides the user the option of creating chapters for their game. Ea ## Reporting Bugs -If you find any bugs or compatibility issues, feel free to fill out our [bug report form](https://lunatechs.dev/report-bug/) \ No newline at end of file +If you find any bugs or compatibility issues, feel free to fill out our [bug report form](https://lunatechs.dev/report-bug/) + +TODO + +Chapters always show as disabled +Unlocking chapters don't appear to work. +Add a window padding parameter \ No newline at end of file diff --git a/haxe_libraries/LunaTea.hxml b/haxe_libraries/LunaTea.hxml index 3f0a184..9adee6f 100644 --- a/haxe_libraries/LunaTea.hxml +++ b/haxe_libraries/LunaTea.hxml @@ -1,6 +1,6 @@ -# @install: lix --silent download "gh://github.com/LunaTechsDev/LunaTea#e25fda16191479445ea86c9361d2fd43019ede09" into LunaTea/0.9.3/github/e25fda16191479445ea86c9361d2fd43019ede09 +# @install: lix --silent download "gh://github.com/LunaTechsDev/LunaTea#ba5ef9281256c7de17d660a171433f8a38079ab7" into LunaTea/1.1.1/github/ba5ef9281256c7de17d660a171433f8a38079ab7 -lib hxnodejs -lib jsfps -lib pixijs --cp ${HAXE_LIBCACHE}/LunaTea/0.9.3/github/e25fda16191479445ea86c9361d2fd43019ede09/src/ --D LunaTea=0.9.3 \ No newline at end of file +-cp ${HAXE_LIBCACHE}/LunaTea/1.1.1/github/ba5ef9281256c7de17d660a171433f8a38079ab7/src/ +-D LunaTea=1.1.1 \ No newline at end of file diff --git a/src/Chapters.hx b/src/Chapters.hx index 6172f41..f772a54 100644 --- a/src/Chapters.hx +++ b/src/Chapters.hx @@ -1,5 +1,8 @@ package; +import types.LockCommand; +import scenes.Scene_Chapters; +import rm.managers.SceneManager; import rm.managers.StorageManager; import overrides.DataManager; import pixi.interaction.EventEmitter; @@ -21,8 +24,27 @@ class Chapters { Emitter.on('game-saved', (savename: String) -> { StorageManager.saveObject(savename, Store); }); + registerCommands(); DataManager.patch(); SceneTitle.patch(); TitleCommand.patch(); } + + public static function registerCommands() { + var pluginName: String = 'Luna_Chapters'; + + PluginManager.registerCommand(pluginName, 'lock', (args) -> { + var userInput: LockCommand = utils.Parse.parseParameters(args); + Chapters.Store.lockChapter(userInput.chapterId); + }); + + PluginManager.registerCommand(pluginName, 'unlock', (args) -> { + var userInput: LockCommand = utils.Parse.parseParameters(args); + Chapters.Store.unlockChapter(userInput.chapterId); + }); + + PluginManager.registerCommand(pluginName, 'openScene', (_) -> { + SceneManager.push(Scene_Chapters); + }); + } } diff --git a/src/Parameters.js b/src/Parameters.js index 27a874a..d5c2b56 100644 --- a/src/Parameters.js +++ b/src/Parameters.js @@ -2,6 +2,7 @@ * @plugindesc A chapter selection system for your games * * + * @target MZ MV * @author LunaTechs | inc0der * @url https://lunatechs.dev/plugins/luna-chapters/ * @@ -60,6 +61,30 @@ * @desc The text to use as the command's name on the title scene's command window * @default Chapter Select * + * -- Plugin Commands -- + * + * @command openScene + * @text Open Scene + * @desc Opens the chapter selection scene. + * + * @command lock + * @text Lock + * @desc Locks a chapter from being accessed. + * @arg chapterId + * @text Chapter ID + * @desc The chapter by its ID you would like to lock. + * @type number + * @default true + * + * @command unlock + * @text Unlock + * @desc Unlocks a chapter so it can be accessed. + * @arg chapterId + * @text Chapter ID + * @desc The chapter by its ID you would like to unlock. + * @type number + * @default true + * * @help -------------------------------------------------------------------------------- # TERMS OF USE diff --git a/src/types/LockCommand.hx b/src/types/LockCommand.hx new file mode 100644 index 0000000..575c85e --- /dev/null +++ b/src/types/LockCommand.hx @@ -0,0 +1,5 @@ +package types; + +typedef LockCommand = { + chapterId: Int +} \ No newline at end of file diff --git a/src/windows/Window_ChapterList.hx b/src/windows/Window_ChapterList.hx index e46d558..fe86497 100644 --- a/src/windows/Window_ChapterList.hx +++ b/src/windows/Window_ChapterList.hx @@ -62,13 +62,16 @@ class Window_ChapterList extends Window_Selectable { var chapter: Chapter = this._data[index]; if (chapter != null) { var rect: Rectangle = this.itemRect(index); - rect.width -= 8; + // rect.width -= 8; + rect.y += 5; + rect.x += 5; changePaintOpacity(this.isOkEnabled()); makeFontBigger(); drawText(chapter.name, Math.round(rect.x), Math.round(rect.y), Math.round(rect.width), 'left'); drawTextRect(chapter.name, rect); makeFontSmaller(); - drawTextEx(chapter.description, Math.round(rect.x), Math.round(rect.y + 50), contents.width); + var width = drawTextEx(chapter.description, Math.round(rect.x), Math.round(rect.y + 50), rect.width); + trace(width); } } } diff --git a/src/windows/Window_ChapterSummary.hx b/src/windows/Window_ChapterSummary.hx index d341d7c..3621764 100644 --- a/src/windows/Window_ChapterSummary.hx +++ b/src/windows/Window_ChapterSummary.hx @@ -47,7 +47,7 @@ class Window_ChapterSummary extends Window_Base { } public function drawChapterSummary() { - drawTextEx(_chapter.summary, 0, 45, contents.width); + drawTextEx(_chapter.summary, 0, 45, contents.width - 20); this.resetFontSettings(); } }