You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

import os
import json
class UserControls:
def __init__(self):
print("UserControls init")
self.configs = self.get_config()
def get_config(self):
configs = {}
for file in os.listdir("conf"):
if file.endswith(".json"):
with open(os.path.join("conf", file)) as f:
configs[file[:-5]] = json.load(f)
return configs
def handle_events(self, mapping, event):
if event.startswith("MOUSEMOTION"):
x, y = event.split(":")[1:]
self.game.set_cursor(int(x), int(y))
if method := self.configs[mapping].get(event):
getattr(self, method)()
def scroll_up(self):
self.graphics.view_offset_y += 10
def scroll_down(self):
self.graphics.view_offset_y -= 10
def scroll_left(self):
self.graphics.view_offset_x += 10
def scroll_right(self):
self.graphics.view_offset_x -= 10
def zoom_in(self):
self.graphics.set_scaling_factor(self.graphics.scaling_factor + 0.1)
def zoom_out(self):
self.graphics.set_scaling_factor(self.graphics.scaling_factor - 0.1)