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