Browse Source

Add keybindings configuration in JSON and YAML formats; remove obsolete YAML file

master
Matteo Benedetto 4 months ago
parent
commit
0141063baa
  1. 32
      conf/keybindings.json
  2. 29
      conf/keybindings.yaml
  3. 21
      conf/keybindings_rg40xx.yaml
  4. 10
      engine/controls.py

32
conf/keybindings.json

@ -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"
}
}

29
conf/keybindings.yaml

@ -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

21
conf/keybindings_rg40xx.yaml

@ -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
engine/controls.py

@ -2,10 +2,16 @@
# The key_pressed method is called when a key is pressed, and it contains the logic for handling different key presses.
import random
import yaml
import os
import json
# read yaml config file
bindings = {}
if os.path.exists("conf/keybindings.json"):
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)

Loading…
Cancel
Save