From 1bab4d89d753f402f9f11e940f4e30b4f4488f5b Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Fri, 21 Feb 2025 20:31:26 +0000 Subject: [PATCH] done with saving updated keybindings, both saving to application's RAM memory and to disk --- fcore/core-key.sml | 23 +++++++++++++++++++++++ shell/gl-draw.sml | 11 +++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/fcore/core-key.sml b/fcore/core-key.sml index cf4c90d..16de3e0 100644 --- a/fcore/core-key.sml +++ b/fcore/core-key.sml @@ -139,6 +139,7 @@ sig val keyFromString: string -> key_code option val keyToString: key_code -> string + val userKeysToString: user_key -> string val containsKey: key_code * key_code list -> bool val containsAttack: user_key * key_code list -> bool @@ -531,6 +532,28 @@ struct | KEY_RIGHT_SUPER => "KEY_RIGHT_SUPER" | KEY_MENU => "KEY_MENU" + fun userKeysToString {left, right, up, down, jump, attack, escape = _} = + String.concat + [ "ACTION_LEFT:" + , keyToString left + , "\n" + , "ACTION_RIGHT:" + , keyToString right + , "\n" + , "ACTION_UP:" + , keyToString up + , "\n" + , "ACTION_DOWN:" + , keyToString down + , "\n" + , "ACTION_JUMP:" + , keyToString jump + , "\n" + , "ACTION_ATTACK:" + , keyToString attack + , "\n" + ] + fun containsKey (searchKey, lst) = case lst of hd :: tl => hd = searchKey orelse containsKey (searchKey, tl) diff --git a/shell/gl-draw.sml b/shell/gl-draw.sml index 6001db0..33ca740 100644 --- a/shell/gl-draw.sml +++ b/shell/gl-draw.sml @@ -287,8 +287,15 @@ struct end fun saveKeys game = - let val () = InputState.setControls (#userKeys game) - in () + let + val newKeys = #userKeys game + val () = InputState.setControls newKeys + + val io = TextIO.openOut "controls.config" + val () = TextIO.output (io, CoreKey.userKeysToString newKeys) + val () = TextIO.closeOut io + in + () end fun runEffects game =