Skip to content

Commit 86e60e5

Browse files
committed
LegacyLua.
1 parent 6c47240 commit 86e60e5

File tree

9 files changed

+115
-19
lines changed

9 files changed

+115
-19
lines changed

source/backend/ClientPrefs.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ import states.TitleState;
115115
'loopPlayMult' => 1.05,
116116
'bothMode' => false,
117117
'maniaMode' => false,
118+
'legacyMode' => false
118119
];
119120

120121
// public var inputSystem:String = 'Native';

source/backend/CoolUtil.hx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ class CoolUtil
191191
}
192192
}
193193

194+
public static function precacheSound(sound:String, ?library:String = null):Void {
195+
Paths.sound(sound);
196+
}
197+
198+
public static function precacheMusic(sound:String, ?library:String = null):Void {
199+
Paths.music(sound);
200+
}
201+
194202
public static function updateTheEngine():Void
195203
{
196204
// Get the directory of the executable

source/import.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ import flixel.group.FlxGroup.FlxTypedGroup;
7575
import flixel.addons.transition.FlxTransitionableState;
7676

7777
using StringTools;
78+
using yutautil.CollectionUtils;
79+
using yutautil.MetaData;
7880
#end

source/options/GameplayChangersSubstate.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class GameplayChangersSubstate extends MusicBeatSubstate
9191
option.displayFormat = '%vX';
9292
option.decimals = 2;
9393
optionsArray.push(option);
94+
95+
optionsArray.push(new GameplayOption('Legacy Psych Mode', 'legacyMode', BOOL, false));
9496
}
9597

9698
public function getOptionByName(name:String)

source/psychlua/FunkinLua.hx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ class FunkinLua {
227227
});*/
228228

229229
// mod manager
230+
231+
232+
Lua_helper.add_callback(lua, "runInLegacyMode", function() {
233+
this.closed = true;
234+
PlayState.instance.luaArray.remove(this);
235+
new LegacyFunkinLua(scriptName);
236+
trace('A script has been converted to Legacy mode: ' + scriptName);
237+
});
238+
239+
230240
Lua_helper.add_callback(lua, "newPlayField", function()
231241
{
232242
PlayState.instance.newPlayfield();

source/psychlua/LegacyFunkinLua.hx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import sys.io.File;
4545

4646
import Type.ValueType;
4747
import backend.Controls;
48-
import backend.cutscenes.DialogueBoxPsych;
48+
import cutscenes.DialogueBoxPsych;
4949
import states.PlayState;
5050
import objects.Character;
5151

@@ -61,6 +61,12 @@ import backend.Discord;
6161

6262
using StringTools;
6363

64+
import objects.StrumNote;
65+
import objects.Note;
66+
import backend.WeekData;
67+
import backend.Song;
68+
import backend.Highscore;
69+
6470
class LegacyFunkinLua {
6571
public static var Function_Stop:Dynamic = 1;
6672
public static var Function_Continue:Dynamic = 0;
@@ -106,6 +112,7 @@ class LegacyFunkinLua {
106112
return;
107113
}
108114
scriptName = script;
115+
states.PlayState.instance.legacyLuaArray.push(this);
109116
initHaxeModule();
110117

111118
trace('lua file loaded succesfully:' + script);
@@ -256,7 +263,7 @@ class LegacyFunkinLua {
256263

257264
Lua_helper.add_callback(lua, "runInNewMode", function(mode:String, song:String, week:Int, difficulty:Int, stage:Int, storyMode:Bool = false) {
258265
this.closed = true;
259-
PlayState.instance.luaArray.remove(this);
266+
PlayState.instance.legacyLuaArray.remove(this);
260267
new FunkinLua(this.scriptName);
261268
trace('A script has been reloaded in New FunkinLua.');
262269
});
@@ -490,6 +497,8 @@ class LegacyFunkinLua {
490497
var runningScripts:Array<String> = [];
491498
for (idx in 0...PlayState.instance.luaArray.length)
492499
runningScripts.push(PlayState.instance.luaArray[idx].getScriptName());
500+
for (idx in 0...PlayState.instance.legacyLuaArray.length)
501+
runningScripts.push(PlayState.instance.legacyLuaArray[idx].getScriptName());
493502

494503

495504
return runningScripts;
@@ -839,7 +848,7 @@ class LegacyFunkinLua {
839848
}
840849
}
841850
}
842-
PlayState.instance.luaArray.push(new FunkinLua(cervix));
851+
PlayState.instance.legacyLuaArray.push(new LegacyFunkinLua(cervix));
843852
return;
844853
}
845854
luaTrace("addLuaScript: Script doesn't exist!", false, false, FlxColor.RED);
@@ -1759,7 +1768,7 @@ class LegacyFunkinLua {
17591768
{
17601769
leSprite.loadGraphic(Paths.image(image));
17611770
}
1762-
leSprite.antialiasing = ClientPrefs.data.globalAntialiasing;
1771+
leSprite.antialiasing = ClientPrefs.data.antialiasing;
17631772
PlayState.instance.modchartSprites.set(tag, leSprite);
17641773
leSprite.active = true;
17651774
});
@@ -1769,7 +1778,7 @@ class LegacyFunkinLua {
17691778
var leSprite:ModchartSprite = new ModchartSprite(x, y);
17701779

17711780
loadFrames(leSprite, image, spriteType);
1772-
leSprite.antialiasing = ClientPrefs.data.globalAntialiasing;
1781+
leSprite.antialiasing = ClientPrefs.data.antialiasing;
17731782
PlayState.instance.modchartSprites.set(tag, leSprite);
17741783
});
17751784

source/psychlua/LuaUtils.hx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ class LuaUtils
3939
} : null;
4040
}
4141

42+
// Legacy shit.
43+
44+
inline public static function getTextObject(name:String):FlxText
45+
{
46+
return #if LUA_ALLOWED PlayState.instance.modchartTexts.exists(name) ? PlayState.instance.modchartTexts.get(name) : #end Reflect.getProperty(PlayState.instance, name);
47+
}
48+
49+
50+
public static function resetTextTag(tag:String) {
51+
#if LUA_ALLOWED
52+
if(!PlayState.instance.modchartTexts.exists(tag)) {
53+
return;
54+
}
55+
56+
var target:FlxText = PlayState.instance.modchartTexts.get(tag);
57+
target.kill();
58+
PlayState.instance.remove(target, true);
59+
target.destroy();
60+
PlayState.instance.modchartTexts.remove(tag);
61+
#end
62+
}
63+
64+
4265
public static function setVarInArray(instance:Dynamic, variable:String, value:Dynamic, allowMaps:Bool = false):Any
4366
{
4467
var splitProps:Array<String> = variable.split('[');

source/states/PlayState.hx

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@ class PlayState extends MusicBeatState
143143
public var hscriptArray:Array<HScript> = [];
144144
#end
145145

146+
147+
#if LUA_ALLOWED
148+
public var modchartTweens:Map<String, FlxTween> = new Map<String, FlxTween>();
149+
public var modchartSprites:Map<String, ModchartSprite> = new Map<String, ModchartSprite>();
150+
public var modchartTimers:Map<String, FlxTimer> = new Map<String, FlxTimer>();
151+
public var modchartSounds:Map<String, FlxSound> = new Map<String, FlxSound>();
152+
public var modchartTexts:Map<String, FlxText> = new Map<String, FlxText>();
153+
public var modchartSaves:Map<String, FlxSave> = new Map<String, FlxSave>();
154+
#end
155+
146156
public var BF_X:Float = 770;
147157
public var BF_Y:Float = 100;
148158
public var BF2_X:Float = 770;
@@ -326,7 +336,8 @@ class PlayState extends MusicBeatState
326336

327337
// Lua shit
328338
public static var instance:PlayState;
329-
#if LUA_ALLOWED public var luaArray:Array<FunkinLua> = []; #end
339+
#if LUA_ALLOWED public var luaArray:Array<FunkinLua> = [];
340+
public var legacyLuaArray:Array<LegacyFunkinLua> = []; #end
330341

331342
#if (LUA_ALLOWED || HSCRIPT_ALLOWED)
332343
private var luaDebugGroup:FlxTypedGroup<psychlua.DebugLuaText>;
@@ -771,15 +782,16 @@ class PlayState extends MusicBeatState
771782
{
772783
#if LUA_ALLOWED
773784
if(file.toLowerCase().endsWith('.lua'))
774-
new FunkinLua(folder + file);
785+
(ClientPrefs.getGameplaySetting('legacyMode', false) ? new LegacyFunkinLua(folder + file) : new FunkinLua(folder + file));
775786
#end
776787

777788
#if HSCRIPT_ALLOWED
778789
if(file.toLowerCase().endsWith('.hx'))
779790
initHScript(folder + file);
780791
#end
781-
}
792+
782793
#end
794+
}
783795

784796
var camPos:FlxPoint = FlxPoint.get(girlfriendCameraOffset[0], girlfriendCameraOffset[1]);
785797
if(gf != null)
@@ -1127,7 +1139,7 @@ class PlayState extends MusicBeatState
11271139
{
11281140
#if LUA_ALLOWED
11291141
if(file.toLowerCase().endsWith('.lua'))
1130-
new FunkinLua(folder + file);
1142+
(ClientPrefs.getGameplaySetting('legacyMode', false) ? new LegacyFunkinLua(folder + file) : new FunkinLua(folder + file));
11311143
#end
11321144

11331145
#if HSCRIPT_ALLOWED
@@ -1342,7 +1354,9 @@ class PlayState extends MusicBeatState
13421354
break;
13431355
}
13441356
}
1345-
if(doPush) new FunkinLua(luaFile);
1357+
if(doPush)
1358+
(ClientPrefs.getGameplaySetting('legacyMode', false) ? new LegacyFunkinLua(luaFile) : new FunkinLua(luaFile));
1359+
13461360
}
13471361
#end
13481362

@@ -1375,8 +1389,18 @@ class PlayState extends MusicBeatState
13751389
#end
13761390
}
13771391

1378-
public function getLuaObject(tag:String):Dynamic
1379-
return variables.get(tag);
1392+
public function getLuaObject(tag:String, text:Bool = true):FlxSprite
1393+
{
1394+
#if LUA_ALLOWED
1395+
if (modchartSprites.exists(tag))
1396+
return modchartSprites.get(tag);
1397+
if (text && modchartTexts.exists(tag))
1398+
return modchartTexts.get(tag);
1399+
if (variables.exists(tag))
1400+
return variables.get(tag);
1401+
#end
1402+
return null;
1403+
}
13801404

13811405
function startCharacterPos(char:Character, ?gfCheck:Bool = false) {
13821406
if(gfCheck && char.curCharacter.startsWith('gf')) { //IF DAD IS GIRLFRIEND, HE GOES TO HER POSITION
@@ -3950,7 +3974,14 @@ class PlayState extends MusicBeatState
39503974
}
39513975
}
39523976

3953-
public function triggerEvent(eventName:String, value1:String, value2:String, strumTime:Float) {
3977+
public function getControl(key:String)
3978+
{
3979+
var pressed:Bool = Reflect.getProperty(controls, key);
3980+
// trace('Control result: ' + pressed);
3981+
return pressed;
3982+
}
3983+
3984+
public function triggerEvent(eventName:String, value1:String, value2:String, ?strumTime:Float) {
39543985
var flValue1:Null<Float> = Std.parseFloat(value1);
39553986
var flValue2:Null<Float> = Std.parseFloat(value2);
39563987
if(Math.isNaN(flValue1)) flValue1 = null;
@@ -5797,7 +5828,13 @@ class PlayState extends MusicBeatState
57975828
lua.call('onDestroy', []);
57985829
lua.stop();
57995830
}
5831+
for (lua in legacyLuaArray)
5832+
{
5833+
lua.call('onDestroy', []);
5834+
lua.stop();
5835+
}
58005836
luaArray = null;
5837+
legacyLuaArray = null;
58015838
FunkinLua.customFunctions.clear();
58025839
#end
58035840

@@ -6020,7 +6057,7 @@ class PlayState extends MusicBeatState
60206057
for (script in luaArray)
60216058
if(script.scriptName == luaToLoad) return false;
60226059

6023-
new FunkinLua(luaToLoad);
6060+
(ClientPrefs.getGameplaySetting('legacyMode', false) ? new LegacyFunkinLua(luaToLoad) : new FunkinLua(luaToLoad));
60246061
return true;
60256062
}
60266063
return false;
@@ -6087,8 +6124,10 @@ class PlayState extends MusicBeatState
60876124
if(exclusions == null) exclusions = [];
60886125
if(excludeValues == null) excludeValues = [LuaUtils.Function_Continue];
60896126

6090-
var arr:Array<FunkinLua> = [];
6091-
for (script in luaArray)
6127+
// var lua = flixel.util.typeLimit.OneOfTwo;
6128+
6129+
var arr:Array<Dynamic> = [];
6130+
for (script in yutautil.CollectionUtils.toIterable(cast(luaArray:Array<Dynamic>).concat(legacyLuaArray)))
60926131
{
60936132
if(script.closed)
60946133
{
@@ -6114,7 +6153,7 @@ class PlayState extends MusicBeatState
61146153

61156154
if(arr.length > 0)
61166155
for (script in arr)
6117-
luaArray.remove(script);
6156+
(luaArray.contains(script)) ? luaArray.remove(script) : legacyLuaArray.remove(cast(script, LegacyFunkinLua));
61186157
#end
61196158
return returnVal;
61206159
}

source/yutautil/CollectionUtils.hx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ using yutautil.CollectionUtils;
2626
*/
2727
@:generic typedef Predicate<T> = T->Bool;
2828

29+
typedef LuaScript = flixel.util.typeLimit.OneOfTwo<psychlua.FunkinLua, psychlua.LegacyFunkinLua>;
30+
2931
// abstract Collection<T>(Dynamic) from Array<T> to Array<T> {
3032
// @:from public static inline function fromList<T>(list:List<T>):Collection<T> {
3133
// return cast list;
@@ -1146,7 +1148,7 @@ class CollectionUtils
11461148

11471149
// Only for Funkin Lua Legacy...
11481150

1149-
/*public static inline function getScriptName(s:LuaScript):String
1151+
public static inline function getScriptName(s:LuaScript):String
11501152
{
11511153
return switch (Type.getClass(s)) {
11521154
case psychlua.FunkinLua:
@@ -1180,7 +1182,7 @@ class CollectionUtils
11801182
default:
11811183
throw "Unsupported LuaScript type";
11821184
}
1183-
}*/
1185+
}
11841186

11851187

11861188
public static function createTestData():Void

0 commit comments

Comments
 (0)