Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
fixed up some character crashing stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
Leather128 committed Dec 12, 2021
1 parent dfc93d4 commit 0e9a95f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 44 deletions.
36 changes: 25 additions & 11 deletions source/game/Character.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ package game;
import flixel.FlxG;
import flixel.addons.effects.FlxTrail;
import flixel.util.FlxColor;
import modding.CharacterCreationState.SpritesheetType;
import lime.utils.Assets;
import flixel.graphics.frames.FlxFramesCollection;
import haxe.Json;
#if sys
import sys.io.File;
import polymod.backends.PolymodAssets;
#end
import utilities.CoolUtil;
import states.PlayState;
import flixel.FlxSprite;
Expand Down Expand Up @@ -48,13 +42,16 @@ class Character extends FlxSprite

public var icon:String;

var isDeathCharacter:Bool = false;

public function new(x:Float, y:Float, ?character:String = "bf", ?isPlayer:Bool = false, ?isDeathCharacter:Bool = false)
{
super(x, y);

animOffsets = new Map<String, Array<Dynamic>>();
curCharacter = character;
this.isPlayer = isPlayer;
this.isDeathCharacter = isDeathCharacter;

antialiasing = true;

Expand Down Expand Up @@ -408,7 +405,15 @@ class Character extends FlxSprite
{
var rawJson:String;

rawJson = Assets.getText(Paths.json("character data/" + characterName + "/config")).trim();
if(Assets.exists(Paths.json("character data/" + characterName + "/config")))
rawJson = Assets.getText(Paths.json("character data/" + characterName + "/config")).trim();
else
{
rawJson = Assets.getText(Paths.json("character data/bf/config")).trim();

curCharacter = "bf";
characterName = "bf";
}

var config:CharacterConfig = cast Json.parse(rawJson);

Expand Down Expand Up @@ -446,7 +451,10 @@ class Character extends FlxSprite

dancesLeftAndRight = config.dancesLeftAndRight;

frames = Paths.getSparrowAtlas('characters/' + config.imagePath, 'shared');
if(Assets.exists(Paths.file("images/characters/" + config.imagePath + ".xml", TEXT, "shared")))
frames = Paths.getSparrowAtlas('characters/' + config.imagePath, 'shared');
else if(Assets.exists(Paths.file("images/characters/" + config.imagePath + ".txt", TEXT, "shared")))
frames = Paths.getPackerAtlas('characters/' + config.imagePath, 'shared');

if(config.graphicsSize != null)
setGraphicSize(Std.int(width * config.graphicsSize));
Expand Down Expand Up @@ -474,9 +482,15 @@ class Character extends FlxSprite
}
}

playAnim("firstDeath");
playAnim("danceRight");
playAnim("idle");
if(isDeathCharacter)
playAnim("firstDeath");
else
{
if(dancesLeftAndRight)
playAnim("danceRight");
else
playAnim("idle");
}

if(debugMode)
flipX = config.defaultFlipX;
Expand Down
29 changes: 4 additions & 25 deletions source/modding/CharacterCreationState.hx
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package modding;

#if discord_rpc
import utilities.Discord.DiscordClient;
#end

import ui.FlxUIDropDownMenuCustom;
import states.MusicBeatState;
import flixel.util.FlxColor;
import states.MainMenuState;
import flixel.util.FlxTimer.FlxTimerManager;
import openfl.events.IOErrorEvent;
import openfl.events.Event;
import openfl.net.FileReference;
#if discord_rpc
import utilities.Discord.DiscordClient;
#end
import flixel.ui.FlxButton;
import openfl.display.BitmapData;
import lime.utils.Assets;
import flixel.addons.ui.FlxUICheckBox;
import flixel.text.FlxText;
Expand All @@ -25,13 +23,7 @@ import flixel.addons.ui.FlxUI;
import flixel.group.FlxGroup;
import game.Character;
import haxe.Json;
#if sys
import sys.io.File;
import sys.FileSystem;
import polymod.backends.PolymodAssets;
#end
import modding.CharacterConfig;
import flixel.FlxState;

using StringTools;

Expand All @@ -47,8 +39,6 @@ class CharacterCreationState extends MusicBeatState
public var Default_FlipX:Bool = true;
public var LeftAndRight_Idle:Bool = false;

public var Spritesheet_Type:SpritesheetType = SPARROW;

public var Animations:Array<CharacterAnimation> = [];

public var Graphics_Size:Float;
Expand Down Expand Up @@ -127,7 +117,6 @@ class CharacterCreationState extends MusicBeatState
Image_Path = CC_Data.imagePath;
Default_FlipX = CC_Data.defaultFlipX;
LeftAndRight_Idle = CC_Data.dancesLeftAndRight;
Spritesheet_Type = SPARROW;
Animations = CC_Data.animations;

if(CC_Data.graphicsSize != null)
Expand Down Expand Up @@ -287,11 +276,7 @@ class CharacterCreationState extends MusicBeatState
{
Raw_JSON_Data = "";

#if sys
Raw_JSON_Data = PolymodAssets.getText(Paths.jsonSYS("character data/" + Character_Name + "/config")).trim();
#else
Raw_JSON_Data = Assets.getText(Paths.json("character data/" + Character_Name + "/config")).trim();
#end

Read_JSON_Data();
}
Expand Down Expand Up @@ -418,10 +403,4 @@ class CharacterCreationState extends MusicBeatState
_file = null;
FlxG.log.error("Problem saving Level data");
}
}

enum SpritesheetType
{
SPARROW;
PACKER;
}
16 changes: 8 additions & 8 deletions source/ui/HealthIcon.hx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package ui;

#if sys
import polymod.backends.PolymodAssetLibrary;
import polymod.Polymod;
import polymod.backends.PolymodAssets;
#end
import openfl.display.BitmapData;
import lime.utils.Assets;
import flixel.FlxSprite;

class HealthIcon extends FlxSprite
Expand Down Expand Up @@ -36,7 +31,12 @@ class HealthIcon extends FlxSprite
{
antialiasing = true;

loadGraphic(Paths.image('icons/' + char + '-icons'), true, 150, 150);
if(Assets.exists(Paths.image('icons/' + char + '-icons'))) // LE ICONS
loadGraphic(Paths.image('icons/' + char + '-icons'), true, 150, 150);
else if(Assets.exists(Paths.image('icons/' + 'icon-' + char))) // PSYCH ICONS
loadGraphic(Paths.image('icons/' + 'icon-' + char), true, 150, 150);
else // UNKNOWN ICON
loadGraphic(Paths.image('icons/placeholder-icon'), true, 150, 150);

animation.add(char, [0, 1, 2], 0, false, isPlayer);
animation.play(char);
Expand All @@ -56,4 +56,4 @@ class HealthIcon extends FlxSprite
if (sprTracker != null)
setPosition(sprTracker.x + sprTracker.width + 10, sprTracker.y - 30);
}
}
}

0 comments on commit 0e9a95f

Please sign in to comment.