Try load chunk data.
This commit is contained in:
36
tools/editortool/map/ChunkData.py
Normal file
36
tools/editortool/map/ChunkData.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import json
|
||||
|
||||
class ChunkData:
|
||||
def __init__(self):
|
||||
self.current = {}
|
||||
self.original = {}
|
||||
self.filename = None
|
||||
|
||||
def load(self, filename):
|
||||
try:
|
||||
with open(filename, 'r') as f:
|
||||
self.current = json.load(f)
|
||||
self.filename = filename
|
||||
self.original = json.loads(json.dumps(self.current)) # Deep copy
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to load chunk file: {e}")
|
||||
|
||||
def save(self, filename=None):
|
||||
fname = filename if filename else self.filename
|
||||
if not fname:
|
||||
raise ValueError("No filename specified for saving chunk.")
|
||||
try:
|
||||
with open(fname, 'w') as f:
|
||||
json.dump(self.current, f, indent=2)
|
||||
self.original = json.loads(json.dumps(self.current)) # Deep copy
|
||||
self.filename = fname
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to save chunk file: {e}")
|
||||
|
||||
def new(self):
|
||||
self.current = {}
|
||||
self.original = {}
|
||||
self.filename = None
|
||||
|
||||
def isDirty(self):
|
||||
return json.dumps(self.current, sort_keys=True) != json.dumps(self.original, sort_keys=True)
|
||||
Reference in New Issue
Block a user