shithub: zelda3

Download patch

ref: 5ce0996691986e7704d58e53d052fca3a1256a85
parent: 2ff515fb66263fc50bb9285208192bb22234267e
author: Snesrev <[email protected]>
date: Wed Oct 12 14:37:54 EDT 2022

functools.cache doesn't exist in Python3.8

--- a/tables/compile_resources.py
+++ b/tables/compile_resources.py
@@ -6,7 +6,7 @@
 import tables
 import compile_music
 import array, hashlib, struct
-from functools import cache
+from util import cache
 import sprite_sheets
 
 def flatten(xss):
--- a/tables/extract_resources.py
+++ b/tables/extract_resources.py
@@ -2,13 +2,12 @@
 import sys
 import text_compression
 import util
-from util import get_bytes, get_words, get_byte, get_word, get_int8, get_int16
+from util import get_bytes, get_words, get_byte, get_word, get_int8, get_int16, cache
 import tables
 import yaml
 import extract_music
 import os
 import sprite_sheets
-from functools import cache
 
 def print_map32_to_map16(f):
   for i in range(2218):
--- a/tables/sprite_sheets.py
+++ b/tables/sprite_sheets.py
@@ -1,10 +1,9 @@
 from PIL import Image
 import sprite_sheet_info
 import util
-from util import get_bytes, get_words, get_byte
+from util import get_bytes, get_words, get_byte, cache
 import array
 import tables
-from functools import cache
 
 def save_as_png(dimensions, data, fname, palette = None):
   img = Image.new('L' if palette == None else 'P', dimensions)
--- a/tables/util.py
+++ b/tables/util.py
@@ -2,7 +2,11 @@
 import sys
 import hashlib
 import os
-from functools import cache
+from functools import lru_cache
+
+def cache(user_function, /):
+  'Simple lightweight unbounded cache.  Sometimes called "memoize".'
+  return lru_cache(maxsize=None)(user_function)
 
 # Both are common SNES rom extensions. For Zelda3 (NA), they are equivalent files.
 COMMON_ROM_NAMES = ['zelda3.sfc', 'zelda3.smc']