@tora-editor/tora 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -58
- package/assets/free-audio/arcade-pop/audio/loss.wav +0 -0
- package/assets/free-audio/arcade-pop/audio/reward.wav +0 -0
- package/assets/free-audio/arcade-pop/audio/win.wav +0 -0
- package/assets/free-audio/arcade-pop/source/INFO.txt +11 -11
- package/assets/kenney-food-starter/License.txt +28 -0
- package/assets/kenney-food-starter/burger.glb +0 -0
- package/assets/kenney-food-starter/frying-pan.glb +0 -0
- package/assets/kenney-food-starter/plan.json +61 -0
- package/assets/kenney-food-starter/plate.glb +0 -0
- package/assets/kenney-food-starter/pot.glb +0 -0
- package/assets/kenney-harvest/audio/victory.wav +0 -0
- package/assets/kenney-harvest/source/music-jingles/OGG/jingles_NES/jingles_NES03.ogg +0 -0
- package/assets/kenney-harvest/source/music-jingles/OGG/jingles_PIZZA/jingles_PIZZA03.ogg +0 -0
- package/assets/kenney-harvest/source/music-jingles/license.txt +14 -0
- package/bin/tora.mjs +322 -28
- package/crates/packer/trusted/native-3d-meta.json +4 -3
- package/crates/packer/trusted/native-3d.js +181 -181
- package/crates/packer/trusted/native-meta.json +3 -3
- package/crates/packer/trusted/native.js +5 -5
- package/crates/packer/trusted/release-manifest.json +17 -17
- package/crates/packer/trusted/review-runtime-meta.json +4 -3
- package/crates/packer/trusted/review-runtime.js +182 -182
- package/docs/MIGRATION_0_3.md +39 -0
- package/docs/NATIVE_AGENT_TOOLS.md +12 -363
- package/docs/TORA_AGENT_SETUP.md +24 -95
- package/docs/TORA_CREATION_API.md +63 -348
- package/docs/reference/CORE_AUTHORING.md +10 -3
- package/docs/reference/PLAYABLE_STARTERS.md +20 -0
- package/docs/reference/packs/3d.md +11 -3
- package/network-rules/mintegral-appgrowth-single-html.json +10 -10
- package/package.json +6 -6
- package/packages/creative-project/project-v21.schema.json +372 -9
- package/scripts/lean/editor/entry.js +11 -6
- package/scripts/lean/editor/project-launcher.js +116 -0
- package/scripts/lean/editor/quick-edit-panel.js +479 -0
- package/scripts/lean/editor/review-editor.css +256 -68
- package/scripts/lean/editor/review-editor.js +1834 -1086
- package/scripts/lean/editor-state.mjs +6 -0
- package/scripts/lean/editor.mjs +6 -3
- package/scripts/lean/matrix.mjs +5 -0
- package/scripts/lean/native/agent-tools.mjs +39 -62
- package/scripts/lean/native/api.mjs +161 -136
- package/scripts/lean/native/asset-catalog.mjs +7 -6
- package/scripts/lean/native/asset-lineage.mjs +54 -0
- package/scripts/lean/native/asset-prep.mjs +173 -40
- package/scripts/lean/native/assets.mjs +107 -11
- package/scripts/lean/native/audio-assets.mjs +30 -0
- package/scripts/lean/native/browser-pool.mjs +34 -0
- package/scripts/lean/native/build-cache.mjs +38 -7
- package/scripts/lean/native/cc0-inputs.mjs +24 -0
- package/scripts/lean/native/cc0-staging.mjs +28 -8
- package/scripts/lean/native/compiler.mjs +9 -3
- package/scripts/lean/native/contracts.mjs +16 -11
- package/scripts/lean/native/creative-qa.mjs +365 -128
- package/scripts/lean/native/demos.mjs +53 -18
- package/scripts/lean/native/document.mjs +50 -12
- package/scripts/lean/native/export-budget.mjs +75 -0
- package/scripts/lean/native/local-bundle.mjs +7 -3
- package/scripts/lean/native/mcp-server.mjs +42 -74
- package/scripts/lean/native/media-validate.mjs +124 -0
- package/scripts/lean/native/modules/harvest-restore.mjs +3 -284
- package/scripts/lean/native/modules/sort-puzzle.mjs +51 -0
- package/scripts/lean/native/modules/star-salvage.mjs +3 -368
- package/scripts/lean/native/native-bin.mjs +3 -3
- package/scripts/lean/native/outcome-playthrough.mjs +97 -0
- package/scripts/lean/native/project-bundle.mjs +6 -5
- package/scripts/lean/native/project-index.mjs +0 -2
- package/scripts/lean/native/qa-adapters.mjs +10 -0
- package/scripts/lean/native/quick-edit.mjs +328 -0
- package/scripts/lean/native/remote-cc0-fetcher.mjs +403 -197
- package/scripts/lean/native/review.mjs +205 -571
- package/scripts/lean/native/schema-vocabulary.mjs +10 -0
- package/scripts/lean/native/schema.mjs +7 -5
- package/scripts/lean/native/scope.mjs +45 -0
- package/scripts/lean/native/service.mjs +378 -79
- package/scripts/lean/native/starters.mjs +563 -0
- package/scripts/lean/native/variant-adapters.mjs +8 -0
- package/scripts/lean/native/variants-core.mjs +186 -0
- package/scripts/lean/native/variants.mjs +63 -0
- package/scripts/lean/native/win-cues.mjs +96 -0
- package/skills/tora-playables/SKILL.md +1 -1
- package/scripts/lean/editor/review-intake.js +0 -837
- package/scripts/lean/model-client.mjs +0 -119
- package/scripts/lean/native/author-expansion-proofs.mjs +0 -240
- package/scripts/lean/native/author-games.mjs +0 -160
- package/scripts/lean/native/author-harvest.mjs +0 -74
- package/scripts/lean/native/author-primitive-proofs.mjs +0 -874
- package/scripts/lean/native/author-salvage.mjs +0 -71
- package/scripts/lean/native/chat-compose.mjs +0 -287
- package/scripts/lean/native/check-harvest-outcome-audio.mjs +0 -191
- package/scripts/lean/native/check-salvage.mjs +0 -197
- package/scripts/lean/native/compatibility.mjs +0 -34
- package/scripts/lean/native/concept.mjs +0 -633
- package/scripts/lean/native/draw-stroke.mjs +0 -26
- package/scripts/lean/native/erase-mask.mjs +0 -18
- package/scripts/lean/native/harvest-recipe.mjs +0 -21
- package/scripts/lean/native/instance-steering.mjs +0 -24
- package/scripts/lean/native/intake-creator-agent.mjs +0 -98
- package/scripts/lean/native/intake-creator-tools.mjs +0 -165
- package/scripts/lean/native/interaction-gestures.mjs +0 -45
- package/scripts/lean/native/match-board.mjs +0 -138
- package/scripts/lean/native/modules/index.mjs +0 -54
- package/scripts/lean/native/modules/tap-collect.mjs +0 -54
- package/scripts/lean/native/path-network.mjs +0 -132
- package/scripts/lean/native/physics-2d.mjs +0 -154
- package/scripts/lean/native/physics-3d.mjs +0 -259
- package/scripts/lean/native/prepare-audio-collections.mjs +0 -112
- package/scripts/lean/native/prepare-game-audio.mjs +0 -372
- package/scripts/lean/native/prepare-golf-3d-assets.py +0 -177
- package/scripts/lean/native/prepare-golf-assets.py +0 -211
- package/scripts/lean/native/prepare-harvest-audio.mjs +0 -83
- package/scripts/lean/native/prepare-harvest-images.mjs +0 -31
- package/scripts/lean/native/prepare-primitive-images.py +0 -25
- package/scripts/lean/native/prepare-space-salvage-images.mjs +0 -89
- package/scripts/lean/native/prepare-traffic-assets.py +0 -329
- package/scripts/lean/native/presentation.mjs +0 -335
- package/scripts/lean/native/review-agent-tools.mjs +0 -561
- package/scripts/lean/native/review-connection.mjs +0 -303
- package/scripts/lean/native/review-fields.mjs +0 -24
- package/scripts/lean/native/review-intake.mjs +0 -385
- package/scripts/lean/native/review-intents.mjs +0 -217
- package/scripts/lean/native/review-provider.mjs +0 -580
- package/scripts/lean/native/review-receipts.mjs +0 -76
- package/scripts/lean/native/review-resolver.mjs +0 -429
- package/scripts/lean/native/review-targets.mjs +0 -35
- package/scripts/lean/native/runtime.mjs +0 -1623
- package/scripts/lean/native/salvage-recipe.mjs +0 -20
- package/scripts/lean/native/stage-3d.mjs +0 -818
- package/scripts/lean/native/verify.mjs +0 -4
- package/scripts/lean/scene-document.mjs +0 -48
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Prepare rich Kenney CC0 sunlit waterfront isometric city assets for Traffic Tycoon."""
|
|
3
|
-
import hashlib
|
|
4
|
-
import json
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from PIL import Image, ImageDraw
|
|
7
|
-
|
|
8
|
-
ROOT = Path(__file__).resolve().parents[3]
|
|
9
|
-
SRC = ROOT / "fixtures" / "traffic-tycoon" / "assets"
|
|
10
|
-
ORIG_CITY = ROOT / ".data" / "T028" / "originals" / "isometric-tiles-city" / "PNG"
|
|
11
|
-
ORIG_LAND = ROOT / ".data" / "T028" / "originals" / "isometric-tiles-landscape" / "PNG"
|
|
12
|
-
ORIG_VEH = ROOT / ".data" / "T028" / "originals" / "isometric-tiles-vehicles" / "PNG"
|
|
13
|
-
OUT = ROOT / "assets" / "tora-traffic" / "imported"
|
|
14
|
-
PLAN_PATH = ROOT / "assets" / "tora-traffic" / "plan.json"
|
|
15
|
-
OUT.mkdir(parents=True, exist_ok=True)
|
|
16
|
-
|
|
17
|
-
HALF_W = 66
|
|
18
|
-
HALF_H = 33
|
|
19
|
-
COLS = 7 # x = 0..6
|
|
20
|
-
ROWS = 6 # y = 0..5 (row 5 is sparkling turquoise waterfront harbor!)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def project(x: float, y: float) -> tuple[float, float]:
|
|
24
|
-
return ((x - y) * HALF_W, (x + y) * HALF_H)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ORIGIN_X = 408
|
|
28
|
-
ORIGIN_Y = 66
|
|
29
|
-
CANVAS_W = 884
|
|
30
|
-
CANVAS_H = 490
|
|
31
|
-
OUT_W = 680
|
|
32
|
-
OUT_H = 377
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def sha256_file(path: Path) -> str:
|
|
36
|
-
return "sha256:" + hashlib.sha256(path.read_bytes()).hexdigest()
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def load_rgba(src) -> Image.Image:
|
|
40
|
-
p = Path(src)
|
|
41
|
-
if p.is_absolute():
|
|
42
|
-
return Image.open(p).convert("RGBA")
|
|
43
|
-
return Image.open(SRC / src).convert("RGBA")
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def save_compact_png(im: Image.Image, dest: Path, colors: int = 256) -> Path:
|
|
47
|
-
"""Save compact quantized PNG-8 with full alpha preservation for lean standalone HTML bundles."""
|
|
48
|
-
q = im.convert("RGBA").quantize(colors=colors, method=Image.Quantize.FASTOCTREE, dither=Image.Dither.NONE)
|
|
49
|
-
q.save(dest, format="PNG", optimize=True)
|
|
50
|
-
return dest
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def paste_tile(canvas: Image.Image, tile: Image.Image, x: float, y: float, y_lift: int = 0):
|
|
54
|
-
sx, sy = project(x, y)
|
|
55
|
-
w, h = tile.size
|
|
56
|
-
px = int(round(ORIGIN_X + sx - w / 2))
|
|
57
|
-
py = int(round(ORIGIN_Y + sy + 66 - h - y_lift))
|
|
58
|
-
canvas.alpha_composite(tile, (px, py))
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def mask_top_diamond(tile: Image.Image) -> Image.Image:
|
|
62
|
-
"""Mask an isometric 132x101 tile to its exact top diamond surface."""
|
|
63
|
-
mask = Image.new("L", tile.size, 0)
|
|
64
|
-
md = ImageDraw.Draw(mask)
|
|
65
|
-
md.polygon([(66, 0), (132, 33), (66, 67), (0, 33)], fill=255)
|
|
66
|
-
out = Image.new("RGBA", tile.size, (0, 0, 0, 0))
|
|
67
|
-
out.paste(tile, (0, 0), mask)
|
|
68
|
-
return out
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# S-curve Express Highway across the sunlit waterfront city:
|
|
72
|
-
# Depot (0,4) -> Crosswalk (1,4) -> GAP 1 (1,3) -> Curve TL (1,2) -> Lamp Avenue (2,2)
|
|
73
|
-
# -> GAP 2 (3,2) -> Curve BR (4,2) -> GAP 3 (4,1) -> Market Crosswalk (4,0) -> Market (5,0)
|
|
74
|
-
# Plus live ambient Waterfront Boulevard along row y=4: (2,4) <-> (5,4) right beside the turquoise harbor!
|
|
75
|
-
GAP_TILES = {
|
|
76
|
-
"gap1": (1, 3, "y"),
|
|
77
|
-
"gap2": (3, 2, "x"),
|
|
78
|
-
"gap3": (4, 1, "y"),
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def build_city_base() -> tuple[Path, list[Path]]:
|
|
83
|
-
"""Tile Kenney CC0 waterfront harbor, tree-lined boulevards, crosswalks, plazas, and 3 crisp blueprint road gaps."""
|
|
84
|
-
canvas = Image.new("RGBA", (CANVAS_W, CANVAS_H), (0, 0, 0, 0))
|
|
85
|
-
|
|
86
|
-
grass_p = ORIG_LAND / "landscapeTiles_067.png"
|
|
87
|
-
water_p = ORIG_LAND / "landscapeTiles_066.png"
|
|
88
|
-
plaza_p = SRC / "city74.png"
|
|
89
|
-
planter_p = ORIG_CITY / "cityTiles_067.png"
|
|
90
|
-
canal_p = SRC / "city52.png"
|
|
91
|
-
road_x_p = SRC / "city73.png"
|
|
92
|
-
road_y_p = SRC / "city81.png"
|
|
93
|
-
road_x_trees_p = SRC / "city36.png"
|
|
94
|
-
road_x_lamp_p = SRC / "city57.png"
|
|
95
|
-
road_y_cross_p = SRC / "city56.png"
|
|
96
|
-
road_y_cross2_p = SRC / "city64.png"
|
|
97
|
-
corner_tl_p = ORIG_CITY / "cityTiles_122.png"
|
|
98
|
-
corner_br_p = ORIG_CITY / "cityTiles_126.png"
|
|
99
|
-
|
|
100
|
-
grass = load_rgba(grass_p)
|
|
101
|
-
water = load_rgba(water_p)
|
|
102
|
-
plaza = load_rgba(plaza_p)
|
|
103
|
-
planter = load_rgba(planter_p)
|
|
104
|
-
canal = load_rgba(canal_p)
|
|
105
|
-
road_x = load_rgba(road_x_p)
|
|
106
|
-
road_y = load_rgba(road_y_p)
|
|
107
|
-
road_x_trees = load_rgba(road_x_trees_p)
|
|
108
|
-
road_x_lamp = load_rgba(road_x_lamp_p)
|
|
109
|
-
road_y_cross = load_rgba(road_y_cross_p)
|
|
110
|
-
road_y_cross2 = load_rgba(road_y_cross2_p)
|
|
111
|
-
corner_tl = load_rgba(corner_tl_p)
|
|
112
|
-
corner_br = load_rgba(corner_br_p)
|
|
113
|
-
|
|
114
|
-
building_lots = {(0, 4), (5, 0), (0, 1), (2, 0), (2, 3), (6, 1), (6, 2), (5, 3)}
|
|
115
|
-
planter_lots = {(1, 0), (3, 0), (1, 1), (5, 1), (0, 3), (4, 3), (6, 4)}
|
|
116
|
-
waterfront_x_trees = {(2, 4), (5, 4)}
|
|
117
|
-
waterfront_x_lamp = {(3, 4)}
|
|
118
|
-
waterfront_x_plain = {(4, 4)}
|
|
119
|
-
|
|
120
|
-
for s in range(COLS + ROWS - 1):
|
|
121
|
-
for x in range(COLS):
|
|
122
|
-
y = s - x
|
|
123
|
-
if y < 0 or y >= ROWS:
|
|
124
|
-
continue
|
|
125
|
-
pos = (x, y)
|
|
126
|
-
if y == 5:
|
|
127
|
-
# Sparkling turquoise harbor edge framing the southern waterfront!
|
|
128
|
-
paste_tile(canvas, water, x, y, y_lift=-4)
|
|
129
|
-
elif pos == (1, 2):
|
|
130
|
-
paste_tile(canvas, corner_tl, x, y)
|
|
131
|
-
elif pos == (4, 2):
|
|
132
|
-
paste_tile(canvas, corner_br, x, y)
|
|
133
|
-
elif pos == (1, 4):
|
|
134
|
-
paste_tile(canvas, road_y_cross, x, y)
|
|
135
|
-
elif pos == (4, 0):
|
|
136
|
-
paste_tile(canvas, road_y_cross2, x, y)
|
|
137
|
-
elif pos == (2, 2):
|
|
138
|
-
paste_tile(canvas, road_x_lamp, x, y)
|
|
139
|
-
elif pos in waterfront_x_trees:
|
|
140
|
-
paste_tile(canvas, road_x_trees, x, y)
|
|
141
|
-
elif pos in waterfront_x_lamp:
|
|
142
|
-
paste_tile(canvas, road_x_lamp, x, y)
|
|
143
|
-
elif pos in waterfront_x_plain:
|
|
144
|
-
paste_tile(canvas, road_x, x, y)
|
|
145
|
-
elif pos == (3, 1):
|
|
146
|
-
paste_tile(canvas, canal, x, y)
|
|
147
|
-
elif pos in planter_lots:
|
|
148
|
-
paste_tile(canvas, planter, x, y)
|
|
149
|
-
elif pos in building_lots:
|
|
150
|
-
paste_tile(canvas, plaza, x, y)
|
|
151
|
-
elif pos in {(1, 3), (3, 2), (4, 1)}:
|
|
152
|
-
# Clean concrete foundation base under each missing road slot
|
|
153
|
-
paste_tile(canvas, plaza, x, y)
|
|
154
|
-
else:
|
|
155
|
-
paste_tile(canvas, grass, x, y, y_lift=2)
|
|
156
|
-
|
|
157
|
-
# Crisp sunlit architectural road-blueprint markings right inside the 3 missing road slots
|
|
158
|
-
# (clean open center, subtle dashed lane guide — zero heavy opaque clutter!)
|
|
159
|
-
overlay = Image.new("RGBA", (CANVAS_W, CANVAS_H), (0, 0, 0, 0))
|
|
160
|
-
draw = ImageDraw.Draw(overlay)
|
|
161
|
-
for _name, (gx, gy, axis) in GAP_TILES.items():
|
|
162
|
-
sx, sy = project(gx, gy)
|
|
163
|
-
ox, oy = ORIGIN_X + sx, ORIGIN_Y + sy
|
|
164
|
-
outer = [(ox, oy - 30), (ox + 60, oy), (ox, oy + 30), (ox - 60, oy)]
|
|
165
|
-
inner = [(ox, oy - 22), (ox + 44, oy), (ox, oy + 22), (ox - 44, oy)]
|
|
166
|
-
draw.polygon(outer, fill=(40, 82, 102, 130), outline=(255, 214, 72, 235))
|
|
167
|
-
draw.polygon(inner, fill=(255, 216, 84, 58), outline=(255, 248, 218, 220))
|
|
168
|
-
if axis == "y":
|
|
169
|
-
draw.line([(ox - 24, oy + 12), (ox - 8, oy + 4)], fill=(255, 250, 224, 245), width=4)
|
|
170
|
-
draw.line([(ox + 8, oy - 4), (ox + 24, oy - 12)], fill=(255, 250, 224, 245), width=4)
|
|
171
|
-
else:
|
|
172
|
-
draw.line([(ox - 24, oy - 12), (ox - 8, oy - 4)], fill=(255, 250, 224, 245), width=4)
|
|
173
|
-
draw.line([(ox + 8, oy + 4), (ox + 24, oy + 12)], fill=(255, 250, 224, 245), width=4)
|
|
174
|
-
canvas.alpha_composite(overlay)
|
|
175
|
-
|
|
176
|
-
out_img = canvas.resize((OUT_W, OUT_H), Image.Resampling.LANCZOS)
|
|
177
|
-
dest = save_compact_png(out_img, OUT / "city.base.png", colors=256)
|
|
178
|
-
sources = [
|
|
179
|
-
grass_p, water_p, plaza_p, planter_p, canal_p,
|
|
180
|
-
road_x_p, road_y_p, road_x_trees_p, road_x_lamp_p,
|
|
181
|
-
road_y_cross_p, road_y_cross2_p, corner_tl_p, corner_br_p,
|
|
182
|
-
]
|
|
183
|
-
return dest, sources
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
def build_gap_patch(name: str, gx: int, gy: int, axis: str) -> tuple[Path, list[Path]]:
|
|
187
|
-
"""Exact cropped top-diamond road patch positioned cleanly for one built road segment."""
|
|
188
|
-
road_p = SRC / ("city73.png" if axis == "x" else "city81.png")
|
|
189
|
-
road_top = mask_top_diamond(load_rgba(road_p))
|
|
190
|
-
canvas = Image.new("RGBA", (CANVAS_W, CANVAS_H), (0, 0, 0, 0))
|
|
191
|
-
paste_tile(canvas, road_top, gx, gy, y_lift=1)
|
|
192
|
-
out_img = canvas.resize((OUT_W, OUT_H), Image.Resampling.LANCZOS)
|
|
193
|
-
dest = save_compact_png(out_img, OUT / f"road.{name}.png", colors=128)
|
|
194
|
-
return dest, [road_p]
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
def build_building(name: str, body_file: str, roof_file: str, floors: int = 1) -> Path:
|
|
198
|
-
body = load_rgba(body_file)
|
|
199
|
-
roof = load_rgba(roof_file)
|
|
200
|
-
bw, bh = body.size
|
|
201
|
-
rw, rh = roof.size
|
|
202
|
-
w = max(bw, rw) + 8
|
|
203
|
-
total_h = bh + (floors - 1) * 33 + rh
|
|
204
|
-
canvas = Image.new("RGBA", (w, total_h), (0, 0, 0, 0))
|
|
205
|
-
base_y = total_h - 4
|
|
206
|
-
for floor in range(floors):
|
|
207
|
-
bx = (w - bw) // 2
|
|
208
|
-
by = base_y - bh - floor * 33
|
|
209
|
-
canvas.alpha_composite(body, (bx, by))
|
|
210
|
-
rx = (w - rw) // 2
|
|
211
|
-
ry = base_y - 1 - bh - (floors - 1) * 33 - rh + 44
|
|
212
|
-
canvas.alpha_composite(roof, (rx, ry))
|
|
213
|
-
bbox = canvas.getbbox()
|
|
214
|
-
cropped = canvas.crop(bbox) if bbox else canvas
|
|
215
|
-
return save_compact_png(cropped, OUT / f"{name}.png", colors=128)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
def build_vehicle_strip(name: str, files: list) -> Path:
|
|
219
|
-
"""Pack 4 Kenney isometric directional vehicle PNGs [SE, SW, NW, NE] into a 4-column sprite strip."""
|
|
220
|
-
imgs = [load_rgba(f) for f in files]
|
|
221
|
-
cell_w = max(im.width for im in imgs) + 4
|
|
222
|
-
cell_h = max(im.height for im in imgs) + 4
|
|
223
|
-
strip = Image.new("RGBA", (cell_w * 4, cell_h), (0, 0, 0, 0))
|
|
224
|
-
for i, im in enumerate(imgs):
|
|
225
|
-
px = i * cell_w + (cell_w - im.width) // 2
|
|
226
|
-
py = cell_h - im.height - 2
|
|
227
|
-
strip.alpha_composite(im, (px, py))
|
|
228
|
-
return save_compact_png(strip, OUT / f"{name}.png", colors=128)
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
def copy_compact(src_name: str, dest_name: str) -> Path:
|
|
232
|
-
im = load_rgba(src_name)
|
|
233
|
-
return save_compact_png(im, OUT / f"{dest_name}.png", colors=128)
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
files_manifest = []
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
def record(asset_id: str, dest: Path, sources: list, kind: str):
|
|
240
|
-
resolved = [Path(s) if Path(s).is_absolute() else (SRC / s) for s in sources]
|
|
241
|
-
files_manifest.append({
|
|
242
|
-
"id": asset_id,
|
|
243
|
-
"file": str(dest.relative_to(ROOT)),
|
|
244
|
-
"bytes": dest.stat().st_size,
|
|
245
|
-
"sha256": sha256_file(dest),
|
|
246
|
-
"processing": {
|
|
247
|
-
"kind": kind,
|
|
248
|
-
"sourceFiles": [str(p.relative_to(ROOT)) for p in resolved],
|
|
249
|
-
"sourceSha256": [sha256_file(p) for p in resolved],
|
|
250
|
-
"tool": "Pillow faithful compositing + PNG-8 quantization",
|
|
251
|
-
},
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
base_dest, base_sources = build_city_base()
|
|
256
|
-
record("city.base", base_dest, base_sources, "isometric-tile-composite")
|
|
257
|
-
|
|
258
|
-
for gap_name, (gx, gy, axis) in GAP_TILES.items():
|
|
259
|
-
patch_dest, patch_sources = build_gap_patch(gap_name, gx, gy, axis)
|
|
260
|
-
record(f"road.{gap_name}", patch_dest, patch_sources, "isometric-road-patch")
|
|
261
|
-
|
|
262
|
-
# Distinct downtown landmarks & waterfront neighborhood buildings
|
|
263
|
-
record("building.depot", build_building("building.depot", "building25.png", "building84.png", 1), ["building25.png", "building84.png"], "isometric-building-stack")
|
|
264
|
-
record("building.market", build_building("building.market", "building18.png", "building69.png", 1), ["building18.png", "building69.png"], "isometric-building-stack")
|
|
265
|
-
record("building.cafe", build_building("building.cafe", "building43.png", "building88.png", 1), ["building43.png", "building88.png"], "isometric-building-stack")
|
|
266
|
-
record("building.office", build_building("building.office", "building15.png", "building96.png", 3), ["building15.png", "building96.png"], "isometric-building-stack")
|
|
267
|
-
record("building.house", build_building("building.house", "building32.png", "building80.png", 1), ["building32.png", "building80.png"], "isometric-building-stack")
|
|
268
|
-
record("building.tower", build_building("building.tower", "building11.png", "building84.png", 2), ["building11.png", "building84.png"], "isometric-building-stack")
|
|
269
|
-
record("building.shop", build_building("building.shop", "building0.png", "building69.png", 1), ["building0.png", "building69.png"], "isometric-building-stack")
|
|
270
|
-
record("building.villa", build_building("building.villa", "building39.png", "building96.png", 2), ["building39.png", "building96.png"], "isometric-building-stack")
|
|
271
|
-
|
|
272
|
-
# Streetscape props
|
|
273
|
-
record("prop.tree", copy_compact("tree.png", "prop.tree"), ["tree.png"], "png8-copy")
|
|
274
|
-
record("prop.lamp", copy_compact("lamp.png", "prop.lamp"), ["lamp.png"], "png8-copy")
|
|
275
|
-
|
|
276
|
-
# 3 distinct 4-directional isometric animated vehicle strips [SE, SW, NW, NE]
|
|
277
|
-
taxi_files = ["taxiSE.png", "taxiSW.png", "taxiNW.png", "taxiNE.png"]
|
|
278
|
-
record("vehicle.taxi", build_vehicle_strip("vehicle.taxi", taxi_files), taxi_files, "iso-4-sprite-pack")
|
|
279
|
-
|
|
280
|
-
police_files = [
|
|
281
|
-
ORIG_VEH / "Police/police_SE.png",
|
|
282
|
-
ORIG_VEH / "Police/police_SW.png",
|
|
283
|
-
ORIG_VEH / "Police/police_NW.png",
|
|
284
|
-
ORIG_VEH / "Police/police_NE.png",
|
|
285
|
-
]
|
|
286
|
-
record("vehicle.police", build_vehicle_strip("vehicle.police", police_files), police_files, "iso-4-sprite-pack")
|
|
287
|
-
|
|
288
|
-
cargo_files = [
|
|
289
|
-
ORIG_VEH / "Garbage/garbage_SE.png",
|
|
290
|
-
ORIG_VEH / "Garbage/garbage_SW.png",
|
|
291
|
-
ORIG_VEH / "Garbage/garbage_NW.png",
|
|
292
|
-
ORIG_VEH / "Garbage/garbage_NE.png",
|
|
293
|
-
]
|
|
294
|
-
record("vehicle.cargo", build_vehicle_strip("vehicle.cargo", cargo_files), cargo_files, "iso-4-sprite-pack")
|
|
295
|
-
|
|
296
|
-
plan = {
|
|
297
|
-
"format": "tora-native-asset-plan-1",
|
|
298
|
-
"source": {
|
|
299
|
-
"id": "kenney-isometric-city-collection",
|
|
300
|
-
"author": "Kenney",
|
|
301
|
-
"sourceUrl": "https://kenney.nl/assets/isometric-tiles-city",
|
|
302
|
-
"license": "CC0-1.0",
|
|
303
|
-
"licenseUrl": "https://creativecommons.org/publicdomain/zero/1.0/",
|
|
304
|
-
"licenseFiles": [
|
|
305
|
-
"fixtures/traffic-tycoon/licenses/isometric-tiles-city.txt",
|
|
306
|
-
"fixtures/traffic-tycoon/licenses/isometric-tiles-buildings.txt",
|
|
307
|
-
"fixtures/traffic-tycoon/licenses/isometric-tiles-landscape.txt",
|
|
308
|
-
"fixtures/traffic-tycoon/licenses/isometric-tiles-vehicles.txt",
|
|
309
|
-
],
|
|
310
|
-
"attributionRequired": False,
|
|
311
|
-
},
|
|
312
|
-
"visualDirection": "Sunlit isometric waterfront metropolis with turquoise harbor canal, tree-lined waterfront boulevard with live ambient traffic, multi-story downtown skyline, crosswalks, open-center architectural blueprint road gaps, and an express delivery highway from Depot to Market.",
|
|
313
|
-
"preparation": "Faithful pixel compositing, PNG-8 alpha quantization, and 4-frame directional sprite packing from verified CC0 Kenney isometric packs.",
|
|
314
|
-
"projection": {
|
|
315
|
-
"originX": ORIGIN_X,
|
|
316
|
-
"originY": ORIGIN_Y,
|
|
317
|
-
"canvasW": CANVAS_W,
|
|
318
|
-
"canvasH": CANVAS_H,
|
|
319
|
-
"halfW": HALF_W,
|
|
320
|
-
"halfH": HALF_H,
|
|
321
|
-
"cols": COLS,
|
|
322
|
-
"rows": ROWS,
|
|
323
|
-
},
|
|
324
|
-
"files": files_manifest,
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
PLAN_PATH.write_text(json.dumps(plan, indent=2) + "\n")
|
|
328
|
-
total_bytes = sum(f["bytes"] for f in files_manifest)
|
|
329
|
-
print(f"Prepared {len(files_manifest)} Traffic Tycoon assets ({total_bytes} bytes total) -> {PLAN_PATH.relative_to(ROOT)}")
|
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
const turn = Math.PI * 2;
|
|
2
|
-
const randomUnit = (index, salt) => ((Math.imul(index + 1, 0x9e3779b9) ^ Math.imul(salt, 0x85ebca6b)) >>> 0) / 4294967296;
|
|
3
|
-
|
|
4
|
-
export function pixelConfetti(parameters, position, clipId) {
|
|
5
|
-
const colors = [parameters.color, parameters.color2, parameters.color3].filter(Boolean);
|
|
6
|
-
const spread = (parameters.spread ?? 360) * Math.PI / 180;
|
|
7
|
-
const heading = (parameters.direction ?? -90) * Math.PI / 180;
|
|
8
|
-
return Array.from({length:parameters.count}, (_,index) => {
|
|
9
|
-
const angle = heading + ((index + .2 + randomUnit(index,1)*.6) / parameters.count - .5) * spread;
|
|
10
|
-
const speed = parameters.speed * (.42 + .65 * randomUnit(index,2));
|
|
11
|
-
return {
|
|
12
|
-
...position, clipId, shape:'pixel-confetti', age:-.12 * randomUnit(index,3),
|
|
13
|
-
vx:Math.cos(angle)*speed, vy:Math.sin(angle)*speed, gravity:parameters.gravity??250,
|
|
14
|
-
life:(parameters.lifetime??.7)*(.6 + .4 * randomUnit(index,4)),
|
|
15
|
-
color:colors[index % colors.length], size:3 + Math.floor(3 * randomUnit(index,5)),
|
|
16
|
-
angle:turn*randomUnit(index,6), spin:(randomUnit(index,7)-.5)*12,
|
|
17
|
-
};
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function screenConfetti(parameters) {
|
|
22
|
-
const cols = Math.min(12, Math.ceil(Math.sqrt(parameters.count)));
|
|
23
|
-
const rows = Math.ceil(parameters.count / cols);
|
|
24
|
-
const speed = parameters.speed;
|
|
25
|
-
return pixelConfetti(parameters).map((particle,index)=>({
|
|
26
|
-
...particle, screen:true,
|
|
27
|
-
x:(index % cols + .15 + .7*randomUnit(index,8)) / cols,
|
|
28
|
-
y:(Math.floor(index / cols) + .15 + .7*randomUnit(index,9)) / rows,
|
|
29
|
-
vx:speed * (randomUnit(index,10)-.5) * .7,
|
|
30
|
-
vy:speed * (.3 + .5*randomUnit(index,11)),
|
|
31
|
-
size:particle.size+1,
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const wrap = (value, length) => ((value % length) + length) % length;
|
|
36
|
-
|
|
37
|
-
export function drawPixelConfetti(ctx, particle, screen) {
|
|
38
|
-
const {x,y,vx,vy,age,life,gravity,size,angle,spin,color} = particle;
|
|
39
|
-
if(age<0)return;
|
|
40
|
-
const dx = vx * age;
|
|
41
|
-
const dy = vy * age + gravity * age * age / 2;
|
|
42
|
-
const left = Math.round(screen ? screen.x+wrap(x*screen.width+dx,screen.width) : x+dx);
|
|
43
|
-
const top = Math.round(screen ? screen.y+wrap(y*screen.height+dy,screen.height) : y+dy);
|
|
44
|
-
const direction = Math.round((angle + spin * age) / (Math.PI/4)) & 3;
|
|
45
|
-
ctx.globalAlpha *= Math.min(1, (life - age) * 4);
|
|
46
|
-
ctx.fillStyle = '#3c293388';
|
|
47
|
-
if(direction===0)ctx.fillRect(left-size+1,top+1,size*2+1,size+1);
|
|
48
|
-
else if(direction===2)ctx.fillRect(left+1,top-size+1,size+1,size*2+1);
|
|
49
|
-
else for(let step=-1;step<=1;step++){
|
|
50
|
-
ctx.fillRect(left+step*size+1,top+step*size*(direction===1?1:-1)+1,size+1,size+1);
|
|
51
|
-
}
|
|
52
|
-
ctx.fillStyle = color;
|
|
53
|
-
if(direction===0)ctx.fillRect(left-size,top,size*2,size);
|
|
54
|
-
else if(direction===2)ctx.fillRect(left,top-size,size,size*2);
|
|
55
|
-
else for(let step=-1;step<=1;step++){
|
|
56
|
-
ctx.fillRect(left+step*size,top+step*size*(direction===1?1:-1),size,size);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function vectorConfetti(parameters, position, clipId) {
|
|
61
|
-
const colors = [parameters.color, parameters.color2, parameters.color3, '#ff6b6b', '#4ecdc4', '#fff3b0'].filter(Boolean);
|
|
62
|
-
const spread = (parameters.spread ?? 360) * Math.PI / 180;
|
|
63
|
-
const heading = (parameters.direction ?? -90) * Math.PI / 180;
|
|
64
|
-
return Array.from({length:parameters.count}, (_,index) => {
|
|
65
|
-
const angle = heading + ((index + .2 + randomUnit(index,11)*.6) / parameters.count - .5) * spread;
|
|
66
|
-
const speed = parameters.speed * (.45 + .65 * randomUnit(index,12));
|
|
67
|
-
return {
|
|
68
|
-
...position, clipId, shape:'confetti', age:-.15 * randomUnit(index,13),
|
|
69
|
-
vx:Math.cos(angle)*speed, vy:Math.sin(angle)*speed, gravity:parameters.gravity??140,
|
|
70
|
-
life:(parameters.lifetime??2.6)*(.75 + .35 * randomUnit(index,14)),
|
|
71
|
-
color:colors[index % colors.length],
|
|
72
|
-
size:5 + Math.floor(5 * randomUnit(index,15)),
|
|
73
|
-
kind:index % 5 === 0 ? 'star' : 'ribbon',
|
|
74
|
-
angle:turn*randomUnit(index,16),
|
|
75
|
-
spin:(randomUnit(index,17)-.5)*5.5,
|
|
76
|
-
flutter:1.6 + 2.2 * randomUnit(index,18),
|
|
77
|
-
phase:turn*randomUnit(index,19),
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function screenVectorConfetti(parameters) {
|
|
83
|
-
const cols = Math.min(14, Math.ceil(Math.sqrt(parameters.count)));
|
|
84
|
-
const rows = Math.ceil(parameters.count / cols);
|
|
85
|
-
const speed = parameters.speed;
|
|
86
|
-
return vectorConfetti(parameters, {x:0,y:0}).map((particle,index)=>({
|
|
87
|
-
...particle, screen:true,
|
|
88
|
-
x:(index % cols + .12 + .76*randomUnit(index,20)) / cols,
|
|
89
|
-
y:(Math.floor(index / cols) + .08 + .84*randomUnit(index,21)) / rows,
|
|
90
|
-
vx:speed * (randomUnit(index,22)-.5) * .65,
|
|
91
|
-
vy:speed * (.38 + .55*randomUnit(index,23)),
|
|
92
|
-
gravity:Math.min(parameters.gravity ?? 90, 90),
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function drawVectorConfetti(ctx, particle, screen) {
|
|
97
|
-
const {x,y,vx,vy,age,life,gravity,size,angle,spin,flutter,phase,color,kind} = particle;
|
|
98
|
-
if(age<0)return;
|
|
99
|
-
const sway = Math.sin(age * flutter + phase) * 14;
|
|
100
|
-
const dx = vx * age + sway;
|
|
101
|
-
const dy = vy * age + gravity * age * age / 2;
|
|
102
|
-
const px = screen ? screen.x + wrap(x * screen.width + dx, screen.width) : x + dx;
|
|
103
|
-
const py = screen ? screen.y + wrap(y * screen.height + dy, screen.height) : y + dy;
|
|
104
|
-
const fade = Math.min(1, age * 2.8, (life - age) * 2.2);
|
|
105
|
-
if(fade <= 0) return;
|
|
106
|
-
ctx.save();
|
|
107
|
-
ctx.globalAlpha *= fade;
|
|
108
|
-
ctx.translate(px, py);
|
|
109
|
-
ctx.rotate(angle + spin * age);
|
|
110
|
-
const tumble = Math.cos(age * flutter * 1.4 + phase);
|
|
111
|
-
ctx.scale(1, Math.max(.22, Math.abs(tumble)));
|
|
112
|
-
ctx.fillStyle = color;
|
|
113
|
-
if(kind === 'star'){
|
|
114
|
-
const r = size * .85;
|
|
115
|
-
ctx.beginPath();
|
|
116
|
-
for(let i=0;i<8;i++){
|
|
117
|
-
const rad = i % 2 === 0 ? r : r * .38;
|
|
118
|
-
const a = (i * Math.PI) / 4;
|
|
119
|
-
if(i === 0) ctx.moveTo(Math.cos(a)*rad, Math.sin(a)*rad);
|
|
120
|
-
else ctx.lineTo(Math.cos(a)*rad, Math.sin(a)*rad);
|
|
121
|
-
}
|
|
122
|
-
ctx.closePath();
|
|
123
|
-
ctx.fill();
|
|
124
|
-
}else{
|
|
125
|
-
ctx.fillRect(-size * .7, -size * .34, size * 1.4, size * .68);
|
|
126
|
-
ctx.fillStyle = '#ffffff55';
|
|
127
|
-
ctx.fillRect(-size * .7, -size * .34, size * 1.4, size * .2);
|
|
128
|
-
}
|
|
129
|
-
ctx.restore();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function drawPixelCta(ctx, p, fill, pressed, shineAge) {
|
|
133
|
-
const {width:w,height:h} = p;
|
|
134
|
-
if(w<=0||h<=0)return;
|
|
135
|
-
const unit = Math.min(3, Math.floor(Math.min(w,h)/8));
|
|
136
|
-
if(!unit){
|
|
137
|
-
ctx.fillStyle = fill;
|
|
138
|
-
ctx.fillRect(0,0,w,h);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
const top = pressed ? unit*2 : 0;
|
|
142
|
-
const faceBottom = h - (pressed ? unit : unit*3);
|
|
143
|
-
const pulse = shineAge >= 0 ? .5 + .5 * Math.sin(shineAge * 4.0) : 0;
|
|
144
|
-
// Warm golden pixel aura glow pulse
|
|
145
|
-
if(p.enabled && !pressed && shineAge >= 0){
|
|
146
|
-
ctx.save();
|
|
147
|
-
ctx.shadowColor = '#ffd05a99';
|
|
148
|
-
ctx.shadowBlur = 8 + pulse * 9;
|
|
149
|
-
ctx.fillStyle = fill;
|
|
150
|
-
ctx.fillRect(unit,top+unit,w-2*unit,h-top-2*unit);
|
|
151
|
-
ctx.restore();
|
|
152
|
-
}
|
|
153
|
-
// The casing and face share the ordinary button's hit rectangle.
|
|
154
|
-
ctx.fillStyle = p.stroke;
|
|
155
|
-
ctx.fillRect(unit,0,w-2*unit,h);
|
|
156
|
-
ctx.fillRect(0,unit,w,h-2*unit);
|
|
157
|
-
ctx.fillStyle = fill;
|
|
158
|
-
ctx.fillRect(unit,top+unit,w-2*unit,h-top-2*unit);
|
|
159
|
-
ctx.fillStyle = '#431d1380';
|
|
160
|
-
ctx.fillRect(unit,faceBottom,w-2*unit,h-unit-faceBottom);
|
|
161
|
-
ctx.fillStyle = p.enabled ? '#fff4be' : '#ffffff55';
|
|
162
|
-
ctx.fillRect(2*unit,top+unit,w-4*unit,pressed?unit:unit*2);
|
|
163
|
-
ctx.fillStyle = '#ffffff55';
|
|
164
|
-
ctx.fillRect(unit,top+3*unit,unit,Math.max(0,faceBottom-top-3*unit));
|
|
165
|
-
ctx.fillStyle = '#521b2444';
|
|
166
|
-
ctx.fillRect(w-2*unit,top+3*unit,unit,Math.max(0,faceBottom-top-3*unit));
|
|
167
|
-
|
|
168
|
-
const cycleAge = shineAge >= 0 ? (shineAge % 1.9) : -1;
|
|
169
|
-
const shineProgress = (cycleAge-.1)/.55;
|
|
170
|
-
if(p.enabled&&!pressed&&shineProgress>=0&&shineProgress<1){
|
|
171
|
-
ctx.save();
|
|
172
|
-
ctx.beginPath();
|
|
173
|
-
ctx.rect(2*unit,top+3*unit,w-4*unit,Math.max(0,faceBottom-top-3*unit));
|
|
174
|
-
ctx.clip();
|
|
175
|
-
const leading = Math.floor(((w+14*unit)*shineProgress-6*unit)/unit)*unit;
|
|
176
|
-
for(let y=top+3*unit,row=0;y<faceBottom;y+=unit,row++){
|
|
177
|
-
const x = leading-Math.floor(row/2)*unit;
|
|
178
|
-
ctx.fillStyle = '#fff4be44';
|
|
179
|
-
ctx.fillRect(x-2*unit,y,9*unit,unit);
|
|
180
|
-
ctx.fillStyle = '#fffef0aa';
|
|
181
|
-
ctx.fillRect(x,y,4*unit,unit);
|
|
182
|
-
}
|
|
183
|
-
ctx.restore();
|
|
184
|
-
}
|
|
185
|
-
// Twinkling pixel-cross specular glints on upper corners
|
|
186
|
-
if(p.enabled&&!pressed&&shineAge>=0){
|
|
187
|
-
const g1 = Math.max(0, Math.sin(shineAge * 4.2));
|
|
188
|
-
const g2 = Math.max(0, Math.sin(shineAge * 4.2 + 2.2));
|
|
189
|
-
const drawPixelStar = (cx, cy, g) => {
|
|
190
|
-
if(g < .25) return;
|
|
191
|
-
ctx.save();
|
|
192
|
-
ctx.globalAlpha *= g * .95;
|
|
193
|
-
ctx.fillStyle = '#fffef4';
|
|
194
|
-
const arm = g > .65 ? unit * 2 : unit;
|
|
195
|
-
ctx.fillRect(Math.round(cx - arm), Math.round(cy - unit/2), arm * 2 + unit, unit);
|
|
196
|
-
ctx.fillRect(Math.round(cx - unit/2), Math.round(cy - arm), unit, arm * 2 + unit);
|
|
197
|
-
ctx.restore();
|
|
198
|
-
};
|
|
199
|
-
drawPixelStar(5*unit, top+4*unit, g1);
|
|
200
|
-
drawPixelStar(w-6*unit, top+5*unit, g2);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function roundedPath(ctx, x, y, w, h, r) {
|
|
205
|
-
const rad = Math.max(0, Math.min(r, w / 2, h / 2));
|
|
206
|
-
ctx.beginPath();
|
|
207
|
-
if(typeof ctx.roundRect === 'function') ctx.roundRect(x, y, w, h, rad);
|
|
208
|
-
else {
|
|
209
|
-
ctx.moveTo(x + rad, y);
|
|
210
|
-
ctx.arcTo(x + w, y, x + w, y + h, rad);
|
|
211
|
-
ctx.arcTo(x + w, y + h, x, y + h, rad);
|
|
212
|
-
ctx.arcTo(x, y + h, x, y, rad);
|
|
213
|
-
ctx.arcTo(x, y, x + w, y, rad);
|
|
214
|
-
ctx.closePath();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function drawFourPointGlint(ctx, x, y, r, alpha) {
|
|
219
|
-
if(alpha <= .02 || r <= .5) return;
|
|
220
|
-
ctx.save();
|
|
221
|
-
ctx.translate(x, y);
|
|
222
|
-
ctx.globalAlpha *= alpha;
|
|
223
|
-
ctx.fillStyle = '#fffef0';
|
|
224
|
-
ctx.beginPath();
|
|
225
|
-
for(let i=0;i<8;i++){
|
|
226
|
-
const rad = i % 2 === 0 ? r : r * .24;
|
|
227
|
-
const a = (i * Math.PI) / 4;
|
|
228
|
-
if(i === 0) ctx.moveTo(Math.cos(a)*rad, Math.sin(a)*rad);
|
|
229
|
-
else ctx.lineTo(Math.cos(a)*rad, Math.sin(a)*rad);
|
|
230
|
-
}
|
|
231
|
-
ctx.closePath();
|
|
232
|
-
ctx.fill();
|
|
233
|
-
ctx.restore();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/** Glossy 3D bevelled store CTA with continuous diagonal sheen sweep & twinkling glints. */
|
|
237
|
-
export function drawShinyCta(ctx, p, fill, pressed, age) {
|
|
238
|
-
const {width:w,height:h} = p;
|
|
239
|
-
if(w<=0||h<=0)return;
|
|
240
|
-
const radius = Math.min(p.radius ?? 16, w / 2, h / 2);
|
|
241
|
-
const lip = pressed ? 2 : 6;
|
|
242
|
-
const topOffset = pressed ? 3 : 0;
|
|
243
|
-
const pulse = age >= 0 ? .5 - .5 * Math.cos(age * 2.4) : 0;
|
|
244
|
-
|
|
245
|
-
// Soft warm golden outer breathing glow
|
|
246
|
-
if(p.enabled && !pressed && age >= 0){
|
|
247
|
-
ctx.save();
|
|
248
|
-
ctx.shadowColor = '#ffd23f99';
|
|
249
|
-
ctx.shadowBlur = 10 + pulse * 12;
|
|
250
|
-
roundedPath(ctx, 0, topOffset, w, h - topOffset, radius);
|
|
251
|
-
ctx.fillStyle = fill;
|
|
252
|
-
ctx.fill();
|
|
253
|
-
ctx.restore();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Raised 3D dark base / drop lip
|
|
257
|
-
ctx.save();
|
|
258
|
-
roundedPath(ctx, 0, topOffset + 2, w, Math.max(4, h - topOffset - 2), radius);
|
|
259
|
-
ctx.fillStyle = '#0e2830';
|
|
260
|
-
ctx.fill();
|
|
261
|
-
ctx.restore();
|
|
262
|
-
|
|
263
|
-
// Main glowing button face
|
|
264
|
-
ctx.save();
|
|
265
|
-
roundedPath(ctx, 0, topOffset, w, Math.max(4, h - lip), radius);
|
|
266
|
-
ctx.fillStyle = fill;
|
|
267
|
-
ctx.fill();
|
|
268
|
-
|
|
269
|
-
// Clip glossy highlights & sweeping diagonal specular sheen inside the button face
|
|
270
|
-
ctx.clip();
|
|
271
|
-
|
|
272
|
-
// Top glass highlight sheen
|
|
273
|
-
const sheenGrad = ctx.createLinearGradient?.(0, topOffset, 0, h - lip);
|
|
274
|
-
if(sheenGrad?.addColorStop){
|
|
275
|
-
sheenGrad.addColorStop(0, '#ffffffa8');
|
|
276
|
-
sheenGrad.addColorStop(.42, '#ffffff26');
|
|
277
|
-
sheenGrad.addColorStop(.45, '#00000000');
|
|
278
|
-
sheenGrad.addColorStop(1, '#00000024');
|
|
279
|
-
ctx.fillStyle = sheenGrad;
|
|
280
|
-
ctx.fillRect(0, topOffset, w, h - lip);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Bright crisp top inner specular bar
|
|
284
|
-
ctx.fillStyle = '#fffef0bb';
|
|
285
|
-
ctx.fillRect(radius * .55, topOffset + 3, Math.max(0, w - radius * 1.1), 3);
|
|
286
|
-
|
|
287
|
-
// Smooth eased sweeping diagonal specular reflection every 2.4s
|
|
288
|
-
if(p.enabled && !pressed && age >= 0){
|
|
289
|
-
const sweep = ((age % 2.4) - .15) / .95;
|
|
290
|
-
if(sweep > 0 && sweep < 1){
|
|
291
|
-
const eased = sweep * sweep * (3 - 2 * sweep);
|
|
292
|
-
const env = Math.sin(sweep * Math.PI);
|
|
293
|
-
const cx = -w * .36 + (w * 1.72) * eased;
|
|
294
|
-
ctx.save();
|
|
295
|
-
ctx.globalAlpha *= env;
|
|
296
|
-
ctx.translate(cx, topOffset);
|
|
297
|
-
ctx.transform(1, 0, -.36, 1, 0, 0);
|
|
298
|
-
const beamGrad = ctx.createLinearGradient?.(-48, 0, 48, 0);
|
|
299
|
-
if(beamGrad?.addColorStop){
|
|
300
|
-
beamGrad.addColorStop(0, '#ffffff00');
|
|
301
|
-
beamGrad.addColorStop(.32, '#ffffff48');
|
|
302
|
-
beamGrad.addColorStop(.5, '#fffef8cc');
|
|
303
|
-
beamGrad.addColorStop(.68, '#ffffff48');
|
|
304
|
-
beamGrad.addColorStop(1, '#ffffff00');
|
|
305
|
-
ctx.fillStyle = beamGrad;
|
|
306
|
-
ctx.fillRect(-48, 0, 96, h);
|
|
307
|
-
}else{
|
|
308
|
-
ctx.fillStyle = '#fffef8a8';
|
|
309
|
-
ctx.fillRect(-14, 0, 28, h);
|
|
310
|
-
}
|
|
311
|
-
ctx.restore();
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
ctx.restore();
|
|
315
|
-
|
|
316
|
-
// Crisp outer stroke around the raised face
|
|
317
|
-
if(p.strokeWidth){
|
|
318
|
-
ctx.save();
|
|
319
|
-
roundedPath(ctx, 0, topOffset, w, Math.max(4, h - lip), radius);
|
|
320
|
-
ctx.strokeStyle = p.stroke;
|
|
321
|
-
ctx.lineWidth = p.strokeWidth;
|
|
322
|
-
ctx.stroke();
|
|
323
|
-
ctx.restore();
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// Smoothly blooming 4-point specular sparkles along the corners
|
|
327
|
-
if(p.enabled && !pressed && age >= 0){
|
|
328
|
-
const s1 = Math.max(0, Math.sin(age * 2.4)), g1 = s1 * s1;
|
|
329
|
-
const s2 = Math.max(0, Math.sin(age * 2.4 + 2.1)), g2 = s2 * s2;
|
|
330
|
-
const s3 = Math.max(0, Math.sin(age * 2.4 + 4.2)), g3 = s3 * s3;
|
|
331
|
-
drawFourPointGlint(ctx, w * .12, topOffset + 9, 4 + g1 * 6, g1 * .92);
|
|
332
|
-
drawFourPointGlint(ctx, w * .88, topOffset + 10, 3.8 + g2 * 5.5, g2 * .9);
|
|
333
|
-
drawFourPointGlint(ctx, w * .76, Math.max(topOffset + 14, h - lip - 8), 3 + g3 * 4.2, g3 * .8);
|
|
334
|
-
}
|
|
335
|
-
}
|