Skip to content

Commit

Permalink
make this a bit cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Apr 11, 2024
1 parent 31d5b85 commit 6aef31e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 34 deletions.
6 changes: 4 additions & 2 deletions source/funkin/sound/FlxFunkSound.hx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class FlxFunkSound extends FlxBasic
this.onLoad = onLoad;

if(!path.startsWith("https://")) if (!path.startsWith("./"))
path = './$path';
path = './' + (path.contains(':') ? path.split(':').unsafeGet(1) : path);

final sound = new Sound();
sound.load(new URLRequest(path));
Expand All @@ -148,7 +148,7 @@ class FlxFunkSound extends FlxBasic

public var loops(default, set):Int = 0;
inline function set_loops(value:Int):Int {
if (value < 1) loops = 1;
if (value < 1) value = 1;
return loops = source.loops = value - 1;
}

Expand Down Expand Up @@ -181,6 +181,8 @@ class FlxFunkSound extends FlxBasic
updateVolume();
}

override function draw() {}

var _lastStopTime:Int;

public function stop():Void {
Expand Down
18 changes: 17 additions & 1 deletion source/funkin/states/newchart/ChartGrid.hx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ class ChartGrid extends Group

override function update(elapsed:Float)
{
/*if (FlxG.keys.justPressed.SPACE)
{
if (Conductor.playing)
{
Conductor.songPosition = getTime();
Conductor.pause();
Conductor.sync();
}
else
{
Conductor.inst.time = Conductor.songPosition + Conductor.offset[0] + Conductor.latency;
Conductor.resume();
Conductor.sync();
}
}*/

if (Conductor.playing)
{
updatePosition();
Expand Down Expand Up @@ -127,7 +143,7 @@ class ChartGrid extends Group

// Use inst time when possible to avoid needing to sync all the time lol
inline function getTime():Float {
return Conductor.playing ? Conductor.inst.time + Conductor.offset[0] + Conductor.latency : Conductor.songPosition;
return Conductor.playing ? Conductor.inst.time - Conductor.offset[0] - Conductor.latency : Conductor.songPosition;
}

// TODO: Change the 16 with the snap later
Expand Down
18 changes: 11 additions & 7 deletions source/funkin/util/CoolUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,21 @@ class CoolUtil {
return 0;
}

public static function customSort(input:Array<String>, customOrder:Array<String>):Array<String> {
public static function customSort(input:Array<String>, sort:Array<String>):Array<String>
{
var result:Array<String> = [];
for (i in customOrder) {
if (input.contains(i)) {
result.push(i);
input.remove(i);

sort.fastForEach((file, i) -> {
if (input.contains(file))
{
result.push(file);
input.remove(file);
}
}
});

input.sort(sortAlphabetically);
return result.concat(input);
input.fastForEach((file, i) -> result.push(file));
return result;
}

public static function removeDuplicates(input:Array<String>):Array<String> {
Expand Down
55 changes: 32 additions & 23 deletions source/funkin/util/Paths.hx
Original file line number Diff line number Diff line change
Expand Up @@ -315,38 +315,47 @@ class Paths
return list;
}

static public function getModFileList(folder:String, ?extension:String, fullPath:Bool = true, global:Bool = true, curFolder:Bool = true, allFolders:Bool = false):Array<String> {
public static function getModFileList(folder:String, ?extension:String, fullPath:Bool = true, global:Bool = true, curFolder:Bool = true, allFolders:Bool = false):Array<String> {
#if MODS_ALLOWED
var fileList:Array<String> = [];
var pushFile = function(folderPath:String) {
if (FileSystem.exists(folderPath)) {
var fileSort = CoolUtil.getFileContent('$folderPath/listSort.txt').split(",");
for (i in 0...fileSort.length) {
var sortPrefix = fullPath ? '$folderPath/' : '';
var sortSuffix = extension == null || !fullPath ? "" : '.$extension';
fileSort[i] = '$sortPrefix${fileSort[i]}$sortSuffix';
}
var pushFile = (folder:String) ->
{
if (FileSystem.exists(folder))
{
var sort:Array<String> = CoolUtil.getFileContent('$folder/listSort.txt').split(",");
sort.fastForEach((file, i) -> {
var prefix = fullPath ? '$folder/' : '';
var suffix = ((extension == null) || !fullPath) ? "" : '.$extension';
sort.unsafeSet(i, prefix + file + suffix);
});

var curFolderList = [];
var dirRead = FileSystem.readDirectory(folderPath);
dirRead.sort(CoolUtil.sortAlphabetically);
for (i in dirRead) {
if (i.endsWith(extension) || extension == null)
curFolderList.push(fullPath ? '$folderPath/$i' : Path.withoutExtension(i));
}
var folderList:Array<String> = [];
FileSystem.readDirectory(folder).fastForEach((path, i) -> {
if (extension == null || path.endsWith(extension))
{
var path = fullPath ? '$folder/$path' : Path.withoutExtension(path);
folderList.push(path);
}
});

fileList = fileList.concat(CoolUtil.customSort(curFolderList, fileSort));
var sortedList = CoolUtil.customSort(folderList, sort);
sortedList.fastForEach((file, i) -> fileList.push(file));
}
};
if (global) pushFile(getModPath(folder));
if (curFolder) pushFile(getModPath('${ModdingUtil.curModFolder}/$folder'));

if (global)
pushFile(getModPath(folder));

if (curFolder)
pushFile(getModPath(ModdingUtil.curModFolder + '/$folder'));

if (allFolders) {
for (i in ModdingUtil.activeMods.keys()) {
if (ModdingUtil.activeMods.get(i))
pushFile(getModPath('$i/$folder'));
for (mod => active in ModdingUtil.activeMods) {
if (active)
pushFile(getModPath('$mod/$folder'));
}
}

return fileList;
#else
return [];
Expand Down
5 changes: 4 additions & 1 deletion source/funkin/util/song/WeekSetup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class WeekSetup {
hideFreeplay: false,
}

public static function getWeekList() {//:Array<WeekJson> {
public static function getWeekList():Array<WeekData>
{
var weeks:Array<String> = [];

// Get week json lists
Expand Down Expand Up @@ -102,6 +103,8 @@ class WeekSetup {

for (i in weeks) {
final getJson = CoolUtil.getFileContent(Paths.getPath('data/weeks/$i.json', TEXT, null, true));
if (getJson.length <= 0) continue; // dont add empty weeks

final parsedJson:WeekJson = checkWeek(Json.parse(getJson));

final _data:WeekData = {
Expand Down

0 comments on commit 6aef31e

Please sign in to comment.