Skip to content

Commit

Permalink
first implementation of metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnikTil committed Dec 14, 2024
1 parent fdc8404 commit d5cb5f9
Show file tree
Hide file tree
Showing 27 changed files with 232 additions and 1 deletion.
3 changes: 3 additions & 0 deletions assets/gameplay/songs/2hot/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "2hot"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/blazin/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Blazin'"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/bopeebo/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Bopeebo"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/cocoa/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Cocoa"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/dadbattle/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "DadBattle"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/darnell/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Darnell"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/eggnog/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Eggnog"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/fresh/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Fresh"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/guns/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Guns"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/high/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "High"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/lit-up/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Lit Up"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/milf/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "M.I.L.F"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/monster/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Monster"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/roses/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Roses"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/satin-panties/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Satin Panties"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/senpai/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Senpai"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/south/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "South"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/spookeez/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Spookeez"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/stress/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Stress"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/thorns/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Thorns"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/tutorial/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Tutorial"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/ugh/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Ugh"
}
3 changes: 3 additions & 0 deletions assets/gameplay/songs/winter-horrorland/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Winter Horrorland"
}
37 changes: 37 additions & 0 deletions extras/scripts/GenerateSongsFolder.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package;

import haxe.Json;
import sys.FileSystem;
import sys.io.File;

using StringTools;

class GenerateSongsFolder
{
public static function main()
{
var songsToGenerate:Array<Array<String>> = [];
var generateText:Array<String> = File.getContent('./songsToGenerate.txt').split('\n');

for (i in generateText)
{
songsToGenerate.push(i.split(' - '));
}

for (song in songsToGenerate)
{
var yeah = {
"name": song[1]
};
var yeahAsString:String = Json.stringify(yeah, null, '\t').replace('\\r', '');

FileSystem.createDirectory('./' + song[0]);
File.saveContent('./' + song[0] + '/metadata.json', yeahAsString);
}
}

static function print(string:String)
{
Sys.stdout().writeString(string + '\n');
}
}
113 changes: 113 additions & 0 deletions src/funkin/data/song/Song.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package funkin.data.song;

import flixel.sound.FlxSoundGroup;
import funkin.structures.SongStructure;

class Song
{
static var cachedSongs:Map<String, Song>;

/**
* Caches all songs to use later.
*/
public static function cacheSongs():Void
{
cachedSongs = new Map<String, Song>();

for (file in Paths.location.scan('gameplay/songs', '.json', true, PATH_FILE, false))
{
if (!file.endsWith('metadata'))
continue;

var endLength:Int = file.length - 'metadata'.length - 1;
var songName:String = file.substring('gameplay/songs/'.length, endLength);
var song:Song = new Song(songName);
cachedSongs.set(songName, song);
}
}

/**
* Gets a song using it's ID.
* @param id The ID of the song to search for.
* @return The Song Object.
*/
public static function getSongByID(id:String):Song
{
if (cachedSongs == null)
cacheSongs();

return cachedSongs.get(id);
}

/**
* The song ID.
*/
public final id:String;

/**
* All the metadatas.
* id => structure
*/
public final metadatas:Map<String, SongMetadata>;

public function new(id:String)
{
this.id = id;

metadatas = new Map<String, SongMetadata>();

for (variation in getVariations())
{
metadatas.set(variation, getSongMetadata(id, variation));
}
}

/**
* Get the Display Name for this song.
* @param variation The variation to get the name from.
* @return The name.
*/
public function getDisplayName(variation:String = 'default'):String
{
var metadata:SongMetadata = metadatas.get(variation);
return metadata.name;
}

static function getSongMetadata(id:String, variation:String):SongMetadata
{
var path:String = 'gameplay/songs/' + id + '/';

if (variation != 'default')
path += variation + '-';

path += 'metadata';

return cast haxe.Json.parse(Paths.content.json(path));
}

var _variations:Array<String>;

/**
* Get all of the variations for this Song.
* @return The variations.
*/
public function getVariations():Array<String>
{
if (_variations != null)
return _variations;

_variations = ['default'];

var queryPath:String = 'gameplay/songs/' + id;
for (file in Paths.location.scan(queryPath, 'metadata.json', false, FILE, false))
{
if (file == '') // default
continue;

var variationWithoutDash:String = file.substring(0, file.length - 1);
_variations.push(variationWithoutDash);
}

return _variations;
}
}
9 changes: 9 additions & 0 deletions src/funkin/structures/SongStructure.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package funkin.structures;

typedef SongMetadata =
{
/**
* The name of the song.
*/
var name:String;
}
5 changes: 4 additions & 1 deletion src/funkin/util/Week.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package funkin.util;

import funkin.data.song.Song;
import funkin.structures.WeekStructure;
import haxe.Json;

Expand Down Expand Up @@ -60,7 +61,9 @@ class Week

for (id in songIds)
{
displayNames.push(id);
var songObject:Song = Song.getSongByID(id);
var songName:String = songObject?.getDisplayName('default') ?? id;
displayNames.push(songName);
}

return displayNames;
Expand Down

0 comments on commit d5cb5f9

Please sign in to comment.