From b74abd7c21c3735a8010e5a9c6022936d9cd18b2 Mon Sep 17 00:00:00 2001 From: yenatch Date: Mon, 31 Aug 2015 22:31:39 -0400 Subject: [PATCH] Generalize get_base_stats. --- gfx.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gfx.py b/gfx.py index d69eaa42f..e23a0b697 100644 --- a/gfx.py +++ b/gfx.py @@ -12,12 +12,17 @@ pics = [ 'gfx/shrink2', ] -base_stats = None +cache = {} +def get_cache(filename): + global cache + cached = cache.get(filename) + if cached == None: + cached = open(filename).read() + cache[filename] = cached + return cached + def get_base_stats(): - global base_stats - if not base_stats: - base_stats = open('data/base_stats.asm').read() - return base_stats + return get_cache('data/base_stats.asm') def get_pokemon_dimensions(name): if name == 'egg':