Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Joalor64GH authored Jul 25, 2024
1 parent 585c987 commit 35938b5
Show file tree
Hide file tree
Showing 10 changed files with 297 additions and 326 deletions.
2 changes: 1 addition & 1 deletion Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<!-- _________________________ Application Settings _________________________ -->

<app title="Rhythmo" file="Rhythmo" main="Main" version="0.0.1" company="Joalor64" />
<app title="Rhythmo" file="Rhythmo" main="Main" version="0.0.5" company="Joalor64" />

<!-- ____________________________ Window Settings ___________________________ -->

Expand Down
109 changes: 54 additions & 55 deletions source/backend/Input.hx
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,63 @@ package backend;
import flixel.input.FlxInput.FlxInputState;

class Input {
public static var actionMap:Map<String, FlxKey> = [
"left" => SaveData.settings.keyboardBinds[0],
"down" => SaveData.settings.keyboardBinds[1],
"up" => SaveData.settings.keyboardBinds[2],
"right" => SaveData.settings.keyboardBinds[3],
"accept" => SaveData.settings.keyboardBinds[4],
"exit" => SaveData.settings.keyboardBinds[5]
];
public static var actionMap:Map<String, FlxKey> = [
"left" => SaveData.settings.keyboardBinds[0],
"down" => SaveData.settings.keyboardBinds[1],
"up" => SaveData.settings.keyboardBinds[2],
"right" => SaveData.settings.keyboardBinds[3],
"accept" => SaveData.settings.keyboardBinds[4],
"exit" => SaveData.settings.keyboardBinds[5]
];

public static function is(action:String, ?state:FlxInputState = JUST_PRESSED, ?exact:Bool = false):Bool {
if (!exact) {
if (state == PRESSED && is(action, JUST_PRESSED))
return true;
if (state == RELEASED && is(action, JUST_RELEASED))
return true;
}

return (actionMap.exists(action)) ? FlxG.keys.checkStatus(actionMap.get(action), state)
: FlxG.keys.checkStatus(FlxKey.fromString(action), state);
}
public static function is(action:String, ?state:FlxInputState = JUST_PRESSED, ?exact:Bool = false):Bool {
if (!exact) {
if (state == PRESSED && is(action, JUST_PRESSED))
return true;
if (state == RELEASED && is(action, JUST_RELEASED))
return true;
}

public static function get(action:String):FlxInputState {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;

if (gamepad != null) {
if (gamepadIs(action, JUST_PRESSED))
return JUST_PRESSED;
if (gamepadIs(action, PRESSED))
return PRESSED;
if (gamepadIs(action, JUST_RELEASED))
return JUST_RELEASED;
} else {
if (is(action, JUST_PRESSED))
return JUST_PRESSED;
if (is(action, PRESSED))
return PRESSED;
if (is(action, JUST_RELEASED))
return JUST_RELEASED;
}

return RELEASED;
}
return (actionMap.exists(action)) ? FlxG.keys.checkStatus(actionMap.get(action), state) : FlxG.keys.checkStatus(FlxKey.fromString(action), state);
}

public static var controllerMap:Map<String, FlxGamepadInputID> = [
"gamepad_left" => SaveData.settings.gamepadBinds[0],
"gamepad_down" => SaveData.settings.gamepadBinds[1],
"gamepad_up" => SaveData.settings.gamepadBinds[2],
"gamepad_right" => SaveData.settings.gamepadBinds[3],
"gamepad_accept" => SaveData.settings.gamepadBinds[4],
"gamepad_exit" => SaveData.settings.gamepadBinds[5]
];
public static function get(action:String):FlxInputState {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;

public static function gamepadIs(key:String, ?state:FlxInputState = JUST_PRESSED):Bool {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;
if (gamepad != null)
return (controllerMap.exists(key)) ? gamepad.checkStatus(controllerMap.get(key), state)
: gamepad.checkStatus(FlxGamepadInputID.fromString(key), state);
if (gamepad != null) {
if (gamepadIs(action, JUST_PRESSED))
return JUST_PRESSED;
if (gamepadIs(action, PRESSED))
return PRESSED;
if (gamepadIs(action, JUST_RELEASED))
return JUST_RELEASED;
} else {
if (is(action, JUST_PRESSED))
return JUST_PRESSED;
if (is(action, PRESSED))
return PRESSED;
if (is(action, JUST_RELEASED))
return JUST_RELEASED;
}

return false;
}
return RELEASED;
}

public static var controllerMap:Map<String, FlxGamepadInputID> = [
"gamepad_left" => SaveData.settings.gamepadBinds[0],
"gamepad_down" => SaveData.settings.gamepadBinds[1],
"gamepad_up" => SaveData.settings.gamepadBinds[2],
"gamepad_right" => SaveData.settings.gamepadBinds[3],
"gamepad_accept" => SaveData.settings.gamepadBinds[4],
"gamepad_exit" => SaveData.settings.gamepadBinds[5]
];

public static function gamepadIs(key:String, ?state:FlxInputState = JUST_PRESSED):Bool {
var gamepad:FlxGamepad = FlxG.gamepads.lastActive;
if (gamepad != null)
return (controllerMap.exists(key)) ? gamepad.checkStatus(controllerMap.get(key),
state) : gamepad.checkStatus(FlxGamepadInputID.fromString(key), state);

return false;
}
}
192 changes: 92 additions & 100 deletions source/backend/Localization.hx
Original file line number Diff line number Diff line change
Expand Up @@ -5,111 +5,103 @@ import openfl.system.Capabilities;
#end

typedef ApplicationConfig = {
var languages:Array<String>;
@:optional var directory:String;
@:optional var default_language:String;
var languages:Array<String>;
@:optional var directory:String;
@:optional var default_language:String;
}

/**
* A simple localization system.
* Please credit me if you use it!
* @author Joalor64GH
*/

class Localization
{
private static final DEFAULT_DIR:String = "languages";

private static var data:Map<String, Dynamic>;
private static var currentLanguage:String;

public static var DEFAULT_LANGUAGE:String = "en";
public static var directory:String = DEFAULT_DIR;

public static var systemLanguage(get, never):String;

public static function get_systemLanguage()
{
#if openfl
return Capabilities.language;
#else
return throw "This Variable is for OpenFl only!";
#end
}

public static function init(config:ApplicationConfig)
{
directory = config.directory ?? "languages";
DEFAULT_LANGUAGE = config.default_language ?? "en";

loadLanguages(config.languages);
switchLanguage(DEFAULT_LANGUAGE);
}

public static function loadLanguages(languages:Array<String>)
{
data = new Map<String, Dynamic>();

for (language in languages) {
var languageData:Dynamic = loadLanguageData(language);
data.set(language, languageData);
}
}

private static function loadLanguageData(language:String):Dynamic
{
var jsonContent:String;

try {
#if sys
jsonContent = File.getContent(path(language));
#else
jsonContent = Assets.getText(path(language));
#end
} catch (e) {
trace('file not found: $e');
#if sys
jsonContent = File.getContent(path(DEFAULT_LANGUAGE));
#else
jsonContent = Assets.getText(path(DEFAULT_LANGUAGE));
#end
}

return Json.parse(jsonContent);
}

public static function switchLanguage(newLanguage:String)
{
if (newLanguage == currentLanguage)
return;

var languageData:Dynamic = loadLanguageData(newLanguage);

currentLanguage = newLanguage;
data.set(newLanguage, languageData);
trace('Language changed to $currentLanguage');
}

public static function get(key:String, ?language:String):String
{
var targetLanguage:String = language ?? currentLanguage;
var languageData = data.get(targetLanguage);

if (data == null) {
trace("You haven't initialized the class!");
return null;
}

if (data.exists(targetLanguage))
if (Reflect.hasField(languageData, key))
return Reflect.field(languageData, key);

return null;
}

private static function path(language:String) {
var localDir = Path.join([directory, language + ".json"]);
var path:String = Paths.file(localDir);
return path;
}
class Localization {
private static final DEFAULT_DIR:String = "languages";

private static var data:Map<String, Dynamic>;
private static var currentLanguage:String;

public static var DEFAULT_LANGUAGE:String = "en";
public static var directory:String = DEFAULT_DIR;

public static var systemLanguage(get, never):String;

public static function get_systemLanguage() {
#if openfl
return Capabilities.language;
#else
return throw "This Variable is for OpenFl only!";
#end
}

public static function init(config:ApplicationConfig) {
directory = config.directory ?? "languages";
DEFAULT_LANGUAGE = config.default_language ?? "en";

loadLanguages(config.languages);
switchLanguage(DEFAULT_LANGUAGE);
}

public static function loadLanguages(languages:Array<String>) {
data = new Map<String, Dynamic>();

for (language in languages) {
var languageData:Dynamic = loadLanguageData(language);
data.set(language, languageData);
}
}

private static function loadLanguageData(language:String):Dynamic {
var jsonContent:String;

try {
#if sys
jsonContent = File.getContent(path(language));
#else
jsonContent = Assets.getText(path(language));
#end
} catch (e) {
trace('file not found: $e');
#if sys
jsonContent = File.getContent(path(DEFAULT_LANGUAGE));
#else
jsonContent = Assets.getText(path(DEFAULT_LANGUAGE));
#end
}

return Json.parse(jsonContent);
}

public static function switchLanguage(newLanguage:String) {
if (newLanguage == currentLanguage)
return;

var languageData:Dynamic = loadLanguageData(newLanguage);

currentLanguage = newLanguage;
data.set(newLanguage, languageData);
trace('Language changed to $currentLanguage');
}

public static function get(key:String, ?language:String):String {
var targetLanguage:String = language ?? currentLanguage;
var languageData = data.get(targetLanguage);

if (data == null) {
trace("You haven't initialized the class!");
return null;
}

if (data.exists(targetLanguage))
if (Reflect.hasField(languageData, key))
return Reflect.field(languageData, key);

return null;
}

private static function path(language:String) {
var localDir = Path.join([directory, language + ".json"]);
var path:String = Paths.file(localDir);
return path;
}
}
8 changes: 4 additions & 4 deletions source/game/GameSprite.hx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package game;

class GameSprite extends FlxSprite {
public function new(x:Float = 0, y:Float = 0) {
super(x, y);
antialiasing = SaveData.settings.antialiasing;
}
public function new(x:Float = 0, y:Float = 0) {
super(x, y);
antialiasing = SaveData.settings.antialiasing;
}
}
32 changes: 16 additions & 16 deletions source/game/Note.hx
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package game;

class Note extends GameSprite {
public var dir:String = ''; // note direction
public var type:String = ''; // receptor or plain note
public var dir:String = ''; // note direction
public var type:String = ''; // receptor or plain note

public function new(x:Float, y:Float, dir:String, type:String) {
super(x, y);
public function new(x:Float, y:Float, dir:String, type:String) {
super(x, y);

this.dir = dir;
this.type = type;
this.dir = dir;
this.type = type;

loadGraphic(Paths.image('ui/note_$dir'), true, 200, 200);
scale.set(0.6, 0.6);
loadGraphic(Paths.image('ui/note_$dir'), true, 200, 200);
scale.set(0.6, 0.6);

animation.add("note", [0], 1);
animation.add("press", [1], 1);
animation.add("receptor", [2], 1);
animation.add("note", [0], 1);
animation.add("press", [1], 1);
animation.add("receptor", [2], 1);

animation.play((type == 'receptor') ? "receptor" : "note");
}
animation.play((type == 'receptor') ? "receptor" : "note");
}

public function press() {
animation.play("press");
}
public function press() {
animation.play("press");
}
}
Loading

0 comments on commit 35938b5

Please sign in to comment.