Skip to content

Commit

Permalink
Fix Psych 1.0 Support (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnikTil authored Jan 13, 2025
1 parent 836d2e1 commit ca167d4
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 9 deletions.
77 changes: 72 additions & 5 deletions source/backend/Song.hx
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,59 @@ class Song
public var player2:String = 'dad';
public var gfVersion:String = 'gf';

private static function onLoadJson(songJson:Dynamic) // Convert old charts to newest format
private static function onLoadJson(songJson:Dynamic) // Convert old charts to newest format, or convert new format to old format?
{
if(songJson.format == null)
throw new haxe.Exception('No chart format found!');

trace('Loaded ${songJson.format} Song!');

if(songJson.gfVersion == null)
{
songJson.gfVersion = songJson.player3;
songJson.player3 = null;
}

if(songJson.events == null)
if(StringTools.startsWith(songJson.format, 'psych_v1'))
{
var characters:Array<String> = [songJson.player1, songJson.player2, songJson.gfVersion];
for (i in 0...characters.length)
{
switch(characters[i])
{
case 'pico-playable':
characters[i] = 'pico-player';

case 'tankman-playable':
characters[i] = 'tankman-player';
}
}

songJson.player1 = characters[0];
songJson.player2 = characters[1];
songJson.gfVersion = characters[2];

for (secNum in 0...songJson.notes.length)
{
var sec:SwagSection = songJson.notes[secNum];
for(i in 0...sec.sectionNotes.length)
{
var note:Array<Dynamic> = sec.sectionNotes[i];

var secondPlayer:Bool = note[1] > 3;

if(!sec.mustHitSection)
secondPlayer = !secondPlayer;

note[1] = note[1] % 4;

if(secondPlayer)
note[1] += 4;
}
}
}

if(songJson.events == null && songJson.format == 'psych_legacy')
{
songJson.events = [];
for (secNum in 0...songJson.notes.length)
Expand Down Expand Up @@ -163,8 +207,31 @@ class Song
public static function parseJSONshit(rawJson:String):SwagSong
{
var parsed:Dynamic = Json.parse(rawJson);
if (!(parsed.song is String))
return cast parsed.song;
return cast parsed;

if (parsed.song != null && !Std.isOfType(parsed.song, String))
{
parsed.song.format = 'psych_legacy';
return parsed.song;
}
else if(parsed.song != null)
return parsed;
else if (parsed.events != null)
{
return {
events: cast parsed.events,
song: "",
notes: [],
bpm: 0,
needsVoices: true,
speed: 1,
player1: "",
player2: "",
gfVersion: "",
stage: "",
format: 'psych_v1'
};
}
else
throw new haxe.Exception("No song data found, or is invalid.");
}
}
9 changes: 5 additions & 4 deletions source/objects/HealthIcon.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ class HealthIcon extends FlxSprite
if(!Paths.fileExists('images/' + name + '.png', IMAGE)) name = 'icons/icon-face'; //Prevents crash from missing icon

var graphic = Paths.image(name, allowGPU);
loadGraphic(graphic, true, Math.floor(graphic.width / 2), Math.floor(graphic.height));
iconOffsets[0] = (width - 150) / 2;
iconOffsets[1] = (height - 150) / 2;
var iSize:Float = Math.round(graphic.width / graphic.height);
loadGraphic(graphic, true, Math.floor(graphic.width / iSize), Math.floor(graphic.height));
iconOffsets[0] = (width - 150) / iSize;
iconOffsets[1] = (height - 150) / iSize;
updateHitbox();

animation.add(char, [0, 1], 0, false, isPlayer);
animation.add(char, [for(i in 0...frames.frames.length) i], 0, false, isPlayer);
animation.play(char);
this.char = char;

Expand Down
35 changes: 35 additions & 0 deletions source/psychlua/ReflectionFunctions.hx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,41 @@ class ReflectionFunctions
}
return value;
});
Lua_helper.add_callback(lua, "addToGroup", function(group:String, tag:String, ?index:Int = -1) {
var obj:FlxSprite = LuaUtils.getObjectDirectly(tag);
if(obj == null || obj.destroy == null)
{
FunkinLua.luaTrace('addToGroup: Object $tag is not valid!', false, false, FlxColor.RED);
return;
}

// uiGroup and such is not existent in psych online, so we can sorta imitate it by just adding it onto PlayState
if(['comboGroup', 'uiGroup', 'noteGroup'].contains(group))
{
PlayState.instance.add(obj);
return;
}

var groupOrArray:Dynamic = Reflect.getProperty(LuaUtils.getTargetInstance(), group);
if(groupOrArray == null)
{
FunkinLua.luaTrace('addToGroup: Group/Array $group is not valid!', false, false, FlxColor.RED);
return;
}

if(index < 0)
{
switch(Type.typeof(groupOrArray))
{
case TClass(Array): //Is Array
groupOrArray.push(obj);

default: //Is Group
groupOrArray.add(obj);
}
}
else groupOrArray.insert(index, obj);
});
Lua_helper.add_callback(lua, "removeFromGroup", function(obj:String, index:Int, dontDestroy:Bool = false) {
var groupOrArray:Dynamic = Reflect.getProperty(LuaUtils.getTargetInstance(), obj);
if(Std.isOfType(groupOrArray, FlxTypedGroup)) {
Expand Down

0 comments on commit ca167d4

Please sign in to comment.