Skip to content

Commit e2242c4

Browse files
authored
Move item data to JSON files (#1)
* Move game items to json files for live editing * Attempt to fix specfile for json data * Remove conversion script * Try to fix replacement file loading for frozen bundles
1 parent 4fab40d commit e2242c4

File tree

23 files changed

+1141
-328
lines changed

23 files changed

+1141
-328
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,5 @@ tags
179179
.vscode
180180
.venv
181181
imgui.ini
182+
183+
/game/*.json

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include slimseditor/game/*.json
2+

readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,20 @@ env/bin/pip install -r requirements.txt
6969
env/bin/python setup.py develop
7070
env/bin/python -m slimseditor
7171
```
72+
73+
74+
Adding savegame items
75+
---------------------
76+
77+
Savegame item positions are defined by `.json` files in `slimseditor/game`.
78+
For prebuilt editions, these files are bundled with the application data.
79+
80+
To submit new items, or change existing item definitions,
81+
simply edit the appropriate lines in the `.json` files.
82+
The editor will re-read the `.json` files every time you open a savegame or click a `refresh` button.
83+
84+
If you are working with a prebuilt edition,
85+
you can create a folder called `game` in the directory `slimseditor.exe` is in.
86+
The editor will then search for game files in this directory instead.
87+
To get started with this, download the `.json` file for the game you're editing from GitHub,
88+
and put it in your new `game` folder.

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
url='https://github.com/maikelwever/slimseditor/',
1919
packages=['slimseditor'],
2020
ext_modules=[slimscbindings],
21+
include_package_data=True,
2122
)

slimseditor/game/__init__.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
import json
2+
import os
3+
import pkgutil
4+
import sys
5+
16
from enum import Enum
27

3-
from slimseditor.game.acit import get_acit_items
4-
from slimseditor.game.dl import get_dl_items
5-
from slimseditor.game.gc import get_gc_items
6-
from slimseditor.game.nexus import get_nexus_items
7-
from slimseditor.game.qfb import get_qfb_items
8-
from slimseditor.game.rac import get_rac_items
9-
from slimseditor.game.tod import get_tod_items
10-
from slimseditor.game.uya import get_uya_items
8+
from slimseditor.saveentry import RangedInteger, Integer, Boolean
9+
10+
11+
ITEM_CLASSES = {
12+
'RangedInteger': RangedInteger,
13+
'Integer': Integer,
14+
'Boolean': Boolean,
15+
}
16+
17+
if getattr(sys, 'frozen', False):
18+
APP_PATH = sys._MEIPASS
19+
else:
20+
APP_PATH = os.path.dirname(os.path.abspath(__file__))
1121

1222

1323
class Game(Enum):
@@ -22,12 +32,32 @@ class Game(Enum):
2232
NEXUS = "Ratchet and Clank : Into the Nexus"
2333

2434
def get_items(self):
25-
if self == Game.RAC: return get_rac_items()
26-
if self == Game.GC: return get_gc_items()
27-
if self == Game.UYA: return get_uya_items()
28-
if self == Game.DL: return get_dl_items()
29-
if self == Game.TOD: return get_tod_items()
30-
if self == Game.QFB: return get_qfb_items()
31-
if self == Game.ACIT: return get_acit_items()
32-
if self == Game.NEXUS: return get_nexus_items()
33-
return dict()
35+
return get_game_items(self)
36+
37+
38+
def get_game_file(game: Game):
39+
game_filename = '{0}.json'.format(str(game.name).lower())
40+
possible_game_folder = os.path.join(APP_PATH, 'game')
41+
if os.path.exists(possible_game_folder) and os.path.isdir(possible_game_folder):
42+
possible_filename = os.path.join(possible_game_folder, game_filename)
43+
if os.path.exists(possible_filename):
44+
with open(possible_filename, 'r') as f:
45+
return f.read()
46+
47+
return pkgutil.get_data('slimseditor.game', game_filename).decode('utf-8')
48+
49+
50+
def get_game_items(game: Game):
51+
json_data = get_game_file(game)
52+
parsed_data = json.loads(json_data)
53+
items = dict()
54+
for key, value in parsed_data.items():
55+
item_list = []
56+
for item in value:
57+
copied_item = item
58+
item_type = copied_item.pop('type')
59+
item_list.append(ITEM_CLASSES[item_type](**copied_item))
60+
61+
items[key] = item_list
62+
63+
return items

slimseditor/game/acit.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Bolt counts": []
3+
}

slimseditor/game/acit.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

slimseditor/game/dl.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Bolt counts": []
3+
}

slimseditor/game/dl.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)