Skip to content

Commit

Permalink
prepare fs for 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AbnormalPoof committed Feb 19, 2025
1 parent 2628bc3 commit 73e8000
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 98 deletions.
51 changes: 18 additions & 33 deletions scripts/modules/FS_CharacterDataHandler.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -200,34 +200,34 @@ class FS_CharacterDataHandler extends Module
// I basically just put this all in one big object so that I don't have to do a bunch of null checks lol
var result:FS_characterData =
{
version: nullCoalesce(parsedData?.version, "1.0.0"),
characterID: nullCoalesce(parsedData?.characterID, null),
characterType: nullCoalesce(parsedData?.characterType, "bf"),
mustUnlock: nullCoalesce(parsedData?.mustUnlock, false),
voiceID: nullCoalesce(parsedData?.voiceID, parsedData?.characterID),
introSwapFrame: nullCoalesce(parsedData?.introSwapFrame, 3),
unlockMethod: nullCoalesce(parsedData?.unlockMethod, null),
version: parsedData?.version ?? "1.0.0",
characterID: parsedData?.characterID ?? null,
characterType: parsedData?.characterType ?? "bf",
mustUnlock: parsedData?.mustUnlock ?? false,
voiceID: parsedData?.voiceID ?? parsedData?.characterID,
introSwapFrame: parsedData?.introSwapFrame ?? 3,
unlockMethod: parsedData?.unlockMethod ?? null,
description:
{
text: nullCoalesce(parsedData?.description?.text, "No description was specified in the JSON file."),
unlockCondition: nullCoalesce(parsedData?.description?.unlockCondition, "No unlock condition was specified in the JSON file.")
text: parsedData?.description?.text ?? "No description was specified in the JSON file.",
unlockCondition: parsedData?.description?.unlockCondition ?? "No unlock condition was specified in the JSON file."
},
characterMenu:
{
position: nullCoalesce(parsedData?.characterMenu?.position, [0, 0]),
scale: calculateCharacterScale(parsedData.characterMenu?.scale, parsedData?.characterMenu?.isPixel),
isPixel: nullCoalesce(parsedData?.characterMenu?.isPixel, false),
flipX: nullCoalesce(parsedData?.characterMenu?.flipX, false),
selectedAnim: nullCoalesce(parsedData?.characterMenu?.selectedAnim, "hey")
position: parsedData?.characterMenu?.position ?? [0, 0],
scale: calculateCharacterScale(parsedData.characterMenu?.scale ?? 1, parsedData?.characterMenu?.isPixel ?? false),
isPixel: parsedData?.characterMenu?.isPixel ?? false,
flipX: parsedData?.characterMenu?.flipX ?? false,
selectedAnim: parsedData?.characterMenu?.selectedAnim ?? "hey"
},
// We still set suffixes to null to account for scripts.
suffixes:
{
gameOverMusic: nullCoalesce(parsedData?.suffixes?.gameOverMusic, null),
blueBall: nullCoalesce(parsedData?.suffixes?.blueBall, null),
pauseMusic: nullCoalesce(parsedData?.suffixes?.pauseMusic, null)
gameOverMusic: parsedData?.suffixes?.gameOverMusic ?? null,
blueBall: parsedData?.suffixes?.blueBall ?? null,
pauseMusic: parsedData?.suffixes?.pauseMusic ?? null
},
characterVariations: nullCoalesce(parsedData?.characterVariations, [])
characterVariations: parsedData?.characterVariations ?? []
};

return result;
Expand Down Expand Up @@ -487,21 +487,6 @@ class FS_CharacterDataHandler extends Module
}
MemoryUtil.collect(true);
}

/**
* HELPER FUNCTIONS
* These are functions that are simply nice to have. They make the code cleaner.
*/
/**
* Imitates null coalescing since HScript doesn't support it yet.
* @param value The value to check.
* @param fallback The fallback value.
* @return The value if it's not null, otherwise the fallback value.
*/
public function nullCoalesce(value:Dynamic, fallback:Dynamic):Dynamic
{
return value != null ? value : fallback;
}
}

/**
Expand Down
25 changes: 7 additions & 18 deletions scripts/modules/FS_CoreModule.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class FS_CoreModule extends Module

if (songMatch && variationMatch)
{
fs_characterData = nullCoalesce(FS_CharacterDataHandler.scriptCall('getCharacterData', [variation.characterID]), fs_characterData);
fs_characterData = FS_CharacterDataHandler.scriptCall('getCharacterData', [variation.characterID]) ?? fs_characterData;

if (FS_CharacterDataHandler.scriptCall('charJSONCheck', [variation.characterID]))
{
Expand Down Expand Up @@ -270,9 +270,9 @@ class FS_CoreModule extends Module

if (characterType == CharacterType.BF)
{
PauseSubState.musicSuffix = nullCoalesce(fs_characterData.suffixes.pauseMusic, PauseSubState.musicSuffix);
GameOverSubState.musicSuffix = nullCoalesce(fs_characterData.suffixes.gameOverMusic, GameOverSubState.musicSuffix);
GameOverSubState.blueBallSuffix = nullCoalesce(fs_characterData.suffixes.blueBall, GameOverSubState.blueBallSuffix);
PauseSubState.musicSuffix = fs_characterData?.suffixes?.pauseMusic ?? PauseSubState.musicSuffix;
GameOverSubState.musicSuffix = fs_characterData?.suffixes?.gameOverMusic ?? GameOverSubState.musicSuffix;
GameOverSubState.blueBallSuffix = fs_characterData?.suffixes?.blueBall ?? GameOverSubState.blueBallSuffix;
}

trace('[Funker Selector] Suffixes\n\nPause Music: ' + PauseSubState.musicSuffix + '\nGame Over Music: ' + GameOverSubState.musicSuffix
Expand All @@ -290,8 +290,8 @@ class FS_CoreModule extends Module
var result:VoicesGroup = new VoicesGroup();
var songVoices:Array<String> = currentChart.buildVoiceList();

result.addPlayerVoice(FunkinSound.load(nullCoalesce(voiceList[0], songVoices[0])));
result.addOpponentVoice(FunkinSound.load(nullCoalesce(voiceList[1], songVoices[1])));
result.addPlayerVoice(FunkinSound.load(voiceList[0] ?? songVoices[0]));
result.addOpponentVoice(FunkinSound.load(voiceList[1] ?? songVoices[1]));

result.playerVoicesOffset = currentChart.offsets.getVocalOffset(currentChart.characters.player);
result.opponentVoicesOffset = currentChart.offsets.getVocalOffset(currentChart.characters.opponent);
Expand Down Expand Up @@ -532,17 +532,6 @@ class FS_CoreModule extends Module
public function isDebugBuild():Bool
{
// Debug builds use a different background color.
return Application.current.window.context.attributes.background == 0xFFFF00FF;
}

/**
* Imitates null coalescing since HScript doesn't support it yet.
* @param value The value to check.
* @param fallback The fallback value.
* @return The value if it's not null, otherwise the fallback value.
*/
public function nullCoalesce(value:Dynamic, fallback:Dynamic):Dynamic
{
return value != null ? value : fallback;
return Constants.DEBUG_BUILD;
}
}
17 changes: 1 addition & 16 deletions scripts/modules/FS_FreeplayDJReplace.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class DJReplace extends Module
var freeplayDJ:FreeplayDJ = FlxG.state.subState.dj;
var characterID:String = PlayerRegistry.instance.isCharacterOwned(saveData.characterIDs.bf) ? PlayerRegistry.instance.getCharacterOwnerId(saveData.characterIDs.bf) : FlxG.state.subState.currentCharacterId;
var playableChar:PlayableCharacter = PlayerRegistry.instance.fetchEntry(characterID);
var playableCharData:Dynamic = playableChar != null ? playableChar.getFreeplayDJData() : null;
var playableCharData:Dynamic = playableChar.getFreeplayDJData() ?? null;

var fs_characterData:Dynamic = ModuleHandler.getModule("FS_CharacterDataHandler").scriptCall('getCharacterData', [saveData.characterIDs.bf]);
var introFrame:Int = fs_characterData.introSwapFrame;
Expand Down Expand Up @@ -254,19 +254,4 @@ class DJReplace extends Module

textObject.speed = speed;
}

/**
* HELPER FUNCTIONS
* These are functions that are simply nice to have. They make the code cleaner.
*/
/**
* Imitates null coalescing since HScript doesn't support it yet.
* @param value The value to check.
* @param fallback The fallback value.
* @return The value if it's not null, otherwise the fallback value.
*/
public function nullCoalesce(value:Dynamic, fallback:Dynamic):Dynamic
{
return value != null ? value : fallback;
}
}
27 changes: 8 additions & 19 deletions scripts/modules/FS_SaveDataHandler.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,21 @@ class FS_SaveDataHandler extends Module
version: FS_SAVE_DATA_VERSION,
characterIDs:
{
bf: nullCoalesce(oldCharacterIDs?.bf, 'default'),
gf: nullCoalesce(oldCharacterIDs?.gf, 'default'),
dad: nullCoalesce(oldCharacterIDs?.dad, 'default')
bf: oldCharacterIDs?.bf ?? 'default',
gf: oldCharacterIDs?.gf ?? 'default',
dad: oldCharacterIDs?.dad ?? 'default'
},
preferences: new StringMap(),
seenUnlocks: nullCoalesce(oldSeenUnlocks, [])
seenUnlocks: oldSeenUnlocks ?? []
};

// Settings is a special case...
var settings:Dynamic =
{
potatoMode: nullCoalesce(oldPrefs?.potatoMode, false),
preloadSprites: nullCoalesce(oldPrefs?.preloadSprites, false),
preferredSFX: nullCoalesce(oldPrefs?.preferredSFX, 'funkin'),
djSwapping: nullCoalesce(oldPrefs?.djSwapping, true)
potatoMode: oldPrefs?.potatoMode ?? false,
preloadSprites: oldPrefs?.preloadSprites ?? false,
preferredSFX: oldPrefs?.preferredSFX ?? 'funkin',
djSwapping: oldPrefs?.djSwapping ?? true
};

for (key in ReflectUtil.getAnonymousFieldsOf(settings))
Expand Down Expand Up @@ -301,15 +301,4 @@ class FS_SaveDataHandler extends Module
saveData.preferences[key] = value;
writeSaveData();
}

/**
* Imitates null coalescing since HScript doesn't support it yet.
* @param value The value to check.
* @param fallback The fallback value.
* @return The value if it's not null, otherwise the fallback value.
*/
public function nullCoalesce(value:Dynamic, fallback:Dynamic):Dynamic
{
return value != null ? value : fallback;
}
}
14 changes: 2 additions & 12 deletions scripts/states/FS_CharacterMenu.hxc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import funkin.save.Save;
import funkin.ui.MusicBeatSubState;
import funkin.ui.charSelect.Lock;
import funkin.ui.freeplay.charselect.PlayableCharacter;
import funkin.util.Constants;
import funkin.util.MathUtil;
import funkin.util.SortUtil;
import funkin.util.WindowUtil;
Expand Down Expand Up @@ -1492,18 +1493,7 @@ class FS_CharacterMenu extends MusicBeatSubState
public function isDebugBuild():Bool
{
// Debug builds use a different background color.
return Application.current.window.context.attributes.background == 0xFFFF00FF;
}

/**
* Imitates null coalescing since HScript doesn't support it yet.
* @param value The value to check.
* @param fallback The fallback value.
* @return The value if it's not null, otherwise the fallback value.
*/
public function nullCoalesce(value:Dynamic, fallback:Dynamic):Dynamic
{
return value != null ? value : fallback;
return Constants.DEBUG_BUILD;
}

/**
Expand Down

0 comments on commit 73e8000

Please sign in to comment.