Skip to content

Commit

Permalink
built in alt inst lock
Browse files Browse the repository at this point in the history
  • Loading branch information
MidyGamy committed Jan 28, 2025
1 parent 6216655 commit d8b8c66
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
11 changes: 9 additions & 2 deletions source/funkin/data/song/SongData.hx
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,12 @@ class SongCharacterData implements ICloneable<SongCharacterData>
@:optional
public var playerVocals:Null<Array<String>> = null;

@:optional
@:default(true)
public var unlockedInstByDefault:Null<Bool> = true;

public function new(player:String = '', girlfriend:String = '', opponent:String = '', instrumental:String = '', ?altInstrumentals:Array<String>,
?opponentVocals:Array<String>, ?playerVocals:Array<String>)
?opponentVocals:Array<String>, ?playerVocals:Array<String>, ?unlockedInstByDefault:Bool)
{
this.player = player;
this.girlfriend = girlfriend;
Expand All @@ -563,6 +567,7 @@ class SongCharacterData implements ICloneable<SongCharacterData>
this.altInstrumentals = altInstrumentals;
this.opponentVocals = opponentVocals;
this.playerVocals = playerVocals;
this.unlockedInstByDefault = unlockedInstByDefault;

if (opponentVocals == null) this.opponentVocals = [opponent];
if (playerVocals == null) this.playerVocals = [player];
Expand All @@ -572,6 +577,7 @@ class SongCharacterData implements ICloneable<SongCharacterData>
{
var result:SongCharacterData = new SongCharacterData(this.player, this.girlfriend, this.opponent, this.instrumental);
result.altInstrumentals = this.altInstrumentals.clone();
result.unlockedInstByDefault = this.unlockedInstByDefault;

return result;
}
Expand All @@ -581,7 +587,8 @@ class SongCharacterData implements ICloneable<SongCharacterData>
*/
public function toString():String
{
return 'SongCharacterData(${this.player}, ${this.girlfriend}, ${this.opponent}, ${this.instrumental}, [${this.altInstrumentals.join(', ')}])';
return
'SongCharacterData(${this.player}, ${this.girlfriend}, ${this.opponent}, ${this.instrumental}, [${this.altInstrumentals.join(', ')}], ${this.unlockedInstByDefault})';
}
}

Expand Down
20 changes: 20 additions & 0 deletions source/funkin/play/song/Song.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import funkin.modding.IScriptedClass.IPlayStateScriptedClass;
import funkin.modding.events.ScriptEvent;
import funkin.ui.freeplay.charselect.PlayableCharacter;
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.save.Save;
import funkin.util.SortUtil;

/**
Expand Down Expand Up @@ -588,6 +589,25 @@ class Song implements IPlayStateScriptedClass implements IRegistryEntry<SongMeta
return variation.playData.difficulties.contains(diffId);
}

/**
* Return if the inst alt as been unlocked, default to true.
* @param variationId
* @param difficultyId
*/
public function isAltInstUnlocked(difficultyId:String, variationId:String):Bool
{
var targetDifficulty:Null<SongDifficulty> = getDifficulty(difficultyId, variationId);
if (targetDifficulty == null) return true;

var unlocked:Bool = (targetDifficulty?.characters?.unlockedInstByDefault) || Save.instance.hasBeatenSong(this.id, null, variationId);

trace('Is ${this.id}-${variationId} alt inst unlocked: '
+ unlocked
+ ((targetDifficulty?.characters?.unlockedInstByDefault ?? true) ? ' (by default)' : ''));

return unlocked;
}

/**
* Return the list of available alternate instrumentals.
* Scripts can override this, fun.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ChartEditorMetadataToolbox extends ChartEditorBaseToolbox
var inputSongCharter:TextField;
var inputStage:DropDown;
var inputNoteStyle:DropDown;
var inputIsunlockedInstByDefault:CheckBox;
var buttonCharacterPlayer:Button;
var buttonCharacterGirlfriend:Button;
var buttonCharacterOpponent:Button;
Expand Down Expand Up @@ -122,6 +123,10 @@ class ChartEditorMetadataToolbox extends ChartEditorBaseToolbox
var startingValueNoteStyle = ChartEditorDropdowns.populateDropdownWithNoteStyles(inputNoteStyle, chartEditorState.currentSongMetadata.playData.noteStyle);
inputNoteStyle.value = startingValueNoteStyle;

inputIsunlockedInstByDefault.onChange = function(event:UIEvent) {
chartEditorState.currentSongMetadata.playData.characters.unlockedInstByDefault = event.target.value;
};

inputBPM.onChange = function(event:UIEvent) {
if (event.value == null || event.value <= 0) return;

Expand Down Expand Up @@ -196,6 +201,7 @@ class ChartEditorMetadataToolbox extends ChartEditorBaseToolbox
inputSongCharter.value = chartEditorState.currentSongMetadata.charter;
inputStage.value = chartEditorState.currentSongMetadata.playData.stage;
inputNoteStyle.value = chartEditorState.currentSongMetadata.playData.noteStyle;
inputIsunlockedInstByDefault.selected = chartEditorState.currentSongMetadata.playData.characters.unlockedInstByDefault;
inputBPM.value = chartEditorState.currentSongMetadata.timeChanges[0].bpm;
inputDifficultyRating.value = chartEditorState.currentSongChartDifficultyRating;
inputScrollSpeed.value = chartEditorState.currentSongChartScrollSpeed;
Expand Down
17 changes: 15 additions & 2 deletions source/funkin/ui/freeplay/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1865,12 +1865,25 @@ class FreeplayState extends MusicBeatSubState
trace('target variation: ${targetDifficulty?.variation ?? Constants.DEFAULT_VARIATION}');

var baseInstrumentalId:String = targetSong.getBaseInstrumentalId(targetDifficultyId, targetDifficulty?.variation ?? Constants.DEFAULT_VARIATION) ?? '';
var hasBeenBeaten:Bool = Save.instance.hasBeatenSong(targetSongId, null, baseInstrumentalId);
trace('Has ${targetSongId}'
+ ((baseInstrumentalId.length > 0) ? '-${baseInstrumentalId}' : '')
+ " been beaten"
+ hasBeenBeaten);
var altInstrumentalIds:Array<String> = targetSong.listAltInstrumentalIds(targetDifficultyId,
targetDifficulty?.variation ?? Constants.DEFAULT_VARIATION) ?? [];
var instrumentalIds = [baseInstrumentalId].concat(altInstrumentalIds);
for (altInstrumentalId in instrumentalIds)
{
var altIsUnlocked = targetSong.isAltInstUnlocked(targetDifficultyId, altInstrumentalId) ?? true;
if (!altIsUnlocked)
{
instrumentalIds.remove(altInstrumentalId);
}
}

if (altInstrumentalIds.length > 0)
if (instrumentalIds.length > 1 && hasBeenBeaten)
{
var instrumentalIds = [baseInstrumentalId].concat(altInstrumentalIds);
openInstrumentalList(cap, instrumentalIds);
}
else
Expand Down

0 comments on commit d8b8c66

Please sign in to comment.