Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
// 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
},
{
"name": "Haxe Interpreter",
"type": "haxe-eval",
"request": "launch",
"args": ["compile.hxml", "--interp"]
}
]
}
12 changes: 12 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"group": "build",
"label": "lix: compile.hxml",
"command": "lix",
"args": ["compile.hxml"]
}
]
}
77 changes: 0 additions & 77 deletions CleanJs.hx

This file was deleted.

102 changes: 102 additions & 0 deletions Macros.hx
Original file line number Diff line number Diff line change
@@ -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<Field>,
types: Array<haxe.macro.Type>
}

typedef ClassData = {
externs: ClassType,
local: FieldData
}

class Macros {
public static var rmClasses: Map<String, ClassData> = new Map();

private static function allInheritedFields(cType: ClassType): Array<Field> {
var fields: Array<Field> = 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<Field> {
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;
}
}
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
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
29 changes: 17 additions & 12 deletions compile.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
6 changes: 3 additions & 3 deletions haxe_libraries/LunaTea.hxml
Original file line number Diff line number Diff line change
@@ -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#ba5ef9281256c7de17d660a171433f8a38079ab7" into LunaTea/1.1.1/github/ba5ef9281256c7de17d660a171433f8a38079ab7
-lib hxnodejs
-lib jsfps
-lib pixijs
-cp ${HAXE_LIBCACHE}/LunaTea/0.7.9/github/15389955e5769766b8ab65c273168102a8c521e0/src/
-D LunaTea=0.7.9
-cp ${HAXE_LIBCACHE}/LunaTea/1.1.1/github/ba5ef9281256c7de17d660a171433f8a38079ab7/src/
-D LunaTea=1.1.1
36 changes: 36 additions & 0 deletions src/ChapterStore.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package;

import types.Chapter;
import Chapters.Params;

class ChapterStore {
public var chapters(default, null): Array<Chapter> = [];

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;
}
}
46 changes: 41 additions & 5 deletions src/Chapters.hx
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
package;

import utils.Comment;
import types.LockCommand;
import scenes.Scene_Chapters;
import rm.managers.SceneManager;
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 <Luna_Chapters>.
");
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);
});
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);
});
}
}
Loading