Skip to content

Commit 0c113d1

Browse files
committed
Reapply "...": deduping foundation sprite seems to be buggy and does not
This reverts commit 757f443.
1 parent 757f443 commit 0c113d1

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

agrf/global_cache/digest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import json
2+
import hashlib
3+
4+
5+
def digest(fingerprint):
6+
return hashlib.sha384(json.dumps(fingerprint, sort_keys=True).encode()).hexdigest()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from agrf.graphics.sprites.foundation import FoundationSprite
2+
from .digest import digest
3+
4+
CACHE = {}
5+
6+
7+
def make_foundation_sprite(*args, **kwargs):
8+
ret = FoundationSprite(*args, **kwargs)
9+
dig = digest(ret.get_fingerprint())
10+
11+
if dig not in CACHE:
12+
CACHE[dig] = ret
13+
return CACHE[dig]

agrf/global_cache/switch.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import json
2-
import hashlib
31
import grf
42
from agrf.magic import Switch
53
from agrf.lib.building.foundation import Foundation
4+
from .digest import digest
65

76
switch_cache = {}
87

@@ -22,7 +21,7 @@ def switch_fingerprint(s):
2221

2322

2423
def switch_hash(s):
25-
return hashlib.sha384(json.dumps(switch_fingerprint(s), sort_keys=True).encode()).hexdigest()
24+
return digest(switch_fingerprint(s))
2625

2726

2827
def make_switch(ranges, default, code):

agrf/lib/building/foundation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import dataclass, replace
55
from dataclass_type_validator import dataclass_type_validator
66
from agrf.graphics import SCALE_TO_ZOOM
7-
from agrf.graphics.sprites.foundation import FoundationSprite
7+
from agrf.global_cache.foundation_sprite import make_foundation_sprite
88
from agrf.graphics.helpers.blend import blend_alternative_sprites
99
from agrf.magic import CachedFunctorMixin
1010

@@ -129,7 +129,7 @@ def make_foundations_subset(self, subset):
129129
g = None
130130

131131
if s is not None or g is not None:
132-
fs = FoundationSprite(
132+
fs = make_foundation_sprite(
133133
s, g, l, r, self.cut_inside, zshift=self.zshift, zoffset=(8 if style == "ground" else 0)
134134
)
135135
alts.append(fs)

0 commit comments

Comments
 (0)