Add new game assets and update asset paths in code
This commit is contained in:
1 parent
53e98cf3fe
commit
69484866db
20 files changed
+228
-36
No files matched your search
@@ -3,7 +3,7 @@ import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from PIL import Image
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
import asset_pipeline
|
||||
|
||||
@@ -51,6 +51,38 @@ class AssetPipelineTests(unittest.TestCase):
|
||||
self.assertEqual(asset_pipeline.audit_image(
|
||||
bad, "tile")["quality"], "bad")
|
||||
|
||||
def test_seamless_transform_makes_tile_edges_continuous(self):
|
||||
image_path = self.root / "tile.png"
|
||||
output = self.root / "seamless.png"
|
||||
image = Image.new("RGB", (512, 512))
|
||||
for x in range(512):
|
||||
for y in range(512):
|
||||
image.putpixel((x, y), (x // 2, y // 2, (x + y) // 4))
|
||||
image.save(image_path)
|
||||
|
||||
asset_pipeline.seamless_image(image_path, output)
|
||||
|
||||
self.assertEqual(asset_pipeline.audit_image(
|
||||
output, "tile")["quality"], "good")
|
||||
|
||||
def test_tile_generation_applies_seamless_transform(self):
|
||||
output = self.root / "generated_tile.png"
|
||||
args = type("Args", (), {
|
||||
"prompt": "brick", "role": "tile", "output": str(output),
|
||||
"width": None, "height": None, "transparent": False,
|
||||
"model": "test-model", "request_size": 1024,
|
||||
})()
|
||||
generated = Image.new("RGB", (512, 512), (80, 80, 80))
|
||||
for y in range(512):
|
||||
generated.putpixel((0, y), (255, 0, 0))
|
||||
|
||||
with patch.object(asset_pipeline.generate_textures, "generate_image",
|
||||
return_value=generated):
|
||||
asset_pipeline._generate(args)
|
||||
|
||||
self.assertEqual(asset_pipeline.audit_image(
|
||||
output, "tile")["quality"], "good")
|
||||
|
||||
def test_background_audit_rejects_small_image(self):
|
||||
image_path = self.root / "small.png"
|
||||
Image.new("RGB", (640, 360)).save(image_path)
|
||||
@@ -63,11 +95,27 @@ class AssetPipelineTests(unittest.TestCase):
|
||||
|
||||
def test_grayscale_vignette_is_valid_without_alpha(self):
|
||||
image_path = self.root / "vignette.png"
|
||||
Image.new("L", (512, 512), 0).save(image_path)
|
||||
image = Image.new("L", (512, 512), 0)
|
||||
draw = ImageDraw.Draw(image)
|
||||
for radius in range(255, -1, -1):
|
||||
value = int(255 * (1 - radius / 255))
|
||||
draw.ellipse((256 - radius, 256 - radius,
|
||||
256 + radius, 256 + radius), fill=value)
|
||||
image.save(image_path)
|
||||
|
||||
self.assertEqual(asset_pipeline.audit_image(
|
||||
image_path, "overlay")["quality"], "good")
|
||||
|
||||
def test_overlay_audit_rejects_blank_transparent_image(self):
|
||||
image_path = self.root / "blank_overlay.png"
|
||||
Image.new("RGBA", (512, 512), (0, 0, 0, 0)).save(image_path)
|
||||
|
||||
result = asset_pipeline.audit_image(image_path, "overlay")
|
||||
|
||||
self.assertEqual(result["quality"], "bad")
|
||||
self.assertTrue(any("near-blank frame" in error
|
||||
for error in result["errors"]))
|
||||
|
||||
def test_icon_audit_rejects_opaque_rgba_images(self):
|
||||
image_path = self.root / "opaque_icon.png"
|
||||
Image.new("RGBA", (64, 64), (255, 255, 255, 255)).save(image_path)
|
||||
@@ -78,6 +126,16 @@ class AssetPipelineTests(unittest.TestCase):
|
||||
self.assertTrue(any("transparency required" in error
|
||||
for error in result["errors"]))
|
||||
|
||||
def test_backdrop_audit_requires_transparency(self):
|
||||
image_path = self.root / "skyline.png"
|
||||
Image.new("RGB", (1024, 256), (20, 30, 40)).save(image_path)
|
||||
|
||||
result = asset_pipeline.audit_image(image_path, "backdrop")
|
||||
|
||||
self.assertEqual(result["quality"], "bad")
|
||||
self.assertTrue(any("transparency required" in error
|
||||
for error in result["errors"]))
|
||||
|
||||
def test_generation_reuses_existing_backend_and_targets_role_dimensions(self):
|
||||
output = self.root / "background.png"
|
||||
args = type("Args", (), {
|
||||
@@ -93,9 +151,43 @@ class AssetPipelineTests(unittest.TestCase):
|
||||
|
||||
self.assertIn("Hollywood at night", backend.call_args.args[0])
|
||||
self.assertIn("wide 16:9", backend.call_args.args[0])
|
||||
self.assertEqual(backend.call_args.kwargs["aspect_ratio"], "3:2")
|
||||
with Image.open(output) as image:
|
||||
self.assertEqual(image.size, (1920, 1080))
|
||||
|
||||
def test_generation_can_recolor_transparent_glyph(self):
|
||||
output = self.root / "icon.png"
|
||||
args = type("Args", (), {
|
||||
"prompt": "flashlight", "role": "icon", "output": str(output),
|
||||
"width": None, "height": None, "transparent": True,
|
||||
"model": "test-model", "request_size": 1024,
|
||||
"foreground": (255, 255, 255, 255),
|
||||
})()
|
||||
generated = Image.new("RGBA", (64, 64), (0, 0, 0, 0))
|
||||
generated.putpixel((32, 32), (20, 20, 20, 255))
|
||||
|
||||
with patch.object(asset_pipeline.generate_textures, "generate_image",
|
||||
return_value=generated):
|
||||
asset_pipeline._generate(args)
|
||||
|
||||
with Image.open(output) as image:
|
||||
self.assertEqual(image.getpixel((32, 32)), (255, 255, 255, 255))
|
||||
self.assertEqual(image.getpixel((0, 0))[3], 0)
|
||||
|
||||
def test_screenshot_audit_accepts_game_frame_and_rejects_blank_capture(self):
|
||||
valid = self.root / "frame.png"
|
||||
blank = self.root / "blank.png"
|
||||
frame = Image.new("RGB", (1280, 720), (0, 0, 0))
|
||||
ImageDraw.Draw(frame).rectangle(
|
||||
(640, 0, 1279, 719), fill=(255, 255, 255))
|
||||
frame.save(valid)
|
||||
Image.new("RGB", (1280, 720), (0, 0, 0)).save(blank)
|
||||
|
||||
self.assertEqual(asset_pipeline.audit_image(
|
||||
valid, "screenshot")["quality"], "good")
|
||||
self.assertEqual(asset_pipeline.audit_image(
|
||||
blank, "screenshot")["quality"], "bad")
|
||||
|
||||
def test_role_inference_uses_game_asset_paths(self):
|
||||
self.assertEqual(asset_pipeline.infer_role(
|
||||
Path("assets/textures/icons/wand.png")), "icon")
|
||||
@@ -104,6 +196,12 @@ class AssetPipelineTests(unittest.TestCase):
|
||||
self.assertEqual(asset_pipeline.infer_role(
|
||||
Path("assets/textures/skyline.png")), "backdrop")
|
||||
|
||||
def test_role_generator_defaults_to_validated_image_model(self):
|
||||
args = asset_pipeline.build_parser().parse_args([
|
||||
"generate", "--prompt", "test", "--role", "tile", "--output", "tile.png"])
|
||||
|
||||
self.assertEqual(args.model, asset_pipeline.DEFAULT_ROLE_IMAGE_MODEL)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user