Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
some cleaner script group/layer stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Dec 11, 2023
1 parent a683a10 commit e9b09cb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion source/funkin/objects/note/Note.hx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Note extends FlxSpriteExt implements INoteData {
if (isSustainNote) {
if (init) { // Offset sustain
final _off = getPosMill(NoteUtil.swagHeight * 0.5, NotesGroup.songSpeed);
initSusLength += _off - (NoteUtil.swagHeight * 0.5 / Math.pow(NotesGroup.songSpeed, 2));
initSusLength += _off - (NoteUtil.swagHeight * 0.5 / NotesGroup.songSpeed);
}
} else {
loadFromSprite(refSprite);
Expand Down
1 change: 1 addition & 0 deletions source/funkin/states/editors/StageDebug.hx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class StageDebug extends MusicBeatState {

// TODO add a better layer system you big goof
Stage.createStageObjects(stageData.layers, null, ["bg" => bgGroup, "fg" => fgGroup]);
FlxG.camera.zoom = stageData.zoom;
}

final speed = 50;
Expand Down
7 changes: 4 additions & 3 deletions source/funkin/states/menus/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ class FreeplayState extends MusicBeatState {
if (Math.abs(lerpScore - intendedScore) <= 10) lerpScore = intendedScore;
scoreText.text = "PERSONAL BEST: " + lerpScore;

for (i in [scoreText,diffText,scoreBG]) {
i.x = CoolUtil.coolLerp(i.x, lerpPosition, 0.2);
}
//for (i in [scoreText,diffText,scoreBG]) i.x = CoolUtil.coolLerp(i.x, lerpPosition, 0.2);
scoreBG.x = Math.max(CoolUtil.coolLerp(scoreBG.x, lerpPosition, 0.2), 0);
scoreText.x = Math.max(CoolUtil.coolLerp(scoreText.x, lerpPosition, 0.2), 0);
diffText.x = CoolUtil.coolLerp(diffText.x, lerpPosition, 0.2);

if (getKey('UI_LEFT-P')) changeDiff(-1);
if (getKey('UI_RIGHT-P')) changeDiff(1);
Expand Down
18 changes: 4 additions & 14 deletions source/funkin/util/modding/FunkScript.hx
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ class FunkScript extends hscript.Script implements IFlxDestroyable {
});

set('existsSpr', function(key:String):Null<Dynamic> {
for (i in ['fg', 'bg']) {
if (ScriptUtil.objMap.exists(ScriptUtil.getSpriteKey(i, key))) {
return true;
}
}
return false;
return ScriptUtil.existsSprite(key);
});

set('removeSpr', function(key:String) {
Expand All @@ -245,21 +240,16 @@ class FunkScript extends hscript.Script implements IFlxDestroyable {
set('makeGroup', function(key:String, ?order:Int):FlxTypedGroup<Dynamic> {
var newGroup:FlxTypedGroup<Dynamic> = new FlxTypedGroup<Dynamic>();
order != null ? FlxG.state.insert(order, newGroup) : FlxG.state.add(newGroup);
if (cast FlxG.state is PlayState) ScriptUtil.objMap.set('_group_$key', newGroup);
if (cast FlxG.state is PlayState) ScriptUtil.objMap.set(ScriptUtil.getGroupKey(key), newGroup);
return newGroup;
});

set('getGroup', function(key:String):Null<FlxTypedGroup<Dynamic>> {
if (ScriptUtil.objMap.exists('_group_$key'))
return ScriptUtil.objMap.get('_group_$key');
else {
errorPrint('Group not found: $key');
return null;
}
return ScriptUtil.getGroup(key);
});

set('existsGroup', function(key:String):Bool {
return ScriptUtil.objMap.exists('_group_$key');
return ScriptUtil.existsGroup(key);
});

set('cacheCharacter', function(name:String):Character {
Expand Down
32 changes: 29 additions & 3 deletions source/funkin/util/modding/ScriptUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@ class ScriptUtil {

public static function getSprite(key:String) {
for (i in ['fg', 'bg']) {
final sprKey = '_${i}_sprite_$key';
final sprKey = getSpriteKey(i, key);
if (objMap.exists(sprKey))
return objMap.get(sprKey);
}
ModdingUtil.errorPrint('Sprite not found: $key');
return null;
return null;
}

public static function existsSprite(key:String) {
for (i in ['fg', 'bg']) {
if (objMap.exists(getSpriteKey(i, key)))
return true;
}
return false;
}

inline public static function formatSpriteKey(key:String, layer:SpriteLayer) {
Expand All @@ -46,8 +54,26 @@ class ScriptUtil {
return '_${group}_sprite_$key';
}

inline public static function existsGroup(key:String) {
return objMap.exists(getGroupKey(key));
}

inline public static function getGroup(key:String) {
return key == 'fg' ? PlayState.instance.fgSpr : PlayState.instance.bgSpr;
switch(key) {
case "bg": return PlayState.instance.bgSpr;
case "fg": return PlayState.instance.fgSpr;
default:
if (existsGroup(key))
return objMap.get(getGroupKey(key));
else {
ModdingUtil.errorPrint('Group not found: $key');
return null;
}
}
}

inline public static function getGroupKey(key:String) {
return '_group_$key';
}

public static var stateQueue:{state:MusicBeatState, skipTrans:Bool} = null;
Expand Down

0 comments on commit e9b09cb

Please sign in to comment.