some hscript stuff!!

This commit is contained in:
Yoshman29
2022-11-04 19:55:29 +01:00
parent ccf0c833b2
commit ea8e2ba35d
6 changed files with 33 additions and 12 deletions
+1
View File
@@ -1,3 +1,4 @@
function create() {
importScript("data/scripts/pixel");
pixelNotesForBF = false;
}
+8 -11
View File
@@ -1,17 +1,12 @@
import funkin.system.Paths;
public var pixelNotesForBF = true;
public var pixelNotesForDad = true;
var daPixelZoom = 6;
// function onStrumCreation(event) {
// event.cancel();
// var strum = event.strum;
// strum.loadGraphic(Paths.image('stages/school/arrows-pixels'), true, 17, 17);
// strum.animation.add("scroll", [6 + strum.ID]);
// }
var song = PlayState.SONG.song.toLowerCase();
function onNoteCreation(event) {
if (song == "test" && event.note.mustPress) return;
if (event.note.mustPress && !pixelNotesForBF) return;
if (!event.note.mustPress && !pixelNotesForDad) return;
event.cancel();
var note = event.note;
@@ -27,7 +22,9 @@ function onNoteCreation(event) {
note.updateHitbox();
}
function onStrumCreation(event) {
if (song == "test" && event.player == 1) return;
if (event.player == 1 && !pixelNotesForBF) return;
if (event.player == 0 && !pixelNotesForDad) return;
event.cancel();
var strum = event.strum;
+1 -1
View File
@@ -1 +1 @@
1102
1104
+6
View File
@@ -17,6 +17,8 @@ class HScript extends Script {
var parser = new hscript.Parser();
parser.allowJSON = parser.allowMetadata = parser.allowTypes = true;
interp.errorHandler = _errorHandler;
interp.staticVariables = Script.staticVariables;
interp.variables.set("trace", this.trace);
try {
expr = parser.parseString(code, fileName);
@@ -79,4 +81,8 @@ class HScript extends Script {
Logs.logText(Std.string(v))
], TRACE);
}
public override function setPublicMap(map:Map<String, Dynamic>) {
this.interp.publicVariables = map;
}
}
+15
View File
@@ -9,6 +9,13 @@ import openfl.utils.Assets;
* Class used for scripting.
*/
class Script extends FlxBasic implements IFlxDestroyable {
/**
* Use "static var thing = true;" in hscript to use those!!
* are reset every mod switch so once youre done with them make sure to make them null!!
*/
public static var staticVariables:Map<String, Dynamic> = [];
public static function getDefaultVariables():Map<String, Dynamic> {
return [
// Haxe related stuff
@@ -128,6 +135,14 @@ class Script extends FlxBasic implements IFlxDestroyable {
curScript = oldScript;
}
/**
* HSCRIPT ONLY FOR NOW
* Sets the "public" variables map for ScriptPack
*/
public function setPublicMap(map:Map<String, Dynamic>) {
}
/**
* Hot-reloads the script, if possible
*/
+2
View File
@@ -6,6 +6,7 @@ import funkin.scripting.events.CancellableEvent;
class ScriptPack extends Script {
public var scripts:Array<Script> = [];
public var additionalDefaultVariables:Map<String, Dynamic> = [];
public var publicVariables:Map<String, Dynamic> = [];
public var parent:Dynamic = null;
public override function load() {
@@ -94,6 +95,7 @@ class ScriptPack extends Script {
private function __configureNewScript(script:Script) {
if (parent != null) script.setParent(parent);
script.setPublicMap(publicVariables);
for(k=>e in additionalDefaultVariables) script.set(k, e);
}
}