Fix loading characters and improve access to outline items

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
This commit is contained in:
TheJackiMonster 2023-01-28 20:17:42 +01:00
parent 172a5b6b1c
commit d15871676c
No known key found for this signature in database
GPG key ID: D850A5F772E880F9
2 changed files with 13 additions and 0 deletions

View file

@ -144,6 +144,9 @@ class Characters:
def load(self):
self.data.clear()
if not os.path.isdir(self.dir_path):
return
for filename in os.listdir(self.dir_path):
path = os.path.join(self.dir_path, filename)
@ -160,5 +163,9 @@ class Characters:
self.data[character.UID.value] = character
def save(self):
if not self.data:
return
os.makedirs(self.dir_path, exist_ok=True)
for character in self.data.values():
character.save()

View file

@ -238,11 +238,15 @@ class Outline:
self.labels = labels
self.statuses = statuses
self.items = list()
self.cache = dict()
def __iter__(self):
return self.items.__iter__()
def getItemByID(self, ID: int) -> OutlineItem | None:
if ID in self.cache:
return self.cache.get(ID)
for item in self.all():
if item.UID.value == ID:
return item
@ -255,6 +259,7 @@ class Outline:
while len(queue) > 0:
item = queue.pop()
self.cache[item.UID.value] = item
if type(item) is OutlineFolder:
for child in item:
@ -289,6 +294,7 @@ class Outline:
def load(self):
self.items.clear()
self.cache.clear()
names = os.listdir(self.dir_path)
names.sort()