From ed8c496856e787aac48a7e364c60d440d5e4565f Mon Sep 17 00:00:00 2001 From: cecilkorik Date: Sun, 4 Feb 2024 00:23:53 -0500 Subject: [PATCH] start building skeleton WIP --- conf/README.md | 1 + conf/init.json | 2 ++ data/README.md | 1 + engine/__init__.py | 3 +++ engine/config.py | 29 +++++++++++++++++++++++++++++ engine/data.py | 17 +++++++++++++++++ engine/screen.py | 21 +++++++++++++++++++++ pyglet_demo.py | 3 +++ requirements.txt | 0 9 files changed, 77 insertions(+) create mode 100644 conf/README.md create mode 100644 conf/init.json create mode 100644 data/README.md create mode 100644 engine/__init__.py create mode 100644 engine/config.py create mode 100644 engine/data.py create mode 100644 engine/screen.py create mode 100644 pyglet_demo.py create mode 100644 requirements.txt diff --git a/conf/README.md b/conf/README.md new file mode 100644 index 0000000..fb857fe --- /dev/null +++ b/conf/README.md @@ -0,0 +1 @@ +game configuration goes here \ No newline at end of file diff --git a/conf/init.json b/conf/init.json new file mode 100644 index 0000000..2c63c08 --- /dev/null +++ b/conf/init.json @@ -0,0 +1,2 @@ +{ +} diff --git a/data/README.md b/data/README.md new file mode 100644 index 0000000..74a7c74 --- /dev/null +++ b/data/README.md @@ -0,0 +1 @@ +game data goes here \ No newline at end of file diff --git a/engine/__init__.py b/engine/__init__.py new file mode 100644 index 0000000..c316a1b --- /dev/null +++ b/engine/__init__.py @@ -0,0 +1,3 @@ +import data +import config +import screen \ No newline at end of file diff --git a/engine/config.py b/engine/config.py new file mode 100644 index 0000000..42c288d --- /dev/null +++ b/engine/config.py @@ -0,0 +1,29 @@ +import json +from collections import UserDict +import os +import sys +import data + +class SettingsLoader(UserDict): + def __init__(self: object, file: str) -> None: + self.data = {} + self.load_settings_file(file) + + def load_settings_file(self: object, file: str) -> None: + ext = os.path.splitext(file)[1] + with data.open('conf', file) as fd: + if ext == '.json': + self.data.extend(json.load(fd)) + else: + raise ValueError("Cannot open this type of settings file") + +class SettingsReadOnly(SettingsLoader): + pass + +class SettingsMutable(SettingsLoader): + pass + +class SettingsWritable(SettingsMutable): + pass + +init = SettingsWritable('init.json') diff --git a/engine/data.py b/engine/data.py new file mode 100644 index 0000000..dc5d226 --- /dev/null +++ b/engine/data.py @@ -0,0 +1,17 @@ +import os +import sys + +g_pp = None +def program_path() -> str: + global g_pp + + if g_pp == None: + g_pp = os.path.abspath(os.path.split(sys.argv[0])[0]) + + return g_pp + +def open(vault: str, path: str) -> object: + fp = os.path.join(program_path(), vault, path) + with open(fp, 'r') as fd: + return fd.read() + diff --git a/engine/screen.py b/engine/screen.py new file mode 100644 index 0000000..0d9e45e --- /dev/null +++ b/engine/screen.py @@ -0,0 +1,21 @@ +import pyglet +from . import config + +def auto_res(res) -> list: + return res + +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') + + if fs and not borderless: + # real fullscreen mode is requested + # that means we need to carefully select + # an available resolution + pass + + + + pyglet.window.Window() \ No newline at end of file diff --git a/pyglet_demo.py b/pyglet_demo.py new file mode 100644 index 0000000..e1cfec7 --- /dev/null +++ b/pyglet_demo.py @@ -0,0 +1,3 @@ +import pyglet + +pyglet.window \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29