fixed a lot of stupid bugs

This commit is contained in:
Yoshman29
2022-12-13 22:51:54 +01:00
parent 53f9389715
commit 43492f89d4
20 changed files with 75 additions and 53 deletions
+1
View File
@@ -58,6 +58,7 @@ class FlxView3D extends FlxSprite
{
Main.instance.removeChild(view);
view.dispose();
_loader.disposeWithChildren();
super.destroy();
if (bmp != null)
{
+9 -9
View File
@@ -792,10 +792,10 @@ class PlayState extends MusicBeatState
}
}
#end
// if (__wasAutoPause && __songPlaying) {
// inst.play();
// vocals.play();
// }
if (__wasAutoPause && __songPlaying) {
inst.play();
vocals.play();
}
super.onFocus();
}
@@ -809,11 +809,11 @@ class PlayState extends MusicBeatState
DiscordClient.changePresence(detailsPausedText, SONG.song + " (" + difficultyText + ")", iconRPC);
}
#end
// if (__wasAutoPause = FlxG.autoPause) {
// __songPlaying = inst.playing;
// inst.pause();
// vocals.pause();
// }
if (__wasAutoPause = FlxG.autoPause) {
__songPlaying = inst.playing;
inst.pause();
vocals.pause();
}
super.onFocusLost();
+1 -1
View File
@@ -57,7 +57,7 @@ class Stage extends FlxBasic implements IBeatReceiver {
case "sprite" | "spr" | "sparrow":
if (!node.has.sprite || !node.has.name || !node.has.x || !node.has.y) continue;
var spr = XMLUtil.createSpriteFromXML(node, spritesParentFolder);
var spr = XMLUtil.createSpriteFromXML(node, spritesParentFolder, BEAT);
if (!node.has.zoomfactor && PlayState.instance != null)
spr.initialZoom = PlayState.instance.defaultCamZoom;
+17
View File
@@ -8,7 +8,24 @@ import flixel.math.FlxMath;
import funkin.interfaces.IBeatReceiver;
import flixel.FlxSprite;
@:enum
abstract XMLAnimType(Int) {
var NONE = 0;
var BEAT = 1;
var LOOP = 2;
public static function fromString(str:String, def:XMLAnimType = NONE) {
return switch(str.trim().toLowerCase()) {
case "none": NONE;
case "beat" | "onbeat": BEAT;
case "loop": LOOP;
default: def;
}
}
}
class XMLSprite extends FlxSprite implements IBeatReceiver {
public var spriteAnimType:XMLAnimType = NONE;
public var beatAnims:Array<String> = [];
public var name:String;
public var zoomFactor:Float = 1;
+25 -2
View File
@@ -1,5 +1,6 @@
package funkin.system;
import funkin.system.XMLSprite.XMLAnimType;
import flixel.math.FlxMath;
import funkin.interfaces.IBeatReceiver;
import haxe.xml.Access;
@@ -44,15 +45,19 @@ class XMLUtil {
/**
* Creates a new sprite based on a XML node.
*/
public static function createSpriteFromXML(node:Access, parentFolder:String = "", ?cl:Class<XMLSprite>):XMLSprite {
public static function createSpriteFromXML(node:Access, parentFolder:String = "", defaultAnimType:XMLAnimType = BEAT, ?cl:Class<XMLSprite>):XMLSprite {
if (parentFolder == null) parentFolder = "";
var spr = cl != null ? Type.createInstance(cl, []) : new XMLSprite();
var spr:XMLSprite = cl != null ? Type.createInstance(cl, []) : new XMLSprite();
spr.name = node.getAtt("name");
spr.antialiasing = true;
spr.loadAnimatedGraphic(Paths.image('$parentFolder${node.getAtt("sprite")}', null, true));
spr.spriteAnimType = defaultAnimType;
if (node.has.type)
spr.spriteAnimType = XMLAnimType.fromString(node.att.type, spr.spriteAnimType);
var x:Null<Float> = node.has.x ? Std.parseFloat(node.att.x) : null;
var y:Null<Float> = node.has.y ? Std.parseFloat(node.att.y) : null;
if (x != null) spr.x = x;
@@ -91,17 +96,23 @@ class XMLUtil {
* @param anim Animation (Must be a `anim` XML node)
*/
public static function addXMLAnimation(sprite:FlxSprite, anim:Access, loop:Bool = false):ErrorCode {
var animType:XMLAnimType = NONE;
if (sprite is XMLSprite)
animType = cast(sprite, XMLSprite).spriteAnimType;
var animData:AnimData = {
name: null,
anim: null,
fps: 24,
loop: loop,
animType: animType,
x: 0,
y: 0,
indices: []
};
if (anim.has.name) animData.name = anim.att.name;
if (anim.has.type) animData.animType = XMLAnimType.fromString(anim.att.type, animData.animType);
if (anim.has.anim) animData.anim = anim.att.anim;
if (anim.has.fps) animData.fps = Std.parseInt(anim.att.fps);
if (anim.has.x) animData.x = Std.parseFloat(anim.att.x);
@@ -127,6 +138,17 @@ class XMLUtil {
if (sprite is IOffsetCompatible)
cast(sprite, IOffsetCompatible).addOffset(animData.name, animData.x, animData.y);
if (sprite is XMLSprite) {
var xmlSpr = cast(sprite, XMLSprite);
switch(animData.animType) {
case BEAT:
xmlSpr.beatAnims.push(animData.name);
case LOOP:
xmlSpr.animation.play(animData.name);
default:
// nothing
}
}
return OK;
}
return MISSING_PROPERTY;
@@ -141,4 +163,5 @@ typedef AnimData = {
var x:Float;
var y:Float;
var indices:Array<Int>;
var animType:XMLAnimType;
}