Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
89 lines (76 loc) · 2.73 KB
/
Copy pathapp.py
File metadata and controls
89 lines (76 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import json
import os
import shutil
import webview
# Setup user data folder in Application Support
USER_NAME = os.path.expanduser('~').split('/')[-1]
SUPPORT_DIR = os.path.expanduser('~/Library/Application Support/Forsaken_Legends-Cursed_Isle')
os.makedirs(SUPPORT_DIR, exist_ok=True)
# Bundled data location
BUNDLED_DATA_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data.json')
# User data location
DATA_FILE = os.path.join(SUPPORT_DIR, 'data.json')
# Copy bundled data.json if support folder is new
if not os.path.exists(DATA_FILE):
shutil.copy(BUNDLED_DATA_FILE, DATA_FILE)
class Api:
def _read_bundled_data(self):
"""Read the bundled data.json template"""
if not os.path.exists(BUNDLED_DATA_FILE):
return {}
try:
with open(BUNDLED_DATA_FILE, 'r', encoding='utf-8') as f:
return json.load(f)
except Exception:
return {}
def _read_data(self):
"""Read user's local data"""
if not os.path.exists(DATA_FILE):
return {}
try:
with open(DATA_FILE, 'r', encoding='utf-8') as f:
data = json.load(f)
return data if isinstance(data, dict) else {}
except Exception:
return {}
def _write_data(self, data):
"""Write user's local data"""
with open(DATA_FILE, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2)
def _migrate_data(self):
"""Merge bundled fields into local data, preserve slots and update version"""
local_data = self._read_data()
bundled_data = self._read_bundled_data()
# Update version to bundled version
if 'Version' in bundled_data:
local_data['Version'] = bundled_data['Version']
# Add any new fields from bundled data (except slots)
for key, value in bundled_data.items():
if key not in local_data and not key.startswith('slot'):
local_data[key] = value
self._write_data(local_data)
return local_data
def save_slot(self, slot, name, value):
data = self._migrate_data()
data[f'slot{slot}'] = {
'name': name,
'value': value
}
self._write_data(data)
return True
def get_all_saves(self):
data = self._migrate_data()
return data
if __name__ == '__main__':
api = Api()
INDEX_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'index.html')
webview.create_window(
'Forsaken Legends Cursed Isle',
INDEX_FILE,
js_api=api,
width=1100,
height=900,
min_size=(960, 720),
resizable=True
)
webview.start(http_server=True)