Skip to content

Commit

Permalink
update shit
Browse files Browse the repository at this point in the history
  • Loading branch information
EyeDaleHim committed Dec 4, 2023
1 parent 17a88cd commit 2d11b41
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 950 deletions.
2 changes: 2 additions & 0 deletions source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class Main extends Sprite

addChild(gameInstance);

InputHandler.init();

#if ALLOW_FLIXEL_SLEEPING
_MUTEX = new Mutex();

Expand Down
9 changes: 7 additions & 2 deletions source/MusicBeatState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class MusicBeatState extends FlxUIState
});
}

super.create();

#if SCRIPTS_ALLOWED
for (key => script in TeaScript.global)
script.call("create", []);
Expand Down Expand Up @@ -228,4 +226,11 @@ class MusicBeatState extends FlxUIState
FlxTween.tween(FlxG.sound.music, {volume: 1}, 1.5);
}
}

override public function destroy():Void
{
InputHandler.clearInputs();

super.destroy();
}
}
90 changes: 90 additions & 0 deletions source/backend/InputHandler.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package backend;

import flixel.input.keyboard.FlxKey;
import backend.data.Controls;
import openfl.events.KeyboardEvent;

class InputHandler
{
private static var _isInit:Bool = false;

private static var keyMapping:Map<Int, Array<KeyFunction>>;

public static function init():Void
{
if (_isInit)
return;

_isInit = true;

keyMapping = new Map<Int, Array<KeyFunction>>();

FlxG.stage.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent)
{
if (keyMapping.exists(e.keyCode))
{
var keyMap:Array<KeyFunction> = keyMapping.get(e.keyCode);

for (i in 0...keyMap.length)
{
if (keyMap[i].KEY_DOWN != null)
keyMap[i].KEY_DOWN();
}
}
});

FlxG.stage.addEventListener(KeyboardEvent.KEY_UP, function(e:KeyboardEvent)
{
if (keyMapping.exists(e.keyCode))
{
var keyMap:Array<KeyFunction> = keyMapping.get(e.keyCode);

for (i in 0...keyMap.length)
{
if (keyMap[i].KEY_UP != null)
keyMap[i].KEY_UP();
}
}
});
}

public static function registerControl(control:String, ?keyDown:() -> Void = null, ?keyUp:() -> Void = null):Void
{
if (!_isInit)
return;

if (Controls.instance.LIST_CONTROLS.exists(control))
{
@:privateAccess
registerKeys(Controls.instance.LIST_CONTROLS.get(control).__keys, keyDown, keyUp);
}
}

public static function registerKeys(keys:Array<Int>, ?keyDown:() -> Void = null, ?keyUp:() -> Void = null):Void
{
if (!_isInit && keys != null)
return;

for (key in keys)
{
if (!keyMapping.exists(key))
keyMapping.set(key, []);

keyMapping.get(key).push({KEY_DOWN: keyDown, KEY_UP: keyUp});
}
}

public static function clearInputs():Void
{
if (!_isInit)
return;

keyMapping.clear();
}
}

typedef KeyFunction =
{
@:optional var KEY_DOWN:() -> Void;
@:optional var KEY_UP:() -> Void;
}
2 changes: 2 additions & 0 deletions source/backend/data/Settings.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Settings
prefs = _save.data.settings ?? new Map<String, Dynamic>();
controls = _save.data.controls ?? new Map<String, Array<Int>>();

trace(controls);

onSet.set('framerate', function(value:Dynamic)
{
FlxG.drawFramerate = FlxG.updateFramerate = Std.int(FlxMath.bound(value, 60, 240));
Expand Down
11 changes: 11 additions & 0 deletions source/backend/graphic/CacheManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ class CacheManager
DYNAMIC => new Map<String, CachedAsset>()
];

public static function recursiveCache(folder:String, type:AssetTypeData):Array<CachedAsset>
{
var assets:Array<CachedAsset> = [];

if (assets.length > 0)
return assets;

trace("Found none!");
return [];
}

public static function getBitmap(key:String = ''):FlxGraphic
{
if (FlxG.bitmap.checkCache(key))
Expand Down
12 changes: 6 additions & 6 deletions source/backend/macro/Macro.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import haxe.macro.Context;

class Macro
{
macro
public static function initiateMacro()
macro public static function initiateMacro()
{
#if (haxe_ver < 4.3)
#if (haxe_ver < 4.3)
Context.fatalError('Please use Haxe 4.3.2.', (macro null).pos);
#end
return macro {}
#end
return macro
{}
}
}
}
40 changes: 0 additions & 40 deletions source/backend/query/ControlQueries.hx

This file was deleted.

3 changes: 3 additions & 0 deletions source/import.hx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ import flixel.util.FlxTimer;
import flixel.util.FlxSort;
import flixel.util.FlxDestroyUtil;

import flixel.input.keyboard.FlxKey;

import tjson.TJSON as Json;

import openfl.Assets;
import sys.FileSystem;

import backend.InputHandler;
import backend.data.Settings;
import backend.data.Controls;
import backend.InternalHelper;
Expand Down
Loading

0 comments on commit 2d11b41

Please sign in to comment.