Skip to content

Commit

Permalink
pppp
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesisfeline committed Jun 28, 2024
1 parent 0e34515 commit bb38d50
Show file tree
Hide file tree
Showing 6 changed files with 499 additions and 3 deletions.
2 changes: 1 addition & 1 deletion source/funkin/play/PauseSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ class PauseSubState extends MusicBeatSubState
FlxTransitionableState.skipNextTransOut = true;
state.openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new funkin.ui.options.OptionsState()));
}

/**
* Quit the game and return to the chart editor.
* @param state The current PauseSubState.
Expand Down
3 changes: 2 additions & 1 deletion source/funkin/play/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,7 @@ class PlayState extends MusicBeatSubState
// Skip this if the music is paused (GameOver, Pause menu, start-of-song offset, etc.)
if (!FlxG.sound.music.playing) return;

FlxG.sound.music.pause();
vocals.pause();

FlxG.sound.music.time = Conductor.instance.songPosition;
Expand Down Expand Up @@ -2703,7 +2704,7 @@ class PlayState extends MusicBeatSubState
vocals.playerVolume = 0;

applyScore(-10, 'miss', healthChange, true);
songMisses += 1;
songMisses += 1;
if (playSound)
{
vocals.playerVolume = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ChartEditorDropdowns
{
dropDown.dataSource.clear();

var returnValue:DropDownEntry = lookupNoteKind('~CUSTOM');
var returnValue:DropDownEntry = lookupNoteKind('~CUSTOM~');

for (noteKindId in NOTE_KINDS.keys())
{
Expand Down
31 changes: 31 additions & 0 deletions source/funkin/util/MathUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ class MathUtil
return flixel.math.FlxMath.bound(ratio * 60 * FlxG.elapsed, 0, 1);
}

inline public static function quantize(f:Float, interval:Float)
{
return Std.int((f + interval / 2) / interval) * interval;
}

public static function numberArray(max:Int, ?min = 0):Array<Int>
{
var dumbArray:Array<Int> = [];
for (i in min...max)
dumbArray.push(i);
return dumbArray;
}

public static function truncateFloat(number:Float, precision:Int):Float
{
var num = number;
num = num * Math.pow(10, precision);
num = Math.round(num) / Math.pow(10, precision);
return num;
}

public static function easeInOutCirc(x:Float):Float
{
if (x <= 0.0) return 0.0;
Expand Down Expand Up @@ -103,6 +124,16 @@ class MathUtil
return 1 + (c + 1) * Math.pow(x - 1, 3) + c * Math.pow(x - 1, 2);
}

public static inline function addZeros(str:String, num:Int)
{
while (str.length < num)
str = '0${str}';
return str;
}

inline public static function GCD(a, b)
return b == 0 ? FlxMath.absInt(a) : GCD(b, a % b);

/**
* Get the base-2 logarithm of a value.
* @param x value
Expand Down
136 changes: 136 additions & 0 deletions source/funkin/util/StructureUtil.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package funkin.util;

import funkin.util.tools.MapTools;
import haxe.DynamicAccess;

/**
* Utilities for working with anonymous structures.
*/
class StructureUtil
{
/**
* Merge two structures, with the second overwriting the first.
* Performs a SHALLOW clone, where child structures are not merged.
* @param a The base structure.
* @param b The new structure.
* @return The merged structure.
*/
public static function merge(a:Dynamic, b:Dynamic):Dynamic
{
var result:DynamicAccess<Dynamic> = Reflect.copy(a);

for (field in Reflect.fields(b))
{
result.set(field, Reflect.field(b, field));
}

return result;
}

public static function toMap(a:Dynamic):haxe.ds.Map<String, Dynamic>
{
var result:haxe.ds.Map<String, Dynamic> = [];

for (field in Reflect.fields(a))
{
result.set(field, Reflect.field(a, field));
}

return result;
}

public static function isMap(a:Dynamic):Bool
{
return Std.isOfType(a, haxe.Constraints.IMap);
}

public static function isObject(a:Dynamic):Bool
{
switch (Type.typeof(a))
{
case TObject:
return true;
default:
return false;
}
}

public static function isPrimitive(a:Dynamic):Bool
{
switch (Type.typeof(a))
{
case TInt | TFloat | TBool:
return true;
case TClass(c):
return false;
case TEnum(e):
return false;
case TObject:
return false;
case TFunction:
return false;
case TNull:
return true;
case TUnknown:
return false;
default:
return false;
}
}

/**
* Merge two structures, with the second overwriting the first.
* Performs a DEEP clone, where child structures are also merged recursively.
* @param a The base structure.
* @param b The new structure.
* @return The merged structure.
*/
public static function deepMerge(a:Dynamic, b:Dynamic):Dynamic
{
if (a == null) return b;
if (b == null) return null;
if (isPrimitive(a) && isPrimitive(b)) return b;
if (isMap(b))
{
if (isMap(a))
{
return MapTools.merge(a, b);
}
else
{
return StructureUtil.toMap(a).merge(b);
}
}
if (!Reflect.isObject(a) || !Reflect.isObject(b)) return b;
if (Std.isOfType(b, haxe.ds.StringMap))
{
if (Std.isOfType(a, haxe.ds.StringMap))
{
return MapTools.merge(a, b);
}
else
{
return StructureUtil.toMap(a).merge(b);
}
}

var result:DynamicAccess<Dynamic> = Reflect.copy(a);

for (field in Reflect.fields(b))
{
if (Reflect.isObject(b))
{
// Note that isObject also returns true for class instances,
// but we just assume that's not a problem here.
result.set(field, deepMerge(Reflect.field(result, field), Reflect.field(b, field)));
}
else
{
// If we're here, b[field] is a primitive.
result.set(field, Reflect.field(b, field));
}
}

return result;
}
}
Loading

0 comments on commit bb38d50

Please sign in to comment.