Use dict lookup for charset and palette loading
This commit is contained in:
parent
f3c2b6b695
commit
6ab43bebc8
1 changed files with 10 additions and 6 deletions
|
|
@ -409,6 +409,8 @@ class Application:
|
|||
self.onion_renderables_prev, self.onion_renderables_next = [], []
|
||||
# lists of currently loaded character sets and palettes
|
||||
self.charsets, self.palettes = [], []
|
||||
self._charset_map = {}
|
||||
self._palette_map = {}
|
||||
self.csl = CharacterSetLord(self)
|
||||
self.pl = PaletteLord(self)
|
||||
# set/create an active art
|
||||
|
|
@ -739,12 +741,13 @@ class Application:
|
|||
# already loaded?
|
||||
base_charset_to_load = os.path.basename(charset_to_load)
|
||||
base_charset_to_load = os.path.splitext(base_charset_to_load)[0]
|
||||
for charset in self.charsets:
|
||||
if charset.base_filename == base_charset_to_load:
|
||||
return charset
|
||||
cached = self._charset_map.get(base_charset_to_load)
|
||||
if cached is not None:
|
||||
return cached
|
||||
new_charset = CharacterSet(self, charset_to_load, log)
|
||||
if new_charset.init_success:
|
||||
self.charsets.append(new_charset)
|
||||
self._charset_map[base_charset_to_load] = new_charset
|
||||
return new_charset
|
||||
elif self.ui and self.ui.active_art:
|
||||
# if init failed (eg bad filename) return something safe
|
||||
|
|
@ -753,12 +756,13 @@ class Application:
|
|||
def load_palette(self, palette_to_load, log=False):
|
||||
base_palette_to_load = os.path.basename(palette_to_load)
|
||||
base_palette_to_load = os.path.splitext(base_palette_to_load)[0]
|
||||
for palette in self.palettes:
|
||||
if palette.base_filename == base_palette_to_load:
|
||||
return palette
|
||||
cached = self._palette_map.get(base_palette_to_load)
|
||||
if cached is not None:
|
||||
return cached
|
||||
new_palette = Palette(self, palette_to_load, log)
|
||||
if new_palette.init_success:
|
||||
self.palettes.append(new_palette)
|
||||
self._palette_map[base_palette_to_load] = new_palette
|
||||
return new_palette
|
||||
elif self.ui and self.ui.active_art:
|
||||
# if init failed (eg bad filename) return something safe
|
||||
|
|
|
|||
Loading…
Reference in a new issue