Skip to content

Commit

Permalink
(agrf) Test get_fingerprint.
Browse files Browse the repository at this point in the history
Note that the methods getting tested are also modified, let's hope this doesn't break anything -- we are refactoring away this code anyways.
  • Loading branch information
ahyangyi committed Jan 9, 2025
1 parent 3e82253 commit ff98e72
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions agrf/lib/building/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions agrf/lib/building/layout_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()

Expand 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()

Expand Down

0 comments on commit ff98e72

Please sign in to comment.