Skip to content

Commit

Permalink
Rewritten data saving system (with no errors by now), removed Cache c…
Browse files Browse the repository at this point in the history
…lass and KeyBinds class, and added some imports to improve readability, etc.

Rewritten data saving system (with no errors by now), removed Cache class and KeyBinds class, and added some imports to improve readability, etc.
  • Loading branch information
TheGaloXx committed Apr 19, 2024
1 parent 85bb8f0 commit 6bcbadc
Show file tree
Hide file tree
Showing 46 changed files with 877 additions and 808 deletions.
109 changes: 0 additions & 109 deletions source/Cache.hx

This file was deleted.

111 changes: 69 additions & 42 deletions source/CoolUtil.hx
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package;

import lime.app.Application;
import flixel.FlxSprite;
import openfl.filters.GlowFilter;
import Discord.DiscordClient;
import flixel.graphics.frames.FlxFilterFrames;
import data.GlobalData;
import flixel.FlxG;
import flixel.math.FlxMath;
import states.PlayState;
import haxe.DynamicAccess;
import flixel.util.FlxAxes;

using StringTools;

class CoolUtil
Expand All @@ -14,10 +23,9 @@ class CoolUtil
return Language.get('Difficulties', '$difficulty');
}

//Psych Engine
inline public static function boundTo(value:Float, min:Float = 0, max:Float = 1):Float
{
return Math.max(min, Math.min(max, value));
return FlxMath.bound(value, min, max);
}

public static function getDialogue(?fromSection:String):Array<String>
Expand All @@ -26,22 +34,23 @@ class CoolUtil

if (fromSection != null)
{
var langDialogue:haxe.DynamicAccess<Dynamic> = Language.getSection(fromSection);
var langDialogue:DynamicAccess<Dynamic> = Language.getSection(fromSection);
for (idx => val in langDialogue)
{
dialogue[Std.parseInt(idx)] = val;
}

return dialogue;
}

var song = states.PlayState.SONG.song;
var song = PlayState.SONG.song;

var suffix:String = '';
if ((!data.KadeEngineData.settings.data.mechanics || PlayState.storyDifficulty == 0) && Reflect.fields(Language.getSection('${song}_Dialogue_ALT')).length > 0)
if ((!GlobalData.settings.mechanicsEnabled || PlayState.storyDifficulty == 0) && Reflect.fields(Language.getSection('${song}_Dialogue_ALT')).length > 0)
suffix = '_ALT';

// omg im so fucking smart
var langDialogue:haxe.DynamicAccess<Dynamic> = Language.getSection('${song}_Dialogue' + suffix);
var langDialogue:DynamicAccess<Dynamic> = Language.getSection('${song}_Dialogue' + suffix);
for (idx => val in langDialogue)
{
dialogue[Std.parseInt(idx)] = val;
Expand All @@ -50,50 +59,50 @@ class CoolUtil
return dialogue;
}

inline static public function sound(sound:String, library:String = '', volume:Float = 1)
static public function sound(sound:String, library:String = '', volume:Float = 1)
{
flixel.FlxG.sound.play(Paths.sound(sound, library), volume);
FlxG.sound.play(Paths.sound(sound, library), volume);
}

/**
* Function that changes the `Discord Rich Presence`.
* @param state The second line in the presence (use it for misses).
* @param details The first line in the presence (use for current state and song details).
* @param hasStartTimestamp Time left indicator (ignore).
* @param endTimestamp End time indicator (ignore).
* @param smallImageKey The small image name.
* Function that changes the `Discord Rich Presence`.
* @param state The second line in the presence (use it for misses).
* @param details The first line in the presence (use for current state and song details).
* @param hasStartTimestamp Time left indicator (ignore).
* @param endTimestamp End time indicator (ignore).
* @param smallImageKey The small image name.
**/

public static function presence(state:String, details:String, ?hasStartTimestamp:Bool, ?endTimestamp:Float, smallImageKey:String, addLittleIcon:Bool = false)
{
Discord.DiscordClient.changePresence(state, details, hasStartTimestamp, endTimestamp, smallImageKey, addLittleIcon);
DiscordClient.changePresence(state, details, hasStartTimestamp, endTimestamp, smallImageKey, addLittleIcon);
}

public static function firstLetterUpperCase(string:String):String
{
//way shorter 😍
return (string.charAt(0).toUpperCase() + string.substring(1, string.length)).replace('-', ' ');
}
{
// way shorter 😍 - yeah galo from the past you fucking love one-liners you stupid fuck 😍
return (string.charAt(0).toUpperCase() + string.substring(1, string.length)).replace('-', ' ');
}

public static function title(state:String, deleteAppTitle:Bool = false)
{
var daTitle:String = "";
if (!deleteAppTitle)
daTitle = Main.appTitle;
daTitle = 'Funkergarten' /* Main.appTitle */;

if (state != null && state != "")
daTitle = ('$daTitle - $state');

lime.app.Application.current.window.title = daTitle;
Application.current.window.title = daTitle;
}

public static function glow(sprite:flixel.FlxSprite, blurX:Int = 50, blurY = 50, color:Int = 0x000000):Void
public static function glow(sprite:FlxSprite, blurX:Int = 50, blurY = 50, color:Int = 0x000000):Void
{
//long ass code for glow effect. Got it from https://haxeflixel.com/demos/FlxSpriteFilters
flixel.graphics.frames.FlxFilterFrames.fromFrames(sprite.frames, blurX, blurY, [new openfl.filters.GlowFilter(color, sprite.alpha, blurX, blurY, 3)]).applyToSprite(sprite, false, true);
// long ass code for glow effect. Got it from https://haxeflixel.com/demos/FlxSpriteFilters
FlxFilterFrames.fromFrames(sprite.frames, blurX, blurY, [new GlowFilter(color, sprite.alpha, blurX, blurY, 3)]).applyToSprite(sprite, false, true);
}

public static function middleSprite(staticSprite:flixel.FlxSprite, toMoveSprite:flixel.FlxSprite, axes:flixel.util.FlxAxes):Void
public static function middleSprite(staticSprite:FlxSprite, toMoveSprite:FlxSprite, axes:FlxAxes):Void
{
var x = (staticSprite.x + (staticSprite.width / 2)) - (toMoveSprite.width / 2);
var y = (staticSprite.y + (staticSprite.height / 2)) - (toMoveSprite.height / 2);
Expand All @@ -103,7 +112,7 @@ class CoolUtil
else if (axes == XY) toMoveSprite.setPosition(x, y);
}

public static function size(sprite:flixel.FlxSprite, mult:Float, updateHitbox:Bool = true, height:Bool = false):Void
public static function size(sprite:FlxSprite, mult:Float, updateHitbox:Bool = true, height:Bool = false):Void
{
if (!height)
sprite.setGraphicSize(Std.int(sprite.width * mult));
Expand All @@ -123,29 +132,14 @@ class CoolUtil
public static function overlaps(spr:flixel.FlxSprite):Bool
{
// I spent hours trying to make this work, but thanks to ✦ Sword ✦ (swordcube) from the official Haxe Discord server it works now!!!
return spr.overlapsPoint(flixel.FlxG.mouse.getWorldPosition(spr.camera), true, spr.camera);
return spr.overlapsPoint(FlxG.mouse.getWorldPosition(spr.camera), true, spr.camera);
}

public inline static function normalize(path:String):String
{
return StringTools.replace(path, " ", "-").toLowerCase();
}

/*
public inline static function setFont():String
{
final language = cast (KadeEngineData.settings.data.language, String);
var font:String;
if (language == 'en_US')
font = Paths.font('Crayawn-v58y.ttf');
else
font = Paths.font("vcr.ttf");
return font;
}
*/

public static inline function convertVolume(oldValue:Float):Float
{
oldValue = FlxMath.bound(oldValue, 0, 100);
Expand All @@ -171,6 +165,39 @@ class CoolUtil
FlxG.sound.volume = CoolUtil.convertVolume(CoolUtil.volume);
Main.tray.show();
}

public static function uncachCharacters():Void
{
var characters:Int = 0;
var names:Array<String> = [];

@:privateAccess
for (key => i in FlxG.bitmap._cache)
{
// trace(key, key.contains('characters'));

if (!key.contains('characters'))
continue;

final graphic = FlxG.bitmap.get(key);

if (graphic != null)
{
if (graphic.persist)
continue;

characters++;

var path:Array<String> = key.split('/');
names.push(path.pop());

FlxG.bitmap.remove(graphic);
}
}

if (characters > 0)
trace('Cleaned $characters character sprites from the cache. ($names)');
}
}


4 changes: 2 additions & 2 deletions source/Language.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package;
it has a simpler syntax (.ini) and not the old horrible one (.xml) which can be hell sometimes (no autocompletion!!!)
*/

import lime.utils.AssetType;
import data.GlobalData;
import openfl.utils.Assets;
import SSIni;
using StringTools;
Expand All @@ -25,7 +25,7 @@ class Language
@:noCompletion
private static function get_curLang()
{
var saveLang:String = data.KadeEngineData.settings.data.language;
var saveLang:String = GlobalData.settings.language;
return (saveLang != null ? saveLang : 'en_US');
}

Expand Down
Loading

0 comments on commit 6bcbadc

Please sign in to comment.