Add keybindings configuration in JSON and YAML formats; remove obsolete YAML file
This commit is contained in:
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"keybinding_game": {
|
||||||
|
"keydown_Return": "spawn_rat",
|
||||||
|
"keydown_D": "kill_rat",
|
||||||
|
"keydown_M": "toggle_audio",
|
||||||
|
"keydown_F": "toggle_full_screen",
|
||||||
|
"keydown_Up": "start_scrolling|Up",
|
||||||
|
"keydown_Down": "start_scrolling|Down",
|
||||||
|
"keydown_Left": "start_scrolling|Left",
|
||||||
|
"keydown_Right": "start_scrolling|Right",
|
||||||
|
"keyup_Up": "stop_scrolling",
|
||||||
|
"keyup_Down": "stop_scrolling",
|
||||||
|
"keyup_Left": "stop_scrolling",
|
||||||
|
"keyup_Right": "stop_scrolling",
|
||||||
|
"keydown_Space": "spawn_new_bomb",
|
||||||
|
"keydown_N": "spawn_new_nuclear_bomb",
|
||||||
|
"keydown_Left_Ctrl": "spawn_new_mine",
|
||||||
|
"keydown_P": "toggle_pause"
|
||||||
|
},
|
||||||
|
"keybinding_start_menu": {
|
||||||
|
"keydown_Return": "reset_game",
|
||||||
|
"keydown_Escape": "quit_game",
|
||||||
|
"keydown_M": "toggle_audio",
|
||||||
|
"keydown_F": "toggle_full_screen"
|
||||||
|
},
|
||||||
|
"keybinding_paused": {
|
||||||
|
"keydown_Return": "reset_game",
|
||||||
|
"keydown_Escape": "quit_game",
|
||||||
|
"keydown_M": "toggle_audio",
|
||||||
|
"keydown_F": "toggle_full_screen"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
keybinding_game:
|
|
||||||
keydown_Return: spawn_rat
|
|
||||||
keydown_D: kill_rat
|
|
||||||
keydown_M: toggle_audio
|
|
||||||
keydown_F: toggle_full_screen
|
|
||||||
keydown_Up: start_scrolling|Up
|
|
||||||
keydown_Down: start_scrolling|Down
|
|
||||||
keydown_Left: start_scrolling|Left
|
|
||||||
keydown_Right: start_scrolling|Right
|
|
||||||
keyup_Up: stop_scrolling
|
|
||||||
keyup_Down: stop_scrolling
|
|
||||||
keyup_Left: stop_scrolling
|
|
||||||
keyup_Right: stop_scrolling
|
|
||||||
keydown_Space: spawn_new_bomb
|
|
||||||
keydown_N: spawn_new_nuclear_bomb
|
|
||||||
keydown_Left_Ctrl: spawn_new_mine
|
|
||||||
keydown_P: toggle_pause
|
|
||||||
|
|
||||||
keybinding_start_menu:
|
|
||||||
keydown_Return: reset_game
|
|
||||||
keydown_Escape: quit_game
|
|
||||||
keydown_M: toggle_audio
|
|
||||||
keydown_F: toggle_full_screen
|
|
||||||
|
|
||||||
keybinding_paused:
|
|
||||||
keydown_Return: reset_game
|
|
||||||
keydown_Escape: quit_game
|
|
||||||
keydown_M: toggle_audio
|
|
||||||
keydown_F: toggle_full_screen
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
keybinding_game:
|
||||||
|
joybuttondown_13: spawn_rat
|
||||||
|
joyhatmotion_0_1: start_scrolling|Up
|
||||||
|
joyhatmotion_0_4: start_scrolling|Down
|
||||||
|
joyhatmotion_0_8: start_scrolling|Left
|
||||||
|
joyhatmotion_0_2: start_scrolling|Right
|
||||||
|
joyhatmotion_0_0: stop_scrolling
|
||||||
|
joybuttondown_3: spawn_new_bomb
|
||||||
|
joybuttondown_5: spawn_new_nuclear_bomb
|
||||||
|
joybuttondown_4: spawn_new_mine
|
||||||
|
joybuttondown_10: toggle_pause
|
||||||
|
|
||||||
|
keybinding_start_menu:
|
||||||
|
joybuttondown_9: reset_game
|
||||||
|
joybuttondown_10: toggle_pause
|
||||||
|
joybuttondown_11: quit_game
|
||||||
|
|
||||||
|
keybinding_paused:
|
||||||
|
joybuttondown_9: reset_game
|
||||||
|
joybuttondown_10: toggle_pause
|
||||||
|
joybuttondown_11: quit_game
|
||||||
+10
-4
@@ -2,12 +2,18 @@
|
|||||||
# The key_pressed method is called when a key is pressed, and it contains the logic for handling different key presses.
|
# The key_pressed method is called when a key is pressed, and it contains the logic for handling different key presses.
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import yaml
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
# read yaml config file
|
|
||||||
bindings = {}
|
bindings = {}
|
||||||
with open("conf/keybindings.yaml", "r") as f:
|
if os.path.exists("conf/keybindings.json"):
|
||||||
bindings = yaml.safe_load(f)
|
with open("conf/keybindings.json", "r") as f:
|
||||||
|
bindings = json.load(f)
|
||||||
|
else:
|
||||||
|
import yaml
|
||||||
|
# read yaml config file
|
||||||
|
with open("conf/keybindings.yaml", "r") as f:
|
||||||
|
bindings = yaml.safe_load(f)
|
||||||
|
|
||||||
class KeyBindings:
|
class KeyBindings:
|
||||||
def trigger(self, action):
|
def trigger(self, action):
|
||||||
|
|||||||
Reference in New Issue
Block a user