Skip to content

Commit af46ad6

Browse files
KoloInDaCribKade-github
authored andcommitted
0.7.4 stuff
1 parent 45951f1 commit af46ad6

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

assets/content/cookbook/Advanced/3.ScriptedSongs.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,37 @@ class BallisticSong extends Song {
2424

2525
You can then add override functions to perform custom behavior.
2626

27+
## Variation-Specific Song Scripts
28+
29+
As of 0.7.4, if in the constructor you were to add an anonymous structure with the field `variation` as a parameter next to the song id, the song script will only be active for that variation. This prevents many conflicts with base game scripts and other mods that may add a variation, as the game would only call the functions from the variation-specific script. If a song doesn't have a variation-specific script, it will fallback to the default one, if it exists. An example of a variation-specific script can be found for Darnell Erect[^darnell]
30+
```haxe
31+
import funkin.play.song.Song;
32+
import funkin.save.Save;
33+
34+
class DarnellErectSong extends Song
35+
{
36+
public function new()
37+
{
38+
super('darnell',
39+
{
40+
variation: 'erect'
41+
});
42+
}
43+
44+
// ...
45+
}
46+
```
47+
2748
## Custom 'NEW'-Label criteria
2849

29-
Usually, in the Freeplay menu, a song would not have the glowing 'NEW' label. However if you override the function `isSongNew`, you can have the label appear if a specific criteria is met. An example of this is found in the script for Cocoa[^cocoa] which returns true if the variation is Pico and the player hasn't beaten Cocoa Pico Mix.
50+
Usually, in the Freeplay menu, a song would not have the glowing 'NEW' label. However if you override the function `isSongNew`, you can have the label appear if a specific criteria is met. An example of this is found in the script for Cocoa (Pico Mix)[^cocoa] which returns true if the variation is Pico and the player hasn't beaten Cocoa Pico Mix.
3051
```haxe
3152
// ...
3253
33-
// Line 29
54+
// Line 14
3455
public override function isSongNew(currentDifficulty:String, currentVariation:String):Bool
3556
{
36-
if (currentVariation == 'pico') return !Save.instance.hasBeatenSong(this.id, null, 'pico');
57+
if (currentVariation == 'pico') return !Save.instance.hasBeatenSong(this.id, null, this.variation);
3758
3859
return false;
3960
}
@@ -47,25 +68,19 @@ Instead of reading from the song's metadata file for possible alternate instrume
4768
```haxe
4869
// ...
4970
50-
// Line 42
71+
// Line 21
5172
public override function listAltInstrumentalIds(difficultyId:String, variationId:String):Array<String>
5273
{
74+
var results:Array<String> = super.listAltInstrumentalIds(difficultyId, variationId);
75+
5376
if (difficultyId == 'easy' || difficultyId == 'normal' || difficultyId == 'hard')
5477
{
5578
var hasBeatenPicoMix = Save.instance.hasBeatenSong(this.id, null, 'pico');
5679
57-
switch (variationId)
58-
{
59-
case 'pico':
60-
// return hasBeatenPicoMix ? [''] : [];
61-
// No Pico mix on BF instrumental, sorry!
62-
return [];
63-
default:
64-
return hasBeatenPicoMix ? ['pico'] : [];
65-
}
80+
if (!hasBeatenPicoMix) results = [for (id in results) if (id != 'pico') id];
6681
}
6782
68-
return [];
83+
return results;
6984
}
7085
7186
// ...
@@ -92,8 +107,9 @@ public function listDifficulties(variationId:String, variationIds:Array<String>,
92107
// ...
93108
```
94109

95-
[^cocoa]: <https://github.com/FunkinCrew/funkin.assets/blob/main/preload/scripts/songs/cocoa.hxc>
96-
[^2hot]: <https://github.com/FunkinCrew/funkin.assets/blob/main/preload/scripts/songs/2hot.hxc>
110+
[^darnell]: <https://github.com/FunkinCrew/funkin.assets/blob/main/preload/scripts/songs/darnell-erect.hxc>
111+
[^cocoa]: <https://github.com/FunkinCrew/funkin.assets/blob/main/preload/scripts/songs/cocoa-pico.hxc>
97112
[^stress]: <https://github.com/FunkinCrew/funkin.assets/blob/main/preload/scripts/songs/stress.hxc>
113+
[^2hot]: <https://github.com/FunkinCrew/funkin.assets/blob/main/preload/scripts/songs/2hot.hxc>
98114

99115
> Author: [EliteMasterEric](https://github.com/EliteMasterEric)

0 commit comments

Comments
 (0)