From ff98e72f928ef7d21a3d554babdec3bebfad77fc Mon Sep 17 00:00:00 2001 From: "Yi Yang @ Anteros" Date: Thu, 9 Jan 2025 14:04:05 +0800 Subject: [PATCH] (agrf) Test get_fingerprint. Note that the methods getting tested are also modified, let's hope this doesn't break anything -- we are refactoring away this code anyways. --- agrf/lib/building/layout.py | 13 +++++++++++-- agrf/lib/building/layout_test.py | 9 +++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/agrf/lib/building/layout.py b/agrf/lib/building/layout.py index 0050b574..0328f24e 100644 --- a/agrf/lib/building/layout.py +++ b/agrf/lib/building/layout.py @@ -4,6 +4,7 @@ import functools import numpy as np from agrf.graphics import LayeredImage, SCALE_TO_ZOOM +from agrf.graphics.spritesheet import LazyAlternativeSprites from agrf.magic import CachedFunctorMixin from agrf.utils import unique_tuple from agrf.pkg import load_third_party_image @@ -221,7 +222,11 @@ def sprites(self): return unique_tuple((self.sprite,) + self.alternatives + self.sprites_from_child) def get_fingerprint(self): - return {"ground_sprite": self.sprite.get_fingerprint()} + if isinstance(self.sprite, LazyAlternativeSprites): + fingerprint = self.sprite.get_fingerprint() + else: + fingerprint = id(self.sprite) + return {"ground_sprite": fingerprint} def get_resource_files(self): return self.sprite.get_resource_files() @@ -461,7 +466,11 @@ def sprites(self): return unique_tuple((self.sprite,) + self.sprites_from_child) def get_fingerprint(self): - return {"parent_sprite": self.sprite.get_fingerprint(), "extent": self.extent, "offset": self.offset} + if isinstance(self.sprite, LazyAlternativeSprites): + fingerprint = self.sprite.get_fingerprint() + else: + fingerprint = id(self.sprite) + return {"parent_sprite": fingerprint, "extent": self.extent, "offset": self.offset} def get_resource_files(self): return self.sprite.get_resource_files() diff --git a/agrf/lib/building/layout_test.py b/agrf/lib/building/layout_test.py index 81a918c2..6f1a3923 100644 --- a/agrf/lib/building/layout_test.py +++ b/agrf/lib/building/layout_test.py @@ -1,5 +1,6 @@ import grf import numpy as np +import json from PIL import Image from station.lib import Registers from agrf.lib.building.layout import AGroundSprite, ADefaultGroundSprite, AParentSprite, AChildSprite, ALayout @@ -54,6 +55,10 @@ def test_groundsprite_to_action2(): assert isinstance(gs1012.to_action2(gs1012.sprites)[0]["sprite"], grf.SpriteRef) +def test_groundsprite_fingerprint(): + json.dumps(gs1012.get_fingerprint()) + + def test_parentsprite(): assert (temperate_1012 == ps1012.graphics(4, 32).to_image()).all() @@ -66,6 +71,10 @@ def test_parentsprite_to_action2(): assert isinstance(ps1012.to_action2(ps1012.sprites)[0]["sprite"], grf.SpriteRef) +def test_parentsprite_fingerprint(): + json.dumps(ps1012.get_fingerprint()) + + def test_layout(): assert (temperate_1012 == l1012.graphics(4, 32).to_image()).all()