diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..43976f4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: pyglet_demo", + "type": "debugpy", + "request": "launch", + "program": "${workspaceFolder}/pyglet_demo.py", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/engine/__init__.py b/engine/__init__.py index 3ccbe29..c7ddc81 100644 --- a/engine/__init__.py +++ b/engine/__init__.py @@ -1,3 +1,6 @@ from . import data from . import config -from . import screen \ No newline at end of file +from . import screen +from . import control +from . import input +from . import binding diff --git a/engine/binding.py b/engine/binding.py new file mode 100644 index 0000000..e69de29 diff --git a/engine/config.py b/engine/config.py index cf771f1..4c3ed3f 100644 --- a/engine/config.py +++ b/engine/config.py @@ -5,9 +5,10 @@ import sys from . import data class SettingsLoader(UserDict): - def __init__(self: object, file: str) -> None: + def __init__(self: object, files: list) -> None: self.data = {} - self.load_settings_file(file) + self.files = files + self.reload() def load_settings_file(self: object, file: str) -> None: ext = os.path.splitext(file)[1] @@ -16,6 +17,11 @@ class SettingsLoader(UserDict): self.data.update(json.load(fd)) else: raise ValueError("Cannot open this type of settings file") + + def reload(self: object) -> None: + self.data = {} + for f in self.files: + self.load_settings_file(f) class SettingsReadOnly(SettingsLoader): pass @@ -26,4 +32,4 @@ class SettingsMutable(SettingsLoader): class SettingsWritable(SettingsMutable): pass -init = SettingsWritable('init.json') +init = SettingsWritable(['init.json']) diff --git a/engine/control.py b/engine/control.py new file mode 100644 index 0000000..643c478 --- /dev/null +++ b/engine/control.py @@ -0,0 +1,21 @@ + +# an input is something the player does +# it can be instantaneous (keydown, keyup) +# it can be have duration (keypressed) +# it can be analog (joystick) +# it can be positional (mouse, touch) +# a control is a function the game provides +# it allows external control over the game +# it +# a binding is the configuration for which inputs map to which controls +# it can be 1-to-1 +# it can be left unmapped +# it may not apply in all contexts +# a context is a state in which a particular set of bindings are active +# it is a tree +# multiple contexts can be active, but only one will match and order matters +# it can add bindings, remove bindings, or redefine bindings from the context above it +# the root of the tree represents bindings that are universally active (unless removed) +# different branches of the tree apply to different sections of the game +# for example, an inventory screen may have its own context with additional or redefined bindings +# several context branches may inherit bindings from a common parent diff --git a/engine/input.py b/engine/input.py new file mode 100644 index 0000000..e69de29 diff --git a/engine/screen.py b/engine/screen.py index 0d9e45e..182e616 100644 --- a/engine/screen.py +++ b/engine/screen.py @@ -1,16 +1,25 @@ import pyglet from . import config -def auto_res(res) -> list: - return res +def auto_res(res: list) -> list: + return res + +def get_config() -> dict: + return config.init + def init_window() -> None: - res = [config.init.get('width'), config.init.get('height')] - fs = config.init.get('fullscreen') - borderless = config.init.get('borderless') - scaling = config.init.get('scaling') + global window - if fs and not borderless: + cfg = get_config() + res = [cfg.get('width'), cfg.get('height')] + fs = cfg.get('fullscreen') + borderless_fullscreen = cfg.get('borderless_fullscreen') + borderless_window = cfg.get('borderless_window') + scaling = cfg.get('scaling') + vsync = cfg.get('vsync') + + if fs and not borderless_fullscreen: # real fullscreen mode is requested # that means we need to carefully select # an available resolution @@ -18,4 +27,4 @@ def init_window() -> None: - pyglet.window.Window() \ No newline at end of file + window = pyglet.window.Window() \ No newline at end of file diff --git a/pyglet_demo.py b/pyglet_demo.py index 5868610..9d086c8 100644 --- a/pyglet_demo.py +++ b/pyglet_demo.py @@ -1,7 +1,20 @@ import pyglet import engine +import unittest + +unittest.main() engine.screen.init_window() +label = pyglet.text.Label('Hello, world', + font_name='Times New Roman', + font_size=36, + x=window.width//2, y=window.height//2, + anchor_x='center', anchor_y='center') + +@window.event +def on_draw(): + engine.screen.window.clear() + label.draw() pyglet.app.run() \ No newline at end of file diff --git a/tests/test_settings.py b/tests/test_settings.py new file mode 100644 index 0000000..db9cadc --- /dev/null +++ b/tests/test_settings.py @@ -0,0 +1,7 @@ +import unittest +import engine + +class TestSettings(unittest.TestCase): + def test_empty_settings(self: object) -> None: + engine.screen.auto_res([None, None]) + \ No newline at end of file