Skip to content

Commit

Permalink
Move item data to JSON files (#1)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
maikelwever authored Jun 22, 2020
1 parent 4fab40d commit e2242c4
Show file tree
Hide file tree
Showing 23 changed files with 1,141 additions and 328 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,5 @@ tags
.vscode
.venv
imgui.ini

/game/*.json
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include slimseditor/game/*.json

17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,20 @@ env/bin/pip install -r requirements.txt
env/bin/python setup.py develop
env/bin/python -m slimseditor
```


Adding savegame items
---------------------

Savegame item positions are defined by `.json` files in `slimseditor/game`.
For prebuilt editions, these files are bundled with the application data.

To submit new items, or change existing item definitions,
simply edit the appropriate lines in the `.json` files.
The editor will re-read the `.json` files every time you open a savegame or click a `refresh` button.

If you are working with a prebuilt edition,
you can create a folder called `game` in the directory `slimseditor.exe` is in.
The editor will then search for game files in this directory instead.
To get started with this, download the `.json` file for the game you're editing from GitHub,
and put it in your new `game` folder.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
url='https://github.com/maikelwever/slimseditor/',
packages=['slimseditor'],
ext_modules=[slimscbindings],
include_package_data=True,
)
64 changes: 47 additions & 17 deletions slimseditor/game/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import json
import os
import pkgutil
import sys

from enum import Enum

from slimseditor.game.acit import get_acit_items
from slimseditor.game.dl import get_dl_items
from slimseditor.game.gc import get_gc_items
from slimseditor.game.nexus import get_nexus_items
from slimseditor.game.qfb import get_qfb_items
from slimseditor.game.rac import get_rac_items
from slimseditor.game.tod import get_tod_items
from slimseditor.game.uya import get_uya_items
from slimseditor.saveentry import RangedInteger, Integer, Boolean


ITEM_CLASSES = {
'RangedInteger': RangedInteger,
'Integer': Integer,
'Boolean': Boolean,
}

if getattr(sys, 'frozen', False):
APP_PATH = sys._MEIPASS
else:
APP_PATH = os.path.dirname(os.path.abspath(__file__))


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

def get_items(self):
if self == Game.RAC: return get_rac_items()
if self == Game.GC: return get_gc_items()
if self == Game.UYA: return get_uya_items()
if self == Game.DL: return get_dl_items()
if self == Game.TOD: return get_tod_items()
if self == Game.QFB: return get_qfb_items()
if self == Game.ACIT: return get_acit_items()
if self == Game.NEXUS: return get_nexus_items()
return dict()
return get_game_items(self)


def get_game_file(game: Game):
game_filename = '{0}.json'.format(str(game.name).lower())
possible_game_folder = os.path.join(APP_PATH, 'game')
if os.path.exists(possible_game_folder) and os.path.isdir(possible_game_folder):
possible_filename = os.path.join(possible_game_folder, game_filename)
if os.path.exists(possible_filename):
with open(possible_filename, 'r') as f:
return f.read()

return pkgutil.get_data('slimseditor.game', game_filename).decode('utf-8')


def get_game_items(game: Game):
json_data = get_game_file(game)
parsed_data = json.loads(json_data)
items = dict()
for key, value in parsed_data.items():
item_list = []
for item in value:
copied_item = item
item_type = copied_item.pop('type')
item_list.append(ITEM_CLASSES[item_type](**copied_item))

items[key] = item_list

return items
3 changes: 3 additions & 0 deletions slimseditor/game/acit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Bolt counts": []
}
10 changes: 0 additions & 10 deletions slimseditor/game/acit.py

This file was deleted.

3 changes: 3 additions & 0 deletions slimseditor/game/dl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Bolt counts": []
}
10 changes: 0 additions & 10 deletions slimseditor/game/dl.py

This file was deleted.

Loading

0 comments on commit e2242c4

Please sign in to comment.