forge
Explore
Log in

Don't you dare go Hollow

🎉 init: courier game with web build and forge CI publishing the wasm bundle

Browse files at this commit

b39671e63c34359d5c28e298006d4c80b4e8b33eAhmet Kaan GümüşParent: 5734911
Some checks failed
Show checks

179 changed files +15363 -0

.forge/ci.tomladded+36 -0
@@ -0,0 +1,36 @@
1+name = "build"
2+
3+[on]
4+push = ["main"]
5+pull_request = true
6+manual = true
7+tags = ["v*"]
8+
9+[jobs.build]
10+image = "docker.io/library/rust:1"
11+env = { CARGO_HOME = "/workspace/.cargo-home", SOURCE_DATE_EPOCH = "0" }
12+run = """
13+exec 2>&1
14+echo "::group::Tools"
15+apt-get update -qq && apt-get install -y -qq binaryen >/dev/null
16+rustup target add wasm32-unknown-unknown
17+WBG=$(grep -A1 '^name = "wasm-bindgen"$' Cargo.lock | sed -n 's/^version = "\\(.*\\)"$/\\1/p')
18+WBG_DIR=wasm-bindgen-$WBG-$(uname -m)-unknown-linux-musl
19+curl -fsSL https://github.com/wasm-bindgen/wasm-bindgen/releases/download/$WBG/$WBG_DIR.tar.gz | tar xz -C /usr/local
20+export PATH=/usr/local/$WBG_DIR:$PATH
21+wasm-bindgen --version
22+echo "::endgroup::"
23+echo "::group::Web build"
24+bash tools/web.sh
25+echo "::endgroup::"
26+echo "::group::Package"
27+tar czf courier-web.tar.gz -C dist .
28+sha256sum courier-web.tar.gz > SHA256SUMS
29+echo "::endgroup::"
30+"""
31+artifacts = ["courier-web.tar.gz", "SHA256SUMS"]
32+cache = ["target", ".cargo-home"]
33+timeout_minutes = 120
34+
35+[release]
36+assets = ["build:courier-web.tar.gz", "build:SHA256SUMS"]
.gitignoreadded+7 -0
@@ -0,0 +1,7 @@
1+/target
2+/dist
3+/.cargo-home
4+/courier-web.tar.gz
5+/SHA256SUMS
6+demo.mp4
7+__pycache__/
Cargo.lockadded+6478 -0

Diff too large; view file

@@ -0,0 +1,6478 @@
1+# This file is automatically @generated by Cargo.
2+# It is not intended for manual editing.
3+version = 4
4+
5+[[package]]
6+name = "ab_glyph"
7+version = "0.2.32"
8+source = "registry+https://github.com/rust-lang/crates.io-index"
9+checksum = "01c0457472c38ea5bd1c3b5ada5e368271cb550be7a4ca4a0b4634e9913f6cc2"
10+dependencies = [
11+ "ab_glyph_rasterizer",
12+ "owned_ttf_parser",
13+]
14+
15+[[package]]
16+name = "ab_glyph_rasterizer"
17+version = "0.1.10"
18+source = "registry+https://github.com/rust-lang/crates.io-index"
19+checksum = "366ffbaa4442f4684d91e2cd7c5ea7c4ed8add41959a31447066e279e432b618"
20+
21+[[package]]
22+name = "accesskit"
23+version = "0.24.1"
24+source = "registry+https://github.com/rust-lang/crates.io-index"
25+checksum = "d3b7f7f85a7e5f68090000ed7622545829afd484d210358702ae4cb97dd0c320"
26+dependencies = [
27+ "uuid",
28+]
29+
30+[[package]]
31+name = "accesskit_consumer"
32+version = "0.38.0"
33+source = "registry+https://github.com/rust-lang/crates.io-index"
34+checksum = "5d10a236f96f87d70732e44520046785431ef01d5bcd6b041317bfadd2f88245"
35+dependencies = [
36+ "accesskit",
37+ "hashbrown 0.16.1",
38+]
39+
40+[[package]]
41+name = "accesskit_ios"
42+version = "0.1.2"
43+source = "registry+https://github.com/rust-lang/crates.io-index"
44+checksum = "750c4e9f6ce888dfe8a10c0f1b5ceb646a7854fd46579d74919219d1bb314083"
45+dependencies = [
46+ "accesskit",
47+ "accesskit_consumer",
48+ "hashbrown 0.16.1",
49+ "objc2 0.5.3",
50+ "objc2-foundation 0.2.2",
51+ "objc2-ui-kit",
52+]
53+
54+[[package]]
55+name = "accesskit_macos"
56+version = "0.26.3"
57+source = "registry+https://github.com/rust-lang/crates.io-index"
58+checksum = "ce02dc63b43f0c9296af9ac946312a2dc8814427d7a64d2d600971dac55b6076"
59+dependencies = [
60+ "accesskit",
61+ "accesskit_consumer",
62+ "hashbrown 0.16.1",
63+ "objc2 0.5.3",
64+ "objc2-app-kit 0.2.2",
65+ "objc2-foundation 0.2.2",
66+]
67+
68+[[package]]
69+name = "accesskit_windows"
70+version = "0.34.0"
71+source = "registry+https://github.com/rust-lang/crates.io-index"
72+checksum = "106c2b961215864d1c2e703ee63269c25c4e80a577ffb2c1017b9c17dcdf83a1"
73+dependencies = [
74+ "accesskit",
75+ "accesskit_consumer",
76+ "hashbrown 0.16.1",
77+ "static_assertions",
78+ "windows",
79+ "windows-core",
80+]
81+
82+[[package]]
83+name = "accesskit_winit"
84+version = "0.33.2"
85+source = "registry+https://github.com/rust-lang/crates.io-index"
86+checksum = "d5b41e63a69f36d9f1f41e70464c7e5f72eee485ef26aab19f0b4f86e6c0a84c"
87+dependencies = [
88+ "accesskit",
89+ "accesskit_ios",
90+ "accesskit_macos",
91+ "accesskit_windows",
92+ "raw-window-handle",
93+ "winit",
94+]
95+
96+[[package]]
97+name = "adler2"
98+version = "2.0.1"
99+source = "registry+https://github.com/rust-lang/crates.io-index"
100+checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
101+
102+[[package]]
103+name = "ahash"
104+version = "0.8.12"
105+source = "registry+https://github.com/rust-lang/crates.io-index"
106+checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
107+dependencies = [
108+ "cfg-if",
109+ "getrandom 0.3.4",
110+ "once_cell",
111+ "version_check",
112+ "zerocopy",
113+]
114+
115+[[package]]
116+name = "aho-corasick"
117+version = "1.1.5"
118+source = "registry+https://github.com/rust-lang/crates.io-index"
119+checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
120+dependencies = [
121+ "memchr",
122+]
123+
124+[[package]]
125+name = "allocator-api2"
126+version = "0.2.21"
127+source = "registry+https://github.com/rust-lang/crates.io-index"
128+checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
129+
130+[[package]]
131+name = "alsa"
132+version = "0.11.0"
133+source = "registry+https://github.com/rust-lang/crates.io-index"
134+checksum = "812947049edcd670a82cd5c73c3661d2e58468577ba8489de58e1a73c04cbd5d"
135+dependencies = [
136+ "alsa-sys",
137+ "bitflags 2.13.2",
138+ "cfg-if",
139+ "libc",
140+]
141+
142+[[package]]
143+name = "alsa-sys"
144+version = "0.4.0"
145+source = "registry+https://github.com/rust-lang/crates.io-index"
146+checksum = "ad7569085a265dd3f607ebecce7458eaab2132a84393534c95b18dcbc3f31e04"
147+dependencies = [
148+ "libc",
149+ "pkg-config",
150+]
151+
152+[[package]]
153+name = "android-activity"
154+version = "0.6.1"
155+source = "registry+https://github.com/rust-lang/crates.io-index"
156+checksum = "0f2a1bb052857d5dd49572219344a7332b31b76405648eabac5bc68978251bcd"
157+dependencies = [
158+ "android-properties",
159+ "bitflags 2.13.2",
160+ "cc",
161+ "jni 0.22.4",
162+ "libc",
163+ "log",
164+ "ndk",
165+ "ndk-context",
166+ "ndk-sys",
167+ "num_enum",
168+ "thiserror 2.0.21",
169+]
170+
171+[[package]]
172+name = "android-properties"
173+version = "0.2.2"
174+source = "registry+https://github.com/rust-lang/crates.io-index"
175+checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04"
176+
177+[[package]]
178+name = "android_log-sys"
179+version = "0.3.2"
180+source = "registry+https://github.com/rust-lang/crates.io-index"
181+checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d"
182+
183+[[package]]
184+name = "android_system_properties"
185+version = "0.1.6"
186+source = "registry+https://github.com/rust-lang/crates.io-index"
187+checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc"
188+dependencies = [
189+ "libc",
190+]
191+
192+[[package]]
193+name = "annotate-snippets"
194+version = "0.12.17"
195+source = "registry+https://github.com/rust-lang/crates.io-index"
196+checksum = "b2a5b0a5ab8561c603f16c3b78c24a386b1f70e7fc1b1b1e8c15738828e4a176"
197+dependencies = [
198+ "anstyle",
199+ "memchr",
200+ "unicode-width",
201+]
202+
203+[[package]]
204+name = "anstream"
205+version = "1.0.0"
206+source = "registry+https://github.com/rust-lang/crates.io-index"
207+checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
208+dependencies = [
209+ "anstyle",
210+ "anstyle-parse",
211+ "anstyle-query",
212+ "anstyle-wincon",
213+ "colorchoice",
214+ "is_terminal_polyfill",
215+ "utf8parse",
216+]
217+
218+[[package]]
219+name = "anstyle"
220+version = "1.0.14"
221+source = "registry+https://github.com/rust-lang/crates.io-index"
222+checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
223+
224+[[package]]
225+name = "anstyle-parse"
226+version = "1.0.0"
227+source = "registry+https://github.com/rust-lang/crates.io-index"
228+checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
229+dependencies = [
230+ "utf8parse",
231+]
232+
233+[[package]]
234+name = "anstyle-query"
235+version = "1.1.5"
236+source = "registry+https://github.com/rust-lang/crates.io-index"
237+checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
238+dependencies = [
239+ "windows-sys 0.61.2",
240+]
241+
242+[[package]]
243+name = "anstyle-wincon"
244+version = "3.0.11"
245+source = "registry+https://github.com/rust-lang/crates.io-index"
246+checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
247+dependencies = [
248+ "anstyle",
249+ "once_cell_polyfill",
250+ "windows-sys 0.61.2",
251+]
252+
253+[[package]]
254+name = "approx"
255+version = "0.5.1"
256+source = "registry+https://github.com/rust-lang/crates.io-index"
257+checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
258+dependencies = [
259+ "num-traits",
260+]
261+
262+[[package]]
263+name = "arboard"
264+version = "3.7.0"
265+source = "registry+https://github.com/rust-lang/crates.io-index"
266+checksum = "aeb9553e62312c8756a5979254fc6d7da8bbeb5986a1e17037fab932f7037917"
267+dependencies = [
268+ "clipboard-win",
269+ "log",
270+ "objc2 0.6.5",
271+ "objc2-app-kit 0.3.2",
272+ "objc2-foundation 0.3.2",
273+ "parking_lot",
274+ "percent-encoding",
275+ "windows-sys 0.61.2",
276+ "wl-clipboard-rs",
277+ "x11rb",
278+]
279+
280+[[package]]
281+name = "arrayref"
282+version = "0.3.9"
283+source = "registry+https://github.com/rust-lang/crates.io-index"
284+checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb"
285+
286+[[package]]
287+name = "arrayvec"
288+version = "0.7.8"
289+source = "registry+https://github.com/rust-lang/crates.io-index"
290+checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
291+
292+[[package]]
293+name = "as-raw-xcb-connection"
294+version = "1.0.1"
295+source = "registry+https://github.com/rust-lang/crates.io-index"
296+checksum = "175571dd1d178ced59193a6fc02dde1b972eb0bc56c892cde9beeceac5bf0f6b"
297+
298+[[package]]
299+name = "ash"
300+version = "0.38.0+1.3.281"
301+source = "registry+https://github.com/rust-lang/crates.io-index"
302+checksum = "0bb44936d800fea8f016d7f2311c6a4f97aebd5dc86f09906139ec848cf3a46f"
303+dependencies = [
304+ "libloading",
305+]
306+
307+[[package]]
308+name = "assert_type_match"
309+version = "0.1.1"
310+source = "registry+https://github.com/rust-lang/crates.io-index"
311+checksum = "f548ad2c4031f2902e3edc1f29c29e835829437de49562d8eb5dc5584d3a1043"
312+dependencies = [
313+ "proc-macro2",
314+ "quote",
315+ "syn 2.0.119",
316+]
317+
318+[[package]]
319+name = "async-broadcast"
320+version = "0.7.2"
321+source = "registry+https://github.com/rust-lang/crates.io-index"
322+checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532"
323+dependencies = [
324+ "event-listener",
325+ "event-listener-strategy",
326+ "futures-core",
327+ "pin-project-lite",
328+]
329+
330+[[package]]
331+name = "async-channel"
332+version = "2.5.0"
333+source = "registry+https://github.com/rust-lang/crates.io-index"
334+checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2"
335+dependencies = [
336+ "concurrent-queue",
337+ "event-listener-strategy",
338+ "futures-core",
339+ "pin-project-lite",
340+]
341+
342+[[package]]
343+name = "async-executor"
344+version = "1.14.1"
345+source = "registry+https://github.com/rust-lang/crates.io-index"
346+checksum = "f426a31126c735126297bc5ea7a521263c9faff4f63ca415267ee625651c4f37"
347+dependencies = [
348+ "async-task",
349+ "concurrent-queue",
350+ "fastrand",
351+ "futures-lite",
352+ "pin-project-lite",
353+ "slab",
354+]
355+
356+[[package]]
357+name = "async-fs"
358+version = "2.2.0"
359+source = "registry+https://github.com/rust-lang/crates.io-index"
360+checksum = "8034a681df4aed8b8edbd7fbe472401ecf009251c8b40556b304567052e294c5"
361+dependencies = [
362+ "async-lock",
363+ "blocking",
364+ "futures-lite",
365+]
366+
367+[[package]]
368+name = "async-io"
369+version = "2.6.0"
370+source = "registry+https://github.com/rust-lang/crates.io-index"
371+checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc"
372+dependencies = [
373+ "autocfg",
374+ "cfg-if",
375+ "concurrent-queue",
376+ "futures-io",
377+ "futures-lite",
378+ "parking",
379+ "polling",
380+ "rustix 1.1.6",
381+ "slab",
382+ "windows-sys 0.61.2",
383+]
384+
385+[[package]]
386+name = "async-lock"
387+version = "3.5.0"
388+source = "registry+https://github.com/rust-lang/crates.io-index"
389+checksum = "0876700b0d007ad25d5508865a4259c3af9af6d296bf663a0d586d0bc3369f6f"
390+dependencies = [
391+ "event-listener",
392+ "event-listener-strategy",
393+ "pin-project-lite",
394+]
395+
396+[[package]]
397+name = "async-task"
398+version = "4.7.1"
399+source = "registry+https://github.com/rust-lang/crates.io-index"
400+checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de"
401+dependencies = [
402+ "portable-atomic",
403+]
404+
405+[[package]]
406+name = "atomic-waker"
407+version = "1.1.2"
408+source = "registry+https://github.com/rust-lang/crates.io-index"
409+checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
410+dependencies = [
411+ "portable-atomic",
412+]
413+
414+[[package]]
415+name = "atomicow"
416+version = "1.2.0"
417+source = "registry+https://github.com/rust-lang/crates.io-index"
418+checksum = "301801c08259e328a1c7da556608c0c22687708831b22024dbd3a57ea741e6de"
419+dependencies = [
420+ "portable-atomic",
421+ "portable-atomic-util",
422+]
423+
424+[[package]]
425+name = "autocfg"
426+version = "1.5.1"
427+source = "registry+https://github.com/rust-lang/crates.io-index"
428+checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
429+
430+[[package]]
431+name = "bevy"
432+version = "0.20.1"
433+source = "registry+https://github.com/rust-lang/crates.io-index"
434+checksum = "78a6c6136c38a50f3d20069adb99064636afcb109cbdf27a00a8c1742f5d630c"
435+dependencies = [
436+ "bevy_internal",
437+]
438+
439+[[package]]
440+name = "bevy_a11y"
441+version = "0.20.1"
442+source = "registry+https://github.com/rust-lang/crates.io-index"
443+checksum = "754be3c143b35aa669588e254a25ec22c7d2c52c0cf3922e8b9aac7805571c8b"
444+dependencies = [
445+ "accesskit",
446+ "bevy_app",
447+ "bevy_derive",
448+ "bevy_ecs",
449+ "bevy_reflect",
450+]
451+
452+[[package]]
453+name = "bevy_android"
454+version = "0.20.1"
455+source = "registry+https://github.com/rust-lang/crates.io-index"
456+checksum = "e06593a351f0220be555b4a2e2c4a8ff9173756791f245613fffb6b7904fae57"
457+dependencies = [
458+ "android-activity",
459+]
460+
461+[[package]]
462+name = "bevy_animation"
463+version = "0.20.1"
464+source = "registry+https://github.com/rust-lang/crates.io-index"
465+checksum = "eeb07a161a4667469dbd515fccfe89cc5be15f0a6650fa8764179e41b460e0c0"
466+dependencies = [
467+ "bevy_animation_macros",
468+ "bevy_app",
469+ "bevy_asset",
470+ "bevy_color",
471+ "bevy_curve",
472+ "bevy_derive",
473+ "bevy_ecs",
474+ "bevy_math",
475+ "bevy_platform",
476+ "bevy_reflect",
477+ "bevy_time",
478+ "bevy_transform",
479+ "bevy_utils",
480+ "bitvec",
481+ "blake3",
482+ "derive_more",
483+ "downcast-rs 2.0.2",
484+ "either",
485+ "petgraph",
486+ "ron",
487+ "serde",
488+ "smallvec",
489+ "thiserror 2.0.21",
490+ "thread_local",
491+ "tracing",
492+ "uuid",
493+]
494+
495+[[package]]
496+name = "bevy_animation_macros"
497+version = "0.20.1"
498+source = "registry+https://github.com/rust-lang/crates.io-index"
499+checksum = "f227e40a03bff5f480feb03f571638272a859d4905fb0b7c0477f4bf4b5a95a6"
500+dependencies = [
501+ "bevy_macro_utils",
502+ "quote",
503+ "syn 2.0.119",
504+]
505+
506+[[package]]
507+name = "bevy_anti_alias"
508+version = "0.20.1"
509+source = "registry+https://github.com/rust-lang/crates.io-index"
510+checksum = "46de632f23bf64b033fdd6b34a64eac37c039fcd8e424b6f56e3d877a8600ed7"
511+dependencies = [
512+ "bevy_app",
513+ "bevy_asset",
514+ "bevy_camera",
515+ "bevy_core_pipeline",
516+ "bevy_derive",
517+ "bevy_diagnostic",
518+ "bevy_ecs",
519+ "bevy_extract",
520+ "bevy_image",
521+ "bevy_math",
522+ "bevy_reflect",
523+ "bevy_render",
524+ "bevy_shader",
525+ "bevy_utils",
526+ "tracing",
527+]
528+
529+[[package]]
530+name = "bevy_app"
531+version = "0.20.1"
532+source = "registry+https://github.com/rust-lang/crates.io-index"
533+checksum = "2549c23ffdf3d3a49483c6716a3502b386f1f9fa523435630b733a77fa414e4f"
534+dependencies = [
535+ "bevy_derive",
536+ "bevy_ecs",
537+ "bevy_platform",
538+ "bevy_reflect",
539+ "bevy_tasks",
540+ "bevy_utils",
541+ "console_error_panic_hook",
542+ "ctrlc",
543+ "downcast-rs 2.0.2",
544+ "log",
545+ "thiserror 2.0.21",
546+ "variadics_please",
547+ "wasm-bindgen",
548+ "web-sys",
549+]
550+
551+[[package]]
552+name = "bevy_asset"
553+version = "0.20.1"
554+source = "registry+https://github.com/rust-lang/crates.io-index"
555+checksum = "f76f4e872ab1723c69dc069a9da605b1d07caeb64992a1e7a0d79ec09d1d8450"
556+dependencies = [
557+ "async-broadcast",
558+ "async-channel",
559+ "async-fs",
560+ "async-io",
561+ "async-lock",
562+ "atomicow",
563+ "bevy_android",
564+ "bevy_app",
565+ "bevy_asset_macros",
566+ "bevy_diagnostic",
567+ "bevy_ecs",
568+ "bevy_platform",
569+ "bevy_reflect",
570+ "bevy_tasks",
571+ "bevy_utils",
572+ "bitflags 2.13.2",
573+ "blake3",
574+ "crossbeam-channel",
575+ "derive_more",
576+ "disqualified",
577+ "downcast-rs 2.0.2",
578+ "either",
579+ "futures-io",
580+ "futures-lite",
581+ "futures-util",
582+ "js-sys",
583+ "ron",
584+ "serde",
585+ "stackfuture",
586+ "thiserror 2.0.21",
587+ "tracing",
588+ "uuid",
589+ "wasm-bindgen",
590+ "wasm-bindgen-futures",
591+ "web-sys",
592+]
593+
594+[[package]]
595+name = "bevy_asset_macros"
596+version = "0.20.1"
597+source = "registry+https://github.com/rust-lang/crates.io-index"
598+checksum = "8b986dd0378a4ab84ec0acdd0660c79c5fe8db5eaec6161227e77d0a81d051f7"
599+dependencies = [
600+ "bevy_macro_utils",
601+ "proc-macro2",
602+ "quote",
603+ "syn 2.0.119",
604+]
605+
606+[[package]]
607+name = "bevy_audio"
608+version = "0.20.1"
609+source = "registry+https://github.com/rust-lang/crates.io-index"
610+checksum = "68c5094f06cce47a4134513d6368c0d6b8c2482b61a0255e51fc955fa434ddfc"
611+dependencies = [
612+ "bevy_app",
613+ "bevy_asset",
614+ "bevy_ecs",
615+ "bevy_math",
616+ "bevy_reflect",
617+ "bevy_transform",
618+ "rodio",
619+ "tracing",
620+]
621+
622+[[package]]
623+name = "bevy_camera"
624+version = "0.20.1"
625+source = "registry+https://github.com/rust-lang/crates.io-index"
626+checksum = "bf4437e702d23468c52a80b5dab68409b41aad7e4973c09e15b2388530704704"
627+dependencies = [
628+ "bevy_app",
629+ "bevy_asset",
630+ "bevy_color",
631+ "bevy_derive",
632+ "bevy_ecs",
633+ "bevy_image",
634+ "bevy_math",
635+ "bevy_mesh",
636+ "bevy_reflect",
637+ "bevy_shape",
638+ "bevy_transform",
639+ "bevy_utils",
640+ "bevy_window",
641+ "derive_more",
642+ "downcast-rs 2.0.2",
643+ "serde",
644+ "smallvec",
645+ "thiserror 2.0.21",
646+ "wgpu-types",
647+]
648+
649+[[package]]
650+name = "bevy_clipboard"
651+version = "0.20.1"
652+source = "registry+https://github.com/rust-lang/crates.io-index"
653+checksum = "1d7460fdf16fd93c8c8d701969c0599a9a4090aa27cf4abf954b16c3e0dfe563"
654+dependencies = [
655+ "arboard",
656+ "bevy_app",
657+ "bevy_ecs",
658+ "bevy_log",
659+ "bevy_platform",
660+ "wasm-bindgen",
661+ "wasm-bindgen-futures",
662+ "web-sys",
663+]
664+
665+[[package]]
666+name = "bevy_color"
667+version = "0.20.1"
668+source = "registry+https://github.com/rust-lang/crates.io-index"
669+checksum = "97928389ed7833ae0f12109a217da51b52a6a00e18b5a77f2eaca1b331ab7830"
670+dependencies = [
671+ "bevy_curve",
672+ "bevy_math",
673+ "bevy_reflect",
674+ "bytemuck",
675+ "derive_more",
676+ "encase",
677+ "serde",
678+ "thiserror 2.0.21",
679+ "wgpu-types",
680+]
681+
682+[[package]]
683+name = "bevy_core_pipeline"
684+version = "0.20.1"
685+source = "registry+https://github.com/rust-lang/crates.io-index"
686+checksum = "2463cf477b683bfe8567c43142295d00ed980f8e2a293c0a69e2f9e10e9c0aaf"
687+dependencies = [
688+ "bevy_app",
689+ "bevy_asset",
690+ "bevy_camera",
691+ "bevy_color",
692+ "bevy_derive",
693+ "bevy_diagnostic",
694+ "bevy_ecs",
695+ "bevy_extract",
696+ "bevy_image",
697+ "bevy_light",
698+ "bevy_log",
699+ "bevy_math",
700+ "bevy_platform",
701+ "bevy_reflect",
702+ "bevy_render",
703+ "bevy_shader",
704+ "bevy_transform",
705+ "bevy_utils",
706+ "bevy_window",
707+ "bitflags 2.13.2",
708+ "indexmap",
709+ "nonmax",
710+]
711+
712+[[package]]
713+name = "bevy_curve"
714+version = "0.20.1"
715+source = "registry+https://github.com/rust-lang/crates.io-index"
716+checksum = "8d9f08cbe2876a34d0ad0534a5b18c4c77da2dafc1cefd744ece45c79e029196"
717+dependencies = [
718+ "approx",
719+ "bevy_math",
720+ "bevy_reflect",
721+ "itertools 0.14.0",
722+ "serde",
723+ "thiserror 2.0.21",
724+ "variadics_please",
725+]
726+
727+[[package]]
728+name = "bevy_derive"
729+version = "0.20.1"
730+source = "registry+https://github.com/rust-lang/crates.io-index"
731+checksum = "b7be8813fd429ff1237bcc5391d1abf4e88ca360302217125d76a1c3cb131b18"
732+dependencies = [
733+ "bevy_macro_utils",
734+ "quote",
735+ "syn 2.0.119",
736+]
737+
738+[[package]]
739+name = "bevy_dev_tools"
740+version = "0.20.1"
741+source = "registry+https://github.com/rust-lang/crates.io-index"
742+checksum = "843a46150d716e44058a56011cc9844ba08e825b5d4f324ee2a0c2f8ec6ab59b"
743+dependencies = [
744+ "bevy_animation",
745+ "bevy_app",
746+ "bevy_asset",
747+ "bevy_audio",
748+ "bevy_camera",
749+ "bevy_color",
750+ "bevy_diagnostic",
751+ "bevy_ecs",
752+ "bevy_extract",
753+ "bevy_image",
754+ "bevy_input",
755+ "bevy_light",
756+ "bevy_log",
757+ "bevy_math",
758+ "bevy_mesh",
759+ "bevy_picking",
760+ "bevy_platform",
761+ "bevy_reflect",
762+ "bevy_render",
763+ "bevy_shader",
764+ "bevy_sprite",
765+ "bevy_state",
766+ "bevy_text",
767+ "bevy_time",
768+ "bevy_transform",
769+ "bevy_ui",
770+ "bevy_ui_widgets",
771+ "bevy_window",
772+ "bevy_world_serialization",
773+ "tracing",
774+]
775+
776+[[package]]
777+name = "bevy_diagnostic"
778+version = "0.20.1"
779+source = "registry+https://github.com/rust-lang/crates.io-index"
780+checksum = "f3a243742d6d3ad9d4ae889b67b307f38a86179b46fadb3acabbdf8bf5d15535"
781+dependencies = [
782+ "atomic-waker",
783+ "bevy_app",
784+ "bevy_ecs",
785+ "bevy_platform",
786+ "bevy_tasks",
787+ "bevy_time",
788+ "const-fnv1a-hash",
789+ "log",
790+ "serde",
791+ "sysinfo",
792+]
793+
794+[[package]]
795+name = "bevy_ecs"
796+version = "0.20.1"
797+source = "registry+https://github.com/rust-lang/crates.io-index"
798+checksum = "9c546460b4e5dbe72a5e8fce733e9306f747d9a74fd0cd67842ee10831d09aa3"
799+dependencies = [
800+ "arrayvec",
801+ "bevy_ecs_macros",
802+ "bevy_platform",
803+ "bevy_ptr",
804+ "bevy_reflect",
805+ "bevy_tasks",
806+ "bevy_utils",
807+ "bitflags 2.13.2",
808+ "bumpalo",
809+ "concurrent-queue",
810+ "derive_more",
811+ "fixedbitset",
812+ "indexmap",
813+ "log",
814+ "nonmax",
815+ "serde",
816+ "slotmap",
817+ "smallvec",
818+ "thiserror 2.0.21",
819+ "variadics_please",
820+]
821+
822+[[package]]
823+name = "bevy_ecs_macro_logic"
824+version = "0.20.1"
825+source = "registry+https://github.com/rust-lang/crates.io-index"
826+checksum = "eb57340122cc39ac36b9ed9c98745c3739dd88c5c89b117c9faf2828978b13f5"
827+dependencies = [
828+ "bevy_macro_utils",
829+ "proc-macro2",
830+ "quote",
831+ "syn 2.0.119",
832+]
833+
834+[[package]]
835+name = "bevy_ecs_macros"
836+version = "0.20.1"
837+source = "registry+https://github.com/rust-lang/crates.io-index"
838+checksum = "2e50a452e8705504c04f80d359be23bcae829053ef58fdd17572d509a1f460b8"
839+dependencies = [
840+ "bevy_ecs_macro_logic",
841+ "bevy_macro_utils",
842+ "proc-macro2",
843+ "quote",
844+ "syn 2.0.119",
845+]
846+
847+[[package]]
848+name = "bevy_encase_derive"
849+version = "0.20.1"
850+source = "registry+https://github.com/rust-lang/crates.io-index"
851+checksum = "6d462345921b71e0a046fd768dd7df65ecacbe6567d12d5ab014eb533e839453"
852+dependencies = [
853+ "bevy_macro_utils",
854+ "encase_derive_impl",
855+]
856+
857+[[package]]
858+name = "bevy_extract"
859+version = "0.20.1"
860+source = "registry+https://github.com/rust-lang/crates.io-index"
861+checksum = "7604e37423fe486a71096fb5c75d7efc80c017dc18b00a12501a8723de0f9e27"
862+dependencies = [
863+ "bevy_app",
864+ "bevy_camera",
865+ "bevy_derive",
866+ "bevy_ecs",
867+ "bevy_extract_macros",
868+ "bevy_log",
869+ "bevy_platform",
870+ "bevy_reflect",
871+ "bevy_time",
872+ "bevy_utils",
873+]
874+
875+[[package]]
876+name = "bevy_extract_macros"
877+version = "0.20.1"
878+source = "registry+https://github.com/rust-lang/crates.io-index"
879+checksum = "ef4fbaf5b7b1dfe68626a12d44bb076cadbf1e15903bac4d71890333f1b03ed9"
880+dependencies = [
881+ "bevy_macro_utils",
882+ "proc-macro2",
883+ "quote",
884+ "syn 2.0.119",
885+]
886+
887+[[package]]
888+name = "bevy_feathers"
889+version = "0.20.1"
890+source = "registry+https://github.com/rust-lang/crates.io-index"
891+checksum = "17d0409c14ba21a6c188ae87fe3609f71670bd323dc63b9725a0acf4cbbe2150"
892+dependencies = [
893+ "accesskit",
894+ "bevy_a11y",
895+ "bevy_app",
896+ "bevy_asset",
897+ "bevy_camera",
898+ "bevy_color",
899+ "bevy_derive",
900+ "bevy_ecs",
901+ "bevy_input",
902+ "bevy_input_focus",
903+ "bevy_log",
904+ "bevy_math",
905+ "bevy_picking",
906+ "bevy_platform",
907+ "bevy_reflect",
908+ "bevy_render",
909+ "bevy_scene",
910+ "bevy_shader",
911+ "bevy_text",
912+ "bevy_ui",
913+ "bevy_ui_render",
914+ "bevy_ui_widgets",
915+ "bevy_window",
916+ "smol_str",
917+]
918+
919+[[package]]
920+name = "bevy_gilrs"
921+version = "0.20.1"
922+source = "registry+https://github.com/rust-lang/crates.io-index"
923+checksum = "6fcc42bbec71537adcd29e2f863a820cc123385427f2987eb84d5f129d61d2f9"
924+dependencies = [
925+ "bevy_app",
926+ "bevy_ecs",
927+ "bevy_input",
928+ "bevy_platform",
929+ "bevy_time",
930+ "gilrs",
931+ "thiserror 2.0.21",
932+ "tracing",
933+]
934+
935+[[package]]
936+name = "bevy_gizmos"
937+version = "0.20.1"
938+source = "registry+https://github.com/rust-lang/crates.io-index"
939+checksum = "90984fdfe73dcb1c8233f1ac91c6719b146910fe60c737e297e88fbce845ceca"
940+dependencies = [
941+ "bevy_app",
942+ "bevy_asset",
943+ "bevy_camera",
944+ "bevy_color",
945+ "bevy_curve",
946+ "bevy_ecs",
947+ "bevy_gizmos_macros",
948+ "bevy_input",
949+ "bevy_log",
950+ "bevy_math",
951+ "bevy_mesh",
952+ "bevy_reflect",
953+ "bevy_shape",
954+ "bevy_time",
955+ "bevy_transform",
956+ "bevy_utils",
957+ "bevy_window",
958+]
959+
960+[[package]]
961+name = "bevy_gizmos_macros"
962+version = "0.20.1"
963+source = "registry+https://github.com/rust-lang/crates.io-index"
964+checksum = "c4345aa000f2482d7d970200cbe835031d243b9835f7a6ee3a63bf2d17e4cee2"
965+dependencies = [
966+ "bevy_macro_utils",
967+ "quote",
968+ "syn 2.0.119",
969+]
970+
971+[[package]]
972+name = "bevy_gizmos_render"
973+version = "0.20.1"
974+source = "registry+https://github.com/rust-lang/crates.io-index"
975+checksum = "649269092becec990815880186214b007212479e124ee1e3456e0c10a6e64f4d"
976+dependencies = [
977+ "bevy_app",
978+ "bevy_asset",
979+ "bevy_camera",
980+ "bevy_color",
981+ "bevy_core_pipeline",
982+ "bevy_ecs",
983+ "bevy_extract",
984+ "bevy_gizmos",
985+ "bevy_image",
986+ "bevy_log",
987+ "bevy_material",
988+ "bevy_math",
989+ "bevy_mesh",
990+ "bevy_reflect",
991+ "bevy_render",
992+ "bevy_shader",
993+ "bevy_shape",
994+ "bevy_sprite_render",
995+ "bevy_transform",
996+ "bevy_utils",
997+ "bytemuck",
998+ "tracing",
999+]
1000+
1001+[[package]]
1002+name = "bevy_image"
1003+version = "0.20.1"
1004+source = "registry+https://github.com/rust-lang/crates.io-index"
1005+checksum = "d4146fc2cb8bb75fa3a8352b5298377801dc6ab48f755539b59d5b2619599618"
1006+dependencies = [
1007+ "bevy_app",
1008+ "bevy_asset",
1009+ "bevy_color",
1010+ "bevy_ecs",
1011+ "bevy_math",
1012+ "bevy_platform",
1013+ "bevy_reflect",
1014+ "bevy_utils",
1015+ "bitflags 2.13.2",
1016+ "bytemuck",
1017+ "futures-lite",
1018+ "guillotiere",
1019+ "half",
1020+ "image",
1021+ "rectangle-pack",
1022+ "serde",
1023+ "thiserror 2.0.21",
1024+ "tracing",
1025+ "wgpu-types",
1026+]
1027+
1028+[[package]]
1029+name = "bevy_input"
1030+version = "0.20.1"
1031+source = "registry+https://github.com/rust-lang/crates.io-index"
1032+checksum = "b591d831373904c0d9dfc1dcd3083148d5a9bc7d3d54e26ec6686009c6568f0e"
1033+dependencies = [
1034+ "bevy_app",
1035+ "bevy_ecs",
1036+ "bevy_math",
1037+ "bevy_platform",
1038+ "bevy_reflect",
1039+ "derive_more",
1040+ "log",
1041+ "smol_str",
1042+ "thiserror 2.0.21",
1043+]
1044+
1045+[[package]]
1046+name = "bevy_input_focus"
1047+version = "0.20.1"
1048+source = "registry+https://github.com/rust-lang/crates.io-index"
1049+checksum = "41559b51a220a521386610015512b5ac180ac42346e997e191a5c917544c7724"
1050+dependencies = [
1051+ "bevy_app",
1052+ "bevy_camera",
1053+ "bevy_ecs",
1054+ "bevy_input",
1055+ "bevy_math",
1056+ "bevy_picking",
1057+ "bevy_reflect",
1058+ "bevy_window",
1059+ "log",
1060+ "thiserror 2.0.21",
1061+]
1062+
1063+[[package]]
1064+name = "bevy_internal"
1065+version = "0.20.1"
1066+source = "registry+https://github.com/rust-lang/crates.io-index"
1067+checksum = "5c1402190b1de36b317af1e9ff4f2f03e5478f0f9d9ac84ccf2ef01fa1dd8182"
1068+dependencies = [
1069+ "bevy_a11y",
1070+ "bevy_android",
1071+ "bevy_animation",
1072+ "bevy_anti_alias",
1073+ "bevy_app",
1074+ "bevy_asset",
1075+ "bevy_audio",
1076+ "bevy_camera",
1077+ "bevy_clipboard",
1078+ "bevy_color",
1079+ "bevy_core_pipeline",
1080+ "bevy_curve",
1081+ "bevy_derive",
1082+ "bevy_dev_tools",
1083+ "bevy_diagnostic",
1084+ "bevy_ecs",
1085+ "bevy_extract",
1086+ "bevy_feathers",
1087+ "bevy_gilrs",
1088+ "bevy_gizmos",
1089+ "bevy_gizmos_render",
1090+ "bevy_image",
1091+ "bevy_input",
1092+ "bevy_input_focus",
1093+ "bevy_light",
1094+ "bevy_log",
1095+ "bevy_material",
1096+ "bevy_math",
1097+ "bevy_mesh",
1098+ "bevy_pbr",
1099+ "bevy_picking",
1100+ "bevy_platform",
1101+ "bevy_post_process",
1102+ "bevy_ptr",
1103+ "bevy_reflect",
1104+ "bevy_render",
1105+ "bevy_scene",
1106+ "bevy_shader",
1107+ "bevy_shape",
1108+ "bevy_sprite",
1109+ "bevy_sprite_render",
1110+ "bevy_state",
1111+ "bevy_tasks",
1112+ "bevy_text",
1113+ "bevy_time",
1114+ "bevy_transform",
1115+ "bevy_ui",
1116+ "bevy_ui_render",
1117+ "bevy_ui_widgets",
1118+ "bevy_utils",
1119+ "bevy_window",
1120+ "bevy_winit",
1121+ "bevy_world_serialization",
1122+]
1123+
1124+[[package]]
1125+name = "bevy_light"
1126+version = "0.20.1"
1127+source = "registry+https://github.com/rust-lang/crates.io-index"
1128+checksum = "a8454efb3391cff0b059470779e6bd4f2147c549833fa36e489f9b51019d7a0a"
1129+dependencies = [
1130+ "bevy_app",
1131+ "bevy_asset",
1132+ "bevy_camera",
1133+ "bevy_color",
1134+ "bevy_curve",
1135+ "bevy_ecs",
1136+ "bevy_gizmos",
1137+ "bevy_image",
1138+ "bevy_log",
1139+ "bevy_math",
1140+ "bevy_mesh",
1141+ "bevy_platform",
1142+ "bevy_reflect",
1143+ "bevy_shape",
1144+ "bevy_transform",
1145+ "bevy_utils",
1146+ "half",
1147+ "smallvec",
1148+ "tracing",
1149+ "wgpu-types",
1150+]
1151+
1152+[[package]]
1153+name = "bevy_log"
1154+version = "0.20.1"
1155+source = "registry+https://github.com/rust-lang/crates.io-index"
1156+checksum = "00742ce2ead8eb76bce32d6049f0ff4b8b60dc8da51a7bc764c69bcc4b32a061"
1157+dependencies = [
1158+ "android_log-sys",
1159+ "bevy_app",
1160+ "bevy_ecs",
1161+ "bevy_platform",
1162+ "bevy_utils",
1163+ "tracing",
1164+ "tracing-log",
1165+ "tracing-oslog",
1166+ "tracing-subscriber",
1167+ "tracing-wasm",
1168+]
1169+
1170+[[package]]
1171+name = "bevy_macro_utils"
1172+version = "0.20.1"
1173+source = "registry+https://github.com/rust-lang/crates.io-index"
1174+checksum = "fdafa048d2bafad7fda1d5a207ab52a6513bbc3a778e5d9e6ab35ac6a41ae11d"
1175+dependencies = [
1176+ "proc-macro2",
1177+ "quote",
1178+ "syn 2.0.119",
1179+ "toml_edit",
1180+]
1181+
1182+[[package]]
1183+name = "bevy_material"
1184+version = "0.20.1"
1185+source = "registry+https://github.com/rust-lang/crates.io-index"
1186+checksum = "3f049627cf0bc06d04dfa1b448476b9597c46e51dc976b71b32ec7d63b17a100"
1187+dependencies = [
1188+ "bevy_asset",
1189+ "bevy_derive",
1190+ "bevy_ecs",
1191+ "bevy_material_macros",
1192+ "bevy_mesh",
1193+ "bevy_platform",
1194+ "bevy_reflect",
1195+ "bevy_shader",
1196+ "bevy_utils",
1197+ "encase",
1198+ "smallvec",
1199+ "thiserror 2.0.21",
1200+ "tracing",
1201+ "variadics_please",
1202+ "wgpu-types",
1203+]
1204+
1205+[[package]]
1206+name = "bevy_material_macros"
1207+version = "0.20.1"
1208+source = "registry+https://github.com/rust-lang/crates.io-index"
1209+checksum = "61b4c90f63e78206aefdc2e0a257af638ab92c2af071ad8fb4743e454607e71c"
1210+dependencies = [
1211+ "bevy_macro_utils",
1212+ "quote",
1213+ "syn 2.0.119",
1214+]
1215+
1216+[[package]]
1217+name = "bevy_math"
1218+version = "0.20.1"
1219+source = "registry+https://github.com/rust-lang/crates.io-index"
1220+checksum = "17b8450e5d05ddd0cbba76e439c769f030a354a685630b919301071943487294"
1221+dependencies = [
1222+ "approx",
1223+ "bevy_reflect",
1224+ "derive_more",
1225+ "glam",
1226+ "libm",
1227+ "rand",
1228+ "serde",
1229+ "thiserror 2.0.21",
1230+ "variadics_please",
1231+]
1232+
1233+[[package]]
1234+name = "bevy_mesh"
1235+version = "0.20.1"
1236+source = "registry+https://github.com/rust-lang/crates.io-index"
1237+checksum = "5f55f324b4204150efb53cb54657dcc8c45cf619adbc3e67c0c6d51ba6fc95ba"
1238+dependencies = [
1239+ "bevy_app",
1240+ "bevy_asset",
1241+ "bevy_derive",
1242+ "bevy_ecs",
1243+ "bevy_encase_derive",
1244+ "bevy_math",
1245+ "bevy_mikktspace",
1246+ "bevy_platform",
1247+ "bevy_reflect",
1248+ "bevy_shape",
1249+ "bevy_transform",
1250+ "bitflags 2.13.2",
1251+ "bytemuck",
1252+ "derive_more",
1253+ "encase",
1254+ "glam",
1255+ "half",
1256+ "hexasphere",
1257+ "thiserror 2.0.21",
1258+ "tracing",
1259+ "wgpu-types",
1260+]
1261+
1262+[[package]]
1263+name = "bevy_mikktspace"
1264+version = "1.0.0"
1265+source = "registry+https://github.com/rust-lang/crates.io-index"
1266+checksum = "bff34eb29ff4b8a8688bc7299f14fb6b597461ca80fec03ed7d22939ab33e48f"
1267+
1268+[[package]]
1269+name = "bevy_pbr"
1270+version = "0.20.1"
1271+source = "registry+https://github.com/rust-lang/crates.io-index"
1272+checksum = "1138d6ed9bbcc43a4d83878062869c20d4292f1112b177acfc1a20cf6ae14f3e"
1273+dependencies = [
1274+ "arrayvec",
1275+ "bevy_app",
1276+ "bevy_asset",
1277+ "bevy_camera",
1278+ "bevy_color",
1279+ "bevy_core_pipeline",
1280+ "bevy_derive",
1281+ "bevy_diagnostic",
1282+ "bevy_ecs",
1283+ "bevy_extract",
1284+ "bevy_image",
1285+ "bevy_light",
1286+ "bevy_log",
1287+ "bevy_material",
1288+ "bevy_math",
1289+ "bevy_mesh",
1290+ "bevy_platform",
1291+ "bevy_reflect",
1292+ "bevy_render",
1293+ "bevy_shader",
1294+ "bevy_shape",
1295+ "bevy_tasks",
1296+ "bevy_transform",
1297+ "bevy_utils",
1298+ "bitflags 2.13.2",
1299+ "bytemuck",
1300+ "derive_more",
1301+ "fixedbitset",
1302+ "indexmap",
1303+ "nonmax",
1304+ "offset-allocator",
1305+ "smallvec",
1306+ "static_assertions",
1307+ "thiserror 2.0.21",
1308+ "tracing",
1309+ "wgpu-types",
1310+]
1311+
1312+[[package]]
1313+name = "bevy_picking"
1314+version = "0.20.1"
1315+source = "registry+https://github.com/rust-lang/crates.io-index"
1316+checksum = "75e55df29bec491abfaec21f4ce211ff90169be815e7cb4ccbd76872d6e2babf"
1317+dependencies = [
1318+ "bevy_app",
1319+ "bevy_asset",
1320+ "bevy_camera",
1321+ "bevy_derive",
1322+ "bevy_ecs",
1323+ "bevy_input",
1324+ "bevy_math",
1325+ "bevy_mesh",
1326+ "bevy_platform",
1327+ "bevy_reflect",
1328+ "bevy_shape",
1329+ "bevy_time",
1330+ "bevy_transform",
1331+ "bevy_window",
1332+ "crossbeam-channel",
1333+ "tracing",
1334+ "uuid",
1335+]
1336+
1337+[[package]]
1338+name = "bevy_platform"
1339+version = "0.20.1"
1340+source = "registry+https://github.com/rust-lang/crates.io-index"
1341+checksum = "9c1280bc12c975ddb041b8341b005415024994477479861ea4490b9b7f9f6185"
1342+dependencies = [
1343+ "bytemuck",
1344+ "critical-section",
1345+ "foldhash 0.2.0",
1346+ "futures-channel",
1347+ "futures-lite",
1348+ "hashbrown 0.16.1",
1349+ "js-sys",
1350+ "portable-atomic",
1351+ "portable-atomic-util",
1352+ "serde",
1353+ "spin",
1354+ "wasm-bindgen",
1355+ "wasm-bindgen-futures",
1356+ "web-time",
1357+ "windows-sys 0.61.2",
1358+]
1359+
1360+[[package]]
1361+name = "bevy_post_process"
1362+version = "0.20.1"
1363+source = "registry+https://github.com/rust-lang/crates.io-index"
1364+checksum = "16a897d6318ed562de228d026b4c4f384c7430fff027c2b4d35367bdad0151ec"
1365+dependencies = [
1366+ "bevy_app",
1367+ "bevy_asset",
1368+ "bevy_camera",
1369+ "bevy_color",
1370+ "bevy_core_pipeline",
1371+ "bevy_curve",
1372+ "bevy_derive",
1373+ "bevy_ecs",
1374+ "bevy_extract",
1375+ "bevy_image",
1376+ "bevy_math",
1377+ "bevy_platform",
1378+ "bevy_reflect",
1379+ "bevy_render",
1380+ "bevy_shader",
1381+ "bevy_utils",
1382+ "smallvec",
1383+ "thiserror 2.0.21",
1384+ "tracing",
1385+]
1386+
1387+[[package]]
1388+name = "bevy_ptr"
1389+version = "0.20.1"
1390+source = "registry+https://github.com/rust-lang/crates.io-index"
1391+checksum = "845b9f43ea7e4be1a19b93673325d47c091df8e3a57a2cd30dd003d0972796be"
1392+
1393+[[package]]
1394+name = "bevy_reflect"
1395+version = "0.20.1"
1396+source = "registry+https://github.com/rust-lang/crates.io-index"
1397+checksum = "31e275d95c84140ae51d58a9e8cae5cf9ed687b59d10e69bfec8da480f5c667f"
1398+dependencies = [
1399+ "assert_type_match",
1400+ "bevy_platform",
1401+ "bevy_ptr",
1402+ "bevy_reflect_derive",
1403+ "bevy_utils",
1404+ "derive_more",
1405+ "disqualified",
1406+ "downcast-rs 2.0.2",
1407+ "erased-serde",
1408+ "foldhash 0.2.0",
1409+ "glam",
1410+ "indexmap",
1411+ "inventory",
1412+ "petgraph",
1413+ "serde",
1414+ "smallvec",
1415+ "smol_str",
1416+ "thiserror 2.0.21",
1417+ "uuid",
1418+ "variadics_please",
1419+ "wgpu-types",
1420+]
1421+
1422+[[package]]
1423+name = "bevy_reflect_derive"
1424+version = "0.20.1"
1425+source = "registry+https://github.com/rust-lang/crates.io-index"
1426+checksum = "c1f0add6e1437551a7f26d22458b6eece9a3e38a5dba0a663a753ab4385d9bfc"
1427+dependencies = [
1428+ "bevy_macro_utils",
1429+ "indexmap",
1430+ "proc-macro2",
1431+ "quote",
1432+ "syn 2.0.119",
1433+ "uuid",
1434+]
1435+
1436+[[package]]
1437+name = "bevy_render"
1438+version = "0.20.1"
1439+source = "registry+https://github.com/rust-lang/crates.io-index"
1440+checksum = "0c74591faf8ff1b84beb59e93f05b233a03c62d1cbc446874bd2231b72dde184"
1441+dependencies = [
1442+ "async-channel",
1443+ "bevy_app",
1444+ "bevy_asset",
1445+ "bevy_camera",
1446+ "bevy_color",
1447+ "bevy_derive",
1448+ "bevy_diagnostic",
1449+ "bevy_ecs",
1450+ "bevy_encase_derive",
1451+ "bevy_extract",
1452+ "bevy_extract_macros",
1453+ "bevy_image",
1454+ "bevy_log",
1455+ "bevy_material",
1456+ "bevy_material_macros",
1457+ "bevy_math",
1458+ "bevy_mesh",
1459+ "bevy_platform",
1460+ "bevy_reflect",
1461+ "bevy_render_macros",
1462+ "bevy_shader",
1463+ "bevy_shape",
1464+ "bevy_tasks",
1465+ "bevy_time",
1466+ "bevy_transform",
1467+ "bevy_utils",
1468+ "bevy_window",
1469+ "bitflags 2.13.2",
1470+ "bytemuck",
1471+ "derive_more",
1472+ "downcast-rs 2.0.2",
1473+ "encase",
1474+ "glam",
1475+ "image",
1476+ "indexmap",
1477+ "itertools 0.14.0",
1478+ "js-sys",
1479+ "nonmax",
1480+ "offset-allocator",
1481+ "send_wrapper",
1482+ "smallvec",
1483+ "static_assertions",
1484+ "thiserror 2.0.21",
1485+ "tracing",
1486+ "variadics_please",
1487+ "wasm-bindgen",
1488+ "weak-table",
1489+ "web-sys",
1490+ "wgpu",
1491+ "wgpu-types",
1492+]
1493+
1494+[[package]]
1495+name = "bevy_render_macros"
1496+version = "0.20.1"
1497+source = "registry+https://github.com/rust-lang/crates.io-index"
1498+checksum = "dc8882ebeef5ed3b9f48d776fd01e36fded2d69574faf775fb25738298a4fbc7"
1499+dependencies = [
1500+ "bevy_extract_macros",
1501+ "bevy_macro_utils",
1502+ "proc-macro2",
1503+ "quote",
1504+ "syn 2.0.119",
1505+]
1506+
1507+[[package]]
1508+name = "bevy_scene"
1509+version = "0.20.1"
1510+source = "registry+https://github.com/rust-lang/crates.io-index"
1511+checksum = "afae77d736b996cc89f542510ded9923df7fabeeb2c8c1bddf8efa1397994c60"
1512+dependencies = [
1513+ "bevy_app",
1514+ "bevy_asset",
1515+ "bevy_derive",
1516+ "bevy_ecs",
1517+ "bevy_log",
1518+ "bevy_platform",
1519+ "bevy_reflect",
1520+ "bevy_scene_macros",
1521+ "bevy_utils",
1522+ "smallvec",
1523+ "thiserror 2.0.21",
1524+ "tracing",
1525+ "variadics_please",
1526+]
1527+
1528+[[package]]
1529+name = "bevy_scene_macros"
1530+version = "0.20.1"
1531+source = "registry+https://github.com/rust-lang/crates.io-index"
1532+checksum = "0461a8968b37cee3e1fa249323515f171ba9fe2daeb26cc2e75343ff10f50079"
1533+dependencies = [
1534+ "bevy_ecs_macro_logic",
1535+ "bevy_macro_utils",
1536+ "proc-macro2",
1537+ "quote",
1538+ "syn 2.0.119",
1539+]
1540+
1541+[[package]]
1542+name = "bevy_shader"
1543+version = "0.20.1"
1544+source = "registry+https://github.com/rust-lang/crates.io-index"
1545+checksum = "c6666ae130a5d6c1be72e2669ee8ae8d1c7f641f3da37915f77cc1f85806a62b"
1546+dependencies = [
1547+ "bevy_asset",
1548+ "bevy_platform",
1549+ "bevy_reflect",
1550+ "bevy_utils",
1551+ "serde",
1552+ "thiserror 2.0.21",
1553+ "tracing",
1554+ "wesl",
1555+ "wgpu-types",
1556+]
1557+
1558+[[package]]
1559+name = "bevy_shape"
1560+version = "0.20.1"
1561+source = "registry+https://github.com/rust-lang/crates.io-index"
1562+checksum = "bc07362ea41db62a442572757ec576239ba4644349df3c646685fc1c526e4608"
1563+dependencies = [
1564+ "arrayvec",
1565+ "bevy_math",
1566+ "bevy_reflect",
1567+ "derive_more",
1568+ "rand",
1569+ "rand_distr",
1570+ "serde",
1571+ "thiserror 2.0.21",
1572+]
1573+
1574+[[package]]
1575+name = "bevy_sprite"
1576+version = "0.20.1"
1577+source = "registry+https://github.com/rust-lang/crates.io-index"
1578+checksum = "f05887e44a45817479f098468d7adc60a632827058a004c20ac1b2a47142f669"
1579+dependencies = [
1580+ "bevy_app",
1581+ "bevy_asset",
1582+ "bevy_camera",
1583+ "bevy_color",
1584+ "bevy_derive",
1585+ "bevy_ecs",
1586+ "bevy_image",
1587+ "bevy_log",
1588+ "bevy_math",
1589+ "bevy_mesh",
1590+ "bevy_picking",
1591+ "bevy_reflect",
1592+ "bevy_text",
1593+ "bevy_transform",
1594+ "bevy_window",
1595+ "radsort",
1596+ "tracing",
1597+ "wgpu-types",
1598+]
1599+
1600+[[package]]
1601+name = "bevy_sprite_render"
1602+version = "0.20.1"
1603+source = "registry+https://github.com/rust-lang/crates.io-index"
1604+checksum = "992e4dd140c8961242c164d6b458c7b53b6e983c4601baac2714fc2083cbe2b8"
1605+dependencies = [
1606+ "bevy_app",
1607+ "bevy_asset",
1608+ "bevy_camera",
1609+ "bevy_color",
1610+ "bevy_core_pipeline",
1611+ "bevy_derive",
1612+ "bevy_ecs",
1613+ "bevy_extract",
1614+ "bevy_image",
1615+ "bevy_material",
1616+ "bevy_math",
1617+ "bevy_mesh",
1618+ "bevy_platform",
1619+ "bevy_reflect",
1620+ "bevy_render",
1621+ "bevy_shader",
1622+ "bevy_shape",
1623+ "bevy_sprite",
1624+ "bevy_text",
1625+ "bevy_transform",
1626+ "bevy_utils",
1627+ "bitflags 2.13.2",
1628+ "bytemuck",
1629+ "derive_more",
1630+ "fixedbitset",
1631+ "nonmax",
1632+ "smallvec",
1633+ "static_assertions",
1634+ "tracing",
1635+]
1636+
1637+[[package]]
1638+name = "bevy_state"
1639+version = "0.20.1"
1640+source = "registry+https://github.com/rust-lang/crates.io-index"
1641+checksum = "5f07338f24a4c1fc772543d7303be5cbdff98fc146ab70e24c2f0556b7f3d6f8"
1642+dependencies = [
1643+ "bevy_app",
1644+ "bevy_ecs",
1645+ "bevy_platform",
1646+ "bevy_reflect",
1647+ "bevy_state_macros",
1648+ "bevy_utils",
1649+ "log",
1650+ "variadics_please",
1651+]
1652+
1653+[[package]]
1654+name = "bevy_state_macros"
1655+version = "0.20.1"
1656+source = "registry+https://github.com/rust-lang/crates.io-index"
1657+checksum = "e456c329db803d9d17568e687444a642fb5f6cef569ffc591e40fe293fc2ffac"
1658+dependencies = [
1659+ "bevy_macro_utils",
1660+ "quote",
1661+ "syn 2.0.119",
1662+]
1663+
1664+[[package]]
1665+name = "bevy_tasks"
1666+version = "0.20.1"
1667+source = "registry+https://github.com/rust-lang/crates.io-index"
1668+checksum = "84c634a7f09e9ccd26137a2f541ab670c84854a1af4107fecca1541cfcd1b466"
1669+dependencies = [
1670+ "async-channel",
1671+ "async-executor",
1672+ "async-task",
1673+ "atomic-waker",
1674+ "bevy_platform",
1675+ "concurrent-queue",
1676+ "crossbeam-queue",
1677+ "derive_more",
1678+ "futures-lite",
1679+ "heapless",
1680+ "web-task",
1681+]
1682+
1683+[[package]]
1684+name = "bevy_text"
1685+version = "0.20.1"
1686+source = "registry+https://github.com/rust-lang/crates.io-index"
1687+checksum = "acee0f4cd88beed48dd1bce01759bc00fc68f9294d34fae4f5f63d881e50fea6"
1688+dependencies = [
1689+ "bevy_app",
1690+ "bevy_asset",
1691+ "bevy_clipboard",
1692+ "bevy_color",
1693+ "bevy_derive",
1694+ "bevy_ecs",
1695+ "bevy_image",
1696+ "bevy_log",
1697+ "bevy_math",
1698+ "bevy_platform",
1699+ "bevy_reflect",
1700+ "bevy_utils",
1701+ "parley",
1702+ "serde",
1703+ "smallvec",
1704+ "smol_str",
1705+ "swash",
1706+ "sys-locale",
1707+ "thiserror 2.0.21",
1708+ "tracing",
1709+ "wgpu-types",
1710+]
1711+
1712+[[package]]
1713+name = "bevy_time"
1714+version = "0.20.1"
1715+source = "registry+https://github.com/rust-lang/crates.io-index"
1716+checksum = "e6f52269fa80326e6d0a9c6e53431fc448651d7fbbb719aa9dfbd4895369ef54"
1717+dependencies = [
1718+ "bevy_app",
1719+ "bevy_ecs",
1720+ "bevy_platform",
1721+ "bevy_reflect",
1722+ "crossbeam-channel",
1723+ "log",
1724+ "serde",
1725+]
1726+
1727+[[package]]
1728+name = "bevy_transform"
1729+version = "0.20.1"
1730+source = "registry+https://github.com/rust-lang/crates.io-index"
1731+checksum = "ef20be97ccdd905cc3f9b66dbea1108ac6bffb1bb9cf9d0b44acd057d10116e9"
1732+dependencies = [
1733+ "bevy_app",
1734+ "bevy_ecs",
1735+ "bevy_math",
1736+ "bevy_reflect",
1737+ "bevy_tasks",
1738+ "bevy_utils",
1739+ "derive_more",
1740+ "serde",
1741+ "thiserror 2.0.21",
1742+]
1743+
1744+[[package]]
1745+name = "bevy_ui"
1746+version = "0.20.1"
1747+source = "registry+https://github.com/rust-lang/crates.io-index"
1748+checksum = "64c375f27a61de095e49bd0426a5249b91bf72e2ab749680097f4419d5a7f255"
1749+dependencies = [
1750+ "accesskit",
1751+ "bevy_a11y",
1752+ "bevy_app",
1753+ "bevy_asset",
1754+ "bevy_camera",
1755+ "bevy_color",
1756+ "bevy_derive",
1757+ "bevy_ecs",
1758+ "bevy_image",
1759+ "bevy_input",
1760+ "bevy_input_focus",
1761+ "bevy_log",
1762+ "bevy_math",
1763+ "bevy_picking",
1764+ "bevy_platform",
1765+ "bevy_reflect",
1766+ "bevy_sprite",
1767+ "bevy_text",
1768+ "bevy_time",
1769+ "bevy_transform",
1770+ "bevy_utils",
1771+ "bevy_window",
1772+ "derive_more",
1773+ "parley",
1774+ "smallvec",
1775+ "swash",
1776+ "taffy",
1777+ "thiserror 2.0.21",
1778+ "tracing",
1779+ "uuid",
1780+]
1781+
1782+[[package]]
1783+name = "bevy_ui_render"
1784+version = "0.20.1"
1785+source = "registry+https://github.com/rust-lang/crates.io-index"
1786+checksum = "f32b47795aa1e5c465246cbf43e010cd75127eeb5ec0c0d0faaf23e98879e1ef"
1787+dependencies = [
1788+ "bevy_a11y",
1789+ "bevy_app",
1790+ "bevy_asset",
1791+ "bevy_camera",
1792+ "bevy_color",
1793+ "bevy_core_pipeline",
1794+ "bevy_derive",
1795+ "bevy_ecs",
1796+ "bevy_extract",
1797+ "bevy_image",
1798+ "bevy_input_focus",
1799+ "bevy_math",
1800+ "bevy_mesh",
1801+ "bevy_platform",
1802+ "bevy_reflect",
1803+ "bevy_render",
1804+ "bevy_shader",
1805+ "bevy_sprite",
1806+ "bevy_sprite_render",
1807+ "bevy_text",
1808+ "bevy_transform",
1809+ "bevy_ui",
1810+ "bevy_utils",
1811+ "bytemuck",
1812+ "derive_more",
1813+ "indexmap",
1814+ "smallvec",
1815+ "tracing",
1816+]
1817+
1818+[[package]]
1819+name = "bevy_ui_widgets"
1820+version = "0.20.1"
1821+source = "registry+https://github.com/rust-lang/crates.io-index"
1822+checksum = "41147a5459b0eaa5534e0a2c4f73999608bd21b369632cf5f3039e0d7d90e2d3"
1823+dependencies = [
1824+ "accesskit",
1825+ "bevy_a11y",
1826+ "bevy_app",
1827+ "bevy_camera",
1828+ "bevy_ecs",
1829+ "bevy_input",
1830+ "bevy_input_focus",
1831+ "bevy_log",
1832+ "bevy_math",
1833+ "bevy_picking",
1834+ "bevy_platform",
1835+ "bevy_reflect",
1836+ "bevy_text",
1837+ "bevy_time",
1838+ "bevy_ui",
1839+ "bevy_window",
1840+ "parley",
1841+ "smol_str",
1842+ "web-sys",
1843+]
1844+
1845+[[package]]
1846+name = "bevy_utils"
1847+version = "0.20.1"
1848+source = "registry+https://github.com/rust-lang/crates.io-index"
1849+checksum = "b1565ae7a124e68a39321620c5339eb501694357c40f50a74413034ed683cdf9"
1850+dependencies = [
1851+ "async-channel",
1852+ "bevy_platform",
1853+ "disqualified",
1854+ "indexmap",
1855+ "thread_local",
1856+]
1857+
1858+[[package]]
1859+name = "bevy_window"
1860+version = "0.20.1"
1861+source = "registry+https://github.com/rust-lang/crates.io-index"
1862+checksum = "796034cbdfa9e8c3f512d659a10b110d7a11004253061a007184451013e7f23f"
1863+dependencies = [
1864+ "bevy_app",
1865+ "bevy_asset",
1866+ "bevy_ecs",
1867+ "bevy_image",
1868+ "bevy_input",
1869+ "bevy_math",
1870+ "bevy_platform",
1871+ "bevy_reflect",
1872+ "log",
1873+ "raw-window-handle",
1874+ "serde",
1875+]
1876+
1877+[[package]]
1878+name = "bevy_winit"
1879+version = "0.20.1"
1880+source = "registry+https://github.com/rust-lang/crates.io-index"
1881+checksum = "397c685e6ab6d4d87b89fb4ce11993c223d0e3c7b34c415cb4b9f69f213d85b6"
1882+dependencies = [
1883+ "accesskit",
1884+ "accesskit_winit",
1885+ "approx",
1886+ "bevy_a11y",
1887+ "bevy_android",
1888+ "bevy_app",
1889+ "bevy_asset",
1890+ "bevy_derive",
1891+ "bevy_ecs",
1892+ "bevy_image",
1893+ "bevy_input",
1894+ "bevy_input_focus",
1895+ "bevy_log",
1896+ "bevy_math",
1897+ "bevy_platform",
1898+ "bevy_reflect",
1899+ "bevy_tasks",
1900+ "bevy_window",
1901+ "bytemuck",
1902+ "js-sys",
1903+ "tracing",
1904+ "wasm-bindgen",
1905+ "web-sys",
1906+ "wgpu-types",
1907+ "winit",
1908+]
1909+
1910+[[package]]
1911+name = "bevy_world_serialization"
1912+version = "0.20.1"
1913+source = "registry+https://github.com/rust-lang/crates.io-index"
1914+checksum = "21d5dfdf18b7f065a23d5ac30e393c82791326d91bd0358f47c75ffcfec855f3"
1915+dependencies = [
1916+ "bevy_app",
1917+ "bevy_asset",
1918+ "bevy_camera",
1919+ "bevy_derive",
1920+ "bevy_ecs",
1921+ "bevy_platform",
1922+ "bevy_reflect",
1923+ "bevy_transform",
1924+ "bevy_utils",
1925+ "derive_more",
1926+ "ron",
1927+ "serde",
1928+ "thiserror 2.0.21",
1929+ "uuid",
1930+]
1931+
1932+[[package]]
1933+name = "bit-set"
1934+version = "0.10.0"
1935+source = "registry+https://github.com/rust-lang/crates.io-index"
1936+checksum = "09ec2f926cc3060f09db9ebc5b52823d85268d24bb917e472c0c4bea35780a7d"
1937+dependencies = [
1938+ "bit-vec",
1939+]
1940+
1941+[[package]]
1942+name = "bit-vec"
1943+version = "0.9.1"
1944+source = "registry+https://github.com/rust-lang/crates.io-index"
1945+checksum = "b71798fca2c1fe1086445a7258a4bc81e6e49dcd24c8d0dd9a1e57395b603f51"
1946+
1947+[[package]]
1948+name = "bitflags"
1949+version = "1.3.2"
1950+source = "registry+https://github.com/rust-lang/crates.io-index"
1951+checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
1952+
1953+[[package]]
1954+name = "bitflags"
1955+version = "2.13.2"
1956+source = "registry+https://github.com/rust-lang/crates.io-index"
1957+checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
1958+dependencies = [
1959+ "bytemuck",
1960+ "serde_core",
1961+]
1962+
1963+[[package]]
1964+name = "bitvec"
1965+version = "1.1.1"
1966+source = "registry+https://github.com/rust-lang/crates.io-index"
1967+checksum = "ddcec3d12c579d40898fe0a9a358a803c23e9c52ca3c425707f81c9436211837"
1968+dependencies = [
1969+ "funty",
1970+ "radium",
1971+ "tap",
1972+ "wyz",
1973+]
1974+
1975+[[package]]
1976+name = "blake3"
1977+version = "1.8.7"
1978+source = "registry+https://github.com/rust-lang/crates.io-index"
1979+checksum = "6d9e454fc11f76977dc803893aff6304ed33d6a26efae8696573bea74baa27ae"
1980+dependencies = [
1981+ "arrayvec",
1982+ "cc",
1983+ "cfg-if",
1984+ "constant_time_eq",
1985+ "cpufeatures",
1986+]
1987+
1988+[[package]]
1989+name = "block2"
1990+version = "0.5.1"
1991+source = "registry+https://github.com/rust-lang/crates.io-index"
1992+checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f"
1993+dependencies = [
1994+ "objc2 0.5.3",
1995+]
1996+
1997+[[package]]
1998+name = "block2"
1999+version = "0.6.2"
2000+source = "registry+https://github.com/rust-lang/crates.io-index"
Cargo.tomladded+30 -0
@@ -0,0 +1,30 @@
1+[package]
2+name = "courier"
3+version = "0.1.0"
4+edition = "2024"
5+default-run = "courier"
6+
7+[dependencies]
8+bevy = { version = "0.20.1", default-features = false, features = ["2d", "ui", "bevy_audio", "vorbis", "symphonia-vorbis"] }
9+
10+[lints.rust]
11+unsafe_code = "forbid"
12+
13+[profile.dev]
14+debug = "line-tables-only"
15+opt-level = 1
16+
17+[profile.dev.package."*"]
18+opt-level = 3
19+
20+[profile.release]
21+debug = "line-tables-only"
22+
23+[profile.web]
24+inherits = "release"
25+opt-level = "s"
26+lto = "fat"
27+codegen-units = 1
28+panic = "abort"
29+strip = false
30+debug = false
assets/CREDITS.txtadded+56 -0
@@ -0,0 +1,56 @@
1+CREDITS
2+
3+Kenney (CC0 1.0) - https://kenney.nl
4+ Author: Kenney Vleugels (Kenney.nl)
5+ License: CC0 1.0 Universal (public domain)
6+ Packs: RPG Audio, Impact Sounds, Music Jingles
7+ audio/step_grass_0..3.ogg <- Impact Sounds: footstep_grass_000..003
8+ audio/step_stone_0..3.ogg <- Impact Sounds: footstep_concrete_000..003
9+ audio/coin.ogg <- RPG Audio: handleCoins.ogg
10+ audio/door.ogg <- RPG Audio: doorOpen_1.ogg
11+ audio/page.ogg <- RPG Audio: bookFlip1.ogg
12+ audio/bag.ogg <- RPG Audio: cloth1.ogg
13+ audio/arrive.ogg <- Music Jingles: Pizzicato jingles_PIZZI01.ogg
14+ audio/home.ogg <- Music Jingles: Sax jingles_SAX01.ogg
15+
16+PagDev - Fireplace Sound Loop (CC0 1.0)
17+ https://opengameart.org/content/fireplace-sound-loop
18+ audio/fire.ogg (trimmed to 60 s)
19+
20+Kresiek The Furry - Amb Rain Loop 1 (CC0 1.0)
21+ https://opengameart.org/content/amb-rain-loop-1
22+ audio/rain.ogg (trimmed to 120 s)
23+
24+Spring Spring - Birds and Wind - Ambient (CC0 1.0)
25+ https://opengameart.org/content/birds-and-wind-ambient-birds-wind-and-synth
26+ audio/amb_wind.ogg (trimmed to 60 s; contains birds)
27+
28+dklon - Crickets (CC-BY 3.0)
29+ https://opengameart.org/content/crickets
30+ audio/amb_night.ogg (trimmed to 120 s; source is not a seamless loop)
31+
32+Machine - Bedtime Music Box (CC-BY 3.0)
33+ https://opengameart.org/content/bedtime-music-box
34+ audio/music_home.ogg
35+
36+YannZ - Contemplative Fantasy Vol 2 (CC-BY 4.0)
37+ https://opengameart.org/content/contemplative-fantasy-vol-2
38+ audio/music_road.ogg (asami_main_loop_a, trimmed to 120 s)
39+
40+
41+Not included: amb_town.ogg (optional, not sourced).
42+Changes from originals: converted to Ogg Vorbis (q4), re-encoded, trimmed. Kenney files are copied unmodified.
43+
44+Kenney Fonts - Kenney Mini (CC0 1.0)
45+ Author: Kenney Vleugels (Kenney.nl)
46+ https://kenney.nl/assets/kenney-fonts
47+ fonts/pixel.ttf <- Fonts/Kenney Mini.ttf (native size 16 px)
48+
49+Generated with ffmpeg, CC0 (synthesized, no source samples)
50+ audio/wolf_howl.ogg <- sine chirp 350-600 Hz, echo tail (generated with ffmpeg, CC0)
51+ audio/wolf_growl.ogg <- low harmonic tone with bit crush (generated with ffmpeg, CC0)
52+ audio/cart_loop.ogg <- brown noise rumble + wheel tick, seamless 5 s loop (generated with ffmpeg, CC0)
53+ audio/lantern.ogg <- inharmonic metal clink (generated with ffmpeg, CC0)
54+ audio/crate.ogg <- low thud + knock (generated with ffmpeg, CC0)
55+
56+Graphics: all gfx/*.png generated procedurally by tools/art_*.py (voxel -> isometric pixel art renderer tools/vox.py). Original work.
assets/audio/amb_night.oggadded+0 -0

Binary file changed

assets/audio/amb_wind.oggadded+0 -0

Binary file changed

assets/audio/arrive.oggadded+0 -0

Binary file changed

assets/audio/bag.oggadded+0 -0

Binary file changed

assets/audio/cart_loop.oggadded+0 -0

Binary file changed

assets/audio/coin.oggadded+0 -0

Binary file changed

assets/audio/crate.oggadded+0 -0

Binary file changed

assets/audio/door.oggadded+0 -0

Binary file changed

assets/audio/fire.oggadded+0 -0

Binary file changed

assets/audio/home.oggadded+0 -0

Binary file changed

assets/audio/lantern.oggadded+0 -0

Binary file changed

assets/audio/music_home.oggadded+0 -0

Binary file changed

assets/audio/music_road.oggadded+0 -0

Binary file changed

assets/audio/page.oggadded+0 -0

Binary file changed

assets/audio/rain.oggadded+0 -0

Binary file changed

assets/audio/step_grass_0.oggadded+0 -0

Binary file changed

assets/audio/step_grass_1.oggadded+0 -0

Binary file changed

assets/audio/step_grass_2.oggadded+0 -0

Binary file changed

assets/audio/step_grass_3.oggadded+0 -0

Binary file changed

assets/audio/step_stone_0.oggadded+0 -0

Binary file changed

assets/audio/step_stone_1.oggadded+0 -0

Binary file changed

assets/audio/step_stone_2.oggadded+0 -0

Binary file changed

assets/audio/step_stone_3.oggadded+0 -0

Binary file changed

assets/audio/wolf_growl.oggadded+0 -0

Binary file changed

assets/audio/wolf_howl.oggadded+0 -0

Binary file changed

assets/fonts/pixel.ttfadded+0 -0

Binary file changed

assets/gfx/a_barn.pngadded+0 -0

Binary file changed

assets/gfx/a_cottage1.pngadded+0 -0

Binary file changed

assets/gfx/a_cottage1_e.pngadded+0 -0

Binary file changed

assets/gfx/a_cottage2.pngadded+0 -0

Binary file changed

assets/gfx/a_cottage2_e.pngadded+0 -0

Binary file changed

assets/gfx/a_home.pngadded+0 -0

Binary file changed

assets/gfx/a_home_e.pngadded+0 -0

Binary file changed

assets/gfx/a_inn.pngadded+0 -0

Binary file changed

assets/gfx/a_inn_e.pngadded+0 -0

Binary file changed

assets/gfx/a_post.pngadded+0 -0

Binary file changed

assets/gfx/a_post_e.pngadded+0 -0

Binary file changed

assets/gfx/a_school.pngadded+0 -0

Binary file changed

assets/gfx/a_school_e.pngadded+0 -0

Binary file changed

assets/gfx/a_shop.pngadded+0 -0

Binary file changed

assets/gfx/a_shop_e.pngadded+0 -0

Binary file changed

assets/gfx/bale.pngadded+0 -0

Binary file changed

assets/gfx/bandit.pngadded+0 -0

Binary file changed

assets/gfx/barmaid.pngadded+0 -0

Binary file changed

assets/gfx/barrel.pngadded+0 -0

Binary file changed

assets/gfx/barrels.pngadded+0 -0

Binary file changed

assets/gfx/bench.pngadded+0 -0

Binary file changed

assets/gfx/birch.pngadded+0 -0

Binary file changed

assets/gfx/boy.pngadded+0 -0

Binary file changed

assets/gfx/bush0.pngadded+0 -0

Binary file changed

assets/gfx/bush1.pngadded+0 -0

Binary file changed

assets/gfx/c_engine.pngadded+0 -0

Binary file changed

assets/gfx/c_headframe.pngadded+0 -0

Binary file changed

assets/gfx/c_inn.pngadded+0 -0

Binary file changed

assets/gfx/c_inn_e.pngadded+0 -0

Binary file changed

assets/gfx/c_pawn.pngadded+0 -0

Binary file changed

assets/gfx/c_row.pngadded+0 -0

Binary file changed

assets/gfx/campfire.pngadded+0 -0

Binary file changed

assets/gfx/cart.pngadded+0 -0

Binary file changed

assets/gfx/coalpile.pngadded+0 -0

Binary file changed

assets/gfx/cobble0.pngadded+0 -0

Binary file changed

assets/gfx/cobble1.pngadded+0 -0

Binary file changed

assets/gfx/cobble2.pngadded+0 -0

Binary file changed

assets/gfx/cobble3.pngadded+0 -0

Binary file changed

assets/gfx/crate.pngadded+0 -0

Binary file changed

assets/gfx/crates.pngadded+0 -0

Binary file changed

assets/gfx/dead.pngadded+0 -0

Binary file changed

assets/gfx/eyes.pngadded+0 -0

Binary file changed

assets/gfx/farmland0.pngadded+0 -0

Binary file changed

assets/gfx/farmland1.pngadded+0 -0

Binary file changed

assets/gfx/fence_x.pngadded+0 -0

Binary file changed

assets/gfx/fence_y.pngadded+0 -0

Binary file changed

assets/gfx/flag0.pngadded+0 -0

Binary file changed

assets/gfx/flag1.pngadded+0 -0

Binary file changed

assets/gfx/flag2.pngadded+0 -0

Binary file changed

assets/gfx/flag3.pngadded+0 -0

Binary file changed

assets/gfx/flame0.pngadded+0 -0

Binary file changed

assets/gfx/flame0_e.pngadded+0 -0

Binary file changed

assets/gfx/flame1.pngadded+0 -0

Binary file changed

assets/gfx/flame1_e.pngadded+0 -0

Binary file changed

assets/gfx/flame2.pngadded+0 -0

Binary file changed

assets/gfx/flame2_e.pngadded+0 -0

Binary file changed

assets/gfx/flame3.pngadded+0 -0

Binary file changed

assets/gfx/flame3_e.pngadded+0 -0

Binary file changed

assets/gfx/flowers0.pngadded+0 -0

Binary file changed

assets/gfx/flowers1.pngadded+0 -0

Binary file changed

assets/gfx/gent.pngadded+0 -0

Binary file changed

assets/gfx/grass0.pngadded+0 -0

Binary file changed

assets/gfx/grass1.pngadded+0 -0

Binary file changed

assets/gfx/grass2.pngadded+0 -0

Binary file changed

assets/gfx/grass3.pngadded+0 -0

Binary file changed

assets/gfx/grave.pngadded+0 -0

Binary file changed

assets/gfx/grocer.pngadded+0 -0

Binary file changed

assets/gfx/haystack.pngadded+0 -0

Binary file changed

assets/gfx/lamp.pngadded+0 -0

Binary file changed

assets/gfx/lamp_e.pngadded+0 -0

Binary file changed

assets/gfx/light.pngadded+0 -0

Binary file changed

assets/gfx/logs.pngadded+0 -0

Binary file changed

assets/gfx/m_inn.pngadded+0 -0

Binary file changed

assets/gfx/m_inn_e.pngadded+0 -0

Binary file changed

assets/gfx/m_mill.pngadded+0 -0

Binary file changed

assets/gfx/m_mill_e.pngadded+0 -0

Binary file changed

assets/gfx/m_shop.pngadded+0 -0

Binary file changed

assets/gfx/m_shop_e.pngadded+0 -0

Binary file changed

assets/gfx/m_terrace.pngadded+0 -0

Binary file changed

assets/gfx/m_terrace_e.pngadded+0 -0

Binary file changed

assets/gfx/m_warehouse.pngadded+0 -0

Binary file changed

assets/gfx/m_warehouse_e.pngadded+0 -0

Binary file changed

assets/gfx/miner.pngadded+0 -0

Binary file changed

assets/gfx/mud0.pngadded+0 -0

Binary file changed

assets/gfx/mud1.pngadded+0 -0

Binary file changed

assets/gfx/oak0.pngadded+0 -0

Binary file changed

assets/gfx/oak1.pngadded+0 -0

Binary file changed

assets/gfx/oak2.pngadded+0 -0

Binary file changed

assets/gfx/old.pngadded+0 -0

Binary file changed

assets/gfx/peddler.pngadded+0 -0

Binary file changed

assets/gfx/pine.pngadded+0 -0

Binary file changed

assets/gfx/planks.pngadded+0 -0

Binary file changed

assets/gfx/player.pngadded+0 -0

Binary file changed

assets/gfx/puff.pngadded+0 -0

Binary file changed

assets/gfx/rail_x.pngadded+0 -0

Binary file changed

assets/gfx/rail_y.pngadded+0 -0

Binary file changed

assets/gfx/road0.pngadded+0 -0

Binary file changed

assets/gfx/road1.pngadded+0 -0

Binary file changed

assets/gfx/road2.pngadded+0 -0

Binary file changed

assets/gfx/road3.pngadded+0 -0

Binary file changed

assets/gfx/rock0.pngadded+0 -0

Binary file changed

assets/gfx/rock1.pngadded+0 -0

Binary file changed

assets/gfx/sack.pngadded+0 -0

Binary file changed

assets/gfx/sacks.pngadded+0 -0

Binary file changed

assets/gfx/signpost.pngadded+0 -0

Binary file changed

assets/gfx/slag.pngadded+0 -0

Binary file changed

assets/gfx/soot0.pngadded+0 -0

Binary file changed

assets/gfx/soot1.pngadded+0 -0

Binary file changed

assets/gfx/soot2.pngadded+0 -0

Binary file changed

assets/gfx/soot3.pngadded+0 -0

Binary file changed

assets/gfx/stall.pngadded+0 -0

Binary file changed

assets/gfx/table.pngadded+0 -0

Binary file changed

assets/gfx/teacher.pngadded+0 -0

Binary file changed

assets/gfx/tent.pngadded+0 -0

Binary file changed

assets/gfx/tub.pngadded+0 -0

Binary file changed

assets/gfx/water0.pngadded+0 -0

Binary file changed

assets/gfx/water1.pngadded+0 -0

Binary file changed

assets/gfx/well.pngadded+0 -0

Binary file changed

assets/gfx/wolf.pngadded+0 -0

Binary file changed

assets/gfx/woman.pngadded+0 -0

Binary file changed

assets/gfx/worker.pngadded+0 -0

Binary file changed

src/audio.rsadded+242 -0
@@ -0,0 +1,242 @@
1+use bevy::audio::{AudioPlayer, AudioSink, AudioSinkPlayback, PlaybackSettings, Volume};
2+use bevy::prelude::*;
3+
4+use crate::cart::CartRolling;
5+use crate::game::{Game, Sfx, Zone};
6+use crate::player::{Mover, Player};
7+
8+pub struct AudioFxPlugin;
9+
10+impl Plugin for AudioFxPlugin {
11+ fn build(&self, app: &mut App) {
12+ app.init_resource::<Steps>()
13+ .add_systems(Startup, spawn_layers)
14+ .add_systems(Update, (fade_layers, footsteps, play_sfx, log_layers).chain());
15+ }
16+}
17+
18+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
19+enum Kind {
20+ MusicHome,
21+ MusicRoad,
22+ Wind,
23+ Night,
24+ Fire,
25+ Rain,
26+ Cart,
27+}
28+
29+#[derive(Component)]
30+struct Layer {
31+ kind: Kind,
32+ current: f32,
33+}
34+
35+#[derive(Resource, Default)]
36+struct Steps {
37+ timer: f32,
38+ index: usize,
39+}
40+
41+const LAYERS: [(Kind, &str); 7] = [
42+ (Kind::MusicHome, "audio/music_home.ogg"),
43+ (Kind::MusicRoad, "audio/music_road.ogg"),
44+ (Kind::Wind, "audio/amb_wind.ogg"),
45+ (Kind::Night, "audio/amb_night.ogg"),
46+ (Kind::Fire, "audio/fire.ogg"),
47+ (Kind::Rain, "audio/rain.ogg"),
48+ (Kind::Cart, "audio/cart_loop.ogg"),
49+];
50+
51+const FADE_SECS: f32 = 1.5;
52+const STEP_SECS: f32 = 0.36;
53+const STEP_SECS_FAST: f32 = 0.22;
54+const STEP_VARIANTS: usize = 4;
55+
56+#[derive(Resource)]
57+pub struct CueLog(pub std::fs::File);
58+
59+fn cue(log: &mut Option<ResMut<CueLog>>, time: &Time, path: &str, vol: f32) -> bool {
60+ use std::io::Write;
61+ match log {
62+ Some(l) => {
63+ let _ = writeln!(l.0, "S {:.4} {} {}", time.elapsed_secs(), path, vol);
64+ true
65+ }
66+ None => false,
67+ }
68+}
69+
70+fn log_layers(time: Res<Time>, log: Option<ResMut<CueLog>>, layers: Query<&Layer>) {
71+ use std::io::Write;
72+ let Some(mut log) = log else { return };
73+ let mut v = vec![0.0f32; LAYERS.len()];
74+ for l in &layers {
75+ if let Some(i) = LAYERS.iter().position(|(k, _)| *k == l.kind) {
76+ v[i] = l.current;
77+ }
78+ }
79+ let _ = writeln!(log.0, "L {:.4} {}", time.elapsed_secs(), v.iter().map(|x| format!("{x:.3}")).collect::<Vec<_>>().join(" "));
80+}
81+
82+fn spawn_layers(mut commands: Commands, assets: Res<AssetServer>, log: Option<Res<CueLog>>) {
83+ use std::io::Write;
84+ if let Some(log) = &log {
85+ let mut f = &log.0;
86+ let _ = writeln!(f, "H {}", LAYERS.map(|(_, p)| p).join(" "));
87+ for (kind, _) in LAYERS {
88+ commands.spawn(Layer { kind, current: 0.0 });
89+ }
90+ return;
91+ }
92+ for (kind, path) in LAYERS {
93+ commands.spawn((
94+ AudioPlayer::new(assets.load(path)),
95+ PlaybackSettings::LOOP.with_volume(Volume::Linear(0.0)),
96+ Layer { kind, current: 0.0 },
97+ ));
98+ }
99+}
100+
101+fn target(kind: Kind, g: &Game, rolling: bool) -> f32 {
102+ let night = g.is_night();
103+ let ashford = g.zone == Zone::Ashford;
104+ match kind {
105+ Kind::MusicHome => {
106+ if ashford {
107+ 0.55
108+ } else {
109+ 0.0
110+ }
111+ }
112+ Kind::MusicRoad => match g.zone {
113+ _ if g.camping => 0.0,
114+ Zone::Road => {
115+ if night {
116+ 0.0
117+ } else {
118+ 0.4
119+ }
120+ }
121+ Zone::Millbrook | Zone::Coalbridge => 0.25,
122+ Zone::Ashford => 0.0,
123+ },
124+ Kind::Wind => {
125+ if !night && !ashford {
126+ 0.35
127+ } else {
128+ 0.0
129+ }
130+ }
131+ Kind::Night => {
132+ if !night {
133+ 0.0
134+ } else if ashford {
135+ 0.25
136+ } else {
137+ 0.45
138+ }
139+ }
140+ Kind::Fire => {
141+ if g.camping {
142+ 0.6
143+ } else {
144+ 0.0
145+ }
146+ }
147+ Kind::Rain => {
148+ if g.raining {
149+ 0.5
150+ } else {
151+ 0.0
152+ }
153+ }
154+ Kind::Cart => {
155+ if rolling {
156+ 0.35
157+ } else {
158+ 0.0
159+ }
160+ }
161+ }
162+}
163+
164+fn fade_layers(
165+ time: Res<Time>,
166+ g: Res<Game>,
167+ rolling: Res<CartRolling>,
168+ mut layers: Query<(&mut Layer, Option<&mut AudioSink>)>,
169+) {
170+ let k = 1.0 - (-time.delta_secs() / FADE_SECS).exp();
171+ for (mut layer, sink) in &mut layers {
172+ layer.current += (target(layer.kind, &g, rolling.0) - layer.current) * k;
173+ if let Some(mut sink) = sink {
174+ sink.set_volume(Volume::Linear(layer.current));
175+ }
176+ }
177+}
178+
179+fn footsteps(
180+ time: Res<Time>,
181+ g: Res<Game>,
182+ mut steps: ResMut<Steps>,
183+ assets: Res<AssetServer>,
184+ mut commands: Commands,
185+ players: Query<&Mover, With<Player>>,
186+ mut log: Option<ResMut<CueLog>>,
187+) {
188+ let Ok(mover) = players.single() else {
189+ return;
190+ };
191+ if !mover.moving {
192+ steps.timer = 0.0;
193+ return;
194+ }
195+ steps.timer += time.delta_secs();
196+ let every = if g.timelapse { STEP_SECS_FAST } else { STEP_SECS };
197+ if steps.timer < every {
198+ return;
199+ }
200+ steps.timer -= every;
201+ let i = steps.index;
202+ steps.index = (i + 1) % STEP_VARIANTS;
203+ let (set, volume) = if g.zone == Zone::Road {
204+ ("step_grass", 0.3)
205+ } else {
206+ ("step_stone", 0.5)
207+ };
208+ let path = format!("audio/{set}_{i}.ogg");
209+ if cue(&mut log, &time, &path, volume) {
210+ return;
211+ }
212+ commands.spawn((
213+ AudioPlayer::new(assets.load(path)),
214+ PlaybackSettings::DESPAWN.with_volume(Volume::Linear(volume)),
215+ ));
216+}
217+
218+fn play_sfx(mut commands: Commands, assets: Res<AssetServer>, mut g: ResMut<Game>, time: Res<Time>, mut log: Option<ResMut<CueLog>>) {
219+ if g.sfx.is_empty() {
220+ return;
221+ }
222+ for sfx in g.sfx.drain(..) {
223+ let path = match sfx {
224+ Sfx::Coin => "audio/coin.ogg",
225+ Sfx::Door => "audio/door.ogg",
226+ Sfx::Page => "audio/page.ogg",
227+ Sfx::Bag => "audio/bag.ogg",
228+ Sfx::Arrive => "audio/arrive.ogg",
229+ Sfx::Home => "audio/home.ogg",
230+ Sfx::Lantern => "audio/lantern.ogg",
231+ Sfx::Howl => "audio/wolf_howl.ogg",
232+ Sfx::Growl => "audio/wolf_growl.ogg",
233+ };
234+ if cue(&mut log, &time, path, 0.6) {
235+ continue;
236+ }
237+ commands.spawn((
238+ AudioPlayer::new(assets.load(path)),
239+ PlaybackSettings::DESPAWN.with_volume(Volume::Linear(0.6)),
240+ ));
241+ }
242+}
src/bin/mixdown.rsadded+76 -0
@@ -0,0 +1,76 @@
1+#![forbid(unsafe_code)]
2+use std::collections::HashMap;
3+use std::io::Write;
4+use std::process::{Command, Stdio};
5+
6+const SR: usize = 44100;
7+const FPS: f32 = 30.0;
8+
9+fn decode(path: &str) -> Vec<f32> {
10+ let out = Command::new("ffmpeg").args(["-v", "error", "-i", path, "-f", "f32le", "-ac", "2", "-ar", "44100", "-"]).output().expect("ffmpeg");
11+ out.stdout.chunks_exact(4).map(|b| f32::from_le_bytes([b[0], b[1], b[2], b[3]])).collect()
12+}
13+
14+fn main() {
15+ let args: Vec<String> = std::env::args().collect();
16+ let (video, root, out) = (&args[1], &args[2], &args[3]);
17+ let cues = std::fs::read_to_string(format!("{video}.cues")).expect("cues");
18+ let mut layers: Vec<String> = Vec::new();
19+ let mut vols: Vec<(f32, Vec<f32>)> = Vec::new();
20+ let mut shots: Vec<(f32, String, f32)> = Vec::new();
21+ for line in cues.lines() {
22+ let p: Vec<&str> = line.split(' ').collect();
23+ match p[0] {
24+ "H" => layers = p[1..].iter().map(|s| s.to_string()).collect(),
25+ "L" => vols.push((p[1].parse().unwrap(), p[2..].iter().map(|v| v.parse().unwrap()).collect())),
26+ "S" => shots.push((p[1].parse().unwrap(), p[2].to_string(), p[3].parse().unwrap())),
27+ _ => {}
28+ }
29+ }
30+ let t0 = 5.0 / FPS;
31+ let dur = vols.last().map(|v| v.0).unwrap_or(0.0) - t0;
32+ let n = (dur.max(0.0) * SR as f32) as usize;
33+ let mut buf = vec![0.0f32; n * 2];
34+ let mut cache: HashMap<String, Vec<f32>> = HashMap::new();
35+ let mut load = |p: &str| -> Vec<f32> { cache.entry(p.to_string()).or_insert_with(|| decode(&format!("{root}/{p}"))).clone() };
36+ for (li, path) in layers.iter().enumerate() {
37+ let data = load(path);
38+ if data.len() < 2 {
39+ continue;
40+ }
41+ let frames = data.len() / 2;
42+ for k in 0..n {
43+ let t = t0 + k as f32 / SR as f32;
44+ let fi = t * FPS;
45+ let i = (fi as usize).min(vols.len() - 1);
46+ let j = (i + 1).min(vols.len() - 1);
47+ let f = fi.fract();
48+ let v = vols[i].1[li] * (1.0 - f) + vols[j].1[li] * f;
49+ if v <= 0.0005 {
50+ continue;
51+ }
52+ let s = k % frames;
53+ buf[k * 2] += data[s * 2] * v;
54+ buf[k * 2 + 1] += data[s * 2 + 1] * v;
55+ }
56+ }
57+ for (t, path, vol) in &shots {
58+ let data = load(path);
59+ let start = ((t - t0).max(0.0) * SR as f32) as usize;
60+ for (i, x) in data.iter().enumerate() {
61+ let k = start * 2 + i;
62+ if k >= buf.len() {
63+ break;
64+ }
65+ buf[k] += x * vol;
66+ }
67+ }
68+ let bytes: Vec<u8> = buf.iter().flat_map(|x| (x * 0.9).tanh().to_le_bytes()).collect();
69+ let mut child = Command::new("ffmpeg")
70+ .args(["-y", "-v", "error", "-i", video, "-f", "f32le", "-ar", "44100", "-ac", "2", "-i", "-", "-map", "0:v", "-map", "1:a", "-c:v", "copy", "-c:a", "aac", "-b:a", "160k", "-shortest", out])
71+ .stdin(Stdio::piped())
72+ .spawn()
73+ .expect("ffmpeg");
74+ child.stdin.take().unwrap().write_all(&bytes).unwrap();
75+ child.wait().unwrap();
76+}
src/cart.rsadded+79 -0
@@ -0,0 +1,79 @@
1+use crate::game::{Game, Item, Zone};
2+use crate::iso::{anchor, depth, to_screen, PX};
3+use crate::player::{self, facing_of, sort_z, Mover, Player};
4+use crate::sheets::CharSheets;
5+use crate::world::{Occluder, ASHFORD};
6+use bevy::prelude::*;
7+
8+#[derive(Component)]
9+pub struct Cart {
10+ pub pos: Vec2,
11+ pub heading: Vec2,
12+ pub wheel: f32,
13+ pub attached: bool,
14+}
15+
16+#[derive(Resource, Default)]
17+pub struct CartRolling(pub bool);
18+
19+pub struct CartPlugin;
20+
21+impl Plugin for CartPlugin {
22+ fn build(&self, app: &mut App) {
23+ app.init_resource::<CartRolling>()
24+ .add_systems(Startup, spawn_cart.after(crate::sheets::load_sheets))
25+ .add_systems(
26+ Update,
27+ follow_cart.after(player::move_player).before(player::set_pose),
28+ );
29+ }
30+}
31+
32+fn spawn_cart(mut commands: Commands, sheets: Res<CharSheets>) {
33+ let pos = ASHFORD + Vec2::new(15.5, 0.5);
34+ commands.spawn((
35+ sheets.sprite("cart", 0),
36+ anchor(sheets.spr("cart")),
37+ Transform::from_translation(to_screen(pos).extend(depth(pos))).with_scale(Vec3::splat(PX)),
38+ Cart { pos, heading: player::to_world_dir(player::screen_of(3)), wheel: 0.0, attached: false },
39+ ));
40+}
41+
42+fn follow_cart(
43+ time: Res<Time>,
44+ g: Res<Game>,
45+ mut rolling: ResMut<CartRolling>,
46+ pq: Query<&Mover, With<Player>>,
47+ occ: Query<&Occluder>,
48+ mut cq: Query<(&mut Cart, &mut Sprite, &mut Transform)>,
49+) {
50+ let (Ok(m), Ok((mut c, mut s, mut t))) = (pq.single(), cq.single_mut()) else { return };
51+ let dt = time.delta_secs();
52+ c.attached = g.zone == Zone::Road && !g.camping;
53+ rolling.0 = c.attached && m.moving;
54+ if c.attached {
55+ let want = player::to_world_dir(player::screen_of(m.facing));
56+ let h = c.heading.lerp(want, 1.0 - (-dt * 6.0).exp());
57+ if h.length_squared() > 1e-6 {
58+ c.heading = h.normalize();
59+ }
60+ let target = m.pos + c.heading * 0.95;
61+ let before = c.pos;
62+ c.pos = if (c.pos - target).length() > 3.0 {
63+ target
64+ } else {
65+ c.pos.lerp(target, 1.0 - (-dt * 20.0).exp())
66+ };
67+ let dist = (c.pos - before).length();
68+ c.wheel = (c.wheel + dist / 0.35) % 4.0;
69+ }
70+ let dir = facing_of(to_screen(c.heading).normalize_or_zero());
71+ let loaded = g.has(Item::Parcel) || g.has(Item::Letter) || g.has(Item::JacksLetter);
72+ let row = if loaded { 8 } else { 0 } + dir;
73+ let col = (c.wheel as usize) % 4;
74+ if let Some(a) = &mut s.texture_atlas {
75+ a.index = row * 4 + col;
76+ }
77+ t.translation = to_screen(c.pos).extend(sort_z(c.pos, &occ));
78+ t.scale = Vec3::splat(PX);
79+}
src/content.rsadded+738 -0
@@ -0,0 +1,738 @@
1+use crate::game::*;
2+
3+pub fn talk(t: Talk, node: &str, g: &Game) -> Dialog {
4+ match t {
5+ Talk::Npc(n) => npc(n, node, g),
6+ Talk::Obj(o) => obj(o, g),
7+ Talk::Ev(e) => ev(e, node, g),
8+ Talk::Camp => camp(g),
9+ }
10+}
11+
12+fn hi(g: &Game, n: Npc, a: &'static str, b: &'static str, c: &'static str) -> &'static str {
13+ match g.heart(n) {
14+ 0 => a,
15+ 1 | 2 => b,
16+ _ => c,
17+ }
18+}
19+
20+fn eat(g: &mut Game) {
21+ if g.pay(1) {
22+ g.hunger = (g.hunger + 45.0).min(100.0);
23+ g.request = Some(Req::Wait { minutes: 30.0 });
24+ }
25+}
26+
27+fn bed(g: &mut Game) {
28+ if g.pay(2) {
29+ g.request = Some(Req::Sleep { until: 7.0 * 60.0, camp: false });
30+ }
31+}
32+
33+fn sleep_home(g: &mut Game) {
34+ g.request = Some(Req::Sleep { until: 7.0 * 60.0, camp: false });
35+}
36+
37+fn buy_ration(g: &mut Game) {
38+ g.buy(Item::Ration, 1);
39+}
40+
41+fn buy_wood(g: &mut Game) {
42+ g.buy(Item::Firewood, 1);
43+}
44+
45+fn buy_tobacco(g: &mut Game) {
46+ g.buy(Item::Tobacco, 1);
47+}
48+
49+fn buy_whistle(g: &mut Game) {
50+ g.buy(Item::TinWhistle, 1);
51+}
52+
53+fn buy_ribbon(g: &mut Game) {
54+ g.buy(Item::Ribbon, 2);
55+}
56+
57+fn buy_book(g: &mut Game) {
58+ g.buy(Item::PoetryBook, 6);
59+}
60+
61+fn give_bread(g: &mut Game) {
62+ g.take(Item::Ration);
63+}
64+
65+fn npc(n: Npc, node: &str, g: &Game) -> Dialog {
66+ match n {
67+ Npc::Hale => hale(node, g),
68+ Npc::Pike => pike(node, g),
69+ Npc::Bess => bess(node, g),
70+ Npc::Edwin => edwin(node, g),
71+ Npc::OldTom => tom(node, g),
72+ Npc::Annie => sam(node, g),
73+ Npc::Foreman => foreman(node, g),
74+ Npc::Quill => quill(node, g),
75+ Npc::Weaver => weaver(node),
76+ Npc::Peddler => market(g),
77+ Npc::Miner => miner(node, g),
78+ Npc::Jack => jack(node, g),
79+ Npc::Pawn => pawn(node, g),
80+ }
81+}
82+
83+fn hale(node: &str, g: &Game) -> Dialog {
84+ let n = Npc::Hale;
85+ match node {
86+ "parcel" => {
87+ if g.flag("job_parcel") || g.flag("delivered_parcel") {
88+ Dialog::new(n.name(), "The Millbrook parcel is in your hands. Mind it.").bye("Leave")
89+ } else {
90+ Dialog::new(n.name(), "A parcel for the Millbrook mill foreman. Five shillings on delivery.")
91+ .act("Take the parcel", None, |g| {
92+ g.give(Item::Parcel);
93+ g.set("job_parcel");
94+ })
95+ .bye("Not today")
96+ }
97+ }
98+ "letter" => {
99+ if g.flag("job_letter") {
100+ Dialog::new(n.name(), "Straight to the pawnbroker in Coalbridge, and back before dark.").bye("Leave")
101+ } else if g.flag("delivered_letter") {
102+ Dialog::new(n.name(), "The pawnbroker paid fair, I'll say that for him.").bye("Leave")
103+ } else {
104+ Dialog::new(n.name(), "A sealed letter for the Coalbridge pawnbroker. Eight shillings on delivery.")
105+ .act("Take the letter", None, |g| {
106+ g.give(Item::Letter);
107+ g.set("job_letter");
108+ })
109+ .bye("Not today")
110+ }
111+ }
112+ "roads" => Dialog::new(
113+ n.name(),
114+ "Surveyors have pegged a line over the moor all summer. Railway, they say. The coaching trade is finished.",
115+ )
116+ .go("Back", "start")
117+ .bye("Leave"),
118+ _ => hale_start(g),
119+ }
120+}
121+
122+fn hale_start(g: &Game) -> Dialog {
123+ let n = Npc::Hale;
124+ if g.flag("delivered_parcel") && !g.flag("hale_thanked") {
125+ return Dialog::new(n.name(), "The foreman's receipt came back. You did well by the parcel.").act(
126+ "Thank you, sir",
127+ Some("letter"),
128+ |g| {
129+ g.bond(Npc::Hale, 1);
130+ g.set("hale_thanked");
131+ },
132+ );
133+ }
134+ let text = hi(
135+ g,
136+ n,
137+ "Morning. The post comes in on the early coach, if the rain lets it.",
138+ "Ah, it's you. Mind the loose step.",
139+ "Good to see you, friend. Sit a minute, the kettle's on.",
140+ );
141+ let mut d = Dialog::new(n.name(), text);
142+ if !g.flag("job_parcel") && !g.flag("delivered_parcel") {
143+ d = d.go("Any work going?", "parcel");
144+ }
145+ if (g.flag("job_parcel") || g.flag("delivered_parcel")) && !g.flag("job_letter") && !g.flag("delivered_letter") {
146+ d = d.go("Any more work?", "letter");
147+ }
148+ d.go("Talk about the roads", "roads").bye("Leave")
149+}
150+
151+fn pike(node: &str, g: &Game) -> Dialog {
152+ let n = Npc::Pike;
153+ match node {
154+ "shop" => {
155+ let mut d = Dialog::new(n.name(), "Prices are up since the mills. Never sleep cold on the moor road. Take wood.");
156+ if g.money >= 1 {
157+ d = d.act("Ration (1s)", Some("shop"), buy_ration);
158+ d = d.act("Firewood (1s)", Some("shop"), buy_wood);
159+ }
160+ if !g.has(Item::Bedroll) && g.money >= 3 {
161+ d = d.act("Bedroll (3s)", Some("shop"), |g| {
162+ g.buy(Item::Bedroll, 3);
163+ });
164+ }
165+ if !g.has(Item::Lantern) && g.money >= 2 {
166+ d = d.act("Lantern (2s)", Some("shop"), |g| {
167+ g.buy(Item::Lantern, 2);
168+ });
169+ }
170+ d.bye("Leave")
171+ }
172+ _ => Dialog::new(
173+ n.name(),
174+ hi(
175+ g,
176+ n,
177+ "Good day. Mind the sugar tins on the sill.",
178+ "Morning. Need anything for the road?",
179+ "Back again? Let me sort you out proper.",
180+ ),
181+ )
182+ .go("Show me your goods", "shop")
183+ .bye("Leave"),
184+ }
185+}
186+
187+fn bess(node: &str, g: &Game) -> Dialog {
188+ let n = Npc::Bess;
189+ match node {
190+ "gossip" => Dialog::new(
191+ n.name(),
192+ "The ironworks took on two hundred men in spring. Half of them left wives on the moor road. Mind yourself out there.",
193+ )
194+ .bye("Leave"),
195+ "wants" => Dialog::new(
196+ n.name(),
197+ "A silk ribbon for chapel on Sunday. They sell them in Millbrook, the peddler there has a tray.",
198+ )
199+ .bye("Leave"),
200+ "ribbon_thanks" => Dialog::new(n.name(), "Oh, look at that. I'll wear it to chapel on Sunday.").bye("Leave"),
201+ _ => {
202+ let mut d = Dialog::new(
203+ n.name(),
204+ hi(
205+ g,
206+ n,
207+ "Hot meal and a fire, if you've the coin.",
208+ "Mind the step. Soup's on.",
209+ "Sit by the fire, love. You look done in.",
210+ ),
211+ );
212+ if g.money >= 1 {
213+ d = d.act("Hot meal (1s)", None, eat);
214+ }
215+ if g.has(Item::Ribbon) && !g.flag("gave_ribbon") {
216+ d = d.act("Give her the silk ribbon", Some("ribbon_thanks"), |g| {
217+ g.take(Item::Ribbon);
218+ g.bond(Npc::Bess, 2);
219+ g.set("gave_ribbon");
220+ });
221+ }
222+ if !g.has(Item::Ribbon) && !g.flag("gave_ribbon") {
223+ d = d.go("Do you need anything?", "wants");
224+ }
225+ d.go("Any news?", "gossip").bye("Leave")
226+ }
227+ }
228+}
229+
230+fn edwin(node: &str, g: &Game) -> Dialog {
231+ let n = Npc::Edwin;
232+ match node {
233+ "wants" => Dialog::new(n.name(), "I'd give a week's wages for Songs of the Moor. Nobody in Ashford stocks it.")
234+ .bye("Leave"),
235+ "thanks" => Dialog::new(n.name(), "Songs of the Moor. Thank you. I'll read it by the stove tonight.").bye("Leave"),
236+ "verse" => Dialog::new(
237+ n.name(),
238+ "The chimneys bloom with smoke by day, the larks have long since fled; but the beck still runs its quiet way beneath the moor's grey bed.",
239+ )
240+ .bye("Leave"),
241+ _ => {
242+ let mut d = Dialog::new(
243+ n.name(),
244+ hi(
245+ g,
246+ n,
247+ "Sit down, the slate's still warm. Don't mind the boys.",
248+ "Ah. Did you bring the post?",
249+ "You're a welcome sight. Sit by the stove.",
250+ ),
251+ );
252+ if g.has(Item::PoetryBook) && !g.flag("gave_book") {
253+ d = d.act("Give him Songs of the Moor", Some("thanks"), |g| {
254+ g.take(Item::PoetryBook);
255+ g.bond(Npc::Edwin, 2);
256+ g.set("gave_book");
257+ });
258+ }
259+ if g.flag("gave_book") {
260+ d = d.go("Recite something", "verse");
261+ } else {
262+ d = d.go("What do you want?", "wants");
263+ }
264+ d.bye("Leave")
265+ }
266+ }
267+}
268+
269+fn tom(node: &str, g: &Game) -> Dialog {
270+ let n = Npc::OldTom;
271+ match node {
272+ "jack" => Dialog::new(
273+ n.name(),
274+ "My Jack went to the Coalbridge ironworks a year gone. Not a line since. Would you look in on him?",
275+ )
276+ .act("I'll look for him", Some("jack_yes"), |g| g.set("quest_jack")),
277+ "jack_yes" => Dialog::new(n.name(), "Thank you. Tell him his father's chest is bad, but his bed's still made.")
278+ .bye("Leave"),
279+ "letter_read" => Dialog::new(
280+ n.name(),
281+ "He can't read, so you read it aloud. 'Dear Father, the works are hard and the wage is steady. I think of the moor every night. Your son, Jack.' He says nothing for a long while, then nods. 'Aye. That's him.'",
282+ )
283+ .bye("Leave"),
284+ "tobacco" => Dialog::new(n.name(), "He packs the pipe with shaking hands. 'That's a kindness, lad.'").bye("Leave"),
285+ _ => {
286+ let mut d = Dialog::new(
287+ n.name(),
288+ hi(
289+ g,
290+ n,
291+ "*Coughs into his sleeve.* Mind the dust, lad.",
292+ "Morning. The chest is bad today.",
293+ "Sit down, lad. Good to see a friendly face.",
294+ ),
295+ );
296+ if !g.flag("quest_jack") && !g.flag("jack_done") {
297+ d = d.go("Anything I can do?", "jack");
298+ }
299+ if g.flag("quest_jack") && g.has(Item::JacksLetter) && !g.flag("jack_done") {
300+ d = d.act("Give him the letter", Some("letter_read"), |g| {
301+ g.take(Item::JacksLetter);
302+ g.bond(Npc::OldTom, 3);
303+ g.set("jack_done");
304+ });
305+ }
306+ if g.has(Item::Tobacco) {
307+ d = d.act("Give him pipe tobacco", Some("tobacco"), |g| {
308+ g.take(Item::Tobacco);
309+ g.bond(Npc::OldTom, 1);
310+ });
311+ }
312+ d.bye("Leave")
313+ }
314+ }
315+}
316+
317+fn sam(node: &str, g: &Game) -> Dialog {
318+ let n = Npc::Annie;
319+ match node {
320+ "wants" => Dialog::new(n.name(), "A tin whistle. The peddler in Millbrook has them for a shilling.").bye("Leave"),
321+ "whistle_play" => Dialog::new(
322+ n.name(),
323+ "He blows three wobbly notes, then a whole tune. The kitchen goes quiet to listen.",
324+ )
325+ .bye("Leave"),
326+ _ => {
327+ let mut d = Dialog::new(
328+ n.name(),
329+ hi(
330+ g,
331+ n,
332+ "He stares at your boots and says nothing.",
333+ "He grins and hides behind the table leg.",
334+ "He shows you his scraped knee, proudly.",
335+ ),
336+ );
337+ if g.has(Item::TinWhistle) {
338+ d = d.act("Give him the tin whistle", Some("whistle_play"), |g| {
339+ g.take(Item::TinWhistle);
340+ g.bond(Npc::Annie, 2);
341+ g.set("gave_whistle");
342+ });
343+ } else if g.flag("gave_whistle") {
344+ d = d.go("Ask for a tune", "whistle_play");
345+ } else {
346+ d = d.go("What do you want?", "wants");
347+ }
348+ d.bye("Leave")
349+ }
350+ }
351+}
352+
353+fn foreman(node: &str, g: &Game) -> Dialog {
354+ let n = Npc::Foreman;
355+ match node {
356+ "bales" => Dialog::new(
357+ n.name(),
358+ "Two bales from the pile to the mill door. Three shillings. They weigh more than they look.",
359+ )
360+ .act("Take the job", None, |g| g.set("job_bales"))
361+ .bye("Not today"),
362+ "parcel_done" => Dialog::new(n.name(), "Good. Tell Hale the mill is still standing.").bye("Leave"),
363+ "bales_paid" => Dialog::new(n.name(), "Three shillings. Don't spend it all at the Arms.").bye("Leave"),
364+ "children" => Dialog::new(
365+ n.name(),
366+ "Eight and nine year olds on the lower frames, under the belts. Their fingers are quick. That's all the mill wants of them.",
367+ )
368+ .bye("Leave"),
369+ _ => {
370+ let mut text = String::from("The frames don't stop. Fourteen hours, six days.");
371+ if g.flag("job_bales") && g.counter("bales") < 2 {
372+ text += &format!(" {} bales still to carry.", 2 - g.counter("bales"));
373+ }
374+ let mut d = Dialog::new(n.name(), text);
375+ if g.has(Item::Parcel) && g.flag("job_parcel") {
376+ d = d.act("Deliver the Millbrook parcel", Some("parcel_done"), |g| {
377+ g.take(Item::Parcel);
378+ g.earn(5);
379+ g.set("delivered_parcel");
380+ g.unset("job_parcel");
381+ });
382+ }
383+ if g.flag("job_bales") && g.counter("bales") >= 2 {
384+ d = d.act("Collect your pay", Some("bales_paid"), |g| {
385+ g.earn(3);
386+ g.unset("job_bales");
387+ g.set("bales_done");
388+ });
389+ } else if !g.flag("job_bales") && !g.flag("bales_done") {
390+ d = d.go("Any extra work?", "bales");
391+ }
392+ d.go("What about the children?", "children").bye("Leave")
393+ }
394+ }
395+}
396+
397+fn quill(node: &str, g: &Game) -> Dialog {
398+ let n = Npc::Quill;
399+ match node {
400+ "news" => Dialog::new(
401+ n.name(),
402+ "Penny papers and Chartist pamphlets, under the counter. The Chartists want the vote and a fair wage. The magistrate wants them quiet. I sell both and read neither.",
403+ )
404+ .bye("Leave"),
405+ _ => {
406+ let mut d = Dialog::new(
407+ n.name(),
408+ hi(
409+ g,
410+ n,
411+ "Come in out of the damp. Mind the stacks.",
412+ "Ah, a customer. Anything in particular?",
413+ "The usual, is it? Shall I put it aside?",
414+ ),
415+ );
416+ if !g.has(Item::PoetryBook) && !g.flag("gave_book") && g.money >= 6 {
417+ d = d.act("Songs of the Moor (6s)", None, buy_book);
418+ }
419+ d.go("Any news?", "news").bye("Leave")
420+ }
421+ }
422+}
423+
424+fn weaver(node: &str) -> Dialog {
425+ let n = Npc::Weaver;
426+ match node {
427+ "loom" => Dialog::new(
428+ n.name(),
429+ "The power looms came in. Cloth at a penny the yard, that I'd never weave for less than sixpence. The mill took my trade and gave me a shed to stand in.",
430+ )
431+ .go("And now?", "last"),
432+ "last" => Dialog::new(n.name(), "Mind the shuttle on the sill. It's all I kept of my trade.").bye("Leave"),
433+ _ => Dialog::new(n.name(), "I had four looms and a bench of my own, once.")
434+ .go("What happened?", "loom")
435+ .bye("Leave"),
436+ }
437+}
438+
439+fn market(g: &Game) -> Dialog {
440+ let mut d = Dialog::new(Npc::Peddler.name(), "Whistles, ribbons, bread. Prices are up since the mill opened.");
441+ if !g.has(Item::TinWhistle) && g.money >= 1 {
442+ d = d.act("Tin Whistle (1s)", Some("start"), buy_whistle);
443+ }
444+ if !g.has(Item::Ribbon) && g.money >= 2 {
445+ d = d.act("Silk Ribbon (2s)", Some("start"), buy_ribbon);
446+ }
447+ if g.money >= 1 {
448+ d = d.act("Ration (1s)", Some("start"), buy_ration);
449+ d = d.act("Firewood (1s)", Some("start"), buy_wood);
450+ }
451+ d.bye("Leave")
452+}
453+
454+fn miner(node: &str, g: &Game) -> Dialog {
455+ let n = Npc::Miner;
456+ match node {
457+ "pit" => Dialog::new(
458+ n.name(),
459+ "Two hundred feet down. Water to the knees, and gas that takes the lamp if you're careless. My father went down at nine. I went at eight.",
460+ )
461+ .bye("Leave"),
462+ "notice" => Dialog::new(
463+ n.name(),
464+ "The notice says the company will not answer for accidents below ground. He nods, as if he'd known it.",
465+ )
466+ .bye("Thank you"),
467+ _ => {
468+ let mut d = Dialog::new(n.name(), "Coal dust in the lines of his face, an unlit lamp at his belt.")
469+ .go("Tell me about the pit", "pit");
470+ if !g.flag("read_notice") {
471+ d = d.act("Read him the posted notice (earn 1s)", Some("notice"), |g| {
472+ g.earn(1);
473+ g.set("read_notice");
474+ g.request = Some(Req::Wait { minutes: 15.0 });
475+ });
476+ }
477+ d.bye("Leave")
478+ }
479+ }
480+}
481+
482+fn jack(node: &str, g: &Game) -> Dialog {
483+ let n = Npc::Jack;
484+ match node {
485+ "ashamed" => Dialog::new(
486+ n.name(),
487+ "I can't write. Never learned, and I was too proud to say so. A year gone and not a word.",
488+ )
489+ .bye("Leave"),
490+ "letter" => Dialog::new(
491+ n.name(),
492+ "He turns his cap in his hands. 'Put it down for me. Tell him I'm well.' You write it on the back of a receipt.",
493+ )
494+ .act("Write it for him", Some("letter_done"), |g| {
495+ g.request = Some(Req::Wait { minutes: 60.0 });
496+ g.give(Item::JacksLetter);
497+ g.set("jack_letter");
498+ }),
499+ "letter_done" => Dialog::new(
500+ n.name(),
501+ "He folds it twice and hands it over. 'Tell him I'm sorry. Don't tell him how I look.'",
502+ )
503+ .bye("Leave"),
504+ _ => {
505+ let text = if g.flag("jack_letter") {
506+ "He nods, and says no more."
507+ } else {
508+ "A wary man in a soot-grey coat. 'What's it to you?'"
509+ };
510+ let mut d = Dialog::new(n.name(), text);
511+ if !g.flag("jack_letter") {
512+ d = d.go("Why haven't you written?", "ashamed").go("I can write a letter for you", "letter");
513+ }
514+ d.bye("Leave")
515+ }
516+ }
517+}
518+
519+fn pawn(node: &str, g: &Game) -> Dialog {
520+ let n = Npc::Pawn;
521+ match node {
522+ "letter_done" => Dialog::new(n.name(), "He reads it through once and counts eight shillings onto the counter.")
523+ .bye("Leave"),
524+ "rings" => Dialog::new(
525+ n.name(),
526+ "Wedding rings every Monday, back every Saturday when the wages come. Some come back twice. I don't ask.",
527+ )
528+ .bye("Leave"),
529+ _ => {
530+ let mut d = Dialog::new(
531+ n.name(),
532+ "Glass case, scales, a drawer of watches. The wedding rings sit at the front.",
533+ );
534+ if g.has(Item::Letter) && g.flag("job_letter") {
535+ d = d.act("Deliver the sealed letter", Some("letter_done"), |g| {
536+ g.take(Item::Letter);
537+ g.earn(8);
538+ g.set("delivered_letter");
539+ g.unset("job_letter");
540+ });
541+ }
542+ if g.money >= 1 {
543+ d = d.act("Pipe Tobacco (1s)", Some("start"), buy_tobacco);
544+ d = d.act("Ration (1s)", Some("start"), buy_ration);
545+ }
546+ d.go("Anything I should know?", "rings").bye("Leave")
547+ }
548+ }
549+}
550+
551+fn obj(o: Obj, g: &Game) -> Dialog {
552+ match o {
553+ Obj::HomeBed => Dialog::new("", "Your cottage. The fire is banked low and the bed is still warm from the night.")
554+ .act("Sleep until morning", None, sleep_home)
555+ .bye("Leave"),
556+ Obj::BalePile => {
557+ if g.flag("job_bales") && !g.flag("carrying") && g.counter("bales") < 2 {
558+ Dialog::new("", "A bale of raw cotton, heavy and sour with oil.")
559+ .act("Heave a bale", None, |g| g.set("carrying"))
560+ .bye("Leave")
561+ } else {
562+ Dialog::new("", "A bale of raw cotton, heavy and sour with oil. The pile is taller than the men who stack it.")
563+ .bye("Leave")
564+ }
565+ }
566+ Obj::BaleDrop => {
567+ if g.flag("carrying") {
568+ let text = match g.counter("bales") {
569+ 0 => "The mill door, and the roar of the looms like weather. Your first bale goes down among the others.",
570+ _ => "The last bale. Your arms have stopped telling you how heavy they are.",
571+ };
572+ Dialog::new("", text)
573+ .act("Drop the bale", None, |g| {
574+ g.unset("carrying");
575+ g.add("bales", 1);
576+ g.request = Some(Req::Wait { minutes: 20.0 });
577+ })
578+ .bye("Leave")
579+ } else {
580+ Dialog::new("", "The mill door. The roar of the looms comes out like weather.").bye("Leave")
581+ }
582+ }
583+ Obj::Signpost => Dialog::new(
584+ "",
585+ "Ashford four miles. Millbrook two, the mill chimney in view. Coalbridge over the moor, where the smoke comes from.",
586+ )
587+ .bye("Leave"),
588+ Obj::MillInn => inn("The Weavers' Arms", g),
589+ Obj::CoalInn => inn("The Miners' Rest", g),
590+ }
591+}
592+
593+fn inn(name: &'static str, g: &Game) -> Dialog {
594+ let mut d = Dialog::new(name, "Smoke, beer and wet wool. A bed upstairs for two shillings.");
595+ if g.money >= 2 {
596+ d = d.act("Bed (2s)", None, bed);
597+ }
598+ if g.money >= 1 {
599+ d = d.act("Hot meal (1s)", None, eat);
600+ }
601+ d.bye("Leave")
602+}
603+
604+fn ev(e: Ev, node: &str, g: &Game) -> Dialog {
605+ match e {
606+ Ev::BrokenCart => cart(node),
607+ Ev::Highwayman => highwayman(node, g),
608+ Ev::Storm => storm(),
609+ Ev::Peddler => tinker(node, g),
610+ Ev::Lost => lost(node, g),
611+ Ev::Wolves => wolves(g),
612+ }
613+}
614+
615+fn cart(node: &str) -> Dialog {
616+ match node {
617+ "done" => Dialog::new("Carter", "He presses a ration into your hand. For the road.").bye("Leave"),
618+ _ => Dialog::new("Carter", "A carter kneels by a cart with a split wheel. His horse stands patient in the rain.")
619+ .act("Help him (1 hour)", Some("done"), |g| {
620+ g.request = Some(Req::Wait { minutes: 60.0 });
621+ g.earn(1);
622+ g.give(Item::Ration);
623+ })
624+ .bye("Can't stop"),
625+ }
626+}
627+
628+fn highwayman(node: &str, g: &Game) -> Dialog {
629+ match node {
630+ "robbed" => Dialog::new("", "He takes the coins without a word and is gone into the dark.").bye("Leave"),
631+ "ran" => Dialog::new("", "You run. Your legs burn and the lamp swings, but nobody follows.").bye("Leave"),
632+ "bread" => Dialog::new(
633+ "Highwayman",
634+ "He lowers the pistol. 'Laid off from the looms in March. I'm not a thief, not really.'",
635+ )
636+ .bye("Leave"),
637+ _ => {
638+ let mut d = Dialog::new("Highwayman", "A man steps out from the wall, a pistol held low. 'Your purse or your life.'")
639+ .act("Hand over your purse", Some("robbed"), |g| {
640+ let n = g.money.min(3);
641+ g.money -= n;
642+ g.toasts.push(format!("- {n}s"));
643+ g.sfx.push(Sfx::Coin);
644+ })
645+ .act("Run for it", Some("ran"), |g| {
646+ g.energy = (g.energy - 25.0).max(0.0);
647+ g.warmth = (g.warmth - 10.0).max(0.0);
648+ });
649+ if g.has(Item::Ration) {
650+ d = d.act("Offer him bread", Some("bread"), give_bread);
651+ }
652+ d
653+ }
654+ }
655+}
656+
657+fn storm() -> Dialog {
658+ Dialog::new("", "Clouds come down over the moor, grey and fast. The first drops hit hard.")
659+ .act("Press on", None, |g| {
660+ g.raining = true;
661+ })
662+ .act("Shelter under the trees (1 hour)", None, |g| {
663+ g.request = Some(Req::Wait { minutes: 60.0 });
664+ })
665+}
666+
667+fn tinker(node: &str, g: &Game) -> Dialog {
668+ match node {
669+ "rail" => Dialog::new(
670+ "Tinker",
671+ "They'll lay rails over the moor by spring. He says it like a man reading a death notice.",
672+ )
673+ .bye("Leave"),
674+ _ => {
675+ let mut d = Dialog::new("Tinker", "A tinker with a handcart and a tin tray. Bread, wood, and news.");
676+ if g.money >= 1 {
677+ d = d.act("Ration (1s)", Some("start"), buy_ration);
678+ d = d.act("Firewood (1s)", Some("start"), buy_wood);
679+ }
680+ d.go("Ask about the railway", "rail").bye("Walk on")
681+ }
682+ }
683+}
684+
685+fn lost(node: &str, g: &Game) -> Dialog {
686+ match node {
687+ "done" => Dialog::new("Boy", "He eats it in three bites and runs off down the beck path.").bye("Leave"),
688+ "point" => Dialog::new(
689+ "Boy",
690+ "Follow the beck down, with the mill chimney on your left. You'll hear the looms before you see them.",
691+ )
692+ .bye("Leave"),
693+ _ => {
694+ let mut d = Dialog::new(
695+ "Boy",
696+ "A boy in a coat too big for him, lost. 'Mill's on the wrong side of the beck, mister. Me mam said the road was straight.'",
697+ );
698+ if g.has(Item::Ration) {
699+ d = d.act("Give him bread and point the way", Some("done"), give_bread);
700+ }
701+ d.go("Point the way", "point").bye("Walk on")
702+ }
703+ }
704+}
705+
706+fn camp(g: &Game) -> Dialog {
707+ let mut text = String::from("A dry hollow off the road, out of the wind.");
708+ text += if g.has(Item::Firewood) { " Wood for a fire." } else { " No wood. It will be cold." };
709+ text += if g.has(Item::Bedroll) { " A bedroll." } else { " Bare ground." };
710+ Dialog::new("", text)
711+ .act("Make camp and sleep", None, |g| {
712+ g.request = Some(Req::Sleep { until: 7.0 * 60.0, camp: true });
713+ })
714+ .act("Rest an hour", None, |g| {
715+ g.request = Some(Req::Wait { minutes: 60.0 });
716+ })
717+ .bye("Not here")
718+}
719+
720+fn wolves(g: &Game) -> Dialog {
721+ let mut d = Dialog::new("", "Yellow eyes in the dark. The pack circles, closer each turn.");
722+ if g.has(Item::Lantern) && !g.flag("lantern") {
723+ d = d.act("Light the lantern", None, |g| g.set("lantern"));
724+ }
725+ if g.has(Item::Ration) {
726+ d = d.act("Throw them a ration", None, |g| {
727+ g.take(Item::Ration);
728+ g.set("wolves_leave");
729+ });
730+ }
731+ d.act("Run for it", None, |g| {
732+ g.energy = (g.energy - 25.0).max(0.0);
733+ if g.money > 0 {
734+ g.money -= 1;
735+ }
736+ g.set("wolves_leave");
737+ })
738+}
src/demo.rsadded+360 -0
@@ -0,0 +1,360 @@
1+use crate::game::*;
2+use crate::iso::*;
3+use crate::player::*;
4+use crate::world::*;
5+use bevy::app::AppExit;
6+use bevy::prelude::*;
7+use bevy::render::view::window::screenshot::{Screenshot, ScreenshotCaptured, save_to_disk};
8+use bevy::time::TimeUpdateStrategy;
9+use std::io::Write;
10+use std::process::{Child, ChildStdin, Command, Stdio};
11+use std::sync::{Arc, Mutex};
12+use std::time::Duration;
13+
14+pub const FPS: f32 = 30.0;
15+
16+pub struct DemoPlugin {
17+ pub record: Option<String>,
18+ pub script: bool,
19+}
20+
21+#[derive(Clone)]
22+pub enum Step {
23+ Walk(Vec2),
24+ Road { leg: usize, forward: bool, journey: bool, until: f32 },
25+ Press,
26+ Pick(&'static str),
27+ Settle,
28+ Wait(f32),
29+ Camp,
30+ Lantern,
31+ Eat,
32+ Inv,
33+ Shot(&'static str),
34+ Tp(Vec2),
35+ Hour(f32),
36+}
37+
38+#[derive(Resource)]
39+struct Script {
40+ steps: Vec<Step>,
41+ i: usize,
42+ t: f32,
43+ road_i: Option<usize>,
44+ auto_t: f32,
45+ path: Vec<Vec2>,
46+}
47+
48+fn find_path(map: &Map, from: Vec2, to: Vec2) -> Vec<Vec2> {
49+ use std::collections::{HashMap, VecDeque};
50+ let (a, b) = (cell(from), cell(to));
51+ let mut prev: HashMap<IVec2, IVec2> = HashMap::new();
52+ let mut q = VecDeque::from([a]);
53+ prev.insert(a, a);
54+ while let Some(c) = q.pop_front() {
55+ if c == b {
56+ break;
57+ }
58+ for d in [IVec2::X, IVec2::NEG_X, IVec2::Y, IVec2::NEG_Y] {
59+ let n = c + d;
60+ if prev.contains_key(&n) || (n - a).abs().max_element() > 40 {
61+ continue;
62+ }
63+ if n != b && !map.walkable(n.as_vec2() + Vec2::splat(0.5)) {
64+ continue;
65+ }
66+ prev.insert(n, c);
67+ q.push_back(n);
68+ }
69+ }
70+ if !prev.contains_key(&b) {
71+ return vec![to];
72+ }
73+ let mut cells = vec![b];
74+ let mut c = b;
75+ while c != a {
76+ c = prev[&c];
77+ cells.push(c);
78+ }
79+ cells.reverse();
80+ let mut out: Vec<Vec2> = cells.iter().skip(1).map(|c| c.as_vec2() + Vec2::splat(0.5)).collect();
81+ out.pop();
82+ out.push(to);
83+ out
84+}
85+
86+const AUTO: &[&str] = &["Light the lantern", "Throw them a ration", "Help him", "Offer him bread", "Point the way", "Press on", "Make camp", "Continue", "Leave", "Walk on", "Run for it"];
87+
88+fn pick(g: &Game, prefs: &[&str]) -> Option<usize> {
89+ let (t, node) = g.dialog?;
90+ let d = crate::content::talk(t, node, g);
91+ if d.choices.is_empty() {
92+ return Some(0);
93+ }
94+ for p in prefs {
95+ if let Some(i) = d.choices.iter().position(|c| c.label.starts_with(p)) {
96+ return Some(i);
97+ }
98+ }
99+ None
100+}
101+
102+#[derive(Resource)]
103+struct Recorder {
104+ pipe: Option<Arc<Mutex<ChildStdin>>>,
105+ child: Option<Child>,
106+ done_at: Option<u32>,
107+ frame: u32,
108+}
109+
110+impl Plugin for DemoPlugin {
111+ fn build(&self, app: &mut App) {
112+ if self.script {
113+ app.insert_resource(Scripted)
114+ .insert_resource(Script { steps: if std::env::var("COURIER_TEST").is_ok() { test_script() } else { script() }, i: 0, t: 0.0, road_i: None, auto_t: 0.0, path: Vec::new() })
115+ .add_systems(PreUpdate, drive);
116+ }
117+ if let Some(path) = &self.record {
118+ app.insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_secs_f32(1.0 / FPS)));
119+ let mut child = Command::new("ffmpeg")
120+ .args(["-y", "-loglevel", "error", "-f", "rawvideo", "-pix_fmt", "rgba", "-s", "1280x720", "-r", "30", "-i", "-", "-c:v", "libx264", "-preset", "medium", "-crf", "20", "-pix_fmt", "yuv420p", path])
121+ .stdin(Stdio::piped())
122+ .spawn()
123+ .expect("ffmpeg");
124+ let stdin = child.stdin.take().unwrap();
125+ app.insert_resource(Recorder { pipe: Some(Arc::new(Mutex::new(stdin))), child: Some(child), done_at: None, frame: 0 })
126+ .add_systems(Last, record);
127+ }
128+ }
129+}
130+
131+fn record(mut commands: Commands, off: Res<crate::Offscreen>, mut rec: ResMut<Recorder>, script: Option<Res<Script>>, mut exit: MessageWriter<AppExit>) {
132+ rec.frame += 1;
133+ let finished = script.map(|s| s.i >= s.steps.len()).unwrap_or(rec.frame > 30 * 20);
134+ if finished && rec.done_at.is_none() {
135+ rec.done_at = Some(rec.frame);
136+ }
137+ if let Some(d) = rec.done_at {
138+ if rec.frame > d + 20 {
139+ rec.pipe = None;
140+ if let Some(mut c) = rec.child.take() {
141+ let _ = c.wait();
142+ }
143+ exit.write(AppExit::Success);
144+ }
145+ return;
146+ }
147+ if rec.frame < 5 {
148+ return;
149+ }
150+ let Some(pipe) = rec.pipe.clone() else { return };
151+ commands.spawn(Screenshot::image(off.0.clone())).observe(move |ev: On<ScreenshotCaptured>| {
152+ if let Ok(img) = ev.image.clone().try_into_dynamic() {
153+ let rgba = img.to_rgba8();
154+ if rgba.width() == 1280 && rgba.height() == 720 {
155+ let _ = pipe.lock().unwrap().write_all(rgba.as_raw());
156+ }
157+ }
158+ });
159+}
160+
161+fn drive(
162+ mut commands: Commands,
163+ time: Res<Time>,
164+ mut s: ResMut<Script>,
165+ mut pad: ResMut<Pad>,
166+ mut g: ResMut<Game>,
167+ map: Res<Map>,
168+ mut pq: Query<&mut Mover, With<Player>>,
169+ mut exit: MessageWriter<AppExit>,
170+ rec: Option<Res<Recorder>>,
171+ off: Option<Res<crate::Offscreen>>,
172+) {
173+ *pad = Pad::default();
174+ let Ok(mut m) = pq.single_mut() else { return };
175+ let Some(step) = s.steps.get(s.i).cloned() else {
176+ if rec.is_none() {
177+ exit.write(AppExit::Success);
178+ }
179+ return;
180+ };
181+ s.t += time.delta_secs();
182+ let mut next = false;
183+ match step {
184+ Step::Walk(target) => {
185+ if s.t == time.delta_secs() || s.path.is_empty() {
186+ s.path = find_path(&map, m.pos, target);
187+ }
188+ while s.path.len() > 1 && (s.path[0] - m.pos).length() < 0.3 {
189+ s.path.remove(0);
190+ }
191+ let d = s.path[0] - m.pos;
192+ if (target - m.pos).length() < 0.25 || s.t > 25.0 {
193+ next = true;
194+ s.path.clear();
195+ } else {
196+ pad.dir = to_screen(d).normalize();
197+ }
198+ }
199+ Step::Road { leg, forward, journey, until } => {
200+ let l = &map.legs[leg];
201+ let i = *s.road_i.get_or_insert_with(|| {
202+ l.iter().enumerate().min_by(|a, b| (*a.1 - m.pos).length().total_cmp(&(*b.1 - m.pos).length())).map(|(i, _)| i).unwrap_or(0)
203+ });
204+ let goal = ((l.len() - 1) as f32 * until) as usize;
205+ let mut j = i;
206+ while j != goal && (l[j] - m.pos).length() < 1.2 {
207+ j = if forward { (j + 1).min(l.len() - 1) } else { j.saturating_sub(1) };
208+ }
209+ s.road_i = Some(j);
210+ if j == goal && (l[j] - m.pos).length() < 0.6 {
211+ next = true;
212+ s.road_i = None;
213+ } else {
214+ pad.dir = to_screen(l[j] - m.pos).normalize();
215+ pad.journey = journey;
216+ }
217+ if g.dialog.is_some() {
218+ pad.dir = Vec2::ZERO;
219+ s.auto_t += time.delta_secs();
220+ if s.auto_t > 2.6 {
221+ s.auto_t = 0.0;
222+ pad.choice = pick(&g, AUTO);
223+ }
224+ } else {
225+ s.auto_t = 0.0;
226+ }
227+ }
228+ Step::Press => {
229+ pad.interact = true;
230+ next = true;
231+ }
232+ Step::Pick(label) => {
233+ if s.t > 2.4 {
234+ if let Some(i) = pick(&g, &[label]) {
235+ pad.choice = Some(i);
236+ }
237+ next = true;
238+ }
239+ }
240+ Step::Settle => next = s.t > 0.5 && g.dialog.is_none() && g.request.is_none() && !g.camping,
241+ Step::Wait(w) => next = s.t >= w,
242+ Step::Camp => {
243+ pad.camp = true;
244+ next = true;
245+ }
246+ Step::Lantern => {
247+ if g.flag("lantern") {
248+ next = true;
249+ } else if g.is_night() {
250+ pad.lantern = true;
251+ }
252+ }
253+ Step::Eat => {
254+ pad.eat = true;
255+ next = true;
256+ }
257+ Step::Inv => {
258+ pad.inventory = true;
259+ next = true;
260+ }
261+ Step::Tp(p) => {
262+ m.pos = p;
263+ next = true;
264+ }
265+ Step::Hour(h) => {
266+ g.minutes = (g.minutes / 1440.0).floor() * 1440.0 + h * 60.0;
267+ next = true;
268+ }
269+ Step::Shot(name) => {
270+ let shot = match &off {
271+ Some(o) => Screenshot::image(o.0.clone()),
272+ None => Screenshot::primary_window(),
273+ };
274+ commands.spawn(shot).observe(save_to_disk(format!("{name}.png")));
275+ next = true;
276+ }
277+ }
278+ if next {
279+ s.i += 1;
280+ s.t = 0.0;
281+ }
282+}
283+
284+fn a(x: f32, y: f32) -> Step {
285+ Step::Walk(ASHFORD + Vec2::new(x, y))
286+}
287+
288+fn m(x: f32, y: f32) -> Step {
289+ Step::Walk(MILLBROOK + Vec2::new(x, y))
290+}
291+
292+fn c(x: f32, y: f32) -> Step {
293+ Step::Walk(COALBRIDGE + Vec2::new(x, y))
294+}
295+
296+fn talk(steps: &mut Vec<Step>, picks: &[&'static str]) {
297+ steps.push(Step::Press);
298+ for p in picks {
299+ steps.push(Step::Pick(p));
300+ }
301+ steps.push(Step::Settle);
302+}
303+
304+fn script() -> Vec<Step> {
305+ use Step::*;
306+ let mut s = vec![Wait(1.5), a(-1.0, 8.4)];
307+ talk(&mut s, &["Anything I can do?", "I'll look for him", "Leave"]);
308+ s.push(a(-7.5, 1.5));
309+ talk(&mut s, &["Any work going?", "Take the parcel"]);
310+ talk(&mut s, &["Any more work?", "Take the letter"]);
311+ s.push(a(-3.5, 1.5));
312+ talk(&mut s, &["Show me your goods", "Firewood", "Ration", "Lantern", "Leave"]);
313+ s.extend([Inv, Wait(2.5), Inv]);
314+ s.extend([a(15.5, 0.5), Road { leg: 0, forward: true, journey: true, until: 1.0 }, Settle]);
315+ s.push(m(6.5, 1.5));
316+ talk(&mut s, &["Deliver the Millbrook parcel", "Leave"]);
317+ talk(&mut s, &["Any extra work?", "Take the job"]);
318+ for _ in 0..2 {
319+ s.push(m(0.0, 0.2));
320+ talk(&mut s, &["Heave a bale"]);
321+ s.push(m(4.5, 1.5));
322+ talk(&mut s, &["Drop the bale"]);
323+ }
324+ s.push(m(6.5, 1.5));
325+ talk(&mut s, &["Collect your pay", "Leave"]);
326+ s.push(m(-10.0, 1.5));
327+ talk(&mut s, &["Songs of the Moor (6s)"]);
328+ s.extend([m(14.0, 0.5), Road { leg: 1, forward: true, journey: true, until: 0.5 }, Settle]);
329+ s.extend([Lantern, Wait(4.0), Camp, Pick("Make camp"), Settle, Eat]);
330+ s.extend([Road { leg: 1, forward: true, journey: true, until: 1.0 }, Settle]);
331+ s.push(c(-1.5, 1.5));
332+ talk(&mut s, &["Deliver the sealed letter", "Leave"]);
333+ s.push(c(-9.5, 1.5));
334+ talk(&mut s, &["Why haven't you written?", "Leave"]);
335+ talk(&mut s, &["I can write a letter for you", "Write it for him", "Leave"]);
336+ s.extend([c(-14.0, 0.5), Road { leg: 1, forward: false, journey: true, until: 0.0 }, Settle]);
337+ s.extend([m(-14.0, 0.5), Road { leg: 0, forward: false, journey: true, until: 0.0 }, Settle]);
338+ s.push(a(9.5, 1.5));
339+ talk(&mut s, &["Give him Songs of the Moor", "Leave"]);
340+ s.push(a(-1.0, 8.4));
341+ talk(&mut s, &["Give him the letter", "Leave"]);
342+ s.push(a(-7.5, 7.8));
343+ talk(&mut s, &["Sleep until morning"]);
344+ s.push(Wait(4.5));
345+ s
346+}
347+
348+fn test_script() -> Vec<Step> {
349+ use Step::*;
350+ let dir = std::env::var("COURIER_TEST").unwrap();
351+ let shot = |n: &str| Shot(Box::leak(format!("{dir}/{n}").into_boxed_str()));
352+ vec![
353+ Wait(1.0), shot("ashford"), a(3.0, 1.0), Wait(1.5), shot("ashford_walk"),
354+ Tp(MILLBROOK + Vec2::new(3.0, 1.0)), Wait(1.5), shot("millbrook"),
355+ Tp(COALBRIDGE + Vec2::new(-6.0, 1.0)), Wait(1.5), shot("coalbridge"),
356+ Tp(ASHFORD + Vec2::new(40.0, -40.0)), Wait(1.0), Road { leg: 0, forward: true, journey: false, until: 0.4 }, shot("road"),
357+ Hour(22.0), Wait(4.0), shot("night"), Step::Wait(4.0), shot("night2"),
358+ Tp(ASHFORD + Vec2::new(0.0, 1.0)), Wait(1.5), shot("ashford_night"),
359+ ]
360+}
src/game.rsadded+307 -0
@@ -0,0 +1,307 @@
1+use bevy::prelude::*;
2+use std::collections::{HashMap, HashSet};
3+
4+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
5+pub enum Item {
6+ Ration,
7+ Firewood,
8+ Bedroll,
9+ Lantern,
10+ Parcel,
11+ Letter,
12+ PoetryBook,
13+ TinWhistle,
14+ Tobacco,
15+ JacksLetter,
16+ Ribbon,
17+}
18+
19+impl Item {
20+ pub fn name(self) -> &'static str {
21+ match self {
22+ Item::Ration => "Ration",
23+ Item::Firewood => "Firewood",
24+ Item::Bedroll => "Bedroll",
25+ Item::Lantern => "Lantern",
26+ Item::Parcel => "Parcel",
27+ Item::Letter => "Sealed Letter",
28+ Item::PoetryBook => "Songs of the Moor",
29+ Item::TinWhistle => "Tin Whistle",
30+ Item::Tobacco => "Pipe Tobacco",
31+ Item::JacksLetter => "Jack's Letter",
32+ Item::Ribbon => "Silk Ribbon",
33+ }
34+ }
35+}
36+
37+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
38+pub enum Npc {
39+ Hale,
40+ Pike,
41+ Bess,
42+ Edwin,
43+ OldTom,
44+ Annie,
45+ Foreman,
46+ Quill,
47+ Weaver,
48+ Peddler,
49+ Miner,
50+ Jack,
51+ Pawn,
52+}
53+
54+impl Npc {
55+ pub fn name(self) -> &'static str {
56+ match self {
57+ Npc::Hale => "Mr. Hale, Postmaster",
58+ Npc::Pike => "Mr. Pike, Grocer",
59+ Npc::Bess => "Bess, Innkeeper",
60+ Npc::Edwin => "Edwin, Schoolmaster",
61+ Npc::OldTom => "Old Tom",
62+ Npc::Annie => "Little Sam",
63+ Npc::Foreman => "Mill Foreman",
64+ Npc::Quill => "Mr. Quill, Bookseller",
65+ Npc::Weaver => "Will, Weaver",
66+ Npc::Peddler => "Peddler",
67+ Npc::Miner => "Collier",
68+ Npc::Jack => "Jack Turner",
69+ Npc::Pawn => "Pawnbroker",
70+ }
71+ }
72+}
73+
74+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
75+pub enum Obj {
76+ HomeBed,
77+ BalePile,
78+ BaleDrop,
79+ Signpost,
80+ MillInn,
81+ CoalInn,
82+}
83+
84+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
85+pub enum Ev {
86+ BrokenCart,
87+ Highwayman,
88+ Storm,
89+ Peddler,
90+ Lost,
91+ Wolves,
92+}
93+
94+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
95+pub enum Talk {
96+ Npc(Npc),
97+ Obj(Obj),
98+ Ev(Ev),
99+ Camp,
100+}
101+
102+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Default)]
103+pub enum Zone {
104+ #[default]
105+ Ashford,
106+ Millbrook,
107+ Coalbridge,
108+ Road,
109+}
110+
111+impl Zone {
112+ pub fn name(self) -> &'static str {
113+ match self {
114+ Zone::Ashford => "Ashford",
115+ Zone::Millbrook => "Millbrook",
116+ Zone::Coalbridge => "Coalbridge",
117+ Zone::Road => "The Road",
118+ }
119+ }
120+}
121+
122+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
123+pub enum Sfx {
124+ Coin,
125+ Door,
126+ Page,
127+ Bag,
128+ Arrive,
129+ Home,
130+ Lantern,
131+ Howl,
132+ Growl,
133+}
134+
135+#[derive(Clone, Copy, PartialEq, Debug)]
136+pub enum Req {
137+ Sleep { until: f32, camp: bool },
138+ Wait { minutes: f32 },
139+ BreakCamp,
140+}
141+
142+pub type Effect = fn(&mut Game);
143+
144+pub struct Choice {
145+ pub label: String,
146+ pub next: Option<&'static str>,
147+ pub effect: Option<Effect>,
148+}
149+
150+pub struct Dialog {
151+ pub speaker: String,
152+ pub text: String,
153+ pub choices: Vec<Choice>,
154+}
155+
156+impl Dialog {
157+ pub fn new(speaker: impl Into<String>, text: impl Into<String>) -> Self {
158+ Self { speaker: speaker.into(), text: text.into(), choices: Vec::new() }
159+ }
160+ pub fn opt(mut self, label: impl Into<String>, next: Option<&'static str>, effect: Option<Effect>) -> Self {
161+ self.choices.push(Choice { label: label.into(), next, effect });
162+ self
163+ }
164+ pub fn go(self, label: impl Into<String>, next: &'static str) -> Self {
165+ self.opt(label, Some(next), None)
166+ }
167+ pub fn act(self, label: impl Into<String>, next: Option<&'static str>, effect: Effect) -> Self {
168+ self.opt(label, next, Some(effect))
169+ }
170+ pub fn bye(self, label: impl Into<String>) -> Self {
171+ self.opt(label, None, None)
172+ }
173+}
174+
175+#[derive(Resource)]
176+pub struct Game {
177+ pub day: u32,
178+ pub minutes: f32,
179+ pub hunger: f32,
180+ pub energy: f32,
181+ pub warmth: f32,
182+ pub money: i32,
183+ pub items: Vec<Item>,
184+ pub hearts: HashMap<Npc, i32>,
185+ pub flags: HashSet<&'static str>,
186+ pub counters: HashMap<&'static str, i32>,
187+ pub zone: Zone,
188+ pub dialog: Option<(Talk, &'static str)>,
189+ pub toasts: Vec<String>,
190+ pub sfx: Vec<Sfx>,
191+ pub request: Option<Req>,
192+ pub camping: bool,
193+ pub timelapse: bool,
194+ pub raining: bool,
195+}
196+
197+impl Default for Game {
198+ fn default() -> Self {
199+ Self {
200+ day: 1,
201+ minutes: 9.0 * 60.0,
202+ hunger: 85.0,
203+ energy: 90.0,
204+ warmth: 80.0,
205+ money: 6,
206+ items: vec![Item::Ration],
207+ hearts: HashMap::new(),
208+ flags: HashSet::new(),
209+ counters: HashMap::new(),
210+ zone: Zone::Ashford,
211+ dialog: None,
212+ toasts: Vec::new(),
213+ sfx: Vec::new(),
214+ request: None,
215+ camping: false,
216+ timelapse: false,
217+ raining: false,
218+ }
219+ }
220+}
221+
222+impl Game {
223+ pub fn hour(&self) -> f32 {
224+ self.minutes / 60.0
225+ }
226+ pub fn is_night(&self) -> bool {
227+ let h = self.hour();
228+ !(6.0..20.0).contains(&h)
229+ }
230+ pub fn has(&self, i: Item) -> bool {
231+ self.items.contains(&i)
232+ }
233+ pub fn count(&self, i: Item) -> usize {
234+ self.items.iter().filter(|x| **x == i).count()
235+ }
236+ pub fn give(&mut self, i: Item) {
237+ self.items.push(i);
238+ self.toasts.push(format!("+ {}", i.name()));
239+ self.sfx.push(Sfx::Bag);
240+ }
241+ pub fn take(&mut self, i: Item) -> bool {
242+ if let Some(p) = self.items.iter().position(|x| *x == i) {
243+ self.items.remove(p);
244+ true
245+ } else {
246+ false
247+ }
248+ }
249+ pub fn pay(&mut self, amount: i32) -> bool {
250+ if self.money < amount {
251+ self.toasts.push("Not enough coin".into());
252+ return false;
253+ }
254+ self.money -= amount;
255+ self.sfx.push(Sfx::Coin);
256+ true
257+ }
258+ pub fn earn(&mut self, amount: i32) {
259+ self.money += amount;
260+ self.toasts.push(format!("+ {amount}s"));
261+ self.sfx.push(Sfx::Coin);
262+ }
263+ pub fn buy(&mut self, i: Item, price: i32) -> bool {
264+ if self.pay(price) {
265+ self.give(i);
266+ true
267+ } else {
268+ false
269+ }
270+ }
271+ pub fn heart(&self, n: Npc) -> i32 {
272+ *self.hearts.get(&n).unwrap_or(&0)
273+ }
274+ pub fn bond(&mut self, n: Npc, d: i32) {
275+ let h = self.hearts.entry(n).or_insert(0);
276+ *h = (*h + d).clamp(0, 5);
277+ if d > 0 {
278+ self.toasts.push(format!("{} \u{2665}", n.name()));
279+ }
280+ }
281+ pub fn flag(&self, f: &'static str) -> bool {
282+ self.flags.contains(f)
283+ }
284+ pub fn set(&mut self, f: &'static str) {
285+ self.flags.insert(f);
286+ }
287+ pub fn unset(&mut self, f: &'static str) {
288+ self.flags.remove(f);
289+ }
290+ pub fn counter(&self, c: &'static str) -> i32 {
291+ *self.counters.get(c).unwrap_or(&0)
292+ }
293+ pub fn add(&mut self, c: &'static str, d: i32) {
294+ *self.counters.entry(c).or_insert(0) += d;
295+ }
296+ pub fn advance(&mut self, minutes: f32) {
297+ self.minutes += minutes;
298+ while self.minutes >= 1440.0 {
299+ self.minutes -= 1440.0;
300+ self.day += 1;
301+ }
302+ }
303+ pub fn clock(&self) -> String {
304+ let m = self.minutes as i32;
305+ format!("Day {} {:02}:{:02}", self.day, m / 60, m % 60)
306+ }
307+}
src/iso.rsadded+37 -0
@@ -0,0 +1,37 @@
1+use crate::sprites::Spr;
2+use bevy::prelude::*;
3+use bevy::sprite::Anchor;
4+
5+pub const TW: f32 = 64.0;
6+pub const TH: f32 = 32.0;
7+pub const PX: f32 = 2.0;
8+
9+pub fn to_screen(p: Vec2) -> Vec2 {
10+ Vec2::new((p.x - p.y) * TW, -(p.x + p.y) * TH)
11+}
12+
13+pub fn to_grid(s: Vec2) -> Vec2 {
14+ let a = s.x / TW;
15+ let b = -s.y / TH;
16+ Vec2::new((a + b) * 0.5, (b - a) * 0.5)
17+}
18+
19+pub fn depth(p: Vec2) -> f32 {
20+ (p.x + p.y) * 0.01
21+}
22+
23+pub fn cell(p: Vec2) -> IVec2 {
24+ IVec2::new(p.x.floor() as i32, p.y.floor() as i32)
25+}
26+
27+pub fn anchor(s: &Spr) -> Anchor {
28+ Anchor(Vec2::new(s.origin.0 / s.cell.0 as f32 - 0.5, 0.5 - s.origin.1 / s.cell.1 as f32))
29+}
30+
31+pub fn hash(x: i32, y: i32, salt: u32) -> f32 {
32+ let mut h = (x as u32).wrapping_mul(0x8da6b343) ^ (y as u32).wrapping_mul(0xd8163841) ^ salt.wrapping_mul(0xcb1ab31f);
33+ h ^= h >> 13;
34+ h = h.wrapping_mul(0x5bd1e995);
35+ h ^= h >> 15;
36+ (h & 0xffffff) as f32 / 16777216.0
37+}
src/main.rsadded+133 -0
@@ -0,0 +1,133 @@
1+mod audio;
2+mod cart;
3+mod content;
4+mod demo;
5+mod game;
6+mod iso;
7+mod night;
8+mod player;
9+mod sheets;
10+mod sprites;
11+mod travel;
12+mod ui;
13+mod world;
14+
15+use bevy::app::ScheduleRunnerPlugin;
16+#[cfg(target_arch = "wasm32")]
17+use bevy::asset::{AssetMetaCheck, AssetPlugin};
18+use bevy::camera::visibility::RenderLayers;
19+use bevy::camera::{Camera, ClearColorConfig, RenderTarget};
20+use bevy::image::ImageSampler;
21+use bevy::prelude::*;
22+use bevy::render::render_resource::{TextureFormat, TextureUsages};
23+use bevy::window::{ExitCondition, WindowResolution};
24+use bevy::winit::WinitPlugin;
25+use std::time::Duration;
26+
27+#[derive(Resource, Clone)]
28+pub struct Offscreen(pub Handle<Image>);
29+
30+#[derive(Resource, Clone)]
31+pub struct Lowres(pub Handle<Image>);
32+
33+#[derive(Resource, Default)]
34+pub struct CamTrue(pub Vec2);
35+
36+#[derive(Component)]
37+pub struct Upscaled;
38+
39+pub struct Cli {
40+ pub demo: bool,
41+ pub record: Option<String>,
42+ pub mute: bool,
43+}
44+
45+impl Cli {
46+ fn parse() -> Self {
47+ let args: Vec<String> = std::env::args().collect();
48+ let record = args.iter().position(|a| a == "--record").and_then(|i| args.get(i + 1).cloned());
49+ Self { demo: args.iter().any(|a| a == "--demo"), mute: args.iter().any(|a| a == "--mute") || record.is_some(), record }
50+ }
51+}
52+
53+fn main() {
54+ let cli = Cli::parse();
55+ let mut app = App::new();
56+ let window = Window {
57+ title: "Courier".into(),
58+ resolution: WindowResolution::new(1280, 720),
59+ resizable: cli.record.is_none(),
60+ ..default()
61+ };
62+ #[cfg(target_arch = "wasm32")]
63+ let window = Window { canvas: Some("#game".into()), fit_canvas_to_parent: true, prevent_default_event_handling: true, ..window };
64+ let plugins = DefaultPlugins.set(WindowPlugin { primary_window: Some(window), ..default() }).set(ImagePlugin::default_nearest());
65+ #[cfg(target_arch = "wasm32")]
66+ let plugins = plugins.set(AssetPlugin { meta_check: AssetMetaCheck::Never, ..default() });
67+ let plugins = if cli.mute { plugins.disable::<bevy::audio::AudioPlugin>() } else { plugins };
68+ if cli.record.is_some() {
69+ app.add_plugins(
70+ plugins
71+ .set(WindowPlugin { primary_window: None, exit_condition: ExitCondition::DontExit, ..default() })
72+ .disable::<WinitPlugin>(),
73+ )
74+ .add_plugins(ScheduleRunnerPlugin::run_loop(Duration::ZERO))
75+ .insert_resource(Offscreen(Handle::default()));
76+ } else {
77+ app.add_plugins(plugins);
78+ }
79+ app
80+ .insert_resource(ClearColor(Color::srgb(0.11, 0.16, 0.10)))
81+ .init_resource::<game::Game>()
82+ .init_resource::<CamTrue>()
83+ .add_systems(Startup, (camera, sheets::load_sheets))
84+ .add_plugins((world::WorldPlugin, player::PlayerPlugin, cart::CartPlugin, ui::UiPlugin, travel::TravelPlugin, night::NightPlugin));
85+ if let Some(r) = &cli.record {
86+ let f = std::fs::File::create(format!("{r}.cues")).expect("cue log");
87+ app.insert_resource(audio::CueLog(f)).add_plugins(audio::AudioFxPlugin);
88+ } else if cli.mute {
89+ app.add_systems(Last, |mut g: ResMut<game::Game>| g.sfx.clear());
90+ } else {
91+ app.add_plugins(audio::AudioFxPlugin);
92+ }
93+ if cli.demo || cli.record.is_some() {
94+ app.add_plugins(demo::DemoPlugin { record: cli.record.clone(), script: cli.demo });
95+ }
96+ app.run();
97+}
98+
99+fn camera(mut commands: Commands, off: Option<ResMut<Offscreen>>, mut images: ResMut<Assets<Image>>) {
100+ let mut low = Image::new_target_texture(644, 364, TextureFormat::Rgba8UnormSrgb, None);
101+ low.sampler = ImageSampler::nearest();
102+ let low = images.add(low);
103+ commands.insert_resource(Lowres(low.clone()));
104+ commands.spawn((
105+ Camera2d,
106+ Camera { order: 0, ..default() },
107+ RenderTarget::Image(low.clone().into()),
108+ Projection::Orthographic(OrthographicProjection { scale: 2.0, ..OrthographicProjection::default_2d() }),
109+ player::MainCamera,
110+ ));
111+ let target = match off {
112+ Some(mut off) => {
113+ let mut img = Image::new_target_texture(1280, 720, TextureFormat::Rgba8UnormSrgb, None);
114+ img.texture_descriptor.usage |= TextureUsages::COPY_SRC;
115+ let h = images.add(img);
116+ off.0 = h.clone();
117+ RenderTarget::Image(h.into())
118+ }
119+ None => RenderTarget::default(),
120+ };
121+ commands.spawn((
122+ Camera2d,
123+ Camera { order: 1, clear_color: ClearColorConfig::Custom(Color::BLACK), ..default() },
124+ target,
125+ RenderLayers::layer(1),
126+ IsDefaultUiCamera,
127+ ));
128+ commands.spawn((
129+ Sprite { image: low, custom_size: Some(Vec2::new(1288.0, 728.0)), ..default() },
130+ RenderLayers::layer(1),
131+ Upscaled,
132+ ));
133+}
src/night.rsadded+313 -0
@@ -0,0 +1,313 @@
1+use crate::game::*;
2+use crate::iso::*;
3+use crate::player::{facing_of, Mover, Pad, Player};
4+use crate::sheets::CharSheets;
5+use crate::sprites;
6+use crate::travel::{self, rnd, CampFlame, CampLight, Rain, Travel, BASE_CLEAR, NIGHT};
7+use crate::world::{Emissive, Glow, Lamp, Puff};
8+use bevy::prelude::*;
9+use std::f32::consts::{FRAC_PI_4, TAU};
10+
11+const WARM: Vec3 = Vec3::new(1.0, 0.86, 0.62);
12+const SEEN: &str = "ev_wolves_seen";
13+const LEAVE: &str = "wolves_leave";
14+const PACK: usize = 3;
15+const SPAWN_R: (f32, f32) = (10.0, 12.0);
16+const WOLF_SPEED: f32 = 2.8;
17+const FLEE_SPEED: f32 = 4.0;
18+const STRIDE: f32 = 1.2;
19+const RING_FIRE: f32 = 5.5;
20+const RING_LIT: f32 = 5.0;
21+const RING_DARK: f32 = 0.9;
22+const BITE: f32 = 1.2;
23+const GIVE_UP: f32 = 18.0;
24+const LAMP_R: f32 = 4.0;
25+const LANTERN_R: f32 = 4.5;
26+const FIRE_R: f32 = 5.5;
27+
28+pub struct NightPlugin;
29+
30+impl Plugin for NightPlugin {
31+ fn build(&self, app: &mut App) {
32+ app.init_resource::<Pack>().add_systems(
33+ Update,
34+ (lantern_key, pack_spawn, pack_run, lantern_glow, lighting, glow_blobs).chain().after(travel::roadside),
35+ );
36+ }
37+}
38+
39+#[derive(Resource, Default)]
40+struct Pack {
41+ ring: f32,
42+}
43+
44+#[derive(Component)]
45+struct Wolf {
46+ pos: Vec2,
47+ facing: usize,
48+ slot: f32,
49+ run: f32,
50+ away: bool,
51+ eyes: Entity,
52+}
53+
54+#[derive(Component)]
55+struct Eyes;
56+
57+#[derive(Component)]
58+struct LanternGlow;
59+
60+#[derive(Clone, Copy)]
61+struct Src {
62+ pos: Vec2,
63+ r: f32,
64+}
65+
66+fn wolf_hours(h: f32) -> bool {
67+ h >= 20.0 || h < 5.5
68+}
69+
70+fn sources(g: &Game, lamps: &Query<&Lamp>, fires: &Query<&CampLight>, player: Option<Vec2>) -> Vec<Src> {
71+ let mut v: Vec<Src> = lamps.iter().map(|l| Src { pos: l.0, r: LAMP_R }).collect();
72+ v.extend(fires.iter().map(|f| Src { pos: f.0, r: FIRE_R }));
73+ if let Some(p) = player {
74+ if g.flag("lantern") && g.has(Item::Lantern) {
75+ v.push(Src { pos: p, r: LANTERN_R });
76+ }
77+ }
78+ v
79+}
80+
81+fn light_at(srcs: &[Src], p: Vec2) -> f32 {
82+ srcs.iter()
83+ .map(|s| {
84+ let t = ((p.distance(s.pos) / s.r - 0.4) / 0.6).clamp(0.0, 1.0);
85+ 1.0 - t * t * (3.0 - 2.0 * t)
86+ })
87+ .fold(0.0, f32::max)
88+}
89+
90+fn lantern_key(pad: Res<Pad>, mut g: ResMut<Game>) {
91+ if !pad.lantern || g.dialog.is_some() || !g.has(Item::Lantern) {
92+ return;
93+ }
94+ if g.flag("lantern") {
95+ g.unset("lantern");
96+ } else {
97+ g.set("lantern");
98+ }
99+ g.sfx.push(Sfx::Lantern);
100+}
101+
102+fn lantern_glow(
103+ mut commands: Commands,
104+ time: Res<Time>,
105+ g: Res<Game>,
106+ assets: Res<AssetServer>,
107+ player: Query<&Mover, With<Player>>,
108+ mut q: Query<(&mut Transform, &mut Sprite, &mut Visibility), With<LanternGlow>>,
109+) {
110+ if q.is_empty() {
111+ commands.spawn((
112+ Sprite::from_image(assets.load(sprites::LIGHT.path)),
113+ Transform::default().with_scale(Vec3::splat(PX * 1.5)),
114+ Visibility::Hidden,
115+ LanternGlow,
116+ ));
117+ return;
118+ }
119+ let Ok(m) = player.single() else { return };
120+ let on = g.flag("lantern") && g.has(Item::Lantern) && travel::night_amount(g.hour()) > 0.05;
121+ let a = 0.45 + 0.05 * (time.elapsed_secs() * 11.0).sin();
122+ for (mut t, mut s, mut v) in &mut q {
123+ t.translation = (to_screen(m.pos) + Vec2::new(0.0, 30.0)).extend(9.6);
124+ s.color = Color::srgba(1.0, 0.8, 0.5, a);
125+ *v = if on { Visibility::Inherited } else { Visibility::Hidden };
126+ }
127+}
128+
129+fn lighting(
130+ g: Res<Game>,
131+ mut clear: ResMut<ClearColor>,
132+ lamps: Query<&Lamp>,
133+ fires: Query<&CampLight>,
134+ player: Query<&Mover, With<Player>>,
135+ mut lit: Query<
136+ (&mut Sprite, &Transform, Has<crate::world::Ground>),
137+ (Without<Glow>, Without<Emissive>, Without<Puff>, Without<CampFlame>, Without<CampLight>, Without<Eyes>, Without<LanternGlow>),
138+ >,
139+ mut overlays: Query<&mut Sprite, With<Emissive>>,
140+) {
141+ let h = g.hour();
142+ let n = travel::night_amount(h);
143+ let mut base = travel::day_tint(h);
144+ if g.raining {
145+ base *= 0.8;
146+ }
147+ let c = BASE_CLEAR * base;
148+ clear.0 = Color::srgb(c.x, c.y, c.z);
149+ let srcs = if n > 0.0 { sources(&g, &lamps, &fires, player.single().ok().map(|m| m.pos)) } else { Vec::new() };
150+ for (mut s, tr, ground) in &mut lit {
151+ let k = if n > 0.0 && !ground { (light_at(&srcs, to_grid(tr.translation.truncate())) * 4.0).round() / 4.0 } else { 0.0 };
152+ let col = base.lerp(NIGHT.lerp(WARM, k), n);
153+ let want = Color::srgb(col.x, col.y, col.z);
154+ if s.color != want {
155+ s.color = want;
156+ }
157+ }
158+ for mut s in &mut overlays {
159+ if (s.color.alpha() - n).abs() > 0.002 {
160+ s.color.set_alpha(n);
161+ }
162+ }
163+}
164+
165+fn glow_blobs(time: Res<Time>, g: Res<Game>, mut q: Query<&mut Sprite, (With<Glow>, Without<Rain>)>) {
166+ let flicker = 0.92 + 0.08 * (time.elapsed_secs() * 7.0).sin();
167+ let a = travel::night_amount(g.hour()) * 0.35 * flicker;
168+ for mut s in &mut q {
169+ s.color = Color::srgba(1.0, 0.75, 0.4, a);
170+ }
171+}
172+
173+fn pack_spawn(
174+ mut commands: Commands,
175+ assets: Res<AssetServer>,
176+ sheets: Res<CharSheets>,
177+ mut g: ResMut<Game>,
178+ t: Res<Travel>,
179+ mut pack: ResMut<Pack>,
180+ mut seed: Local<u32>,
181+ wolves: Query<(), With<Wolf>>,
182+ fires: Query<(), With<CampLight>>,
183+ player: Query<&Mover, With<Player>>,
184+) {
185+ if !wolf_hours(g.hour())
186+ || g.zone != Zone::Road
187+ || g.flag(SEEN)
188+ || !wolves.is_empty()
189+ || !fires.is_empty()
190+ || g.dialog.is_some()
191+ || g.request.is_some()
192+ || t.busy()
193+ {
194+ return;
195+ }
196+ let Ok(m) = player.single() else { return };
197+ g.set(SEEN);
198+ g.unset(LEAVE);
199+ g.sfx.push(Sfx::Howl);
200+ pack.ring = RING_LIT;
201+ let base = rnd(&mut seed) * TAU;
202+ for k in 0..PACK {
203+ let slot = base + k as f32 * TAU / PACK as f32;
204+ let pos = m.pos + Vec2::from_angle(slot) * (SPAWN_R.0 + rnd(&mut seed) * (SPAWN_R.1 - SPAWN_R.0));
205+ let facing = facing_of(to_screen(m.pos - pos));
206+ let eyes = commands
207+ .spawn((
208+ Sprite::from_image(assets.load(sprites::EYES.path)),
209+ anchor(&sprites::EYES),
210+ Transform::from_scale(Vec3::splat(PX)),
211+ Visibility::Hidden,
212+ Eyes,
213+ ))
214+ .id();
215+ commands.spawn((
216+ sheets.sprite("wolf", facing * 7),
217+ anchor(sheets.spr("wolf")),
218+ Transform::from_translation(to_screen(pos).extend(depth(pos))).with_scale(Vec3::splat(PX)),
219+ Wolf { pos, facing, slot, run: 0.0, away: false, eyes },
220+ ));
221+ }
222+}
223+
224+fn pack_run(
225+ mut commands: Commands,
226+ time: Res<Time>,
227+ mut g: ResMut<Game>,
228+ t: Res<Travel>,
229+ mut pack: ResMut<Pack>,
230+ lamps: Query<&Lamp>,
231+ fires: Query<&CampLight>,
232+ player: Query<&Mover, With<Player>>,
233+ mut wolves: Query<(Entity, &mut Wolf, &mut Transform, &mut Sprite), Without<Eyes>>,
234+ mut eyes: Query<(&mut Transform, &mut Visibility), (With<Eyes>, Without<Wolf>)>,
235+) {
236+ let Ok(m) = player.single() else { return };
237+ let p = m.pos;
238+ let dt = time.delta_secs();
239+ let el = time.elapsed_secs();
240+ let h = g.hour();
241+
242+ if g.flag(LEAVE) {
243+ g.unset(LEAVE);
244+ for (_, mut w, _, _) in &mut wolves {
245+ w.away = true;
246+ }
247+ }
248+ if !wolf_hours(h) {
249+ for (_, mut w, _, _) in &mut wolves {
250+ w.away = true;
251+ }
252+ }
253+ let nearest = wolves.iter().map(|(_, w, _, _)| w.pos.distance(p)).fold(f32::MAX, f32::min);
254+ if g.zone != Zone::Road || (g.timelapse && nearest > GIVE_UP) {
255+ for (e, w, _, _) in wolves.iter() {
256+ commands.entity(e).despawn();
257+ commands.entity(w.eyes).despawn();
258+ }
259+ return;
260+ }
261+
262+ let srcs = sources(&g, &lamps, &fires, Some(p));
263+ let lit = light_at(&srcs, p) > 0.0;
264+ let fire = !fires.is_empty();
265+ let frozen = g.dialog.is_some() || g.request.is_some();
266+ let ring = if fire {
267+ RING_FIRE
268+ } else if lit {
269+ RING_LIT
270+ } else {
271+ RING_DARK
272+ };
273+ if !frozen {
274+ let k = if ring > pack.ring { 3.0 } else { 0.5 };
275+ pack.ring += (ring - pack.ring) * (1.0 - (-dt * k).exp());
276+ }
277+
278+ for (_, mut w, mut tr, mut s) in &mut wolves {
279+ let step = if w.away {
280+ (w.pos - p).normalize_or_zero() * FLEE_SPEED * dt
281+ } else if frozen {
282+ Vec2::ZERO
283+ } else {
284+ let d = p + Vec2::from_angle(w.slot + el * 0.25) * pack.ring - w.pos;
285+ let len = d.length();
286+ if len > 1e-4 { d / len * (WOLF_SPEED * dt).min(len) } else { Vec2::ZERO }
287+ };
288+ w.pos += step;
289+ let moving = step.length_squared() > 1e-8;
290+ if moving {
291+ w.facing = facing_of(to_screen(step));
292+ w.run += step.length();
293+ } else if !w.away {
294+ w.facing = facing_of(to_screen(p - w.pos));
295+ }
296+ let col = if moving { 1 + (w.run / STRIDE) as usize % 6 } else { 0 };
297+ if let Some(a) = s.texture_atlas.as_mut() {
298+ a.index = w.facing * 7 + col;
299+ }
300+ tr.translation = to_screen(w.pos).extend(depth(w.pos));
301+ if let Ok((mut et, mut ev)) = eyes.get_mut(w.eyes) {
302+ let sd = Vec2::from_angle((w.facing as f32 - 5.0) * FRAC_PI_4);
303+ let fwd = to_grid(sd).normalize_or_zero() * 0.45;
304+ et.translation = (to_screen(w.pos + fwd) + Vec2::new(0.0, 44.0)).extend(depth(w.pos) + 0.0005);
305+ *ev = if matches!(w.facing, 6 | 7 | 0) { Visibility::Hidden } else { Visibility::Inherited };
306+ }
307+ }
308+
309+ if !lit && !frozen && !t.busy() && g.dialog.is_none() && wolves.iter().any(|(_, w, _, _)| !w.away && w.pos.distance(p) <= BITE) {
310+ g.sfx.push(Sfx::Growl);
311+ g.dialog = Some((Talk::Ev(Ev::Wolves), "start"));
312+ }
313+}
src/player.rsadded+254 -0
@@ -0,0 +1,254 @@
1+use crate::cart::Cart;
2+use crate::game::*;
3+use crate::iso::*;
4+use crate::sheets::CharSheets;
5+use crate::world::*;
6+use bevy::prelude::*;
7+use std::collections::HashMap;
8+
9+const STRIDE: f32 = 1.6;
10+
11+#[derive(Component)]
12+pub struct Mover {
13+ pub pos: Vec2,
14+ pub facing: usize,
15+ pub moving: bool,
16+ pub frame: f32,
17+ pub pose: usize,
18+}
19+
20+impl Mover {
21+ pub fn new(pos: Vec2, facing: usize) -> Self {
22+ Self { pos, facing, moving: false, frame: 0.0, pose: 0 }
23+ }
24+}
25+
26+#[derive(Component)]
27+pub struct Player;
28+
29+#[derive(Component)]
30+pub struct Small;
31+
32+#[derive(Component)]
33+pub struct MainCamera;
34+
35+#[derive(Resource, Default)]
36+pub struct Pad {
37+ pub dir: Vec2,
38+ pub interact: bool,
39+ pub choice: Option<usize>,
40+ pub journey: bool,
41+ pub camp: bool,
42+ pub eat: bool,
43+ pub inventory: bool,
44+ pub lantern: bool,
45+}
46+
47+#[derive(Resource, Default)]
48+pub struct Nearby(pub Option<Talk>);
49+
50+#[derive(Resource)]
51+pub struct Scripted;
52+
53+pub const WALK: f32 = 2.4;
54+
55+pub struct PlayerPlugin;
56+
57+impl Plugin for PlayerPlugin {
58+ fn build(&self, app: &mut App) {
59+ app.init_resource::<Pad>()
60+ .init_resource::<Nearby>()
61+ .add_systems(Startup, spawn_player.after(crate::world::build_world).after(crate::sheets::load_sheets))
62+ .add_systems(PreUpdate, read_keys.run_if(not(resource_exists::<Scripted>)))
63+ .add_systems(
64+ Update,
65+ (move_player, find_nearby, interact, set_pose, animate, place_movers, camera_follow).chain(),
66+ );
67+ }
68+}
69+
70+fn spawn_player(mut commands: Commands, sheets: Res<CharSheets>) {
71+ let pos = ASHFORD + Vec2::new(-7.5, 8.0);
72+ commands.spawn((
73+ sheets.sprite("player", 3 * 9),
74+ anchor(sheets.spr("player")),
75+ Transform::from_translation(to_screen(pos).extend(depth(pos))).with_scale(Vec3::splat(PX)),
76+ Mover::new(pos, 3),
77+ Player,
78+ ));
79+}
80+
81+fn read_keys(keys: Res<ButtonInput<KeyCode>>, mut pad: ResMut<Pad>) {
82+ let mut d = Vec2::ZERO;
83+ if keys.any_pressed([KeyCode::KeyW, KeyCode::ArrowUp]) {
84+ d.y += 1.0;
85+ }
86+ if keys.any_pressed([KeyCode::KeyS, KeyCode::ArrowDown]) {
87+ d.y -= 1.0;
88+ }
89+ if keys.any_pressed([KeyCode::KeyA, KeyCode::ArrowLeft]) {
90+ d.x -= 1.0;
91+ }
92+ if keys.any_pressed([KeyCode::KeyD, KeyCode::ArrowRight]) {
93+ d.x += 1.0;
94+ }
95+ pad.dir = d;
96+ pad.interact = keys.just_pressed(KeyCode::KeyE) || keys.just_pressed(KeyCode::Space);
97+ pad.journey = keys.pressed(KeyCode::ShiftLeft);
98+ pad.camp = keys.just_pressed(KeyCode::KeyC);
99+ pad.eat = keys.just_pressed(KeyCode::KeyF);
100+ pad.inventory = keys.just_pressed(KeyCode::Tab);
101+ pad.lantern = keys.just_pressed(KeyCode::KeyL);
102+ let nums = [KeyCode::Digit1, KeyCode::Digit2, KeyCode::Digit3, KeyCode::Digit4, KeyCode::Digit5];
103+ pad.choice = nums.iter().position(|k| keys.just_pressed(*k));
104+}
105+
106+pub fn facing_of(screen_dir: Vec2) -> usize {
107+ let a = screen_dir.y.atan2(screen_dir.x).to_degrees();
108+ let k = (a / 45.0).round() as i32;
109+ (5 + k).rem_euclid(8) as usize
110+}
111+
112+pub fn screen_of(facing: usize) -> Vec2 {
113+ let a = (facing as f32 - 5.0) * std::f32::consts::FRAC_PI_4;
114+ Vec2::new(a.cos(), a.sin())
115+}
116+
117+pub fn to_world_dir(sd: Vec2) -> Vec2 {
118+ Vec2::new(sd.x / TW - sd.y / TH, -sd.x / TW - sd.y / TH).normalize()
119+}
120+
121+pub fn sort_z(pos: Vec2, occ: &Query<&Occluder>) -> f32 {
122+ let mut z = depth(pos);
123+ for o in occ {
124+ let c = (o.min + o.max) * 0.5;
125+ if (pos - c).length() > 12.0 {
126+ continue;
127+ }
128+ let q = pos.clamp(o.min, o.max);
129+ let d = (pos.x - q.x) + (pos.y - q.y);
130+ if d > 0.0 {
131+ z = z.max(o.z + 0.001);
132+ } else if d < 0.0 {
133+ z = z.min(o.z - 0.001);
134+ }
135+ }
136+ z
137+}
138+
139+pub fn move_player(time: Res<Time>, pad: Res<Pad>, mut g: ResMut<Game>, map: Res<Map>, mut q: Query<&mut Mover, With<Player>>) {
140+ let Ok(mut m) = q.single_mut() else { return };
141+ let busy = g.dialog.is_some() || g.camping || g.request.is_some();
142+ g.timelapse = !busy && pad.journey && g.zone == Zone::Road;
143+ if busy || pad.dir == Vec2::ZERO {
144+ m.moving = false;
145+ return;
146+ }
147+ let sd = pad.dir.normalize();
148+ let gd = to_world_dir(sd);
149+ let tired = if g.energy < 15.0 { 0.6 } else { 1.0 };
150+ let hurry = if g.timelapse { 4.0 } else { 1.0 };
151+ let laden = if g.flag("carrying") { 0.8 } else { 1.0 };
152+ let speed = WALK * tired * hurry * laden;
153+ let step = gd * speed * time.delta_secs();
154+ let mut p = m.pos;
155+ if map.walkable(p + Vec2::new(step.x, 0.0)) {
156+ p.x += step.x;
157+ }
158+ if map.walkable(p + Vec2::new(0.0, step.y)) {
159+ p.y += step.y;
160+ }
161+ m.moving = p != m.pos;
162+ m.pos = p;
163+ m.facing = facing_of(sd);
164+ let z = zone_at(p);
165+ if z != g.zone {
166+ if z != Zone::Road {
167+ g.sfx.push(if z == Zone::Ashford { Sfx::Home } else { Sfx::Arrive });
168+ g.toasts.push(z.name().to_string());
169+ g.flags.retain(|f| !f.starts_with("ev_"));
170+ }
171+ g.zone = z;
172+ }
173+}
174+
175+fn find_nearby(mut near: ResMut<Nearby>, q: Query<&Mover, With<Player>>, objs: Query<&Interact>) {
176+ let Ok(m) = q.single() else { return };
177+ near.0 = objs
178+ .iter()
179+ .map(|i| (i.talk, (i.pos - m.pos).length()))
180+ .filter(|(_, d)| *d < 1.7)
181+ .min_by(|a, b| a.1.total_cmp(&b.1))
182+ .map(|(t, _)| t);
183+}
184+
185+fn interact(pad: Res<Pad>, near: Res<Nearby>, mut g: ResMut<Game>, pq: Query<&Mover, With<Player>>, mut npcs: Query<(&mut Mover, &NpcTag), Without<Player>>) {
186+ if !pad.interact || g.dialog.is_some() || g.camping {
187+ return;
188+ }
189+ let Some(t) = near.0 else { return };
190+ g.dialog = Some((t, "start"));
191+ if let (Talk::Npc(n), Ok(p)) = (t, pq.single()) {
192+ for (mut m, tag) in &mut npcs {
193+ if tag.0 == n {
194+ let d = to_screen(p.pos) - to_screen(m.pos);
195+ m.facing = facing_of(d);
196+ }
197+ }
198+ }
199+}
200+
201+pub fn set_pose(g: Res<Game>, carts: Query<&Cart>, mut q: Query<&mut Mover, With<Player>>) {
202+ let Ok(mut m) = q.single_mut() else { return };
203+ let pushing = carts.iter().any(|c| c.attached);
204+ m.pose = if g.flag("carrying") {
205+ 1
206+ } else if pushing {
207+ 2
208+ } else {
209+ 0
210+ };
211+}
212+
213+fn animate(mut last: Local<HashMap<Entity, Vec2>>, mut q: Query<(Entity, &mut Mover, &mut Sprite)>) {
214+ for (e, mut m, mut s) in &mut q {
215+ let prev = last.insert(e, m.pos).unwrap_or(m.pos);
216+ let dist = (m.pos - prev).length();
217+ m.moving = dist > 1e-6;
218+ if m.moving {
219+ m.frame = (m.frame + dist / STRIDE * 8.0) % 8.0;
220+ } else {
221+ m.frame = 0.0;
222+ }
223+ let col = if m.moving { 1 + m.frame as usize } else { 0 };
224+ let want = (m.pose * 8 + m.facing) * 9 + col;
225+ if let Some(a) = &mut s.texture_atlas {
226+ if a.index != want {
227+ a.index = want;
228+ }
229+ }
230+ }
231+}
232+
233+fn place_movers(mut q: Query<(&Mover, &mut Transform)>, occ: Query<&Occluder>) {
234+ for (m, mut t) in &mut q {
235+ t.translation = to_screen(m.pos).extend(sort_z(m.pos, &occ));
236+ t.scale = Vec3::splat(PX);
237+ }
238+}
239+
240+fn camera_follow(
241+ time: Res<Time>,
242+ mut cam: ResMut<crate::CamTrue>,
243+ pq: Query<&Transform, (With<Player>, Without<MainCamera>, Without<crate::Upscaled>)>,
244+ mut cq: Query<&mut Transform, (With<MainCamera>, Without<crate::Upscaled>)>,
245+ mut uq: Query<&mut Transform, (With<crate::Upscaled>, Without<MainCamera>)>,
246+) {
247+ let (Ok(p), Ok(mut c), Ok(mut u)) = (pq.single(), cq.single_mut(), uq.single_mut()) else { return };
248+ let k = 1.0 - (-time.delta_secs() * 4.0).exp();
249+ let target = p.translation.truncate() + Vec2::new(0.0, 40.0);
250+ cam.0 = cam.0.lerp(target, k);
251+ let snapped = (cam.0 / 2.0).round() * 2.0;
252+ c.translation = snapped.extend(c.translation.z);
253+ u.translation = (-(cam.0 - snapped)).extend(u.translation.z);
254+}
src/sheets.rsadded+43 -0
@@ -0,0 +1,43 @@
1+use crate::sprites::{self, Spr};
2+use bevy::prelude::*;
3+use std::collections::HashMap;
4+
5+pub const SHEETS: &[(&str, &Spr)] = &[
6+ ("player", &sprites::PLAYER),
7+ ("gent", &sprites::GENT),
8+ ("grocer", &sprites::GROCER),
9+ ("woman", &sprites::WOMAN),
10+ ("barmaid", &sprites::BARMAID),
11+ ("teacher", &sprites::TEACHER),
12+ ("old", &sprites::OLD),
13+ ("worker", &sprites::WORKER),
14+ ("miner", &sprites::MINER),
15+ ("peddler", &sprites::PEDDLER),
16+ ("bandit", &sprites::BANDIT),
17+ ("boy", &sprites::BOY),
18+ ("wolf", &sprites::WOLF),
19+ ("cart", &sprites::CART),
20+];
21+
22+#[derive(Resource, Clone, Default)]
23+pub struct CharSheets(pub HashMap<&'static str, (Handle<Image>, Handle<TextureAtlasLayout>, &'static Spr)>);
24+
25+impl CharSheets {
26+ pub fn spr(&self, name: &str) -> &'static Spr {
27+ self.0[name].2
28+ }
29+
30+ pub fn sprite(&self, name: &str, index: usize) -> Sprite {
31+ let (img, layout, _) = self.0[name].clone();
32+ Sprite::from_atlas_image(img, TextureAtlas { layout, index })
33+ }
34+}
35+
36+pub fn load_sheets(mut commands: Commands, assets: Res<AssetServer>, mut layouts: ResMut<Assets<TextureAtlasLayout>>) {
37+ let mut m = HashMap::new();
38+ for (name, s) in SHEETS {
39+ let layout = layouts.add(TextureAtlasLayout::from_grid(UVec2::new(s.cell.0, s.cell.1), s.grid.0, s.grid.1, None, None));
40+ m.insert(*name, (assets.load(s.path), layout, *s));
41+ }
42+ commands.insert_resource(CharSheets(m));
43+}
src/sprites.rsadded+116 -0
@@ -0,0 +1,116 @@
1+#![allow(dead_code)]
2+
3+pub struct Spr {
4+ pub path: &'static str,
5+ pub size: (f32, f32),
6+ pub origin: (f32, f32),
7+ pub foot: (i32, i32),
8+ pub smoke: &'static [(f32, f32)],
9+ pub cell: (u32, u32),
10+ pub grid: (u32, u32),
11+ pub glow: Option<&'static str>,
12+}
13+
14+pub const A_BARN: Spr = Spr { path: "gfx/a_barn.png", size: (156.0, 204.0), origin: (78.0, 138.0), foot: (2, 2), smoke: &[], cell: (156, 204), grid: (1, 1), glow: None };
15+pub const A_COTTAGE1: Spr = Spr { path: "gfx/a_cottage1.png", size: (186.0, 200.0), origin: (77.0, 118.0), foot: (3, 2), smoke: &[(68.0, 224.0)], cell: (186, 200), grid: (1, 1), glow: Some("gfx/a_cottage1_e.png") };
16+pub const A_COTTAGE2: Spr = Spr { path: "gfx/a_cottage2.png", size: (188.0, 197.0), origin: (78.0, 115.0), foot: (3, 2), smoke: &[(-32.0, 218.0)], cell: (188, 197), grid: (1, 1), glow: Some("gfx/a_cottage2_e.png") };
17+pub const A_HOME: Spr = Spr { path: "gfx/a_home.png", size: (188.0, 190.0), origin: (78.0, 108.0), foot: (3, 2), smoke: &[(92.0, 168.0)], cell: (188, 190), grid: (1, 1), glow: Some("gfx/a_home_e.png") };
18+pub const A_INN: Spr = Spr { path: "gfx/a_inn.png", size: (220.0, 273.0), origin: (78.0, 175.0), foot: (4, 2), smoke: &[(-16.0, 338.0), (144.0, 258.0)], cell: (220, 273), grid: (1, 1), glow: Some("gfx/a_inn_e.png") };
19+pub const A_POST: Spr = Spr { path: "gfx/a_post.png", size: (188.0, 186.0), origin: (78.0, 104.0), foot: (3, 2), smoke: &[(96.0, 162.0)], cell: (188, 186), grid: (1, 1), glow: Some("gfx/a_post_e.png") };
20+pub const A_SCHOOL: Spr = Spr { path: "gfx/a_school.png", size: (188.0, 188.0), origin: (78.0, 106.0), foot: (3, 2), smoke: &[], cell: (188, 188), grid: (1, 1), glow: Some("gfx/a_school_e.png") };
21+pub const A_SHOP: Spr = Spr { path: "gfx/a_shop.png", size: (218.0, 195.0), origin: (77.0, 97.0), foot: (4, 2), smoke: &[(164.0, 112.0)], cell: (218, 195), grid: (1, 1), glow: Some("gfx/a_shop_e.png") };
22+pub const C_ENGINE: Spr = Spr { path: "gfx/c_engine.png", size: (191.0, 302.0), origin: (77.0, 220.0), foot: (3, 2), smoke: &[(192.0, 424.0)], cell: (191, 302), grid: (1, 1), glow: None };
23+pub const C_HEADFRAME: Spr = Spr { path: "gfx/c_headframe.png", size: (148.0, 285.0), origin: (74.0, 199.0), foot: (3, 3), smoke: &[], cell: (148, 285), grid: (1, 1), glow: None };
24+pub const C_INN: Spr = Spr { path: "gfx/c_inn.png", size: (220.0, 249.0), origin: (78.0, 151.0), foot: (4, 2), smoke: &[(-16.0, 290.0), (144.0, 210.0)], cell: (220, 249), grid: (1, 1), glow: Some("gfx/c_inn_e.png") };
25+pub const C_PAWN: Spr = Spr { path: "gfx/c_pawn.png", size: (186.0, 185.0), origin: (77.0, 103.0), foot: (3, 2), smoke: &[(96.0, 158.0)], cell: (186, 185), grid: (1, 1), glow: None };
26+pub const C_ROW: Spr = Spr { path: "gfx/c_row.png", size: (218.0, 231.0), origin: (77.0, 133.0), foot: (4, 2), smoke: &[(-32.0, 254.0), (32.0, 222.0), (96.0, 190.0), (160.0, 158.0)], cell: (218, 231), grid: (1, 1), glow: None };
27+pub const M_INN: Spr = Spr { path: "gfx/m_inn.png", size: (220.0, 259.0), origin: (78.0, 161.0), foot: (4, 2), smoke: &[(-24.0, 310.0), (152.0, 222.0)], cell: (220, 259), grid: (1, 1), glow: Some("gfx/m_inn_e.png") };
28+pub const M_MILL: Spr = Spr { path: "gfx/m_mill.png", size: (324.0, 420.0), origin: (109.0, 274.0), foot: (6, 3), smoke: &[(36.0, 534.0)], cell: (324, 420), grid: (1, 1), glow: Some("gfx/m_mill_e.png") };
29+pub const M_SHOP: Spr = Spr { path: "gfx/m_shop.png", size: (186.0, 251.0), origin: (77.0, 169.0), foot: (3, 2), smoke: &[(100.0, 288.0)], cell: (186, 251), grid: (1, 1), glow: Some("gfx/m_shop_e.png") };
30+pub const M_TERRACE: Spr = Spr { path: "gfx/m_terrace.png", size: (220.0, 255.0), origin: (78.0, 157.0), foot: (4, 2), smoke: &[(-32.0, 302.0), (32.0, 270.0), (96.0, 238.0), (160.0, 206.0)], cell: (220, 255), grid: (1, 1), glow: Some("gfx/m_terrace_e.png") };
31+pub const M_WAREHOUSE: Spr = Spr { path: "gfx/m_warehouse.png", size: (186.0, 289.0), origin: (77.0, 207.0), foot: (3, 2), smoke: &[], cell: (186, 289), grid: (1, 1), glow: Some("gfx/m_warehouse_e.png") };
32+pub const BANDIT: Spr = Spr { path: "gfx/bandit.png", size: (414.0, 1560.0), origin: (23.0, 53.0), foot: (1, 1), smoke: &[], cell: (46, 65), grid: (9, 24), glow: None };
33+pub const BARMAID: Spr = Spr { path: "gfx/barmaid.png", size: (396.0, 1488.0), origin: (22.0, 53.0), foot: (1, 1), smoke: &[], cell: (44, 62), grid: (9, 24), glow: None };
34+pub const BOY: Spr = Spr { path: "gfx/boy.png", size: (288.0, 1104.0), origin: (16.0, 37.0), foot: (1, 1), smoke: &[], cell: (32, 46), grid: (9, 24), glow: None };
35+pub const CART: Spr = Spr { path: "gfx/cart.png", size: (248.0, 816.0), origin: (31.0, 41.0), foot: (1, 1), smoke: &[], cell: (62, 51), grid: (4, 16), glow: None };
36+pub const GENT: Spr = Spr { path: "gfx/gent.png", size: (414.0, 1728.0), origin: (23.0, 60.0), foot: (1, 1), smoke: &[], cell: (46, 72), grid: (9, 24), glow: None };
37+pub const GROCER: Spr = Spr { path: "gfx/grocer.png", size: (414.0, 1560.0), origin: (23.0, 53.0), foot: (1, 1), smoke: &[], cell: (46, 65), grid: (9, 24), glow: None };
38+pub const MINER: Spr = Spr { path: "gfx/miner.png", size: (414.0, 1560.0), origin: (23.0, 53.0), foot: (1, 1), smoke: &[], cell: (46, 65), grid: (9, 24), glow: None };
39+pub const OLD: Spr = Spr { path: "gfx/old.png", size: (414.0, 1560.0), origin: (23.0, 55.0), foot: (1, 1), smoke: &[], cell: (46, 65), grid: (9, 24), glow: None };
40+pub const PEDDLER: Spr = Spr { path: "gfx/peddler.png", size: (414.0, 1560.0), origin: (23.0, 53.0), foot: (1, 1), smoke: &[], cell: (46, 65), grid: (9, 24), glow: None };
41+pub const PLAYER: Spr = Spr { path: "gfx/player.png", size: (414.0, 1608.0), origin: (23.0, 55.0), foot: (1, 1), smoke: &[], cell: (46, 67), grid: (9, 24), glow: None };
42+pub const TEACHER: Spr = Spr { path: "gfx/teacher.png", size: (414.0, 1560.0), origin: (23.0, 53.0), foot: (1, 1), smoke: &[], cell: (46, 65), grid: (9, 24), glow: None };
43+pub const WOLF: Spr = Spr { path: "gfx/wolf.png", size: (546.0, 432.0), origin: (39.0, 40.0), foot: (1, 1), smoke: &[], cell: (78, 54), grid: (7, 8), glow: None };
44+pub const WOMAN: Spr = Spr { path: "gfx/woman.png", size: (396.0, 1488.0), origin: (22.0, 53.0), foot: (1, 1), smoke: &[], cell: (44, 62), grid: (9, 24), glow: None };
45+pub const WORKER: Spr = Spr { path: "gfx/worker.png", size: (414.0, 1608.0), origin: (23.0, 55.0), foot: (1, 1), smoke: &[], cell: (46, 67), grid: (9, 24), glow: None };
46+pub const BALE: Spr = Spr { path: "gfx/bale.png", size: (48.0, 41.0), origin: (24.0, 12.0), foot: (1, 1), smoke: &[], cell: (48, 41), grid: (1, 1), glow: None };
47+pub const BARREL: Spr = Spr { path: "gfx/barrel.png", size: (26.0, 30.0), origin: (13.0, 11.0), foot: (1, 1), smoke: &[], cell: (26, 30), grid: (1, 1), glow: None };
48+pub const BARRELS: Spr = Spr { path: "gfx/barrels.png", size: (46.0, 41.0), origin: (20.0, 18.0), foot: (1, 1), smoke: &[], cell: (46, 41), grid: (1, 1), glow: None };
49+pub const BENCH: Spr = Spr { path: "gfx/bench.png", size: (40.0, 43.0), origin: (19.0, 17.0), foot: (1, 1), smoke: &[], cell: (40, 43), grid: (1, 1), glow: None };
50+pub const BIRCH: Spr = Spr { path: "gfx/birch.png", size: (78.0, 146.0), origin: (41.0, 126.0), foot: (1, 1), smoke: &[], cell: (78, 146), grid: (1, 1), glow: None };
51+pub const BUSH0: Spr = Spr { path: "gfx/bush0.png", size: (33.0, 26.0), origin: (17.0, 5.0), foot: (1, 1), smoke: &[], cell: (33, 26), grid: (1, 1), glow: None };
52+pub const BUSH1: Spr = Spr { path: "gfx/bush1.png", size: (33.0, 26.0), origin: (17.0, 5.0), foot: (1, 1), smoke: &[], cell: (33, 26), grid: (1, 1), glow: None };
53+pub const CAMPFIRE: Spr = Spr { path: "gfx/campfire.png", size: (38.0, 23.0), origin: (19.0, -3.0), foot: (1, 1), smoke: &[], cell: (38, 23), grid: (1, 1), glow: None };
54+pub const COALPILE: Spr = Spr { path: "gfx/coalpile.png", size: (47.0, 26.0), origin: (23.0, -1.0), foot: (1, 1), smoke: &[], cell: (47, 26), grid: (1, 1), glow: None };
55+pub const COBBLE0: Spr = Spr { path: "gfx/cobble0.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
56+pub const COBBLE1: Spr = Spr { path: "gfx/cobble1.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
57+pub const COBBLE2: Spr = Spr { path: "gfx/cobble2.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
58+pub const COBBLE3: Spr = Spr { path: "gfx/cobble3.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
59+pub const CRATE: Spr = Spr { path: "gfx/crate.png", size: (48.0, 40.0), origin: (24.0, 11.0), foot: (1, 1), smoke: &[], cell: (48, 40), grid: (1, 1), glow: None };
60+pub const CRATES: Spr = Spr { path: "gfx/crates.png", size: (36.0, 50.0), origin: (18.0, 19.0), foot: (1, 1), smoke: &[], cell: (36, 50), grid: (1, 1), glow: None };
61+pub const DEAD: Spr = Spr { path: "gfx/dead.png", size: (158.0, 123.0), origin: (102.0, 103.0), foot: (1, 1), smoke: &[], cell: (158, 123), grid: (1, 1), glow: None };
62+pub const EYES: Spr = Spr { path: "gfx/eyes.png", size: (5.0, 1.0), origin: (2.0, 0.0), foot: (1, 1), smoke: &[], cell: (5, 1), grid: (1, 1), glow: None };
63+pub const FARMLAND0: Spr = Spr { path: "gfx/farmland0.png", size: (64.0, 34.0), origin: (32.0, 2.0), foot: (1, 1), smoke: &[], cell: (64, 34), grid: (1, 1), glow: None };
64+pub const FARMLAND1: Spr = Spr { path: "gfx/farmland1.png", size: (64.0, 34.0), origin: (32.0, 2.0), foot: (1, 1), smoke: &[], cell: (64, 34), grid: (1, 1), glow: None };
65+pub const FENCE_X: Spr = Spr { path: "gfx/fence_x.png", size: (39.0, 35.0), origin: (33.0, 8.0), foot: (1, 1), smoke: &[], cell: (39, 35), grid: (1, 1), glow: None };
66+pub const FENCE_Y: Spr = Spr { path: "gfx/fence_y.png", size: (39.0, 35.0), origin: (6.0, 8.0), foot: (1, 1), smoke: &[], cell: (39, 35), grid: (1, 1), glow: None };
67+pub const FLAG0: Spr = Spr { path: "gfx/flag0.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
68+pub const FLAG1: Spr = Spr { path: "gfx/flag1.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
69+pub const FLAG2: Spr = Spr { path: "gfx/flag2.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
70+pub const FLAG3: Spr = Spr { path: "gfx/flag3.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
71+pub const FLAME0: Spr = Spr { path: "gfx/flame0.png", size: (22.0, 30.0), origin: (11.0, 8.0), foot: (1, 1), smoke: &[], cell: (22, 30), grid: (1, 1), glow: Some("gfx/flame0_e.png") };
72+pub const FLAME1: Spr = Spr { path: "gfx/flame1.png", size: (22.0, 28.0), origin: (11.0, 8.0), foot: (1, 1), smoke: &[], cell: (22, 28), grid: (1, 1), glow: Some("gfx/flame1_e.png") };
73+pub const FLAME2: Spr = Spr { path: "gfx/flame2.png", size: (22.0, 29.0), origin: (11.0, 7.0), foot: (1, 1), smoke: &[], cell: (22, 29), grid: (1, 1), glow: Some("gfx/flame2_e.png") };
74+pub const FLAME3: Spr = Spr { path: "gfx/flame3.png", size: (22.0, 29.0), origin: (11.0, 8.0), foot: (1, 1), smoke: &[], cell: (22, 29), grid: (1, 1), glow: Some("gfx/flame3_e.png") };
75+pub const FLOWERS0: Spr = Spr { path: "gfx/flowers0.png", size: (60.0, 36.0), origin: (30.0, 4.0), foot: (1, 1), smoke: &[], cell: (60, 36), grid: (1, 1), glow: None };
76+pub const FLOWERS1: Spr = Spr { path: "gfx/flowers1.png", size: (60.0, 36.0), origin: (30.0, 4.0), foot: (1, 1), smoke: &[], cell: (60, 36), grid: (1, 1), glow: None };
77+pub const GRASS0: Spr = Spr { path: "gfx/grass0.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
78+pub const GRASS1: Spr = Spr { path: "gfx/grass1.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
79+pub const GRASS2: Spr = Spr { path: "gfx/grass2.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
80+pub const GRASS3: Spr = Spr { path: "gfx/grass3.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
81+pub const GRAVE: Spr = Spr { path: "gfx/grave.png", size: (34.0, 31.0), origin: (17.0, 6.0), foot: (1, 1), smoke: &[], cell: (34, 31), grid: (1, 1), glow: None };
82+pub const HAYSTACK: Spr = Spr { path: "gfx/haystack.png", size: (44.0, 31.0), origin: (22.0, 3.0), foot: (1, 1), smoke: &[], cell: (44, 31), grid: (1, 1), glow: None };
83+pub const LAMP: Spr = Spr { path: "gfx/lamp.png", size: (32.0, 104.0), origin: (16.0, 83.0), foot: (1, 1), smoke: &[], cell: (32, 104), grid: (1, 1), glow: Some("gfx/lamp_e.png") };
84+pub const LIGHT: Spr = Spr { path: "gfx/light.png", size: (96.0, 48.0), origin: (48.0, 24.0), foot: (1, 1), smoke: &[], cell: (96, 48), grid: (1, 1), glow: None };
85+pub const LOGS: Spr = Spr { path: "gfx/logs.png", size: (59.0, 42.0), origin: (30.0, 13.0), foot: (1, 1), smoke: &[], cell: (59, 42), grid: (1, 1), glow: None };
86+pub const MUD0: Spr = Spr { path: "gfx/mud0.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
87+pub const MUD1: Spr = Spr { path: "gfx/mud1.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
88+pub const OAK0: Spr = Spr { path: "gfx/oak0.png", size: (101.0, 147.0), origin: (55.0, 127.0), foot: (1, 1), smoke: &[], cell: (101, 147), grid: (1, 1), glow: None };
89+pub const OAK1: Spr = Spr { path: "gfx/oak1.png", size: (108.0, 164.0), origin: (55.0, 144.0), foot: (1, 1), smoke: &[], cell: (108, 164), grid: (1, 1), glow: None };
90+pub const OAK2: Spr = Spr { path: "gfx/oak2.png", size: (107.0, 175.0), origin: (49.0, 155.0), foot: (1, 1), smoke: &[], cell: (107, 175), grid: (1, 1), glow: None };
91+pub const PINE: Spr = Spr { path: "gfx/pine.png", size: (106.0, 158.0), origin: (53.0, 137.0), foot: (1, 1), smoke: &[], cell: (106, 158), grid: (1, 1), glow: None };
92+pub const PLANKS: Spr = Spr { path: "gfx/planks.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
93+pub const PUFF: Spr = Spr { path: "gfx/puff.png", size: (12.0, 12.0), origin: (6.0, 6.0), foot: (1, 1), smoke: &[], cell: (12, 12), grid: (1, 1), glow: None };
94+pub const RAIL_X: Spr = Spr { path: "gfx/rail_x.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
95+pub const RAIL_Y: Spr = Spr { path: "gfx/rail_y.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
96+pub const ROAD0: Spr = Spr { path: "gfx/road0.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
97+pub const ROAD1: Spr = Spr { path: "gfx/road1.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
98+pub const ROAD2: Spr = Spr { path: "gfx/road2.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
99+pub const ROAD3: Spr = Spr { path: "gfx/road3.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
100+pub const ROCK0: Spr = Spr { path: "gfx/rock0.png", size: (30.0, 24.0), origin: (15.0, 2.0), foot: (1, 1), smoke: &[], cell: (30, 24), grid: (1, 1), glow: None };
101+pub const ROCK1: Spr = Spr { path: "gfx/rock1.png", size: (27.0, 27.0), origin: (15.0, 2.0), foot: (1, 1), smoke: &[], cell: (27, 27), grid: (1, 1), glow: None };
102+pub const SACK: Spr = Spr { path: "gfx/sack.png", size: (26.0, 23.0), origin: (13.0, 3.0), foot: (1, 1), smoke: &[], cell: (26, 23), grid: (1, 1), glow: None };
103+pub const SACKS: Spr = Spr { path: "gfx/sacks.png", size: (43.0, 32.0), origin: (18.0, 10.0), foot: (1, 1), smoke: &[], cell: (43, 32), grid: (1, 1), glow: None };
104+pub const SIGNPOST: Spr = Spr { path: "gfx/signpost.png", size: (32.0, 40.0), origin: (16.0, 21.0), foot: (1, 1), smoke: &[], cell: (32, 40), grid: (1, 1), glow: None };
105+pub const SLAG: Spr = Spr { path: "gfx/slag.png", size: (98.0, 48.0), origin: (46.0, -5.0), foot: (1, 1), smoke: &[], cell: (98, 48), grid: (1, 1), glow: None };
106+pub const SOOT0: Spr = Spr { path: "gfx/soot0.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
107+pub const SOOT1: Spr = Spr { path: "gfx/soot1.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
108+pub const SOOT2: Spr = Spr { path: "gfx/soot2.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
109+pub const SOOT3: Spr = Spr { path: "gfx/soot3.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
110+pub const STALL: Spr = Spr { path: "gfx/stall.png", size: (97.0, 85.0), origin: (32.0, 38.0), foot: (1, 1), smoke: &[], cell: (97, 85), grid: (1, 1), glow: None };
111+pub const TABLE: Spr = Spr { path: "gfx/table.png", size: (36.0, 39.0), origin: (18.0, 13.0), foot: (1, 1), smoke: &[], cell: (36, 39), grid: (1, 1), glow: None };
112+pub const TENT: Spr = Spr { path: "gfx/tent.png", size: (86.0, 81.0), origin: (27.0, 35.0), foot: (1, 1), smoke: &[], cell: (86, 81), grid: (1, 1), glow: None };
113+pub const TUB: Spr = Spr { path: "gfx/tub.png", size: (40.0, 39.0), origin: (20.0, 15.0), foot: (1, 1), smoke: &[], cell: (40, 39), grid: (1, 1), glow: None };
114+pub const WATER0: Spr = Spr { path: "gfx/water0.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
115+pub const WATER1: Spr = Spr { path: "gfx/water1.png", size: (64.0, 33.0), origin: (32.0, 1.0), foot: (1, 1), smoke: &[], cell: (64, 33), grid: (1, 1), glow: None };
116+pub const WELL: Spr = Spr { path: "gfx/well.png", size: (48.0, 56.0), origin: (24.0, 31.0), foot: (1, 1), smoke: &[], cell: (48, 56), grid: (1, 1), glow: None };
src/travel.rsadded+437 -0
@@ -0,0 +1,437 @@
1+use crate::game::*;
2+use crate::iso::*;
3+use crate::player::{facing_of, MainCamera, Mover, Pad, Player};
4+use crate::sheets::CharSheets;
5+use crate::sprites::{self, Spr};
6+use crate::ui::Fade;
7+use crate::world::{EventSpot, Glow};
8+use bevy::prelude::*;
9+use bevy::sprite::Anchor;
10+
11+const DAY: f32 = 1440.0;
12+const FLAMES: [&Spr; 4] = [&sprites::FLAME0, &sprites::FLAME1, &sprites::FLAME2, &sprites::FLAME3];
13+pub const BASE_CLEAR: Vec3 = Vec3::new(0.11, 0.16, 0.10);
14+const DUSK: Vec3 = Vec3::new(0.9, 0.78, 0.72);
15+pub const NIGHT: Vec3 = Vec3::new(0.42, 0.48, 0.72);
16+const RAIN_COUNT: usize = 120;
17+
18+pub struct TravelPlugin;
19+
20+impl Plugin for TravelPlugin {
21+ fn build(&self, app: &mut App) {
22+ app.init_resource::<Travel>().add_systems(
23+ Update,
24+ (requests, clock, travel, needs, eat, camp_key, roadside, camp_flame, camp_light, rain).chain(),
25+ );
26+ }
27+}
28+
29+#[derive(Clone, Copy, Default)]
30+enum Phase {
31+ #[default]
32+ Idle,
33+ Wait(f32),
34+ Sleep { left: f32, camp: bool },
35+}
36+
37+#[derive(Resource, Default)]
38+pub struct Travel {
39+ phase: Phase,
40+ linger: f32,
41+ rain_since: Option<f32>,
42+}
43+
44+impl Travel {
45+ pub fn busy(&self) -> bool {
46+ !matches!(self.phase, Phase::Idle)
47+ }
48+}
49+
50+#[derive(Component)]
51+struct CampPart;
52+
53+#[derive(Component)]
54+pub struct CampLight(pub Vec2);
55+
56+#[derive(Component)]
57+pub struct CampFlame {
58+ frames: [Handle<Image>; 4],
59+ idx: usize,
60+ timer: f32,
61+}
62+
63+#[derive(Component)]
64+pub struct Bandit;
65+
66+#[derive(Component)]
67+pub struct Rain;
68+
69+fn total(g: &Game) -> f32 {
70+ g.day as f32 * DAY + g.minutes
71+}
72+
73+pub fn day_tint(h: f32) -> Vec3 {
74+ let day = Vec3::ONE;
75+ if (7.0..18.0).contains(&h) {
76+ day
77+ } else if (18.0..19.0).contains(&h) {
78+ day.lerp(DUSK, h - 18.0)
79+ } else if (19.0..21.0).contains(&h) {
80+ DUSK.lerp(NIGHT, (h - 19.0) / 2.0)
81+ } else if h >= 21.0 || h < 5.0 {
82+ NIGHT
83+ } else if h < 6.0 {
84+ NIGHT.lerp(DUSK, h - 5.0)
85+ } else {
86+ DUSK.lerp(day, h - 6.0)
87+ }
88+}
89+
90+pub fn night_amount(h: f32) -> f32 {
91+ ((1.0 - day_tint(h).y) / (1.0 - NIGHT.y)).clamp(0.0, 1.0)
92+}
93+
94+pub fn rnd(seed: &mut u32) -> f32 {
95+ let mut x = (*seed).max(1);
96+ x ^= x << 13;
97+ x ^= x >> 17;
98+ x ^= x << 5;
99+ *seed = x;
100+ x as f32 / u32::MAX as f32
101+}
102+
103+fn requests(
104+ mut commands: Commands,
105+ assets: Res<AssetServer>,
106+ mut g: ResMut<Game>,
107+ mut t: ResMut<Travel>,
108+ pq: Query<&Mover, With<Player>>,
109+ camp_q: Query<Entity, With<CampPart>>,
110+) {
111+ if !matches!(t.phase, Phase::Idle) {
112+ return;
113+ }
114+ let Some(req) = g.request.take() else { return };
115+ match req {
116+ Req::Wait { minutes } => t.phase = Phase::Wait(minutes),
117+ Req::Sleep { until, camp } => {
118+ if camp {
119+ for e in &camp_q {
120+ commands.entity(e).despawn();
121+ }
122+ if let Ok(m) = pq.single() {
123+ spawn_camp(&mut commands, &assets, m.pos, g.has(Item::Firewood));
124+ }
125+ g.camping = true;
126+ t.linger = 0.0;
127+ }
128+ let left = (until - g.minutes).rem_euclid(DAY);
129+ t.phase = Phase::Sleep { left, camp };
130+ }
131+ Req::BreakCamp => {
132+ for e in &camp_q {
133+ commands.entity(e).despawn();
134+ }
135+ g.camping = false;
136+ t.linger = 0.0;
137+ }
138+ }
139+}
140+
141+fn spawn_camp(commands: &mut Commands, assets: &AssetServer, p: Vec2, fire: bool) {
142+ let tent = p + Vec2::new(1.0, -1.0);
143+ commands.spawn((
144+ Sprite::from_image(assets.load(sprites::TENT.path)),
145+ anchor(&sprites::TENT),
146+ Transform::from_translation(to_screen(tent).extend(depth(tent + Vec2::splat(0.5)))).with_scale(Vec3::splat(PX)),
147+ CampPart,
148+ ));
149+ let fire_at = p + Vec2::new(1.0, 1.0);
150+ let z = depth(fire_at + Vec2::splat(0.5));
151+ commands.spawn((
152+ Sprite::from_image(assets.load(sprites::CAMPFIRE.path)),
153+ anchor(&sprites::CAMPFIRE),
154+ Transform::from_translation(to_screen(fire_at).extend(z)).with_scale(Vec3::splat(PX)),
155+ CampPart,
156+ ));
157+ if !fire {
158+ return;
159+ }
160+ commands.spawn((
161+ Sprite::from_image(assets.load(FLAMES[0].path)),
162+ anchor(FLAMES[0]),
163+ Transform::from_translation(to_screen(fire_at).extend(z + 0.002)).with_scale(Vec3::splat(PX)),
164+ CampFlame { frames: FLAMES.map(|s| assets.load(s.path)), idx: 0, timer: 0.0 },
165+ CampPart,
166+ ));
167+ commands.spawn((
168+ Sprite { image: assets.load(sprites::LIGHT.path), color: Color::srgba(1.0, 0.7, 0.35, 0.6), ..default() },
169+ Transform::from_translation((to_screen(fire_at) + Vec2::new(0.0, 40.0)).extend(9.5)).with_scale(Vec3::splat(PX * 2.5)),
170+ CampLight(fire_at),
171+ CampPart,
172+ ));
173+}
174+
175+fn clock(time: Res<Time>, t: Res<Travel>, mut g: ResMut<Game>) {
176+ if !matches!(t.phase, Phase::Idle) || g.dialog.is_some() || g.request.is_some() {
177+ return;
178+ }
179+ let base = if g.zone == Zone::Road { 6.0 } else { 3.0 };
180+ let k = if g.timelapse { base * 2.0 } else { base };
181+ g.advance(time.delta_secs() * k);
182+}
183+
184+fn wake(g: &mut Game, camp: bool) {
185+ g.energy = if !camp || g.has(Item::Bedroll) { 100.0 } else { (g.energy + 45.0).min(100.0) };
186+ if !camp {
187+ g.warmth = 100.0;
188+ } else if g.take(Item::Firewood) {
189+ g.warmth = 100.0;
190+ } else {
191+ g.warmth = 35.0;
192+ g.toasts.push("A cold night".into());
193+ }
194+ g.hunger = (g.hunger - 12.0).max(0.0);
195+}
196+
197+fn travel(
198+ mut commands: Commands,
199+ time: Res<Time>,
200+ mut g: ResMut<Game>,
201+ mut t: ResMut<Travel>,
202+ mut fade: ResMut<Fade>,
203+ camp_q: Query<Entity, With<CampPart>>,
204+) {
205+ let dt = time.delta_secs();
206+ match t.phase {
207+ Phase::Idle => {}
208+ Phase::Wait(left) => {
209+ let step = left.min(300.0 * dt);
210+ g.advance(step);
211+ let left = left - step;
212+ t.phase = if left <= 0.001 { Phase::Idle } else { Phase::Wait(left) };
213+ }
214+ Phase::Sleep { left, camp } => {
215+ let step = left.min(if camp { 80.0 } else { 240.0 } * dt);
216+ g.advance(step);
217+ let left = left - step;
218+ if left <= 0.001 {
219+ wake(&mut g, camp);
220+ t.phase = Phase::Idle;
221+ if camp {
222+ t.linger = 2.5;
223+ }
224+ } else {
225+ t.phase = Phase::Sleep { left, camp };
226+ }
227+ }
228+ }
229+ let target = match t.phase {
230+ Phase::Idle => 0.0,
231+ Phase::Wait(_) => 0.35,
232+ Phase::Sleep { camp: true, .. } => 0.45,
233+ Phase::Sleep { camp: false, .. } => 0.85,
234+ };
235+ fade.0 += (target - fade.0) * (1.0 - (-dt * 6.0).exp());
236+ if t.linger > 0.0 {
237+ t.linger -= dt;
238+ if t.linger <= 0.0 {
239+ t.linger = 0.0;
240+ for e in &camp_q {
241+ commands.entity(e).despawn();
242+ }
243+ g.camping = false;
244+ }
245+ }
246+}
247+
248+fn needs(mut g: ResMut<Game>, mut last: Local<Option<(u32, f32)>>, mut low: Local<[bool; 3]>) {
249+ let prev = last.unwrap_or((g.day, g.minutes));
250+ *last = Some((g.day, g.minutes));
251+ let dm = ((g.day as f32 - prev.0 as f32) * DAY + (g.minutes - prev.1)).max(0.0);
252+ let h = dm / 60.0;
253+
254+ let road = g.zone == Zone::Road;
255+ let night = g.is_night();
256+ g.hunger = (g.hunger - 4.0 * h).clamp(0.0, 100.0);
257+ let drain = if road {
258+ if g.timelapse { 7.5 } else { 5.0 }
259+ } else {
260+ 2.0
261+ };
262+ let starve = if g.hunger <= 0.0 { 2.0 } else { 1.0 };
263+ g.energy = (g.energy - drain * starve * h).clamp(0.0, 100.0);
264+ let mut warm = if road && night {
265+ if g.has(Item::Lantern) { -5.0 } else { -8.0 }
266+ } else {
267+ 15.0
268+ };
269+ if road && g.raining {
270+ warm -= 6.0;
271+ }
272+ g.warmth = (g.warmth + warm * h).clamp(0.0, 100.0);
273+
274+ let vals = [(g.hunger, "Hungry"), (g.energy, "Weary"), (g.warmth, "Cold")];
275+ for (i, (v, msg)) in vals.into_iter().enumerate() {
276+ if v < 20.0 {
277+ if !low[i] {
278+ low[i] = true;
279+ g.toasts.push(msg.into());
280+ }
281+ } else {
282+ low[i] = false;
283+ }
284+ }
285+}
286+
287+fn eat(pad: Res<Pad>, mut g: ResMut<Game>) {
288+ if pad.eat && g.take(Item::Ration) {
289+ g.hunger = (g.hunger + 35.0).min(100.0);
290+ g.toasts.push("Ate a Ration".into());
291+ }
292+}
293+
294+fn camp_key(pad: Res<Pad>, mut g: ResMut<Game>) {
295+ if pad.camp && g.zone == Zone::Road && g.dialog.is_none() && !g.camping {
296+ g.dialog = Some((Talk::Camp, "start"));
297+ }
298+}
299+
300+fn flag_of(ev: Ev) -> &'static str {
301+ match ev {
302+ Ev::BrokenCart => "cart_done",
303+ Ev::Highwayman => "ev_highway",
304+ Ev::Storm => "ev_storm",
305+ Ev::Peddler => "ev_peddler",
306+ Ev::Lost => "ev_lost",
307+ Ev::Wolves => "ev_wolves_seen",
308+ }
309+}
310+
311+pub fn roadside(
312+ mut commands: Commands,
313+ sheets: Res<CharSheets>,
314+ mut g: ResMut<Game>,
315+ spots: Query<&EventSpot>,
316+ pq: Query<&Mover, With<Player>>,
317+ bandits: Query<Entity, With<Bandit>>,
318+) {
319+ if g.dialog.is_none() {
320+ for e in &bandits {
321+ commands.entity(e).despawn();
322+ }
323+ } else {
324+ return;
325+ }
326+ let Ok(p) = pq.single() else { return };
327+ for s in &spots {
328+ if (s.pos - p.pos).length() > 2.5 {
329+ continue;
330+ }
331+ let flag = flag_of(s.ev);
332+ let open = match s.ev {
333+ Ev::BrokenCart | Ev::Lost => !g.is_night(),
334+ Ev::Highwayman => {
335+ let h = g.hour();
336+ h >= 18.5 || h < 5.0
337+ }
338+ Ev::Storm => !g.raining,
339+ Ev::Peddler => true,
340+ Ev::Wolves => false,
341+ };
342+ if !open || g.flag(flag) {
343+ continue;
344+ }
345+ g.set(flag);
346+ g.dialog = Some((Talk::Ev(s.ev), "start"));
347+ if s.ev == Ev::Highwayman {
348+ let pos = p.pos + Vec2::new(1.5, -1.5);
349+ let facing = facing_of(to_screen(p.pos) - to_screen(pos));
350+ commands.spawn((
351+ sheets.sprite("bandit", facing * 9),
352+ anchor(sheets.spr("bandit")),
353+ Transform::from_translation(to_screen(pos).extend(depth(pos))).with_scale(Vec3::splat(PX)),
354+ Mover::new(pos, facing),
355+ Bandit,
356+ ));
357+ }
358+ break;
359+ }
360+}
361+
362+fn camp_flame(time: Res<Time>, mut q: Query<(&mut CampFlame, &mut Sprite, &mut Anchor)>) {
363+ let dt = time.delta_secs();
364+ for (mut f, mut s, mut a) in &mut q {
365+ f.timer += dt;
366+ if f.timer >= 0.125 {
367+ f.timer -= 0.125;
368+ f.idx = (f.idx + 1) % 4;
369+ s.image = f.frames[f.idx].clone();
370+ *a = anchor(FLAMES[f.idx]);
371+ }
372+ }
373+}
374+
375+fn camp_light(time: Res<Time>, mut q: Query<&mut Sprite, With<CampLight>>) {
376+ let t = time.elapsed_secs();
377+ let a = 0.6 + 0.07 * (t * 9.0).sin() + 0.03 * (t * 23.0).cos();
378+ for mut s in &mut q {
379+ s.color = Color::srgba(1.0, 0.7, 0.35, a);
380+ }
381+}
382+
383+fn rain(
384+ mut commands: Commands,
385+ time: Res<Time>,
386+ mut g: ResMut<Game>,
387+ mut t: ResMut<Travel>,
388+ mut seed: Local<u32>,
389+ cam: Query<(&Transform, &Projection), (With<MainCamera>, Without<Rain>)>,
390+ mut drops: Query<(Entity, &mut Transform), With<Rain>>,
391+) {
392+ if g.raining && g.zone != Zone::Road {
393+ g.raining = false;
394+ }
395+ let now = total(&g);
396+ if g.raining {
397+ let since = *t.rain_since.get_or_insert(now);
398+ if now - since >= 180.0 {
399+ g.raining = false;
400+ }
401+ } else {
402+ t.rain_since = None;
403+ }
404+ if !g.raining {
405+ for (e, _) in &drops {
406+ commands.entity(e).despawn();
407+ }
408+ return;
409+ }
410+ let Ok((ct, proj)) = cam.single() else { return };
411+ let scale = match proj {
412+ Projection::Orthographic(o) => o.scale,
413+ _ => 1.0,
414+ };
415+ let (hw, hh) = (640.0 * scale, 360.0 * scale);
416+ let c = ct.translation.truncate();
417+ let dt = time.delta_secs();
418+ let count = drops.iter().count();
419+ for _ in count..RAIN_COUNT {
420+ let x = c.x + (rnd(&mut seed) * 2.0 - 1.0) * hw;
421+ let y = c.y + (rnd(&mut seed) * 2.0 - 1.0) * hh;
422+ commands.spawn((
423+ Sprite { color: Color::srgba(0.8, 0.85, 1.0, 0.35), custom_size: Some(Vec2::new(2.0, 22.0)), ..default() },
424+ Transform::from_xyz(x, y, 20.0).with_rotation(Quat::from_rotation_z(-0.2)),
425+ Glow,
426+ Rain,
427+ ));
428+ }
429+ for (_, mut tr) in &mut drops {
430+ tr.translation.y -= 900.0 * dt;
431+ tr.translation.x -= 180.0 * dt;
432+ if tr.translation.y < c.y - hh - 30.0 || tr.translation.x < c.x - hw - 30.0 {
433+ tr.translation.y = c.y + hh + rnd(&mut seed) * 60.0;
434+ tr.translation.x = c.x + (rnd(&mut seed) * 2.0 - 1.0) * hw;
435+ }
436+ }
437+}
src/ui.rsadded+607 -0
@@ -0,0 +1,607 @@
1+use crate::content;
2+use crate::game::{Game, Item, Npc, Obj, Talk};
3+use crate::player::{Nearby, Pad};
4+use bevy::color::Alpha;
5+use bevy::picking::hover::Hovered;
6+use bevy::prelude::*;
7+use bevy::ui_widgets::{Activate, Button};
8+
9+const PARCH: Color = Color::srgb(0.95, 0.9, 0.78);
10+const MUTED: Color = Color::srgba(0.95, 0.9, 0.78, 0.6);
11+const GOLD: Color = Color::srgb(0.92, 0.75, 0.35);
12+const PANEL: Color = Color::srgba(0.09, 0.07, 0.07, 0.92);
13+const EDGE: Color = Color::srgb(0.78, 0.68, 0.5);
14+const BTN: Color = Color::srgba(0.09, 0.07, 0.07, 0.92);
15+const BTN_HOVER: Color = Color::srgba(0.3, 0.24, 0.18, 0.95);
16+const DOT_OFF: Color = Color::srgb(0.25, 0.22, 0.18);
17+const RED: Color = Color::srgb(0.8, 0.2, 0.2);
18+const AMBER: Color = Color::srgb(0.95, 0.68, 0.2);
19+const BLUE: Color = Color::srgb(0.35, 0.55, 0.9);
20+const WARM: Color = Color::srgb(0.9, 0.35, 0.15);
21+const LANTERN: Color = Color::srgb(1.0, 0.85, 0.2);
22+const BAR_BG: Color = Color::srgb(0.03, 0.025, 0.025);
23+
24+const BIG: f32 = 32.0;
25+const SMALL: f32 = 16.0;
26+const ICON: f32 = 8.0;
27+const BORDER: f32 = 2.0;
28+const PAD: f32 = 8.0;
29+
30+const Z_FADE: i32 = 10;
31+const Z_HUD: i32 = 20;
32+const Z_TOAST: i32 = 25;
33+const Z_DIALOG: i32 = 30;
34+
35+const TOAST_LIFE: f32 = 2.5;
36+const MAX_TOASTS: usize = 4;
37+
38+pub struct UiPlugin;
39+
40+impl Plugin for UiPlugin {
41+ fn build(&self, app: &mut App) {
42+ app.init_resource::<Fade>()
43+ .init_resource::<Picked>()
44+ .init_resource::<DialogUi>()
45+ .init_resource::<InvUi>()
46+ .add_observer(on_choice)
47+ .add_systems(Startup, setup)
48+ .add_systems(Update, (hud, lantern, prompt, dialog, choice_hover, toasts, inventory, fade));
49+ }
50+}
51+
52+#[derive(Resource, Default)]
53+pub struct Fade(pub f32);
54+
55+#[derive(Resource)]
56+struct UiFont(Handle<Font>);
57+
58+#[derive(Resource, Default)]
59+struct Picked(Option<usize>);
60+
61+#[derive(Resource, Default)]
62+struct DialogUi {
63+ shown: Option<(Talk, &'static str)>,
64+ dirty: bool,
65+ root: Option<Entity>,
66+}
67+
68+#[derive(Resource, Default)]
69+struct InvUi {
70+ shown: Vec<(Item, usize)>,
71+ root: Option<Entity>,
72+}
73+
74+#[derive(Component, Clone, Copy)]
75+enum HudText {
76+ Clock,
77+ Zone,
78+ Money,
79+}
80+
81+#[derive(Component, Clone, Copy)]
82+enum Need {
83+ Hunger,
84+ Energy,
85+ Warmth,
86+}
87+
88+#[derive(Component)]
89+struct NeedFill(Need);
90+
91+#[derive(Component)]
92+struct Lantern;
93+
94+#[derive(Component)]
95+struct FadeOverlay;
96+
97+#[derive(Component)]
98+struct PromptRoot;
99+
100+#[derive(Component)]
101+struct PromptText;
102+
103+#[derive(Component)]
104+struct ToastRoot;
105+
106+#[derive(Component)]
107+struct Toast {
108+ age: f32,
109+}
110+
111+#[derive(Component)]
112+struct ChoiceBtn(usize);
113+
114+fn text(s: impl Into<String>, size: f32, color: Color, font: &Handle<Font>) -> impl Bundle {
115+ (Text::new(s), TextFont::from_font_size(size).with_font(font.clone()), TextColor(color))
116+}
117+
118+fn frame(node: Node) -> impl Bundle {
119+ (
120+ Node {
121+ border: UiRect::all(Val::Px(BORDER)),
122+ padding: UiRect::all(Val::Px(PAD)),
123+ ..node
124+ },
125+ BackgroundColor(PANEL),
126+ BorderColor::all(EDGE),
127+ )
128+}
129+
130+fn icon(color: Color) -> impl Bundle {
131+ (
132+ Node {
133+ width: Val::Px(ICON),
134+ height: Val::Px(ICON),
135+ ..default()
136+ },
137+ BackgroundColor(color),
138+ )
139+}
140+
141+fn setup(mut commands: Commands, assets: Res<AssetServer>) {
142+ let font = assets.load::<Font>("fonts/pixel.ttf");
143+ commands.insert_resource(UiFont(font.clone()));
144+
145+ commands.spawn((
146+ FadeOverlay,
147+ Node {
148+ position_type: PositionType::Absolute,
149+ left: Val::Px(0.0),
150+ right: Val::Px(0.0),
151+ top: Val::Px(0.0),
152+ bottom: Val::Px(0.0),
153+ ..default()
154+ },
155+ BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.0)),
156+ GlobalZIndex(Z_FADE),
157+ ));
158+
159+ commands.spawn((
160+ ToastRoot,
161+ Node {
162+ position_type: PositionType::Absolute,
163+ left: Val::Px(0.0),
164+ right: Val::Px(0.0),
165+ top: Val::Px(64.0),
166+ flex_direction: FlexDirection::Column,
167+ align_items: AlignItems::Center,
168+ row_gap: Val::Px(4.0),
169+ ..default()
170+ },
171+ GlobalZIndex(Z_TOAST),
172+ ));
173+
174+ commands
175+ .spawn((
176+ frame(Node {
177+ position_type: PositionType::Absolute,
178+ left: Val::Px(16.0),
179+ top: Val::Px(16.0),
180+ flex_direction: FlexDirection::Column,
181+ row_gap: Val::Px(4.0),
182+ ..default()
183+ }),
184+ GlobalZIndex(Z_HUD),
185+ ))
186+ .with_children(|p| {
187+ p.spawn(Node {
188+ align_items: AlignItems::Center,
189+ column_gap: Val::Px(6.0),
190+ ..default()
191+ })
192+ .with_children(|r| {
193+ r.spawn((HudText::Clock, text("", SMALL, PARCH, &font)));
194+ r.spawn((
195+ Lantern,
196+ Node {
197+ width: Val::Px(ICON),
198+ height: Val::Px(ICON),
199+ ..default()
200+ },
201+ BackgroundColor(LANTERN),
202+ Visibility::Hidden,
203+ ));
204+ });
205+ p.spawn((HudText::Zone, text("", SMALL, MUTED, &font)));
206+ });
207+
208+ commands
209+ .spawn((
210+ frame(Node {
211+ position_type: PositionType::Absolute,
212+ right: Val::Px(16.0),
213+ top: Val::Px(16.0),
214+ align_items: AlignItems::Center,
215+ column_gap: Val::Px(8.0),
216+ ..default()
217+ }),
218+ GlobalZIndex(Z_HUD),
219+ ))
220+ .with_children(|p| {
221+ p.spawn(icon(GOLD));
222+ p.spawn((HudText::Money, text("", BIG, PARCH, &font)));
223+ });
224+
225+ commands
226+ .spawn((
227+ frame(Node {
228+ position_type: PositionType::Absolute,
229+ left: Val::Px(16.0),
230+ bottom: Val::Px(16.0),
231+ flex_direction: FlexDirection::Column,
232+ row_gap: Val::Px(6.0),
233+ ..default()
234+ }),
235+ GlobalZIndex(Z_HUD),
236+ ))
237+ .with_children(|p| {
238+ for (kind, color) in [(Need::Hunger, AMBER), (Need::Energy, BLUE), (Need::Warmth, WARM)] {
239+ p.spawn(Node {
240+ align_items: AlignItems::Center,
241+ column_gap: Val::Px(8.0),
242+ ..default()
243+ })
244+ .with_children(|r| {
245+ r.spawn(icon(color));
246+ r.spawn((
247+ Node {
248+ width: Val::Px(96.0),
249+ height: Val::Px(6.0),
250+ ..default()
251+ },
252+ BackgroundColor(BAR_BG),
253+ ))
254+ .with_children(|b| {
255+ b.spawn((
256+ Node {
257+ position_type: PositionType::Absolute,
258+ left: Val::Px(0.0),
259+ top: Val::Px(0.0),
260+ bottom: Val::Px(0.0),
261+ width: Val::Percent(100.0),
262+ ..default()
263+ },
264+ BackgroundColor(color),
265+ NeedFill(kind),
266+ ));
267+ });
268+ });
269+ }
270+ });
271+
272+ commands
273+ .spawn((
274+ PromptRoot,
275+ Node {
276+ position_type: PositionType::Absolute,
277+ left: Val::Px(0.0),
278+ right: Val::Px(0.0),
279+ bottom: Val::Px(28.0),
280+ justify_content: JustifyContent::Center,
281+ ..default()
282+ },
283+ Visibility::Hidden,
284+ GlobalZIndex(Z_HUD),
285+ ))
286+ .with_children(|p| {
287+ p.spawn(frame(Node::default())).with_children(|b| {
288+ b.spawn((PromptText, text("", SMALL, PARCH, &font)));
289+ });
290+ });
291+}
292+
293+fn on_choice(ev: On<Activate>, q: Query<&ChoiceBtn>, mut picked: ResMut<Picked>) {
294+ if let Ok(c) = q.get(ev.entity) {
295+ picked.0 = Some(c.0);
296+ }
297+}
298+
299+fn hud(g: Res<Game>, mut texts: Query<(&mut Text, &HudText)>, mut fills: Query<(&mut Node, &NeedFill)>) {
300+ for (mut t, k) in &mut texts {
301+ let s = match k {
302+ HudText::Clock => g.clock(),
303+ HudText::Zone => g.zone.name().to_string(),
304+ HudText::Money => g.money.to_string(),
305+ };
306+ if t.0 != s {
307+ t.0 = s;
308+ }
309+ }
310+ for (mut n, f) in &mut fills {
311+ let v = match f.0 {
312+ Need::Hunger => g.hunger,
313+ Need::Energy => g.energy,
314+ Need::Warmth => g.warmth,
315+ };
316+ let w = Val::Percent(v.clamp(0.0, 100.0));
317+ if n.width != w {
318+ n.width = w;
319+ }
320+ }
321+}
322+
323+fn lantern(g: Res<Game>, mut q: Query<&mut Visibility, With<Lantern>>) {
324+ let vis = if g.flag("lantern") { Visibility::Inherited } else { Visibility::Hidden };
325+ for mut v in &mut q {
326+ if *v != vis {
327+ *v = vis;
328+ }
329+ }
330+}
331+
332+fn prompt_label(t: Talk) -> String {
333+ match t {
334+ Talk::Npc(n) => n.name().to_string(),
335+ Talk::Obj(o) => match o {
336+ Obj::HomeBed => "Home",
337+ Obj::BalePile => "Cotton bales",
338+ Obj::BaleDrop => "Mill door",
339+ Obj::MillInn => "The Weavers' Arms",
340+ Obj::CoalInn => "The Black Horse",
341+ Obj::Signpost => "Signpost",
342+ }
343+ .to_string(),
344+ Talk::Ev(_) => "?".to_string(),
345+ Talk::Camp => "Camp".to_string(),
346+ }
347+}
348+
349+fn prompt(
350+ g: Res<Game>,
351+ near: Res<Nearby>,
352+ mut roots: Query<&mut Visibility, With<PromptRoot>>,
353+ mut texts: Query<&mut Text, With<PromptText>>,
354+) {
355+ let label = near.0.filter(|_| g.dialog.is_none() && !g.camping).map(prompt_label);
356+ let vis = if label.is_some() { Visibility::Inherited } else { Visibility::Hidden };
357+ for mut v in &mut roots {
358+ if *v != vis {
359+ *v = vis;
360+ }
361+ }
362+ if let Some(l) = label {
363+ for mut t in &mut texts {
364+ let s = format!("[E] {l}");
365+ if t.0 != s {
366+ t.0 = s;
367+ }
368+ }
369+ }
370+}
371+
372+fn bonded(n: Npc) -> bool {
373+ matches!(n, Npc::Hale | Npc::Pike | Npc::Bess | Npc::Edwin | Npc::OldTom | Npc::Annie)
374+}
375+
376+fn dialog(
377+ mut commands: Commands,
378+ mut g: ResMut<Game>,
379+ pad: Res<Pad>,
380+ mut picked: ResMut<Picked>,
381+ mut ui: ResMut<DialogUi>,
382+ font: Res<UiFont>,
383+) {
384+ let input = pad.choice.or(picked.0.take());
385+ if let (Some(i), Some((talk, node))) = (input, g.dialog) {
386+ let mut d = content::talk(talk, node, &g);
387+ if d.choices.is_empty() {
388+ if i == 0 {
389+ g.dialog = None;
390+ }
391+ } else if i < d.choices.len() {
392+ let c = d.choices.swap_remove(i);
393+ g.dialog = c.next.map(|n| (talk, n));
394+ if let Some(f) = c.effect {
395+ f(&mut g);
396+ }
397+ ui.dirty = true;
398+ }
399+ }
400+
401+ let Some((talk, node)) = g.dialog else {
402+ if let Some(root) = ui.root.take() {
403+ commands.entity(root).despawn();
404+ }
405+ ui.shown = None;
406+ ui.dirty = false;
407+ return;
408+ };
409+ if ui.root.is_some() && ui.shown == Some((talk, node)) && !ui.dirty {
410+ return;
411+ }
412+ if let Some(root) = ui.root.take() {
413+ commands.entity(root).despawn();
414+ }
415+
416+ let d = content::talk(talk, node, &g);
417+ let hearts = match talk {
418+ Talk::Npc(n) if bonded(n) => Some(g.heart(n)),
419+ _ => None,
420+ };
421+ let labels: Vec<String> = if d.choices.is_empty() {
422+ vec!["Continue".to_string()]
423+ } else {
424+ d.choices.iter().map(|c| c.label.clone()).collect()
425+ };
426+ let font = &font.0;
427+
428+ let root = commands
429+ .spawn((
430+ Node {
431+ position_type: PositionType::Absolute,
432+ left: Val::Px(0.0),
433+ right: Val::Px(0.0),
434+ bottom: Val::Px(24.0),
435+ justify_content: JustifyContent::Center,
436+ ..default()
437+ },
438+ GlobalZIndex(Z_DIALOG),
439+ ))
440+ .with_children(|r| {
441+ r.spawn(frame(Node {
442+ width: Val::Px(1000.0),
443+ flex_direction: FlexDirection::Column,
444+ padding: UiRect::all(Val::Px(16.0)),
445+ row_gap: Val::Px(8.0),
446+ ..default()
447+ }))
448+ .with_children(|p| {
449+ p.spawn(Node {
450+ align_items: AlignItems::Center,
451+ column_gap: Val::Px(8.0),
452+ ..default()
453+ })
454+ .with_children(|s| {
455+ s.spawn(text(d.speaker.clone(), BIG, GOLD, font));
456+ if let Some(h) = hearts {
457+ for k in 0..5 {
458+ s.spawn(icon(if k < h { RED } else { DOT_OFF }));
459+ }
460+ }
461+ });
462+ p.spawn(text(d.text.clone(), BIG, PARCH, font));
463+ for (i, label) in labels.iter().enumerate() {
464+ p.spawn((
465+ Button,
466+ Hovered::default(),
467+ ChoiceBtn(i),
468+ Node {
469+ padding: UiRect::axes(Val::Px(PAD), Val::Px(4.0)),
470+ ..default()
471+ },
472+ BackgroundColor(BTN),
473+ ))
474+ .with_children(|b| {
475+ b.spawn(text(format!("{} {}", i + 1, label), BIG, PARCH, font));
476+ });
477+ }
478+ });
479+ })
480+ .id();
481+
482+ ui.root = Some(root);
483+ ui.shown = Some((talk, node));
484+ ui.dirty = false;
485+}
486+
487+fn choice_hover(mut q: Query<(&Hovered, &mut BackgroundColor), With<ChoiceBtn>>) {
488+ for (h, mut bg) in &mut q {
489+ let c = if h.get() { BTN_HOVER } else { BTN };
490+ if bg.0 != c {
491+ bg.0 = c;
492+ }
493+ }
494+}
495+
496+fn toasts(
497+ mut commands: Commands,
498+ time: Res<Time>,
499+ mut g: ResMut<Game>,
500+ font: Res<UiFont>,
501+ roots: Query<Entity, With<ToastRoot>>,
502+ mut q: Query<(Entity, &mut Toast, &mut TextColor, &mut BackgroundColor, &mut BorderColor)>,
503+) {
504+ let Ok(root) = roots.single() else { return };
505+ let dt = time.delta_secs();
506+ let texts = if g.toasts.is_empty() { Vec::new() } else { std::mem::take(&mut g.toasts) };
507+
508+ let mut live = Vec::new();
509+ for (e, mut t, mut tc, mut bg, mut bc) in &mut q {
510+ t.age += dt;
511+ if t.age >= TOAST_LIFE {
512+ commands.entity(e).despawn();
513+ continue;
514+ }
515+ let a = 1.0 - t.age / TOAST_LIFE;
516+ tc.0 = PARCH.with_alpha(a);
517+ bg.0 = PANEL.with_alpha(0.92 * a);
518+ *bc = BorderColor::all(EDGE.with_alpha(a));
519+ live.push((t.age, e));
520+ }
521+
522+ live.sort_by(|a, b| b.0.total_cmp(&a.0));
523+ let fresh = texts.len().min(MAX_TOASTS);
524+ for (_, e) in live.iter().take((live.len() + fresh).saturating_sub(MAX_TOASTS)) {
525+ commands.entity(*e).despawn();
526+ }
527+
528+ let skip = texts.len() - fresh;
529+ for s in texts.into_iter().skip(skip) {
530+ commands.spawn((
531+ Toast { age: 0.0 },
532+ ChildOf(root),
533+ frame(Node::default()),
534+ Text::new(s),
535+ TextFont::from_font_size(SMALL).with_font(font.0.clone()),
536+ TextColor(PARCH),
537+ ));
538+ }
539+}
540+
541+fn inventory(
542+ mut commands: Commands,
543+ g: Res<Game>,
544+ pad: Res<Pad>,
545+ font: Res<UiFont>,
546+ mut ui: ResMut<InvUi>,
547+ mut open: Local<bool>,
548+) {
549+ if pad.inventory {
550+ *open = !*open;
551+ }
552+ let mut items: Vec<(Item, usize)> = Vec::new();
553+ for &i in &g.items {
554+ match items.iter_mut().find(|(x, _)| *x == i) {
555+ Some(e) => e.1 += 1,
556+ None => items.push((i, 1)),
557+ }
558+ }
559+ let stale = if *open { ui.root.is_none() || ui.shown != items } else { ui.root.is_some() };
560+ if !stale {
561+ return;
562+ }
563+ if let Some(root) = ui.root.take() {
564+ commands.entity(root).despawn();
565+ }
566+ if *open {
567+ let font = &font.0;
568+ let root = commands
569+ .spawn((
570+ frame(Node {
571+ position_type: PositionType::Absolute,
572+ right: Val::Px(16.0),
573+ top: Val::Px(72.0),
574+ width: Val::Px(320.0),
575+ flex_direction: FlexDirection::Row,
576+ flex_wrap: FlexWrap::Wrap,
577+ column_gap: Val::Px(12.0),
578+ row_gap: Val::Px(4.0),
579+ ..default()
580+ }),
581+ GlobalZIndex(Z_HUD),
582+ ))
583+ .with_children(|p| {
584+ for (item, n) in &items {
585+ let s = if *n > 1 { format!("{} x{n}", item.name()) } else { item.name().to_string() };
586+ p.spawn(Node {
587+ width: Val::Percent(45.0),
588+ ..default()
589+ })
590+ .with_children(|c| {
591+ c.spawn(text(s, SMALL, PARCH, font));
592+ });
593+ }
594+ })
595+ .id();
596+ ui.root = Some(root);
597+ ui.shown = items;
598+ }
599+}
600+
601+fn fade(time: Res<Time>, target: Res<Fade>, mut shown: Local<f32>, mut q: Query<&mut BackgroundColor, With<FadeOverlay>>) {
602+ let k = 1.0 - (-time.delta_secs() * 6.0).exp();
603+ *shown += (target.0.clamp(0.0, 1.0) - *shown) * k;
604+ for mut bg in &mut q {
605+ bg.0 = Color::srgba(0.0, 0.0, 0.0, *shown);
606+ }
607+}
src/world.rsadded+621 -0
@@ -0,0 +1,621 @@
1+use crate::game::*;
2+use crate::iso::*;
3+use crate::sheets::CharSheets;
4+use crate::sprites::{self, Spr};
5+use bevy::prelude::*;
6+use std::collections::HashSet;
7+
8+pub const ASHFORD: Vec2 = Vec2::new(0.0, 0.0);
9+pub const MILLBROOK: Vec2 = Vec2::new(110.0, -110.0);
10+pub const COALBRIDGE: Vec2 = Vec2::new(220.0, -220.0);
11+pub const TOWN_RADIUS: f32 = 17.0;
12+const BANDS: [Vec2; 3] = [ASHFORD, MILLBROOK, COALBRIDGE];
13+
14+const OAKS: [&Spr; 4] = [&sprites::OAK0, &sprites::OAK1, &sprites::OAK2, &sprites::BIRCH];
15+const PINES: [&Spr; 2] = [&sprites::PINE, &sprites::BIRCH];
16+const GRASS: [&Spr; 4] = [&sprites::GRASS0, &sprites::GRASS1, &sprites::GRASS2, &sprites::GRASS3];
17+const ROAD: [&Spr; 4] = [&sprites::ROAD0, &sprites::ROAD1, &sprites::ROAD2, &sprites::ROAD3];
18+const COBBLE: [&Spr; 4] = [&sprites::COBBLE0, &sprites::COBBLE1, &sprites::COBBLE2, &sprites::COBBLE3];
19+const FLAG: [&Spr; 4] = [&sprites::FLAG0, &sprites::FLAG1, &sprites::FLAG2, &sprites::FLAG3];
20+const SOOT: [&Spr; 4] = [&sprites::SOOT0, &sprites::SOOT1, &sprites::SOOT2, &sprites::SOOT3];
21+const MUD: [&Spr; 2] = [&sprites::MUD0, &sprites::MUD1];
22+const FARMLAND: [&Spr; 2] = [&sprites::FARMLAND0, &sprites::FARMLAND1];
23+const ROCKS: [&Spr; 2] = [&sprites::ROCK0, &sprites::ROCK1];
24+const BUSHES: [&Spr; 2] = [&sprites::BUSH0, &sprites::BUSH1];
25+
26+#[derive(Resource, Default)]
27+pub struct Map {
28+ pub ground: HashSet<IVec2>,
29+ pub blocked: HashSet<IVec2>,
30+ pub legs: Vec<Vec<Vec2>>,
31+}
32+
33+impl Map {
34+ pub fn walkable(&self, p: Vec2) -> bool {
35+ let c = cell(p);
36+ self.ground.contains(&c) && !self.blocked.contains(&c)
37+ }
38+}
39+
40+#[derive(Component)]
41+pub struct Occluder {
42+ pub min: Vec2,
43+ pub max: Vec2,
44+ pub z: f32,
45+}
46+
47+#[derive(Component)]
48+pub struct Interact {
49+ pub talk: Talk,
50+ pub pos: Vec2,
51+}
52+
53+#[derive(Component)]
54+pub struct NpcTag(pub Npc);
55+
56+#[derive(Component)]
57+pub struct Glow;
58+
59+#[derive(Component)]
60+pub struct Emissive;
61+
62+#[derive(Component)]
63+pub struct Lamp(pub Vec2);
64+
65+#[derive(Component)]
66+pub struct Ground;
67+
68+#[derive(Component)]
69+pub struct Water;
70+
71+#[derive(Component)]
72+pub struct Chimney {
73+ pub at: Vec3,
74+ pub t: f32,
75+ pub rate: f32,
76+}
77+
78+#[derive(Component)]
79+pub struct Puff {
80+ pub age: f32,
81+ pub drift: f32,
82+}
83+
84+#[derive(Component)]
85+pub struct EventSpot {
86+ pub ev: Ev,
87+ pub pos: Vec2,
88+}
89+
90+pub fn zone_at(p: Vec2) -> Zone {
91+ for (z, o) in [(Zone::Ashford, ASHFORD), (Zone::Millbrook, MILLBROOK), (Zone::Coalbridge, COALBRIDGE)] {
92+ if (p - o).length() < TOWN_RADIUS {
93+ return z;
94+ }
95+ }
96+ Zone::Road
97+}
98+
99+pub fn town_origin(z: Zone) -> Vec2 {
100+ match z {
101+ Zone::Ashford => ASHFORD,
102+ Zone::Millbrook => MILLBROOK,
103+ Zone::Coalbridge => COALBRIDGE,
104+ Zone::Road => ASHFORD,
105+ }
106+}
107+
108+pub struct WorldPlugin;
109+
110+impl Plugin for WorldPlugin {
111+ fn build(&self, app: &mut App) {
112+ app.init_resource::<Map>()
113+ .add_systems(Startup, build_world.after(crate::sheets::load_sheets))
114+ .add_systems(Update, (smoke, water));
115+ }
116+}
117+
118+pub struct Spawner<'a, 'w, 's> {
119+ pub commands: &'a mut Commands<'w, 's>,
120+ pub assets: &'a AssetServer,
121+ pub map: &'a mut Map,
122+}
123+
124+impl Spawner<'_, '_, '_> {
125+ fn art(&mut self, s: &Spr, at: Vec2, z: f32) -> Entity {
126+ let e = self
127+ .commands
128+ .spawn((Sprite::from_image(self.assets.load(s.path)), anchor(s), Transform::from_translation(to_screen(at).extend(z)).with_scale(Vec3::splat(PX))))
129+ .id();
130+ if let Some(g) = s.glow {
131+ let mut sprite = Sprite::from_image(self.assets.load(g));
132+ sprite.color = Color::srgba(1.0, 1.0, 1.0, 0.0);
133+ self.commands.spawn((sprite, anchor(s), Transform::from_translation(to_screen(at).extend(z + 0.0005)).with_scale(Vec3::splat(PX)), Emissive));
134+ }
135+ e
136+ }
137+
138+ pub fn ground(&mut self, s: &Spr, c: IVec2) {
139+ let e = self.art(s, c.as_vec2(), -10.0 + depth(c.as_vec2()) * 0.01);
140+ self.commands.entity(e).insert(Ground);
141+ self.map.ground.insert(c);
142+ }
143+
144+ pub fn water(&mut self, c: IVec2) {
145+ let e = self.art(&sprites::WATER0, c.as_vec2(), -10.0 + depth(c.as_vec2()) * 0.01);
146+ self.commands.entity(e).insert(Water);
147+ self.map.blocked.insert(c);
148+ }
149+
150+ pub fn prop_fp(&mut self, s: &Spr, c: IVec2, size: IVec2, block: bool) -> Entity {
151+ if block {
152+ for x in 0..size.x {
153+ for y in 0..size.y {
154+ self.map.blocked.insert(c + IVec2::new(x, y));
155+ }
156+ }
157+ }
158+ let center = c.as_vec2() + size.as_vec2() * 0.5;
159+ self.art(s, c.as_vec2(), depth(center))
160+ }
161+
162+ pub fn prop(&mut self, s: &Spr, c: IVec2, block: bool) -> Entity {
163+ self.prop_fp(s, c, IVec2::from(s.foot), block)
164+ }
165+
166+ pub fn tree(&mut self, s: &Spr, c: IVec2) {
167+ self.map.blocked.insert(c);
168+ let center = c.as_vec2() + Vec2::splat(0.5);
169+ self.art(s, c.as_vec2(), depth(center));
170+ }
171+
172+ pub fn building(&mut self, s: &Spr, at: IVec2, talk: Option<Talk>) -> Vec2 {
173+ let size = IVec2::from(s.foot);
174+ for x in 0..size.x {
175+ for y in 0..size.y {
176+ self.map.blocked.insert(at + IVec2::new(x, y));
177+ }
178+ }
179+ let min = at.as_vec2();
180+ let max = min + size.as_vec2();
181+ let z = depth((min + max) * 0.5);
182+ let e = self.art(s, min, z);
183+ self.commands.entity(e).insert(Occluder { min, max, z });
184+ let base = to_screen(min);
185+ let rate = if size.x >= 6 { 0.12 } else { 0.45 };
186+ for (i, (dx, dy)) in s.smoke.iter().enumerate() {
187+ self.commands.spawn(Chimney { at: Vec3::new(base.x + dx, base.y + dy, 8.0), t: i as f32 * 0.3, rate });
188+ }
189+ let door = Vec2::new(at.x as f32 + 1.5, max.y + 0.6);
190+ if let Some(t) = talk {
191+ self.commands.spawn((Interact { talk: t, pos: door }, Transform::default()));
192+ }
193+ door
194+ }
195+
196+ pub fn npc(&mut self, sheets: &CharSheets, n: Npc, sheet: &str, pos: Vec2, facing: usize) -> Entity {
197+ self.map.blocked.insert(cell(pos));
198+ let spr = sheets.spr(sheet);
199+ self.commands
200+ .spawn((
201+ sheets.sprite(sheet, facing * 9),
202+ anchor(spr),
203+ Transform::from_translation(to_screen(pos).extend(depth(pos))).with_scale(Vec3::splat(PX)),
204+ NpcTag(n),
205+ Interact { talk: Talk::Npc(n), pos },
206+ crate::player::Mover::new(pos, facing),
207+ ))
208+ .id()
209+ }
210+}
211+
212+fn band_of(c: IVec2) -> Option<(usize, IVec2)> {
213+ for (i, o) in BANDS.iter().enumerate() {
214+ let l = c - cell(*o);
215+ if (-20..=20).contains(&l.x) && (-18..=18).contains(&l.y) {
216+ return Some((i, l));
217+ }
218+ }
219+ None
220+}
221+
222+fn street(l: IVec2) -> bool {
223+ (-16..=15).contains(&l.x) && (0..=1).contains(&l.y)
224+}
225+
226+fn river(l: IVec2) -> bool {
227+ (9..=11).contains(&l.x)
228+}
229+
230+fn field(l: IVec2) -> bool {
231+ (10..=17).contains(&l.x) && (7..=14).contains(&l.y)
232+}
233+
234+fn rail(l: IVec2) -> bool {
235+ l.y == 10 && (-16..=15).contains(&l.x)
236+}
237+
238+fn reserved(c: IVec2) -> bool {
239+ match band_of(c) {
240+ Some((0, l)) => street(l) || field(l),
241+ Some((_, l)) => street(l),
242+ None => false,
243+ }
244+}
245+
246+fn leg1_t(p: Vec2) -> f32 {
247+ let d = COALBRIDGE - MILLBROOK;
248+ (p - MILLBROOK).dot(d) / d.length_squared()
249+}
250+
251+fn tree_kind(s: f32, k: usize) -> &'static Spr {
252+ if s < 0.4 {
253+ OAKS[k % 4]
254+ } else if s < 0.75 {
255+ PINES[k % 2]
256+ } else {
257+ &sprites::DEAD
258+ }
259+}
260+
261+fn vnoise(c: IVec2, s: f32, salt: u32) -> f32 {
262+ let p = c.as_vec2() / s;
263+ let i = p.floor();
264+ let f = p - i;
265+ let f = f * f * (Vec2::splat(3.0) - 2.0 * f);
266+ let (x, y) = (i.x as i32, i.y as i32);
267+ let a = hash(x, y, salt) + (hash(x + 1, y, salt) - hash(x, y, salt)) * f.x;
268+ let b = hash(x, y + 1, salt) + (hash(x + 1, y + 1, salt) - hash(x, y + 1, salt)) * f.x;
269+ a + (b - a) * f.y
270+}
271+
272+fn biome(c: IVec2, k: usize) -> &'static Spr {
273+ let pm = ((leg1_t(c.as_vec2()) - 0.2) / 0.6).clamp(0.0, 1.0);
274+ if vnoise(c, 5.0, 11) < pm * 0.9 {
275+ MUD[k % 2]
276+ } else if vnoise(c, 4.0, 12) < pm * 0.35 {
277+ SOOT[k]
278+ } else {
279+ GRASS[k]
280+ }
281+}
282+
283+fn dense(points: &[Vec2]) -> Vec<Vec2> {
284+ let mut out = Vec::new();
285+ for w in points.windows(2) {
286+ let (a, b) = (w[0], w[1]);
287+ let n = ((b - a).length() / 0.25).ceil() as i32;
288+ for i in 0..n {
289+ out.push(a.lerp(b, i as f32 / n as f32));
290+ }
291+ }
292+ out.push(*points.last().unwrap());
293+ out
294+}
295+
296+fn leg(from: Vec2, wiggle: [Vec2; 5]) -> Vec<Vec2> {
297+ let start = from + Vec2::new(15.0, 0.5);
298+ let end = from + Vec2::new(110.0 - 15.0, -110.0 + 0.5);
299+ let mut pts = vec![start, start + Vec2::new(6.0, 0.0)];
300+ for (i, w) in wiggle.iter().enumerate() {
301+ let t = (i as f32 + 1.0) / 6.0;
302+ pts.push(start.lerp(end, t) + *w);
303+ }
304+ pts.push(end - Vec2::new(6.0, 0.0));
305+ pts.push(end);
306+ dense(&pts)
307+}
308+
309+pub fn build_world(mut commands: Commands, assets: Res<AssetServer>, mut map: ResMut<Map>, sheets: Res<CharSheets>) {
310+ let legs = vec![
311+ leg(ASHFORD, [Vec2::new(-4.0, -10.0), Vec2::new(6.0, 4.0), Vec2::new(-8.0, -6.0), Vec2::new(5.0, 6.0), Vec2::new(-3.0, -4.0)]),
312+ leg(MILLBROOK, [Vec2::new(6.0, 6.0), Vec2::new(-6.0, -8.0), Vec2::new(4.0, 7.0), Vec2::new(-7.0, -3.0), Vec2::new(3.0, 5.0)]),
313+ ];
314+ let mut sp = Spawner { commands: &mut commands, assets: &assets, map: &mut map };
315+
316+ let mut road_cells: HashSet<IVec2> = HashSet::new();
317+ let mut near: HashSet<IVec2> = HashSet::new();
318+ for l in &legs {
319+ for p in l.iter().step_by(2) {
320+ for dx in -1..=1 {
321+ for dy in -1..=1 {
322+ let q = *p + Vec2::new(dx as f32 * 0.5, dy as f32 * 0.5);
323+ road_cells.insert(cell(q));
324+ }
325+ }
326+ let c = cell(*p);
327+ for dx in -14..=14 {
328+ for dy in -14..=14 {
329+ if dx * dx + dy * dy <= 196 {
330+ near.insert(c + IVec2::new(dx, dy));
331+ }
332+ }
333+ }
334+ }
335+ }
336+ for o in BANDS {
337+ let oc = cell(o);
338+ for dx in -20..=20 {
339+ for dy in -18..=18 {
340+ near.insert(oc + IVec2::new(dx, dy));
341+ }
342+ }
343+ }
344+
345+ for c in &near {
346+ let k = (hash(c.x, c.y, 1) * 4.0) as usize;
347+ let road = road_cells.contains(c);
348+ if let Some((1, l)) = band_of(*c) {
349+ if river(l) {
350+ if street(l) {
351+ sp.ground(&sprites::PLANKS, *c);
352+ } else {
353+ sp.water(*c);
354+ }
355+ continue;
356+ }
357+ }
358+ let tile: &Spr = match band_of(*c) {
359+ Some((0, l)) if street(l) => FLAG[k],
360+ Some((0, l)) if field(l) => FARMLAND[k % 2],
361+ Some((0, _)) if road => ROAD[k],
362+ Some((0, _)) => GRASS[k],
363+ Some((1, l)) if street(l) => COBBLE[k],
364+ Some((1, _)) => ROAD[k],
365+ Some((2, l)) if rail(l) => &sprites::RAIL_X,
366+ Some((2, _)) => SOOT[k],
367+ None if road => ROAD[k],
368+ None => biome(*c, k),
369+ Some(_) => GRASS[k],
370+ };
371+ sp.ground(tile, *c);
372+ }
373+
374+ ashford(&mut sp, &sheets);
375+ millbrook(&mut sp, &sheets);
376+ coalbridge(&mut sp, &sheets);
377+
378+ let mut taken: HashSet<IVec2> = sp.map.blocked.clone();
379+ for c in &near {
380+ if taken.contains(c) || road_cells.contains(c) || reserved(*c) {
381+ continue;
382+ }
383+ let b = band_of(*c);
384+ let road_d = road_dist(&legs, c.as_vec2());
385+ let mut edge = 99;
386+ for dx in -15..=15 {
387+ for dy in -15..=15 {
388+ if !near.contains(&(*c + IVec2::new(dx, dy))) {
389+ edge = edge.min(dx.abs().max(dy.abs()));
390+ }
391+ }
392+ }
393+ let chance = match b {
394+ Some((0, _)) => 0.012,
395+ Some((1, _)) => 0.002,
396+ Some(_) => 0.004,
397+ None => {
398+ if edge <= 3 {
399+ 0.55
400+ } else if road_d < 3.0 {
401+ 0.0
402+ } else {
403+ 0.02 + 0.06 * ((road_d - 3.0) / 8.0).min(1.0)
404+ }
405+ }
406+ };
407+ let k = (hash(c.x, c.y, 3) * 6.0) as usize;
408+ if hash(c.x, c.y, 7) < chance {
409+ sp.tree(tree_kind(leg1_t(c.as_vec2()), k), *c);
410+ taken.insert(*c);
411+ } else if road_d > 2.0 && hash(c.x, c.y, 21) < 0.012 {
412+ sp.prop(ROCKS[k % 2], *c, true);
413+ taken.insert(*c);
414+ } else if road_d > 1.5 && hash(c.x, c.y, 22) < 0.02 {
415+ sp.prop(BUSHES[k % 2], *c, false);
416+ taken.insert(*c);
417+ }
418+ }
419+
420+ for (i, (ev, t)) in [(Ev::BrokenCart, 0.32f32), (Ev::Highwayman, 0.62), (Ev::Peddler, 1.35), (Ev::Storm, 1.7), (Ev::Lost, 0.85)].iter().enumerate() {
421+ let l = &legs[(*t as usize).min(1)];
422+ let f = t.fract();
423+ let p = l[((l.len() - 1) as f32 * f) as usize];
424+ sp.commands.spawn((EventSpot { ev: *ev, pos: p }, Transform::default(), Name::new(format!("event{i}"))));
425+ if *ev == Ev::Lost {
426+ let pos = p + Vec2::new(1.2, 1.2);
427+ let e = sp.npc(&sheets, Npc::Peddler, "boy", pos, 1);
428+ sp.commands.entity(e).insert(Interact { talk: Talk::Ev(Ev::Lost), pos });
429+ }
430+ if *ev == Ev::BrokenCart {
431+ let c = cell(p) + IVec2::new(2, 2);
432+ sp.prop(&sprites::CRATES, c, true);
433+ sp.prop(&sprites::BARREL, c + IVec2::new(1, 0), true);
434+ sp.prop(&sprites::SACK, c + IVec2::new(0, 1), false);
435+ let pos = c.as_vec2() + Vec2::new(-0.5, 1.5);
436+ let e = sp.npc(&sheets, Npc::Peddler, "worker", pos, 1);
437+ sp.commands.entity(e).insert(Interact { talk: Talk::Ev(Ev::BrokenCart), pos });
438+ }
439+ }
440+
441+ sp.map.legs = legs;
442+}
443+
444+fn road_dist(legs: &[Vec<Vec2>], p: Vec2) -> f32 {
445+ let mut d = f32::MAX;
446+ for l in legs {
447+ for q in l.iter().step_by(4) {
448+ d = d.min((*q - p).length());
449+ }
450+ }
451+ d
452+}
453+
454+fn at(o: Vec2, x: i32, y: i32) -> IVec2 {
455+ cell(o) + IVec2::new(x, y)
456+}
457+
458+fn lamp(sp: &mut Spawner, c: IVec2) {
459+ let e = sp.prop(&sprites::LAMP, c, true);
460+ let g = c.as_vec2() + Vec2::splat(0.5);
461+ sp.commands.entity(e).insert(Lamp(g));
462+ let mut light = Sprite::from_image(sp.assets.load(sprites::LIGHT.path));
463+ light.color = Color::srgba(1.0, 0.75, 0.4, 0.0);
464+ sp.commands.spawn((light, anchor(&sprites::LIGHT), Transform::from_translation(to_screen(g).extend(7.0)).with_scale(Vec3::splat(PX * 2.2)), Glow));
465+}
466+
467+fn ashford(sp: &mut Spawner, sh: &CharSheets) {
468+ let o = ASHFORD;
469+ sp.building(&sprites::A_POST, at(o, -11, -2), Some(Talk::Npc(Npc::Hale)));
470+ sp.building(&sprites::A_SHOP, at(o, -6, -2), Some(Talk::Npc(Npc::Pike)));
471+ sp.building(&sprites::A_INN, at(o, 0, -2), Some(Talk::Npc(Npc::Bess)));
472+ sp.building(&sprites::A_SCHOOL, at(o, 6, -2), Some(Talk::Npc(Npc::Edwin)));
473+ sp.building(&sprites::A_HOME, at(o, -9, 4), Some(Talk::Obj(Obj::HomeBed)));
474+ sp.building(&sprites::A_COTTAGE1, at(o, -3, 4), None);
475+ sp.building(&sprites::A_COTTAGE2, at(o, 3, 4), None);
476+ sp.building(&sprites::A_BARN, at(o, 9, 4), None);
477+
478+ sp.npc(sh, Npc::Hale, "gent", o + Vec2::new(-7.5, 0.3), 3);
479+ sp.npc(sh, Npc::Pike, "grocer", o + Vec2::new(-3.5, 0.3), 3);
480+ sp.npc(sh, Npc::Bess, "barmaid", o + Vec2::new(3.5, 0.3), 3);
481+ sp.npc(sh, Npc::Edwin, "teacher", o + Vec2::new(9.5, 0.3), 3);
482+ sp.npc(sh, Npc::OldTom, "old", o + Vec2::new(-1.5, 7.5), 4);
483+ sp.npc(sh, Npc::Annie, "boy", o + Vec2::new(10.5, -4.5), 2);
484+
485+ sp.prop(&sprites::WELL, at(o, 12, -4), true);
486+ sp.prop(&sprites::BENCH, at(o, 13, -2), true);
487+ sp.tree(&sprites::OAK0, at(o, 15, -6));
488+ sp.tree(&sprites::OAK2, at(o, -15, -6));
489+ sp.tree(&sprites::OAK1, at(o, -16, 9));
490+
491+ for x in -13..=-6 {
492+ sp.prop(&sprites::FENCE_X, at(o, x, -5), true);
493+ }
494+ sp.prop(&sprites::FENCE_Y, at(o, -13, -4), true);
495+ sp.prop(&sprites::FENCE_Y, at(o, -13, -3), true);
496+ sp.prop(&sprites::FENCE_Y, at(o, -6, -4), true);
497+ sp.prop(&sprites::FENCE_Y, at(o, -6, -3), true);
498+ for (x, y) in [(-12, -4), (-10, -4), (-11, -3), (-7, -3)] {
499+ sp.prop(&sprites::FLOWERS0, at(o, x, y), false);
500+ }
501+ for (x, y) in [(-8, -4), (-9, -3)] {
502+ sp.prop(&sprites::FLOWERS1, at(o, x, y), false);
503+ }
504+ for x in -12..=-8 {
505+ sp.prop(&sprites::FENCE_X, at(o, x, 9), true);
506+ }
507+ for (x, y) in [(-11, 8), (-9, 8), (-7, 8)] {
508+ sp.prop(&sprites::FLOWERS0, at(o, x, y), false);
509+ }
510+
511+ sp.prop(&sprites::HAYSTACK, at(o, 16, 10), true);
512+ sp.prop(&sprites::SIGNPOST, at(o, 17, 3), true);
513+
514+ for (x, y) in [(-12, 2), (-2, 2), (5, 2), (11, -1)] {
515+ lamp(sp, at(o, x, y));
516+ }
517+}
518+
519+fn millbrook(sp: &mut Spawner, sh: &CharSheets) {
520+ let o = MILLBROOK;
521+ sp.building(&sprites::M_SHOP, at(o, -14, -2), Some(Talk::Npc(Npc::Quill)));
522+ sp.building(&sprites::M_INN, at(o, -8, -2), Some(Talk::Obj(Obj::MillInn)));
523+ sp.building(&sprites::M_MILL, at(o, 3, -3), Some(Talk::Obj(Obj::BaleDrop)));
524+ sp.building(&sprites::M_WAREHOUSE, at(o, 12, -2), None);
525+ sp.building(&sprites::M_TERRACE, at(o, -13, 6), None);
526+ sp.building(&sprites::M_TERRACE, at(o, 1, 6), None);
527+
528+ let bale = sp.prop(&sprites::BALE, at(o, -2, -2), true);
529+ sp.commands.entity(bale).insert(Interact { talk: Talk::Obj(Obj::BalePile), pos: o + Vec2::new(-0.5, -1.0) });
530+ sp.prop(&sprites::BALE, at(o, -1, -2), true);
531+ sp.prop(&sprites::BALE, at(o, -2, -3), true);
532+ sp.prop(&sprites::BARRELS, at(o, -5, -3), true);
533+ sp.prop(&sprites::CRATES, at(o, -13, -3), true);
534+
535+ sp.prop_fp(&sprites::STALL, at(o, -11, 3), IVec2::new(2, 1), true);
536+ sp.prop(&sprites::SACKS, at(o, -13, 3), true);
537+
538+ sp.npc(sh, Npc::Foreman, "worker", o + Vec2::new(5.5, 2.5), 3);
539+ sp.npc(sh, Npc::Quill, "gent", o + Vec2::new(-10.5, 0.3), 3);
540+ sp.npc(sh, Npc::Weaver, "woman", o + Vec2::new(-11.5, 4.5), 3);
541+ sp.npc(sh, Npc::Peddler, "peddler", o + Vec2::new(-7.5, 3.5), 2);
542+
543+ sp.tree(&sprites::BIRCH, at(o, 8, -7));
544+ sp.tree(&sprites::BIRCH, at(o, 13, -6));
545+
546+ sp.prop(&sprites::SIGNPOST, at(o, 17, 3), true);
547+
548+ for (x, y) in [(-5, 2), (2, 2), (7, 2), (13, 2)] {
549+ lamp(sp, at(o, x, y));
550+ }
551+}
552+
553+fn coalbridge(sp: &mut Spawner, sh: &CharSheets) {
554+ let o = COALBRIDGE;
555+ sp.building(&sprites::C_HEADFRAME, at(o, -14, -3), None);
556+ sp.building(&sprites::C_ENGINE, at(o, -9, -2), None);
557+ sp.building(&sprites::C_PAWN, at(o, -4, -2), Some(Talk::Npc(Npc::Pawn)));
558+ sp.building(&sprites::C_INN, at(o, 0, -2), Some(Talk::Obj(Obj::CoalInn)));
559+ sp.building(&sprites::C_ROW, at(o, 6, -2), None);
560+ sp.building(&sprites::C_ROW, at(o, -6, 4), None);
561+
562+ sp.npc(sh, Npc::Jack, "miner", o + Vec2::new(-10.5, 0.5), 3);
563+ sp.npc(sh, Npc::Miner, "miner", o + Vec2::new(-12.5, 2.5), 2);
564+ sp.npc(sh, Npc::Pawn, "grocer", o + Vec2::new(-1.5, 0.3), 3);
565+
566+ for (x, y) in [(-12, 8), (-7, 8), (2, 8), (9, 8)] {
567+ sp.prop(&sprites::TUB, at(o, x, y), true);
568+ }
569+ for (x, y) in [(-15, 7), (12, 6), (12, 8)] {
570+ sp.prop(&sprites::COALPILE, at(o, x, y), true);
571+ }
572+ sp.prop_fp(&sprites::SLAG, at(o, 18, -7), IVec2::new(2, 2), true);
573+ sp.prop_fp(&sprites::SLAG, at(o, -18, -11), IVec2::new(2, 2), true);
574+ sp.tree(&sprites::DEAD, at(o, 14, -6));
575+ sp.tree(&sprites::DEAD, at(o, -16, -7));
576+ sp.prop(&sprites::FLAME1, at(o, -6, -3), false);
577+ sp.prop(&sprites::SIGNPOST, at(o, -17, 3), true);
578+
579+ for (x, y) in [(-4, 2), (4, 2), (10, 2)] {
580+ lamp(sp, at(o, x, y));
581+ }
582+}
583+
584+fn smoke(mut commands: Commands, time: Res<Time>, assets: Res<AssetServer>, mut chims: Query<&mut Chimney>, mut puffs: Query<(Entity, &mut Puff, &mut Transform, &mut Sprite)>) {
585+ let dt = time.delta_secs();
586+ for mut c in &mut chims {
587+ c.t += dt;
588+ if c.t >= c.rate {
589+ c.t = 0.0;
590+ let k = hash((c.at.x * 7.0) as i32, (time.elapsed_secs() * 100.0) as i32, 5);
591+ commands.spawn((
592+ Sprite { image: assets.load("gfx/puff.png"), color: Color::srgba(0.55, 0.53, 0.5, 0.0), custom_size: Some(Vec2::splat(22.0)), ..default() },
593+ Transform::from_translation(c.at + Vec3::new(0.0, 4.0, k * 0.01)),
594+ Puff { age: 0.0, drift: 10.0 + k * 14.0 },
595+ ));
596+ }
597+ }
598+ for (e, mut p, mut t, mut s) in &mut puffs {
599+ p.age += dt;
600+ let life = 6.0;
601+ if p.age > life {
602+ commands.entity(e).despawn();
603+ continue;
604+ }
605+ let f = p.age / life;
606+ t.translation.y += dt * 26.0;
607+ t.translation.x += dt * p.drift;
608+ t.scale = Vec3::splat(1.0 + f * 3.5);
609+ s.color.set_alpha(0.55 * (1.0 - f) * (f * 8.0).min(1.0));
610+ }
611+}
612+
613+fn water(time: Res<Time>, assets: Res<AssetServer>, mut tiles: Query<&mut Sprite, With<Water>>) {
614+ let frame = (time.elapsed_secs() / 0.7) as u32 % 2;
615+ let img = assets.load(if frame == 0 { sprites::WATER0.path } else { sprites::WATER1.path });
616+ for mut s in &mut tiles {
617+ if s.image != img {
618+ s.image = img.clone();
619+ }
620+ }
621+}
tools/art_buildings.pyadded+577 -0
@@ -0,0 +1,577 @@
1+import math
2+import os
3+import sys
4+
5+sys.path.insert(0, os.path.dirname(__file__))
6+
7+import numpy as np
8+from PIL import Image
9+
10+from vox import P, mat, Model, render, project, smoke_offset, save, atlas, hash3, planks, bricks, rows
11+
12+O = 24
13+SCRATCH = '/tmp/claude-1000/-home-tahinli-Documents-Code-Rust/edd994b8-9b3e-47f3-95c7-9404536bd326/scratchpad/bld'
14+ROSE = [(96, 30, 46), (150, 48, 66), (196, 80, 96), (232, 130, 140)]
15+GREEN = [(28, 66, 44), (42, 98, 62), (66, 136, 84), (110, 176, 120)]
16+RED = [(80, 24, 26), (116, 36, 38), (150, 56, 54), (184, 84, 76)]
17+BOOKS = [(40, 52, 44), (72, 44, 52), (104, 64, 40), (146, 112, 64)]
18+DIM = [(64, 50, 36), (92, 72, 44), (120, 96, 54)]
19+GREENDOOR = [(30, 60, 44), (44, 92, 62), (66, 124, 84), (96, 150, 110)]
20+WHITEWASH = [(190, 160, 150), (214, 190, 176), (234, 214, 200), (246, 234, 220)]
21+YELLOWASH = [(196, 170, 110), (218, 196, 138), (236, 218, 166), (248, 236, 196)]
22+DARKTHATCH = [(92, 62, 36), (126, 90, 50), (160, 120, 68), (190, 150, 92)]
23+BRICK = mat(P['brick'], bricks(4, 12))
24+BRICK_DARK = mat(P['brick_dark'], bricks(4, 12))
25+SLATE = mat(P['slate'], rows(3))
26+COAL = mat(P['coal'], rows(3))
27+STONE_DARK = mat(P['stone_dark'], bricks(4, 8))
28+PLASTER = mat(P['plaster'], None)
29+THATCH = mat(P['thatch'], rows(3))
30+
31+
32+def speck(p, seed):
33+ def f(cx, cy, cz, face):
34+ return np.where(hash3(cx, cy, cz, seed) < p, 1, 0)
35+ return f
36+
37+
38+BASE = {}
39+
40+
41+def kit(wall, roof, **kw):
42+ if not BASE:
43+ BASE.update(
44+ frame=mat(P['plaster']),
45+ trim=mat(P['plaster']),
46+ cream=mat(P['plaster']),
47+ timber=mat(P['wood_dark']),
48+ wood=mat(P['wood'], planks(6, 2)),
49+ door=mat(P['wood'], planks(5, 2)),
50+ stone=mat(P['stone'], bricks(5, 10)),
51+ chim=mat(P['brick'], bricks(4, 8)),
52+ cap=mat(P['stone'], None),
53+ glass=mat(P['window'], None, True),
54+ dim=mat(DIM),
55+ rose=mat(ROSE, speck(0.3, 7)),
56+ iron=mat(P['metal']),
57+ brass=mat(P['brass']),
58+ green=mat(GREEN),
59+ red=mat(RED),
60+ books=mat(BOOKS, planks(3, 2)),
61+ hay=mat(P['thatch'], speck(0.15, 4)),
62+ )
63+ d = dict(BASE, wall=wall, roof=roof)
64+ d.update(kw)
65+ return d
66+
67+
68+class Scene:
69+ def __init__(self, name, fx, fy, h):
70+ self.name, self.fx, self.fy = name, fx, fy
71+ self.W, self.D = 32 * fx, 32 * fy
72+ self.m = Model(self.W + 2 * O, self.D + 2 * O, h + O)
73+ self.chim = []
74+
75+ def box(self, x0, y0, z0, x1, y1, z1, m):
76+ self.m.box(x0 + O, y0 + O, z0, x1 + O, y1 + O, z1, m)
77+
78+ def clear_box(self, x0, y0, z0, x1, y1, z1):
79+ self.m.v[x0 + O:x1 + O, y0 + O:y1 + O, z0:z1] = 0
80+
81+ def gable(self, x0, y0, x1, y1, z0, z1, axis, m):
82+ self.m.gable(x0 + O, y0 + O, x1 + O, y1 + O, z0, z1, axis, m)
83+
84+ def cyl(self, a, b, r, m):
85+ self.m.cylinder((a[0] + O, a[1] + O, a[2]), (b[0] + O, b[1] + O, b[2]), r, m)
86+
87+ def cap(self, a, b, r, m):
88+ self.m.capsule((a[0] + O, a[1] + O, a[2]), (b[0] + O, b[1] + O, b[2]), r, m)
89+
90+ def ell(self, c, r, m):
91+ self.m.ellipsoid(c[0] + O, c[1] + O, c[2], r[0], r[1], r[2], m)
92+
93+ def paint(self, fn, m):
94+ self.m.paint(lambda X, Y, Z: fn(X - O, Y - O, Z), m)
95+
96+ def clear(self, fn):
97+ ix, iy, iz = np.nonzero(self.m.v)
98+ sel = np.broadcast_to(fn(ix + 0.5 - O, iy + 0.5 - O, iz + 0.5), ix.shape)
99+ self.m.v[ix[sel], iy[sel], iz[sel]] = 0
100+
101+ def wheel(self, c, R, t, axis, m, spokes=6):
102+ ax = 'xyz'.index(axis)
103+ pa, pb = [i for i in range(3) if i != ax]
104+ lo = list(c)
105+ hi = list(c)
106+ lo[ax] -= t / 2
107+ hi[ax] += t / 2
108+ self.cyl(lo, hi, R, m)
109+
110+ def carve(X, Y, Z):
111+ Q = (X, Y, Z)
112+ r = np.hypot(Q[pa] - c[pa], Q[pb] - c[pb])
113+ th = np.arctan2(Q[pb] - c[pb], Q[pa] - c[pa])
114+ spoke = np.abs(np.sin(spokes * th)) < 0.25
115+ slab = (Q[ax] >= lo[ax]) & (Q[ax] <= hi[ax])
116+ return slab & (r > 5) & (r < R - 5) & ~spoke
117+ self.clear(carve)
118+
119+ def fb(self, f, u0, u1, z0, z1, m, out=0, dep=1):
120+ if f == 'y':
121+ self.box(u0, self.D - dep, z0, u1, self.D + out, z1, m)
122+ else:
123+ self.box(self.W - dep, u0, z0, self.W + out, u1, z1, m)
124+
125+ def win(self, f, u, z, w, h, mm, nx=2, ny=2, glass=None, sill=True):
126+ g = glass if glass is not None else mm['glass']
127+ self.fb(f, u, u + w, z, z + h, mm['frame'])
128+ self.fb(f, u + 1, u + w - 1, z + 1, z + h - 1, g)
129+ for i in range(1, nx):
130+ x = u + round(i * w / nx)
131+ self.fb(f, x, x + 1, z + 1, z + h - 1, mm['frame'])
132+ for j in range(1, ny):
133+ y = z + round(j * h / ny)
134+ self.fb(f, u + 1, u + w - 1, y, y + 1, mm['frame'])
135+ if sill:
136+ self.fb(f, u - 1, u + w + 1, z - 2, z, mm['trim'], out=2)
137+
138+ def flowers(self, f, u, z, w, mm):
139+ self.fb(f, u - 1, u + w + 1, z - 6, z - 2, mm['wood'], out=3)
140+ for k in range(u, u + w, 4):
141+ c = (k + 2, self.D + 2, z - 3) if f == 'y' else (self.W + 2, k + 2, z - 3)
142+ self.ell(c, (2.5, 2.5, 2.5), mm['rose'])
143+
144+ def door(self, mm, cx=48):
145+ D = self.D
146+ self.fb('y', cx - 13, cx + 13, 0, 56, mm['trim'], dep=2)
147+ self.fb('y', cx - 10, cx + 10, 0, 52, mm['door'], dep=2)
148+ self.box(cx - 14, D, 0, cx + 14, D + 3, 3, mm['stone'])
149+
150+ def chimney(self, x, y, top, mm, w=4):
151+ self.box(x - w, y - w, 0, x + w, y + w, top, mm['chim'])
152+ self.box(x - w - 1, y - w - 1, top - 4, x + w + 1, y + w + 1, top, mm['cap'])
153+ self.chim.append((x, y, top + 1))
154+
155+ def roof(self, z0, rise, ov, axis, m, ridge=None):
156+ W, D = self.W, self.D
157+ z1 = z0 + rise
158+ self.gable(-ov, -ov, W + ov, D + ov, z0, z1, axis, m)
159+ if ridge is not None:
160+ if axis == 'x':
161+ self.cyl((-ov, D / 2, z1 - 2), (W + ov, D / 2, z1 - 2), 4, ridge)
162+ else:
163+ self.cyl((W / 2, -ov, z1 - 2), (W / 2, D + ov, z1 - 2), 4, ridge)
164+
165+ def done(self):
166+ img, em, ro = render(self.m)
167+ fo = tuple(int(round(v)) for v in project(O, O, 0, ro))
168+ smoke = [smoke_offset(*project(x, y, z, fo), fo) for x, y, z in self.chim]
169+ save(self.name, img, fo, foot=(self.fx, self.fy), smoke=smoke, emissive=em, group='buildings')
170+ return img, fo
171+
172+
173+def half_timber(s, mm, f, top, rails, posts):
174+ n = s.D if f == 'x' else s.W
175+ for u in posts:
176+ s.fb(f, u, u + 4, 0, top, mm['timber'])
177+ for z in rails:
178+ s.fb(f, 0, n, z, z + 3, mm['timber'])
179+
180+
181+def a_home():
182+ s = Scene('a_home', 3, 2, 170)
183+ mm = kit(mat(P['plaster'], speck(0.03, 3)), mat(P['thatch'], rows(3)), chim=mat(P['stone'], bricks(5, 10)))
184+ W, D = s.W, s.D
185+ s.box(0, 0, 0, W, D, 72, mm['wall'])
186+ half_timber(s, mm, 'y', 72, [36, 66], [0, W - 4])
187+ half_timber(s, mm, 'x', 72, [36, 66], [0, D - 4])
188+ s.box(0, 0, 0, W, D, 6, mm['stone'])
189+ for u in (12, 68):
190+ s.win('y', u, 34, 16, 18, mm, nx=2, ny=3)
191+ s.flowers('y', u, 34, 16, mm)
192+ s.win('x', 12, 34, 14, 18, mm, nx=2, ny=2)
193+ s.door(mm)
194+ s.box(20, D, 14, 36, D + 5, 17, mm['wood'])
195+ s.box(20, D, 0, 23, D + 5, 14, mm['timber'])
196+ s.box(33, D, 0, 36, D + 5, 14, mm['timber'])
197+ s.roof(72, 44, 6, 'x', mm['roof'], ridge=mm['roof'])
198+ s.chimney(W - 18, D // 2, 72 + 44 + 22, mm)
199+ return s.done()
200+
201+
202+def a_post():
203+ s = Scene('a_post', 3, 2, 170)
204+ mm = kit(mat(P['plaster'], speck(0.03, 5)), mat(P['slate'], rows(3)), door=mat(RED, planks(5, 2)))
205+ W, D = s.W, s.D
206+ s.box(0, 0, 0, W, D, 76, mm['wall'])
207+ s.box(0, 0, 0, W, D, 6, mm['stone'])
208+ s.win('y', 12, 40, 16, 20, mm, nx=2, ny=2)
209+ s.win('y', 68, 40, 16, 20, mm, nx=2, ny=2)
210+ s.win('x', 12, 40, 14, 20, mm, nx=2, ny=2)
211+ s.door(mm)
212+ s.fb('y', 34, 62, 60, 68, mm['timber'], out=2)
213+ s.fb('y', 38, 58, 62, 64, mm['cream'], out=2)
214+ s.fb('y', 24, 31, 24, 32, mm['red'], out=2)
215+ s.roof(76, 40, 6, 'x', mm['roof'])
216+ s.chimney(W - 16, D // 2, 76 + 40 + 20, mm)
217+ return s.done()
218+
219+
220+def a_shop():
221+ s = Scene('a_shop', 4, 2, 170)
222+ mm = kit(mat(P['plaster'], speck(0.03, 3)), mat(P['slate'], rows(3)), chim=mat(P['stone'], bricks(5, 10)))
223+ W, D = s.W, s.D
224+ s.box(0, 0, 0, W, D, 72, mm['wall'])
225+ half_timber(s, mm, 'y', 72, [66], [0, W - 4])
226+ half_timber(s, mm, 'x', 72, [66], [0, D - 4])
227+ s.box(0, 0, 0, W, D, 6, mm['stone'])
228+ s.box(64, D, 18, 122, D + 5, 48, mm['wall'])
229+ s.box(64, D, 18, 122, D + 5, 20, mm['timber'])
230+ s.box(64, D, 46, 122, D + 5, 48, mm['timber'])
231+ s.box(66, D + 4, 22, 120, D + 5, 44, mm['books'])
232+ for u in range(78, 120, 12):
233+ s.box(u, D + 4, 22, u + 2, D + 5, 44, mm['timber'])
234+ for k in range(10):
235+ m = mm['green'] if k % 2 == 0 else mm['cream']
236+ u0 = 62 + 6 * k
237+ for j in range(6):
238+ s.box(u0, D + j, 50 - j, u0 + 6, D + j + 1, 52 - j, m)
239+ s.fb('y', 60, 124, 56, 62, mm['timber'], out=2)
240+ s.fb('y', 66, 118, 58, 60, mm['cream'], out=2)
241+ s.win('y', 8, 14, 20, 36, mm, nx=2, ny=2, glass=mm['books'])
242+ s.door(mm)
243+ s.box(20, D, 0, 32, D + 9, 9, mm['wood'])
244+ s.box(22, D + 9, 0, 32, D + 17, 8, mm['timber'])
245+ s.win('x', 12, 36, 14, 18, mm, nx=2, ny=2)
246+ s.roof(72, 36, 6, 'x', mm['roof'])
247+ s.chimney(W - 14, D // 2, 72 + 36 + 20, mm)
248+ return s.done()
249+
250+
251+def a_inn():
252+ s = Scene('a_inn', 4, 2, 230)
253+ mm = kit(mat(P['plaster'], speck(0.03, 3)), THATCH, chim=mat(P['stone'], bricks(5, 10)))
254+ W, D = s.W, s.D
255+ s.box(0, 0, 0, W, D, 124, mm['wall'])
256+ half_timber(s, mm, 'y', 124, [60, 118], [0, 30, 64, 96, W - 4])
257+ half_timber(s, mm, 'x', 124, [60, 118], [0, D - 4])
258+ s.box(0, 0, 0, W, D, 6, mm['stone'])
259+ for u in (10, 68, 100):
260+ s.win('y', u, 26, 18, 24, mm, nx=2, ny=2)
261+ s.flowers('y', u, 26, 18, mm)
262+ for u in (10, 52, 100):
263+ s.win('y', u, 78, 18, 24, mm, nx=2, ny=2)
264+ s.door(mm)
265+ s.box(46, D, 60, 50, D + 8, 62, mm['iron'])
266+ s.box(43, D, 62, 53, D + 6, 68, mm['glass'])
267+ s.box(82, D, 100, 84, D + 14, 102, mm['iron'])
268+ s.box(72, D + 12, 84, 94, D + 14, 98, mm['timber'])
269+ s.box(75, D + 12, 87, 91, D + 14, 95, mm['cream'])
270+ s.box(78, D + 13, 98, 79, D + 14, 100, mm['iron'])
271+ s.box(88, D + 13, 98, 89, D + 14, 100, mm['iron'])
272+ s.roof(124, 50, 6, 'x', mm['roof'], ridge=mm['roof'])
273+ s.chimney(24, D // 2, 124 + 50 + 22, mm)
274+ s.chimney(W - 24, D // 2, 124 + 50 + 22, mm)
275+ return s.done()
276+
277+
278+def a_school():
279+ s = Scene('a_school', 3, 2, 170)
280+ mm = kit(mat(P['stone'], bricks(5, 10)), mat(P['slate'], rows(3)))
281+ W, D = s.W, s.D
282+ s.box(0, 0, 0, W, D, 72, mm['wall'])
283+ s.box(0, 0, 0, W, D, 6, mm['cap'])
284+ for u in (12, 68):
285+ s.win('y', u, 30, 16, 26, mm, nx=2, ny=3)
286+ s.win('x', 12, 30, 16, 26, mm, nx=2, ny=3)
287+ s.win('x', 36, 30, 16, 26, mm, nx=2, ny=3)
288+ s.door(mm)
289+ s.roof(72, 42, 6, 'x', mm['roof'])
290+ cx, cy = W // 2, D // 2
291+ s.box(cx - 7, cy - 7, 100, cx + 7, cy + 7, 126, mm['wall'])
292+ s.gable(cx - 9, cy - 9, cx + 9, cy + 9, 126, 140, 'x', mm['roof'])
293+ s.clear_box(cx - 5, cy - 8, 114, cx + 5, cy + 8, 124)
294+ s.ell((cx, cy, 117), (3, 3, 3), mm['brass'])
295+ return s.done()
296+
297+
298+def a_cottage1():
299+ s = Scene('a_cottage1', 3, 2, 170)
300+ mm = kit(mat(WHITEWASH, speck(0.03, 3)), THATCH, door=mat(GREENDOOR, planks(5, 2)), chim=mat(P['stone'], bricks(5, 10)))
301+ W, D = s.W, s.D
302+ s.box(0, 0, 0, W, D, 70, mm['wall'])
303+ half_timber(s, mm, 'y', 70, [38], [0, W - 4])
304+ half_timber(s, mm, 'x', 70, [38], [0, D - 4])
305+ s.box(0, 0, 0, W, D, 6, mm['stone'])
306+ for u in (12, 68):
307+ s.win('y', u, 30, 16, 20, mm, nx=2, ny=2)
308+ s.flowers('y', u, 30, 16, mm)
309+ s.door(mm)
310+ s.roof(70, 52, 6, 'y', mm['roof'], ridge=mm['roof'])
311+ s.chimney(W // 2, 14, 70 + 52 + 20, mm)
312+ return s.done()
313+
314+
315+def a_cottage2():
316+ s = Scene('a_cottage2', 3, 2, 170)
317+ mm = kit(mat(YELLOWASH, speck(0.03, 8)), mat(DARKTHATCH, rows(3)), chim=mat(P['brick'], bricks(4, 8)))
318+ W, D = s.W, s.D
319+ s.box(0, 0, 0, W, D, 70, mm['wall'])
320+ half_timber(s, mm, 'y', 70, [38], [0, W - 4])
321+ s.box(0, 0, 0, W, D, 6, mm['stone'])
322+ for u in (12, 68):
323+ s.win('y', u, 34, 16, 18, mm, nx=1, ny=2)
324+ s.box(30, D, 0, 33, D + 10, 58, mm['timber'])
325+ s.box(62, D, 0, 65, D + 10, 58, mm['timber'])
326+ s.box(28, D, 56, 67, D + 12, 61, mm['roof'])
327+ s.door(mm)
328+ s.roof(70, 42, 6, 'x', mm['roof'], ridge=mm['roof'])
329+ s.chimney(16, D // 2, 70 + 42 + 20, mm)
330+ return s.done()
331+
332+
333+def a_barn():
334+ s = Scene('a_barn', 2, 2, 150)
335+ mm = kit(mat(P['wood'], planks(6, 2)), THATCH, door=mat(P['wood_dark'], planks(5, 2)))
336+ W, D = s.W, s.D
337+ s.box(0, 0, 0, W, D, 96, mm['wall'])
338+ s.box(0, 0, 0, W, D, 6, mm['stone'])
339+ s.fb('y', 36, 60, 0, 56, mm['timber'], dep=2)
340+ s.fb('y', 40, 56, 70, 88, mm['timber'], dep=2)
341+ s.clear_box(38, D - 14, 0, 58, D, 52)
342+ s.clear_box(42, D - 10, 72, 54, D, 86)
343+ s.box(40, D - 12, 0, 56, D - 2, 18, mm['hay'])
344+ s.box(44, D - 8, 72, 52, D - 2, 84, mm['hay'])
345+ s.box(46, D, 88, 50, D + 8, 91, mm['timber'])
346+ s.roof(96, 50, 6, 'x', mm['roof'], ridge=mm['roof'])
347+ return s.done()
348+
349+
350+
351+def m_mill():
352+ s = Scene('m_mill', 6, 3, 330)
353+ mm = kit(BRICK, SLATE, chim=BRICK_DARK, dark=mat(P['brick_dark'], bricks(4, 12)), frame=mat(P['stone']), trim=mat(P['stone']), door=mat(P['wood_dark'], planks(5, 2)))
354+ W, D = s.W, s.D
355+ s.box(0, 0, 0, W, D, 216, mm['wall'])
356+ s.box(0, 0, 0, W, D, 8, mm['stone'])
357+ for z in (72, 144):
358+ s.fb('y', 0, W, z, z + 3, mm['stone'], out=1)
359+ s.fb('x', 0, D, z, z + 3, mm['stone'], out=1)
360+ for st in range(3):
361+ z0 = 72 * st + 14
362+ skip = (28, 48) if st < 2 else ()
363+ for u in range(8, W - 8, 20):
364+ if u not in skip:
365+ s.win('y', u, z0, 10, 36, mm, nx=2, ny=3)
366+ for v in range(8, D - 8, 20):
367+ s.win('x', v, z0, 10, 36, mm, nx=2, ny=3)
368+ s.door(mm)
369+ s.fb('y', 36, 60, 82, 124, mm['frame'], dep=2)
370+ s.fb('y', 38, 58, 86, 122, mm['timber'], dep=2)
371+ s.box(46, D, 128, 50, D + 16, 131, mm['iron'])
372+ s.box(3, -15, 0, 13, -5, 250, mm['chim'])
373+ s.box(3, -15, 240, 13, -5, 250, mm['dark'])
374+ s.box(4, -14, 250, 12, -6, 262, mm['chim'])
375+ s.box(2, -16, 262, 14, -4, 265, mm['cap'])
376+ s.chim.append((8, -10, 266))
377+ s.roof(216, 30, 6, 'x', mm['roof'])
378+ s.wheel((W + 6, 24, 40), 34, 10, 'x', mm['wood'])
379+ s.cap((W - 4, 24, 40), (W + 12, 24, 40), 3, mm['iron'])
380+ return s.done()
381+
382+
383+def terrace(name, fx, wall_h, rise, mm, win_w, win_h, doors):
384+ s = Scene(name, fx, 2, wall_h + rise + 60)
385+ W, D = s.W, s.D
386+ s.box(0, 0, 0, W, D, wall_h, mm['wall'])
387+ s.box(0, 0, 0, W, D, 6, mm['stone'])
388+ s.fb('y', 0, W, 40, 43, mm['stone'], out=1)
389+ s.fb('x', 0, D, 40, 43, mm['stone'], out=1)
390+ for i in range(fx):
391+ c = 32 * i + 16
392+ if i in doors:
393+ s.door(mm, cx=c)
394+ else:
395+ s.win('y', c - win_w // 2, 20, win_w, win_h, mm, nx=2, ny=2)
396+ s.win('y', c - win_w // 2, wall_h - 40, win_w, win_h, mm, nx=2, ny=2)
397+ s.chimney(c, D // 2, wall_h + rise + 16, mm)
398+ s.roof(wall_h, rise, 6, 'x', mm['roof'])
399+ return s.done()
400+
401+
402+def m_terrace():
403+ return terrace('m_terrace', 4, 118, 40, kit(BRICK, SLATE, chim=BRICK_DARK), 16, 24, (1, 3))
404+
405+
406+def m_shop():
407+ s = Scene('m_shop', 3, 2, 230)
408+ mm = kit(BRICK, SLATE, chim=BRICK_DARK, door=mat(P['wood_dark'], planks(5, 2)))
409+ W, D = s.W, s.D
410+ s.box(0, 0, 0, W, D, 150, mm['wall'])
411+ s.box(0, 0, 0, W, D, 6, mm['stone'])
412+ s.fb('y', 0, W, 74, 77, mm['stone'], out=1)
413+ s.fb('x', 0, D, 74, 77, mm['stone'], out=1)
414+ s.fb('y', 4, W - 4, 56, 72, mm['green'], out=3)
415+ s.fb('y', 12, W - 12, 62, 65, mm['cream'], out=3)
416+ s.win('y', 8, 12, 20, 36, mm, nx=2, ny=2, glass=mm['books'])
417+ s.win('y', 62, 12, 28, 36, mm, nx=3, ny=2, glass=mm['books'])
418+ s.door(mm)
419+ s.win('y', 10, 96, 18, 26, mm, nx=2, ny=2)
420+ s.win('y', 66, 96, 18, 26, mm, nx=2, ny=2)
421+ s.win('x', 12, 96, 16, 26, mm)
422+ s.roof(150, 30, 6, 'x', mm['roof'])
423+ s.chimney(W - 14, D // 2, 150 + 30 + 20, mm)
424+ return s.done()
425+
426+
427+def m_inn():
428+ s = Scene('m_inn', 4, 2, 260)
429+ mm = kit(BRICK, SLATE, chim=BRICK_DARK)
430+ W, D = s.W, s.D
431+ s.box(0, 0, 0, W, D, 116, mm['wall'])
432+ s.box(0, 0, 0, W, D, 6, mm['stone'])
433+ s.fb('y', 0, W, 58, 61, mm['stone'], out=1)
434+ for u in (10, 68, 100):
435+ s.win('y', u, 24, 16, 24, mm, nx=2, ny=2)
436+ for u in (10, 52, 100):
437+ s.win('y', u, 72, 16, 24, mm, nx=2, ny=2)
438+ s.door(mm)
439+ s.box(46, D, 60, 50, D + 8, 62, mm['iron'])
440+ s.box(43, D, 62, 53, D + 6, 68, mm['glass'])
441+ s.roof(116, 44, 6, 'x', mm['roof'])
442+ s.chimney(20, D // 2, 116 + 44 + 20, mm)
443+ s.chimney(W - 20, D // 2, 116 + 44 + 20, mm)
444+ return s.done()
445+
446+
447+def m_warehouse():
448+ s = Scene('m_warehouse', 3, 2, 240)
449+ mm = kit(BRICK, SLATE, chim=BRICK_DARK, door=mat(P['wood_dark'], planks(5, 2)), frame=mat(P['stone']))
450+ W, D = s.W, s.D
451+ s.box(0, 0, 0, W, D, 190, mm['wall'])
452+ s.box(0, 0, 0, W, D, 6, mm['stone'])
453+ s.door(mm)
454+ for z0, z1 in ((84, 118), (140, 174)):
455+ s.fb('y', 36, 60, z0 - 2, z1 + 2, mm['frame'], dep=2)
456+ s.fb('y', 38, 58, z0, z1, mm['door'], dep=2)
457+ s.box(46, D, z1 + 3, 50, D + 12, z1 + 6, mm['iron'])
458+ for z in (112, 150):
459+ s.win('y', 8, z, 12, 16, mm, nx=1, ny=2)
460+ s.win('y', 74, z, 12, 16, mm, nx=1, ny=2)
461+ s.roof(190, 28, 6, 'x', mm['roof'])
462+ return s.done()
463+
464+
465+def c_headframe():
466+ s = Scene('c_headframe', 3, 3, 262)
467+ mm = kit(STONE_DARK, COAL, chim=mat(P['stone_dark'], bricks(4, 8)), frame=mat(P['metal']), trim=mat(P['stone_dark']))
468+ s.box(30, 30, 0, 66, 66, 36, mm['wall'])
469+ s.gable(30, 30, 66, 66, 36, 50, 'x', mm['roof'])
470+ bases = [(14, 14), (82, 14), (14, 82), (82, 82)]
471+ tops = [(44, 44), (52, 44), (44, 52), (52, 52)]
472+
473+ def lp(i, z):
474+ bx, by = bases[i]
475+ tx, ty = tops[i]
476+ t = z / 190
477+ return (bx + (tx - bx) * t, by + (ty - by) * t, z)
478+ for i in range(4):
479+ s.cap((bases[i][0], bases[i][1], 0), (tops[i][0], tops[i][1], 190), 2.5, mm['timber'])
480+ for z in (30, 60, 90, 120, 150, 180):
481+ for a, b in ((0, 1), (2, 3), (0, 2), (1, 3)):
482+ s.cap(lp(a, z), lp(b, z), 1.4, mm['timber'])
483+ s.cap(lp(1, 40), (48, 48, 188), 1.6, mm['timber'])
484+ s.box(40, 40, 188, 56, 56, 192, mm['timber'])
485+ s.wheel((48, 48, 218), 22, 8, 'x', mm['iron'])
486+ s.box(46, 44, 192, 50, 52, 212, mm['iron'])
487+ return s.done()
488+
489+
490+def c_engine():
491+ s = Scene('c_engine', 3, 2, 260)
492+ mm = kit(STONE_DARK, COAL, chim=mat(P['brick_dark'], bricks(4, 12)), stone=mat(P['stone_dark'], bricks(5, 8)), frame=mat(P['stone_dark']), trim=mat(P['stone_dark']), dim=mat(DIM), door=mat(P['wood_dark'], planks(5, 2)))
493+ W, D = s.W, s.D
494+ s.box(0, 0, 0, W, D, 150, mm['wall'])
495+ s.box(0, 0, 0, W, D, 6, mm['stone'])
496+ s.fb('y', 30, 66, 58, 130, mm['stone'], out=1)
497+ s.paint(lambda X, Y, Z: (Y >= D - 1) & (((X >= 38) & (X <= 58) & (Z >= 64) & (Z <= 112)) | ((X - 48) ** 2 + (Z - 112) ** 2 <= 100)), mm['dim'])
498+ s.paint(lambda X, Y, Z: (Y >= D - 1) & (X >= 47) & (X <= 49) & (Z >= 64) & (Z <= 112), mm['stone'])
499+ s.door(mm)
500+ s.win('y', 6, 20, 16, 24, mm, nx=1, ny=2, glass=mm['dim'])
501+ s.win('y', 74, 20, 16, 24, mm, nx=1, ny=2, glass=mm['dim'])
502+ s.win('x', 16, 40, 10, 14, mm, nx=1, ny=2, glass=mm['dim'])
503+ s.cyl((W - 14, -14, 0), (W - 14, -14, 240), 9, mm['chim'])
504+ s.cyl((W - 14, -14, 236), (W - 14, -14, 244), 11, mm['cap'])
505+ s.chim.append((W - 14, -14, 246))
506+ s.roof(150, 30, 6, 'x', mm['roof'])
507+ return s.done()
508+
509+
510+def c_row():
511+ mm = kit(STONE_DARK, COAL, chim=mat(P['stone_dark'], bricks(4, 8)), stone=mat(P['stone_dark'], bricks(5, 8)), frame=mat(P['stone_dark']), trim=mat(P['stone_dark']), glass=mat(DIM), door=mat(P['wood_dark'], planks(5, 2)))
512+ return terrace('c_row', 4, 100, 34, mm, 6, 8, (1, 3))
513+
514+
515+def c_pawn():
516+ s = Scene('c_pawn', 3, 2, 170)
517+ mm = kit(STONE_DARK, COAL, chim=mat(P['stone_dark'], bricks(4, 8)), stone=mat(P['stone_dark'], bricks(5, 8)), frame=mat(P['metal']), trim=mat(P['stone_dark']), glass=mat(DIM), door=mat(P['wood_dark'], planks(5, 2)))
518+ W, D = s.W, s.D
519+ s.box(0, 0, 0, W, D, 80, mm['wall'])
520+ s.box(0, 0, 0, W, D, 6, mm['stone'])
521+ s.fb('y', 0, W, 60, 62, mm['trim'], out=1)
522+ s.win('y', 62, 14, 26, 30, mm, nx=3, ny=2)
523+ s.win('y', 8, 26, 16, 22, mm, nx=2, ny=2)
524+ s.door(mm)
525+ s.box(56, D, 88, 60, D + 14, 90, mm['iron'])
526+ s.ell((54, D + 12, 84), (4, 4, 4), mm['brass'])
527+ s.ell((62, D + 12, 84), (4, 4, 4), mm['brass'])
528+ s.ell((58, D + 12, 76), (4, 4, 4), mm['brass'])
529+ s.roof(80, 34, 6, 'x', mm['roof'])
530+ s.chimney(W - 16, D // 2, 80 + 34 + 20, mm)
531+ return s.done()
532+
533+
534+def c_inn():
535+ s = Scene('c_inn', 4, 2, 230)
536+ mm = kit(STONE_DARK, COAL, chim=mat(P['stone_dark'], bricks(4, 8)), stone=mat(P['stone_dark'], bricks(5, 8)), frame=mat(P['metal']), trim=mat(P['stone_dark']), dim=mat(DIM), door=mat(P['wood_dark'], planks(5, 2)))
537+ W, D = s.W, s.D
538+ s.box(0, 0, 0, W, D, 112, mm['wall'])
539+ s.box(0, 0, 0, W, D, 6, mm['stone'])
540+ s.fb('y', 0, W, 60, 62, mm['trim'], out=1)
541+ s.win('y', 10, 22, 14, 18, mm, nx=2, ny=2)
542+ s.win('y', 68, 22, 14, 18, mm, nx=2, ny=2, glass=mm['dim'])
543+ s.win('y', 100, 22, 14, 18, mm, nx=2, ny=2)
544+ s.win('y', 10, 70, 14, 18, mm, nx=2, ny=2, glass=mm['dim'])
545+ s.win('y', 52, 70, 14, 18, mm, nx=2, ny=2)
546+ s.win('y', 100, 70, 14, 18, mm, nx=2, ny=2, glass=mm['dim'])
547+ s.door(mm)
548+ s.box(46, D, 60, 50, D + 8, 62, mm['iron'])
549+ s.box(43, D, 62, 53, D + 6, 68, mm['glass'])
550+ s.roof(112, 40, 6, 'x', mm['roof'])
551+ s.chimney(24, D // 2, 112 + 40 + 20, mm)
552+ s.chimney(W - 24, D // 2, 112 + 40 + 20, mm)
553+ return s.done()
554+
555+
556+def preview(items, path):
557+ out = atlas([items])[0]
558+ bg = Image.new('RGBA', out.size, (196, 190, 178, 255))
559+ bg.alpha_composite(out)
560+ bg.convert('RGB').resize((out.width * 2, out.height * 2), Image.NEAREST).save(path)
561+
562+
563+def main():
564+ os.makedirs(SCRATCH, exist_ok=True)
565+ towns = {
566+ 'ashford': [a_home, a_post, a_shop, a_inn, a_school, a_cottage1, a_cottage2, a_barn],
567+ 'millbrook': [m_mill, m_terrace, m_shop, m_inn, m_warehouse],
568+ 'coalbridge': [c_headframe, c_engine, c_row, c_pawn, c_inn],
569+ }
570+ done = {t: [f() for f in fns] for t, fns in towns.items()}
571+ preview([x for row in done.values() for x in row], os.path.join(SCRATCH, 'sheet.png'))
572+ for t, row in done.items():
573+ preview(row, os.path.join(SCRATCH, t + '.png'))
574+
575+
576+if __name__ == '__main__':
577+ main()
tools/art_chars.pyadded+463 -0
@@ -0,0 +1,463 @@
1+import math
2+import os
3+import sys
4+
5+import numpy as np
6+from PIL import Image
7+
8+sys.path.insert(0, os.path.dirname(__file__))
9+from vox import P, Model, atlas, mat, planks, project, render, save
10+
11+PREV = '/tmp/claude-1000/-home-tahinli-Documents-Code-Rust/edd994b8-9b3e-47f3-95c7-9404536bd326/scratchpad/chr'
12+D = math.radians
13+TAU = 2 * math.pi
14+ANK = 3.0
15+LEG = 10.5
16+HIP_Y = 3.0
17+ARM_U = 8.5
18+ARM_F = 8.0
19+N_H, NZ_H = 48, 56
20+N_W, NZ_W = 60, 36
21+N_C, NZ_C = 48, 36
22+BOOT_A = np.array([-1.4, 0.0, -1.6])
23+BOOT_B = np.array([3.2, 0.0, -1.6])
24+
25+n1 = None
26+pl = planks()
27+MAT_DEFS = {
28+ 'skin': ('skin', None),
29+ 'coal': ('coal', None),
30+ 'hair_gray': ('hair_gray', None),
31+ 'hair_brown': ('hair_brown', None),
32+ 'hair_black': ('hair_black', None),
33+ 'cloth_gray': ('cloth_gray', n1),
34+ 'cloth_brown': ('cloth_brown', n1),
35+ 'cloth_navy': ('cloth_navy', n1),
36+ 'cloth_cream': ('cloth_cream', n1),
37+ 'cloth_green': ('cloth_green', n1),
38+ 'cloth_wine': ('cloth_wine', n1),
39+ 'cloth_black': ('cloth_black', n1),
40+ 'plaster': ('plaster', n1),
41+ 'leather': ('leather', None),
42+ 'metal': ('metal', None),
43+ 'wood': ('wood', pl),
44+ 'wood_dark': ('wood_dark', pl),
45+ 'canvas': ('canvas', n1),
46+ 'stone': ('stone', n1),
47+ 'stone_dark': ('stone_dark', n1),
48+}
49+M = {k: mat(P[r], pt) for k, (r, pt) in MAT_DEFS.items()}
50+
51+
52+def Rz(a):
53+ c, s = math.cos(a), math.sin(a)
54+ return np.array([[c, -s, 0.0], [s, c, 0.0], [0.0, 0.0, 1.0]])
55+
56+
57+def Ry(a):
58+ c, s = math.cos(a), math.sin(a)
59+ return np.array([[c, 0.0, s], [0.0, 1.0, 0.0], [-s, 0.0, c]])
60+
61+
62+class Xf:
63+ def __init__(self, O=(0, 0, 0), R=None):
64+ self.O = np.asarray(O, float)
65+ self.R = np.eye(3) if R is None else R
66+
67+ def p(self, q):
68+ return self.O + self.R @ np.asarray(q, float)
69+
70+ def at(self, O, R):
71+ return Xf(self.p(O), self.R @ R)
72+
73+
74+class Fr:
75+ def __init__(self, n, nz, yaw, s=1.0):
76+ self.m = Model(n, n, nz)
77+ self.n = n
78+ self.c = np.array([n / 2, n / 2, 0.0])
79+ self.Rz = Rz(yaw)
80+ self.s = s
81+
82+ def W(self, p):
83+ return self.c + self.s * (self.Rz @ np.asarray(p, float))
84+
85+ def cap(self, a, b, r, m):
86+ self.m.capsule(self.W(a), self.W(b), r * self.s, m)
87+
88+ def cyl(self, a, b, r, m):
89+ self.m.cylinder(self.W(a), self.W(b), r * self.s, m)
90+
91+ def solid(self, xf, c, h, m, box=False):
92+ ctr = self.W(xf.p(c))
93+ Rw = self.Rz @ xf.R
94+ h = np.asarray(h, float) * self.s
95+ ext = np.abs(Rw) @ h if box else np.sqrt(((Rw * h) ** 2).sum(1))
96+
97+ def fn(X, Y, Z):
98+ d = [X - ctr[0], Y - ctr[1], Z - ctr[2]]
99+ q = [sum(Rw[i, j] * d[i] for i in range(3)) for j in range(3)]
100+ if box:
101+ return (abs(q[0]) <= h[0]) & (abs(q[1]) <= h[1]) & (abs(q[2]) <= h[2])
102+ return sum((q[j] / h[j]) ** 2 for j in range(3)) <= 1
103+
104+ self.m._fill(ctr - ext, ctr + ext, fn, m)
105+
106+ def ell(self, xf, c, r, m):
107+ self.solid(xf, c, r, m)
108+
109+ def box(self, xf, c, h, m):
110+ self.solid(xf, c, h, m, True)
111+
112+
113+def finish(fr, n):
114+ img, _, origin = render(fr.m)
115+ fx, fy = project(n / 2, n / 2, 0, origin)
116+ return img, (int(round(fx)), int(round(fy)))
117+
118+
119+def yaw_of(d):
120+ a = math.radians((d - 5) * 45)
121+ sx, sy = math.cos(a), math.sin(a)
122+ wx, wy = (sx - 2 * sy) / 2, (-sx - 2 * sy) / 2
123+ return math.atan2(wy, wx)
124+
125+
126+def gait(ph, amp, kmax):
127+ if ph is None:
128+ return 0.0, 0.0
129+ th = D(amp) * math.sin(ph)
130+ k = D(5) + (D(kmax) - D(5)) * max(math.cos(ph), 0.0) ** 1.5
131+ return th, k
132+
133+
134+def leg_pose(hip, th, k, l):
135+ a = np.array([math.sin(th), 0.0, -math.cos(th)])
136+ b = np.array([math.sin(th - k), 0.0, -math.cos(th - k)])
137+ knee = hip + l * a
138+ ankle = knee + l * b
139+ drop = l * (math.cos(th) + math.cos(th - k))
140+ return knee, ankle, drop
141+
142+
143+def ik(S, T, l1, l2, pole):
144+ v = T - S
145+ L = float(np.linalg.norm(v))
146+ d = min(L, l1 + l2 - 1e-3)
147+ u = v / L
148+ a = (l1 * l1 - l2 * l2 + d * d) / (2 * d)
149+ h = math.sqrt(max(l1 * l1 - a * a, 0.0))
150+ perp = pole - S
151+ perp = perp - (perp @ u) * u
152+ perp = perp / np.linalg.norm(perp)
153+ return S + a * u + h * perp
154+
155+
156+STYLES = [
157+ dict(mode='swing', amp=22, kmax=35, lean=0, arm=22, hp=0),
158+ dict(mode='carry', amp=16, kmax=25, lean=-3, arm=0, hp=0),
159+ dict(mode='push', amp=30, kmax=28, lean=12, arm=0, hp=0),
160+]
161+
162+DEFAULT = dict(hair='cloth_gray', vest=None, roll=False, skirt=None, short=False,
163+ coat=False, extras=(), scale=1.0, age=False, boots=True, legs='cloth_navy')
164+
165+LOOKS = {
166+ 'player': dict(head='cap', hair='cloth_gray', torso='cloth_cream', vest='cloth_brown',
167+ sleeve='cloth_cream', legs='cloth_navy', extras=('satchel',)),
168+ 'gent': dict(head='top', hair='cloth_black', torso='cloth_black', sleeve='cloth_black',
169+ legs='cloth_gray', coat=True),
170+ 'grocer': dict(head='bald', hair='hair_gray', torso='cloth_cream', vest='cloth_brown',
171+ sleeve='cloth_cream', roll=True, legs='cloth_brown', extras=('apron',)),
172+ 'woman': dict(head='bonnet', torso='cloth_wine', sleeve='cloth_wine', legs='cloth_wine',
173+ skirt='cloth_wine', boots=False, extras=('shawl',)),
174+ 'barmaid': dict(head='bun', hair='hair_brown', torso='cloth_green', sleeve='cloth_green',
175+ legs='cloth_green', skirt='cloth_green', boots=False, extras=('apron',)),
176+ 'teacher': dict(head='hair', hair='hair_gray', torso='cloth_brown', sleeve='cloth_brown',
177+ legs='cloth_gray', coat=True, extras=('spectacles',)),
178+ 'old': dict(head='hair', hair='hair_gray', torso='cloth_gray', sleeve='cloth_gray',
179+ legs='cloth_black', coat=True, age=True),
180+ 'worker': dict(head='cap', hair='cloth_brown', torso='cloth_cream', vest='cloth_gray',
181+ sleeve='cloth_cream', legs='cloth_brown', extras=('braces',)),
182+ 'miner': dict(head='helmet', hair='cloth_black', torso='cloth_black', sleeve='cloth_black',
183+ legs='cloth_black', extras=('dust',)),
184+ 'peddler': dict(head='hair', hair='hair_black', torso='cloth_brown', sleeve='cloth_brown',
185+ legs='cloth_gray', extras=('pack', 'patch')),
186+ 'bandit': dict(head='tricorn', hair='cloth_black', torso='cloth_black', sleeve='cloth_black',
187+ legs='cloth_navy', coat=True, extras=('scarf',)),
188+ 'boy': dict(head='cap', hair='cloth_brown', torso='cloth_cream', sleeve='cloth_cream',
189+ legs='cloth_brown', short=True, scale=0.68),
190+}
191+
192+
193+def human_skel(st, p):
194+ thL, kL = gait(p, st['amp'], st['kmax'])
195+ thR, kR = gait(None if p is None else p + math.pi, st['amp'], st['kmax'])
196+ dL = LEG * (math.cos(thL) + math.cos(thL - kL))
197+ dR = LEG * (math.cos(thR) + math.cos(thR - kR))
198+ hz = ANK + max(dL, dR)
199+ xf = Xf((0, 0, hz), Ry(D(st['lean'])))
200+ legs = []
201+ for s, th, k in ((1, thL, kL), (-1, thR, kR)):
202+ hip = np.array([0.0, s * HIP_Y, hz])
203+ knee, ankle, _ = leg_pose(hip, th, k, LEG)
204+ legs.append((hip, knee, ankle))
205+ arms = []
206+ for s in (1, -1):
207+ S = xf.p((0, s * 4.8, 9.5))
208+ if st['mode'] == 'swing':
209+ if p is None:
210+ phi, e = D(2.5), D(6)
211+ else:
212+ phi, e = -s * D(st['arm']) * math.sin(p), D(15)
213+ E = S + ARM_U * np.array([math.sin(phi), 0.0, -math.cos(phi)])
214+ H = E + ARM_F * np.array([math.sin(phi + e), 0.0, -math.cos(phi + e)])
215+ else:
216+ if st['mode'] == 'carry':
217+ H = np.array([6.0, s * 5.0, hz + 3.0])
218+ else:
219+ H = np.array([12.0, s * 4.0, hz + 1.0])
220+ E = (S + H) / 2 + np.array([0.0, 0.0, -2.0])
221+ arms.append((S, E, H))
222+ return dict(hz=hz, xf=xf, legs=legs, arms=arms, p=p)
223+
224+
225+def draw_skirt(fr, m, hz, p):
226+ sx = 0.5 * math.cos(p) if p is not None else 0.0
227+ sy = 0.9 * math.sin(p) if p is not None else 0.0
228+ z0, z1, n = 0.8, hz - 0.5, 6
229+ for i in range(n):
230+ za = z0 + (z1 - z0) * i / n
231+ zb = z0 + (z1 - z0) * (i + 1) / n
232+ r = 7.2 - 2.9 * ((za + zb) / 2 - z0) / (z1 - z0)
233+ fr.cyl((sx, sy, za), (sx, sy, zb), r, m)
234+
235+
236+def draw_head(fr, hx, L):
237+ hair = M[L['hair']]
238+ kind = L['head']
239+ if kind == 'cap':
240+ fr.ell(hx, (-1.0, 0, 1.2), (4.3, 4.3, 1.4), hair)
241+ fr.cyl(hx.p((0, 0, 2.6)), hx.p((0, 0, 5.1)), 4.6, hair)
242+ fr.box(hx, (5.5, 0, 2.4), (1.5, 3.4, 0.3), hair)
243+ elif kind == 'top':
244+ fr.cyl(hx.p((0, 0, 3.9)), hx.p((0, 0, 4.6)), 5.2, hair)
245+ fr.cyl(hx.p((0, 0, 4.5)), hx.p((0, 0, 10.5)), 3.4, hair)
246+ elif kind in ('hair', 'bun'):
247+ fr.ell(hx, (-0.8, 0, 0.9), (3.8, 3.8, 4.1), hair)
248+ if kind == 'bun':
249+ fr.ell(hx, (-3.6, 0, 0.3), (1.9, 1.9, 1.9), hair)
250+ elif kind == 'bald':
251+ fr.ell(hx, (-1.9, 0, 2.8), (2.2, 2.9, 1.6), hair)
252+ elif kind == 'bonnet':
253+ fr.ell(hx, (-1.6, 0, 0.4), (4.6, 4.6, 4.4), M['plaster'])
254+ elif kind == 'helmet':
255+ fr.ell(hx, (-0.3, 0, 1.2), (4.0, 3.9, 3.7), M['leather'])
256+ fr.box(hx, (3.3, 0, 1.8), (1.5, 3.0, 0.3), M['leather'])
257+ elif kind == 'tricorn':
258+ fr.ell(hx, (0, 0, 2.8), (3.8, 3.8, 2.2), hair)
259+ fr.box(hx, (0, 0, 2.0), (4.8, 4.6, 0.35), hair)
260+
261+
262+def draw_human(fr, L, sk, st):
263+ hz, xf, p = sk['hz'], sk['xf'], sk['p']
264+ dress = L['skirt'] is not None
265+ lg = M[L['legs']]
266+ tor = M[L['torso']]
267+ sl = M[L['sleeve']]
268+ skin = M['skin']
269+ ext = L['extras']
270+ for hip, knee, ankle in sk['legs']:
271+ fr.cap(hip, knee, 2.0, lg)
272+ fr.cap(knee, ankle, 1.9, skin if L['short'] else lg)
273+ if L['boots'] and not dress:
274+ fr.cap(ankle + BOOT_A, ankle + BOOT_B, 1.4, M['leather'])
275+ fr.ell(Xf((0, 0, hz)), (0, 0, 1.0), (3.4, 4.6, 2.8), M[L['skirt']] if dress else lg)
276+ if dress:
277+ draw_skirt(fr, M[L['skirt']], hz, p)
278+ fr.ell(xf, (0, 0, 7.0), (3.6, 5.0, 7.0), tor)
279+ if L['coat']:
280+ fr.ell(xf, (-0.3, 0, -3.0), (3.9, 5.2, 5.8), tor)
281+ if L['vest']:
282+ fr.ell(xf, (0, 0, 6.8), (3.8, 5.2, 5.8), M[L['vest']])
283+ if 'shawl' in ext:
284+ fr.ell(xf, (0.3, 0, 11.0), (4.6, 6.9, 2.8), M['cloth_cream'])
285+ if 'satchel' in ext:
286+ fr.box(xf, (-0.5, 6.9, 0.8), (1.8, 1.1, 3.0), M['leather'])
287+ fr.cap(xf.p((2.4, -5.8, 10.8)), xf.p((3.8, 0, 6.0)), 0.6, M['leather'])
288+ fr.cap(xf.p((3.8, 0, 6.0)), xf.p((2.4, 5.8, 1.5)), 0.6, M['leather'])
289+ if 'braces' in ext:
290+ for s in (1, -1):
291+ fr.cap(xf.p((3.0, s * 3.4, -1.0)), xf.p((0, s * 5.6, 10.8)), 0.45, M['leather'])
292+ fr.cap(xf.p((0, s * 5.6, 10.8)), xf.p((-3.0, s * 3.4, -1.0)), 0.45, M['leather'])
293+ if 'patch' in ext:
294+ fr.box(xf, (0.5, 5.5, 3.0), (1.5, 0.4, 1.4), M['cloth_cream'])
295+ fr.box(xf, (0.5, -5.2, 6.0), (1.2, 0.4, 1.2), M['cloth_gray'])
296+ if 'pack' in ext:
297+ fr.box(xf, (-5.6, 0, 6.5), (2.3, 4.6, 5.0), M['canvas'])
298+ if 'apron' in ext:
299+ fr.box(xf, (5.3 if dress else 4.4, 0, 2.5), (0.7, 4.3, 4.6), M['plaster'])
300+ for S, E, H in sk['arms']:
301+ fr.cap(S, E, 1.6, sl)
302+ fr.cap(E, H, 1.5, skin if L['roll'] else sl)
303+ fr.cap(H, H, 1.4, skin)
304+ fr.cap(xf.p((0, 0, 10.0)), xf.p((0, 0, 12.6)), 1.5, skin)
305+ hp = D(st['hp'])
306+ hx = xf.at(np.array([0.0, 0.0, 12.0]) + Ry(hp) @ np.array([0.0, 0.0, 6.0]), Ry(hp))
307+ fr.ell(hx, (0, 0, 0), (4.2, 4.2, 4.8), skin)
308+ for y in (1.25, -1.25):
309+ fr.box(hx, (4.1, y, -0.2), (0.45, 0.45, 0.45), M['coal'])
310+ fr.box(hx, (4.3, 0, -0.9), (0.4, 0.35, 0.4), skin)
311+ draw_head(fr, hx, L)
312+ if 'spectacles' in ext:
313+ fr.box(hx, (4.3, 1.7, 0.0), (0.3, 0.6, 0.5), M['metal'])
314+ fr.box(hx, (4.3, -1.7, 0.0), (0.3, 0.6, 0.5), M['metal'])
315+ fr.box(hx, (4.4, 0, 0.3), (0.25, 1.0, 0.15), M['metal'])
316+ if 'dust' in ext:
317+ fr.box(hx, (3.8, 2.4, -1.6), (0.5, 0.7, 0.7), M['coal'])
318+ fr.box(hx, (3.8, -2.4, -1.6), (0.5, 0.7, 0.7), M['coal'])
319+ if 'scarf' in ext:
320+ fr.box(hx, (3.8, 0, -2.4), (1.0, 3.6, 1.2), M['cloth_wine'])
321+
322+
323+def human_frame(look, pose, d, col):
324+ L = dict(DEFAULT)
325+ L.update(look)
326+ st = dict(STYLES[pose])
327+ if L['age']:
328+ st['amp'] *= 0.7
329+ st['kmax'] *= 0.8
330+ st['arm'] *= 0.6
331+ st['lean'] += 18
332+ st['hp'] = 12
333+ fr = Fr(N_H, NZ_H, yaw_of(d), L['scale'])
334+ p = None if col == 0 else TAU * (col - 1) / 8
335+ sk = human_skel(st, p)
336+ if pose == 1:
337+ fr.box(Xf(), (8.0, 0.0, sk['hz'] + 6.0), (6.0, 5.0, 4.0), M['plaster'])
338+ draw_human(fr, L, sk, st)
339+ return finish(fr, N_H)
340+
341+
342+def build_human(look):
343+ rows = []
344+ for pose in range(3):
345+ for d in range(8):
346+ rows.append([human_frame(look, pose, d, c) for c in range(9)])
347+ return atlas(rows)
348+
349+
350+def wolf_frame(d, col):
351+ fr = Fr(N_W, NZ_W, yaw_of(d))
352+ trot = col > 0
353+ p = TAU * (col - 1) / 6 if trot else None
354+ phB = None if p is None else p + math.pi
355+ legs_spec = [(10.0, 2.5, p), (10.0, -2.5, phB), (-10.0, 2.5, phB), (-10.0, -2.5, p)]
356+ gaits = [gait(ph, 25, 40) for _, _, ph in legs_spec]
357+ drops = [7.0 * (math.cos(th) + math.cos(th - k)) for th, k in gaits]
358+ hz = 0.9 + max(drops)
359+ zc = hz + 0.9
360+ body = M['stone']
361+ dark = M['stone_dark']
362+ fr.ell(Xf(), (0, 0, zc), (15.0, 5.0, 5.5), body)
363+ for (x, y, _), (th, k) in zip(legs_spec, gaits):
364+ hip = np.array([x, y, hz])
365+ knee, ankle, _ = leg_pose(hip, th, k, 7.0)
366+ fr.cap(hip, knee, 1.1, body)
367+ fr.cap(knee, ankle, 0.9, dark)
368+ fr.cap(ankle + np.array([-0.5, 0, 0]), ankle + np.array([1.5, 0, 0]), 0.9, dark)
369+ sh = -1.0 if trot else 0.0
370+ fr.cap((-14.0, 0, zc + 1.0), (-18.5, 0, zc - 1.5), 2.0, body)
371+ fr.cap((-18.5, 0, zc - 1.5), (-21.0, 0, zc - 3.5), 1.6, body)
372+ fr.cap((12.0, 0, zc + 1.5), (15.5, 0, zc + 4.0 + sh), 2.6, body)
373+ fr.ell(Xf(), (17.5, 0, zc + 4.5 + sh), (3.6, 2.7, 2.7), body)
374+ fr.cap((19.5, 0, zc + 4.0 + sh), (24.5, 0, zc + 3.4 + sh), 1.3, dark)
375+ for s in (1, -1):
376+ fr.cap((16.5, s * 1.4, zc + 6.8 + sh), (16.0, s * 1.3, zc + 9.2 + sh), 0.8, dark)
377+ fr.box(Xf(), (20.2, s * 1.4, zc + 4.6 + sh), (0.35, 0.35, 0.35), M['coal'])
378+ return finish(fr, N_W)
379+
380+
381+def wheel(fr, y, phi):
382+ C = np.array([0.0, y, 10.6])
383+ iron, wood = M['metal'], M['wood']
384+ pts = [C + 9.2 * np.array([math.cos(TAU * k / 16), 0.0, math.sin(TAU * k / 16)]) for k in range(16)]
385+ for k in range(16):
386+ fr.cap(pts[k], pts[(k + 1) % 16], 0.9, iron)
387+ for k in range(6):
388+ t = phi + TAU * k / 6
389+ u = np.array([math.cos(t), 0.0, math.sin(t)])
390+ fr.cap(C + 1.5 * u, C + 8.3 * u, 0.55, wood)
391+ fr.cyl(C + np.array([0.0, -1.2, 0.0]), C + np.array([0.0, 1.2, 0.0]), 1.9, iron)
392+
393+
394+def cart_frame(d, col, loaded):
395+ fr = Fr(N_C, NZ_C, yaw_of(d))
396+ I = Xf()
397+ wood, dark, canvas, cream = M['wood'], M['wood_dark'], M['canvas'], M['cloth_cream']
398+ phi = D(15 * col)
399+ for y in (-11.5, 11.5):
400+ wheel(fr, y, phi)
401+ fr.cyl((0, -11.5, 10.6), (0, 11.5, 10.6), 0.9, M['metal'])
402+ fr.box(I, (0, 0, 15.5), (14.0, 10.0, 1.0), wood)
403+ fr.box(I, (13.25, 0, 19.0), (0.75, 10.0, 3.0), wood)
404+ fr.box(I, (-13.25, 0, 19.0), (0.75, 10.0, 3.0), wood)
405+ for s in (-1, 1):
406+ fr.box(I, (0, s * 9.25, 19.0), (13.0, 0.75, 3.0), wood)
407+ fr.cap((-13.5, 3.0 * s, 17.0), (-19.0, 3.0 * s, 24.0), 0.9, wood)
408+ fr.cyl((-19.0, -3.0, 24.0), (-19.0, 3.0, 24.0), 1.0, wood)
409+ if not loaded:
410+ fr.cyl((-6.0, -9.0, 19.0), (-6.0, 9.0, 19.0), 2.6, canvas)
411+ else:
412+ fr.box(I, (-5.0, -2.0, 21.0), (5.0, 4.5, 4.5), dark)
413+ fr.box(I, (7.0, -3.0, 20.0), (4.0, 5.0, 3.5), canvas)
414+ fr.box(I, (7.0, -3.0, 23.9), (4.2, 0.45, 0.5), cream)
415+ fr.box(I, (7.0, -3.0, 23.9), (0.45, 5.2, 0.5), cream)
416+ fr.box(I, (-5.0, -2.0, 27.0), (3.5, 3.5, 1.5), canvas)
417+ fr.box(I, (-5.0, -2.0, 28.6), (3.6, 0.4, 0.4), cream)
418+ fr.ell(I, (-9.0, 6.0, 19.5), (3.6, 3.0, 3.0), canvas)
419+ return finish(fr, N_C)
420+
421+
422+def on_bg(img):
423+ bg = Image.new('RGBA', img.size, (206, 200, 186, 255))
424+ bg.alpha_composite(img.convert('RGBA'))
425+ return bg.convert('RGB')
426+
427+
428+def write_sheet(name, out, cell, grid, origin):
429+ save(name, out, origin, cell=cell, grid=grid, group='chars')
430+ on_bg(out.resize((out.width * 3, out.height * 3), Image.NEAREST)).save(os.path.join(PREV, 'sheet_%s.png' % name))
431+
432+
433+def main():
434+ os.makedirs(PREV, exist_ok=True)
435+ player = None
436+ for name, look in LOOKS.items():
437+ out, cell, grid, origin = build_human(look)
438+ write_sheet(name, out, cell, grid, origin)
439+ if name == 'player':
440+ player = (out, cell)
441+ out, cell, grid, origin = atlas([[wolf_frame(d, c) for c in range(7)] for d in range(8)])
442+ write_sheet('wolf', out, cell, grid, origin)
443+ out, cell, grid, origin = atlas([[cart_frame(d, c, ld) for c in range(4)]
444+ for ld in (0, 1) for d in range(8)])
445+ write_sheet('cart', out, cell, grid, origin)
446+
447+ out, (cw, ch) = player
448+ def crop(r, c):
449+ return out.crop((c * cw, r * ch, (c + 1) * cw, (r + 1) * ch))
450+ walk = Image.new('RGBA', (8 * cw, 2 * ch), (0, 0, 0, 0))
451+ for j, d in enumerate((3, 5)):
452+ for i in range(8):
453+ walk.paste(crop(d, i + 1), (i * cw, j * ch))
454+ on_bg(walk.resize((walk.width * 4, walk.height * 4), Image.NEAREST)).save(os.path.join(PREV, 'walk.png'))
455+ poses = Image.new('RGBA', (9 * cw, 2 * ch), (0, 0, 0, 0))
456+ for j, r in enumerate((8 + 4, 16 + 4)):
457+ for i in range(9):
458+ poses.paste(crop(r, i), (i * cw, j * ch))
459+ on_bg(poses.resize((poses.width * 4, poses.height * 4), Image.NEAREST)).save(os.path.join(PREV, 'poses.png'))
460+
461+
462+if __name__ == '__main__':
463+ main()
tools/art_env.pyadded+785 -0
@@ -0,0 +1,785 @@
1+import functools
2+import math
3+import os
4+import sys
5+
6+import numpy as np
7+from PIL import Image
8+
9+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
10+import vox
11+from vox import P, hash3
12+
13+G = 'env'
14+PREVIEW = '/tmp/claude-1000/-home-tahinli-Documents-Code-Rust/edd994b8-9b3e-47f3-95c7-9404536bd326/scratchpad/env'
15+FIRE = P['fire']
16+SLAG = [(28, 22, 22), (52, 40, 36), (78, 60, 50), (116, 76, 56)]
17+EMBER = [(60, 20, 14), (110, 34, 20), (150, 50, 26), (180, 70, 34)]
18+BIRCH = [(70, 66, 60), (150, 144, 136), (200, 194, 182), (232, 228, 216)]
19+BG = (34, 32, 38, 255)
20+RES = {}
21+MC = {}
22+
23+
24+def mt(ramp, pat=None, em=False):
25+ if isinstance(ramp, str):
26+ ramp = P[ramp]
27+ key = (tuple(ramp), em, pat)
28+ if key not in MC:
29+ assert len(vox._MATS) < 255, 'vox material ids exhausted'
30+ MC[key] = vox.mat(list(ramp), pat, em)
31+ return MC[key]
32+
33+
34+@functools.lru_cache(None)
35+def const(k):
36+ return lambda cx, cy, cz, f: k
37+
38+
39+@functools.lru_cache(None)
40+def sprinkle(s, p, a):
41+ return lambda cx, cy, cz, f: np.where(hash3(cx, cy, 0, s) < p, a, 0)
42+
43+
44+def ring(pat=None):
45+ return pat
46+
47+
48+R0 = ring()
49+
50+
51+def gh(s, n=32):
52+ gx, gy = np.indices((n, n))
53+ return hash3(gx, gy, 0, s)
54+
55+
56+def wrap_disc(gx, gy, centers, shrink=0.0):
57+ out = np.zeros(gx.shape, bool)
58+ for px, py, r in centers:
59+ for ox in (-32, 0, 32):
60+ for oy in (-32, 0, 32):
61+ out |= (gx - px - ox) ** 2 + (gy - py - oy) ** 2 <= (r - shrink) ** 2
62+ return out
63+
64+
65+def top(f):
66+ return (f == 2).astype(np.int64)
67+
68+
69+class Cv:
70+ def __init__(self, sx, sy, sz, off=(0, 0)):
71+ self.m = vox.Model(sx, sy, sz)
72+ self.o = off
73+
74+ def p(self, a):
75+ return (a[0] + self.o[0], a[1] + self.o[1], a[2])
76+
77+ def box(self, a, b, m):
78+ pa, pb = self.p(a), self.p(b)
79+ self.m.box(pa[0], pa[1], pa[2], pb[0], pb[1], pb[2], m)
80+
81+ def ell(self, c, r, m):
82+ pc = self.p(c)
83+ self.m.ellipsoid(pc[0], pc[1], pc[2], r[0], r[1], r[2], m)
84+
85+ def cap(self, a, b, r, m):
86+ self.m.capsule(self.p(a), self.p(b), r, m)
87+
88+ def cyl(self, a, b, r, m):
89+ self.m.cylinder(self.p(a), self.p(b), r, m)
90+
91+ def gable(self, x0, y0, x1, y1, z0, z1, axis, m, ov=0):
92+ ox, oy = self.o
93+ self.m.gable(x0 + ox, y0 + oy, x1 + ox, y1 + oy, z0, z1, axis, m, ov)
94+
95+
96+def finish(name, cv, outline=True, edges=True):
97+ img, em, org = vox.render(cv.m, outline, edges)
98+ anchor = [int(round(a)) for a in vox.project(cv.o[0], cv.o[1], 0, org)]
99+ if not edges:
100+ bb = img.getbbox()
101+ img = img.crop(bb)
102+ anchor = [anchor[0] - bb[0], anchor[1] - bb[1]]
103+ anchor = tuple(anchor)
104+ vox.save(name, img, anchor, emissive=em, group=G)
105+ RES[name] = (img, anchor)
106+
107+
108+def add(name, img, origin):
109+ vox.save(name, img, origin, group=G)
110+ RES[name] = (img, origin)
111+
112+
113+def tile(name, base, fix=None, h=3):
114+ cv = Cv(32, 32, h)
115+ cv.m.v[:, :, 0] = base
116+ if fix:
117+ fix(cv.m.v)
118+ finish(name, cv, outline=False, edges=False)
119+
120+
121+def brick(cx, cy, w, h, stag):
122+ row = cy // h
123+ x = cx + (row * stag) % w
124+ return x % w, cy % h, (x // w) % (32 // w), row % (32 // h)
125+
126+
127+def paving(name, ramp, joint, w, h, stag, s, var):
128+ def pat(cx, cy, cz, f):
129+ lx, ly, sx, row = brick(cx, cy, w, h, stag)
130+ sid = hash3(sx, row, 0, s)
131+ v = np.floor(sid * (2 * var + 1)).astype(np.int64) - var
132+ return v + ((lx == 1) | (ly == 1)) - ((lx == w - 1) | (ly == h - 1))
133+ gx, gy = np.indices((32, 32))
134+ lx, ly, _, _ = brick(gx, gy, w, h, stag)
135+ jm = (lx == 0) | (ly == 0)
136+ jmat = mt(joint, ring(sprinkle(s + 3, 0.12, -1)))
137+
138+ def fix(v):
139+ v[:, :, 0][jm] = jmat
140+ tile(name, mt(ramp, ring(pat)), fix)
141+
142+
143+def grass(i):
144+ def pat(cx, cy, cz, f):
145+ return sprinkle(20 + i, 0.03, -1)(cx, cy, cz, f) + sprinkle(30 + i, 0.02, 1)(cx, cy, cz, f)
146+ tuft = mt('grass', const(1))
147+ cream = mt('cloth_cream')
148+ wine = mt('cloth_wine')
149+
150+ def fix(v):
151+ m = gh(40 + i) < 0.012
152+ v[:, :, 1][m] = tuft
153+ if i == 1:
154+ v[:, :, 2][m & (gh(49) < 0.5)] = tuft
155+ if i == 3:
156+ fl = gh(41) < 0.012
157+ c = gh(42) < 0.5
158+ v[:, :, 1][fl & c] = cream
159+ v[:, :, 1][fl & ~c] = wine
160+ tile(f'grass{i}', mt('grass', ring(pat)), fix)
161+
162+
163+def road(i):
164+ def pat(cx, cy, cz, f):
165+ return np.where(hash3(cx // 4, cy // 4, 0, 30 + i) < 0.25, -1, 0) + sprinkle(40 + i, 0.03, 1)(cx, cy, cz, f)
166+ stone = mt('stone')
167+
168+ def fix(v):
169+ v[:, :, 1][gh(50 + i) < 0.01] = stone
170+ tile(f'road{i}', mt('dirt', pat), fix)
171+
172+
173+def soot(i):
174+ def pat(cx, cy, cz, f):
175+ p = sprinkle(40 + i, 0.05, 1)(cx, cy, cz, f)
176+ if i == 1:
177+ p = p + np.where(hash3(cx // 8, cy // 8, 0, 44) < 0.4, -1, 0)
178+ return p
179+ mud = mt('mud', R0)
180+ ember = mt(EMBER, R0)
181+ lump = mt('coal', const(2))
182+
183+ def fix(v):
184+ gx, gy = np.indices((32, 32))
185+ if i == 2:
186+ v[:, :, 0][hash3(gx // 4, gy // 4, 0, 45) < 0.2] = mud
187+ v[:, :, 0][gh(50 + i) < 0.004] = ember
188+ if i == 3:
189+ v[:, :, 1][gh(60) < 0.012] = lump
190+ tile(f'soot{i}', mt('coal', ring(pat)), fix)
191+
192+
193+def mud_pat(s):
194+ def f(cx, cy, cz, face):
195+ return np.where(hash3(cx // 4, cy // 4, 0, s) < 0.35, -1, 0) + sprinkle(s + 9, 0.05, 1)(cx, cy, cz, face)
196+ return f
197+
198+
199+def mud(i):
200+ cen = [(6, 8, 4), (22, 20, 5), (12, 27, 3)] if i == 0 else [(20, 6, 3), (6, 21, 4)]
201+ pud = mt('water', ring(const(-1)))
202+ rim = mt('water', R0)
203+ base = mt('mud', ring(mud_pat(50 + i)))
204+
205+ def fix(v):
206+ gx, gy = np.indices((32, 32)) + 0.5
207+ v[:, :, 0][wrap_disc(gx, gy, cen)] = rim
208+ v[:, :, 0][wrap_disc(gx, gy, cen, 1.2)] = pud
209+ tile(f'mud{i}', base, fix)
210+
211+
212+def farm(i):
213+ gx, gy = np.indices((32, 32))
214+ along = gy
215+ per = 4 if i == 0 else 8
216+ ridge = (along % per) < per // 2
217+ rmat = mt('dirt', R0)
218+ sprout = mt('grass', const(1))
219+
220+ def fix(v):
221+ v[:, :, 1][ridge] = rmat
222+ v[:, :, 1][(~ridge) & (gh(90 + i) < 0.08 + 0.08 * i)] = sprout
223+ tile(f'farmland{i}', mt('dirt', ring(const(-1))), fix)
224+
225+
226+def water(i):
227+ def pat(cx, cy, cz, f):
228+ rip = (cx % 4 != 3) & (hash3(cx // 4, cy, 0, 70 + i) < 0.1)
229+ return rip.astype(np.int64) + sprinkle(80 + i, 0.04, -1)(cx, cy, cz, f)
230+ tile(f'water{i}', mt('water', ring(pat)))
231+
232+
233+def rail():
234+ gx, gy = np.indices((32, 32))
235+ cv = Cv(32, 32, 3)
236+ cv.m.v[:, :, 0] = mt('coal', ring(sprinkle(95, 0.1, 1)))
237+ cv.m.v[:, :, 0][(gx % 8 < 2) & (gy >= 7) & (gy < 25)] = mt('wood_dark', R0)
238+ cv.m.v[:, 11, 1] = mt('metal')
239+ cv.m.v[:, 20, 1] = mt('metal')
240+ finish('rail_x', cv, outline=False, edges=False)
241+ cv2 = Cv(32, 32, 3)
242+ cv2.m.v = np.ascontiguousarray(cv.m.v.transpose(1, 0, 2))
243+ finish('rail_y', cv2, outline=False, edges=False)
244+
245+
246+def tiles():
247+ for i in range(4):
248+ grass(i)
249+ road(i)
250+ soot(i)
251+ paving('cobble0', 'cobble', 'stone_dark', 8, 4, 4, 11, 1)
252+ paving('cobble1', 'cobble', 'stone_dark', 8, 8, 4, 12, 1)
253+ paving('cobble2', 'cobble', 'stone_dark', 4, 4, 2, 13, 1)
254+ paving('cobble3', 'cobble', 'stone_dark', 8, 4, 0, 14, 1)
255+ paving('flag0', 'stone', 'stone_dark', 8, 8, 0, 21, 0)
256+ paving('flag1', 'stone', 'stone_dark', 16, 8, 8, 22, 1)
257+ paving('flag2', 'stone', 'stone_dark', 8, 8, 4, 23, 1)
258+ paving('flag3', 'stone', 'stone_dark', 16, 16, 8, 24, 1)
259+ mud(0)
260+ mud(1)
261+ farm(0)
262+ farm(1)
263+ water(0)
264+ water(1)
265+ tile('planks', mt('wood', ring(vox.planks(4, 0))))
266+ rail()
267+
268+
269+def weave(cx, cy, cz, f):
270+ return np.where(((cx + cz) % 4 == 0) | ((cy + cz) % 4 == 0), -1, 0)
271+
272+
273+def leaf_pat(s):
274+ def f(cx, cy, cz, face):
275+ blob = np.where(hash3(cx // 3, cy // 3, cz // 3, s) < 0.3, -1, 0)
276+ return blob + top(face)
277+ return f
278+
279+
280+def bark_pat(s):
281+ def f(cx, cy, cz, face):
282+ return np.where(hash3(cx // 2, cy // 2, cz // 3, s) < 0.4, -1, 0) + top(face)
283+ return f
284+
285+
286+def rock_pat(s):
287+ def f(cx, cy, cz, face):
288+ return sprinkle(s, 0.06, -1)(cx, cy, cz, face) + sprinkle(s + 1, 0.05, 1)(cx, cy, cz, face) + top(face)
289+ return f
290+
291+
292+def crate_pat(x0, y0, w, d):
293+ def f(cx, cy, cz, face):
294+ edge = (cx == x0) | (cx == x0 + w - 1) | (cy == y0) | (cy == y0 + d - 1)
295+ return edge.astype(np.int64) - (cz % 6 == 0).astype(np.int64)
296+ return f
297+
298+
299+def crate(cv, x0, y0, z0, w, d, h):
300+ cv.box((x0, y0, z0), (x0 + w, y0 + d, z0 + h), mt('wood', crate_pat(x0, y0, w, d)))
301+
302+
303+def barrel(cv, cx, cy, h=22, r=6.5):
304+ cv.ell((cx, cy, h / 2), (r, r, h / 2), mt('wood', vox.rows(4)))
305+ for z in (4, h - 6):
306+ cv.cyl((cx, cy, z), (cx, cy, z + 1), r + 0.7, mt('metal'))
307+ cv.cyl((cx, cy, h - 1), (cx, cy, h), r * 0.6, mt('wood_dark'))
308+
309+
310+def sack(cv, cx, cy, sc):
311+ m = mt('canvas', weave)
312+ cv.ell((cx, cy, 7 * sc), (8 * sc, 6.5 * sc, 7 * sc), m)
313+ cv.cyl((cx, cy, 13 * sc), (cx, cy, 15 * sc), 2.4 * sc, m)
314+
315+
316+def bale_pat(cx, cy, cz, f):
317+ rope = (cx == 9) | (cx == 22) | (cz == 4) | (cz == 10)
318+ return np.where(rope, -2, 0) + sprinkle(7, 0.08, 1)(cx, cy, cz, f)
319+
320+
321+def coal_pat(cx, cy, cz, f):
322+ return sprinkle(111, 0.08, 1)(cx, cy, cz, f) + sprinkle(112, 0.08, -1)(cx, cy, cz, f) + top(f)
323+
324+
325+def slag_pat(cx, cy, cz, f):
326+ return sprinkle(120, 0.02, 1)(cx, cy, cz, f) + sprinkle(121, 0.1, -1)(cx, cy, cz, f) + top(f)
327+
328+
329+def cross_pat(cx, cy, cz, f):
330+ c = ((cx == 15) & (cz >= 7) & (cz <= 11)) | ((cz == 9) & (cx >= 14) & (cx <= 17))
331+ return np.where(c, -1, 0) + top(f)
332+
333+
334+def birch_pat(cx, cy, cz, f):
335+ return np.where(hash3(cx, cy, cz // 2, 311) < 0.15, -2, 0) + top(f)
336+
337+
338+def p_crate():
339+ cv = Cv(32, 32, 16)
340+ crate(cv, 5, 5, 0, 22, 22, 14)
341+ finish('crate', cv)
342+
343+
344+def p_crates():
345+ cv = Cv(32, 32, 28)
346+ crate(cv, 2, 4, 0, 14, 14, 12)
347+ crate(cv, 16, 14, 0, 14, 14, 12)
348+ crate(cv, 4, 6, 12, 11, 11, 10)
349+ finish('crates', cv)
350+
351+
352+def p_barrel():
353+ cv = Cv(32, 32, 24)
354+ barrel(cv, 16, 16)
355+ finish('barrel', cv)
356+
357+
358+def p_barrels():
359+ cv = Cv(32, 32, 24)
360+ barrel(cv, 9, 9)
361+ barrel(cv, 23, 10)
362+ barrel(cv, 16, 23)
363+ finish('barrels', cv)
364+
365+
366+def p_sack():
367+ cv = Cv(32, 32, 18)
368+ sack(cv, 16, 16, 1.0)
369+ finish('sack', cv)
370+
371+
372+def p_sacks():
373+ cv = Cv(32, 32, 18)
374+ sack(cv, 8, 9, 1.0)
375+ sack(cv, 22, 10, 1.0)
376+ sack(cv, 15, 22, 0.8)
377+ finish('sacks', cv)
378+
379+
380+def p_bale():
381+ cv = Cv(32, 32, 20)
382+ cv.box((3, 7, 0), (29, 25, 15), mt('cloth_cream', bale_pat))
383+ finish('bale', cv)
384+
385+
386+def p_haystack():
387+ cv = Cv(32, 32, 28)
388+ cv.ell((16, 16, 0), (14, 14, 13), mt('thatch', lambda cx, cy, cz, f: np.where((cx + 2 * cz) % 5 == 0, -1, 0) + sprinkle(8, 0.06, 1)(cx, cy, cz, f)))
389+ finish('haystack', cv)
390+
391+
392+def p_logs():
393+ cv = Cv(32, 32, 22)
394+ bark = mt('bark', bark_pat(600))
395+ cut = mt('wood', R0)
396+ for y, z in ((7, 3.5), (15, 3.5), (23, 3.5), (11, 9.6), (19, 9.6), (27, 9.6), (15, 15.7)):
397+ cv.cyl((2, y, z), (30, y, z), 3.5, bark)
398+ cv.cyl((2, y, z), (3.6, y, z), 2.6, cut)
399+ cv.cyl((28.4, y, z), (30.5, y, z), 2.6, cut)
400+ finish('logs', cv)
401+
402+
403+def fence_cv():
404+ cv = Cv(32, 32, 22)
405+ cv.box((0, 27, 0), (2, 31, 20), mt('wood_dark'))
406+ cv.box((0, 28, 6), (32, 30, 9), mt('wood', vox.rows(4)))
407+ cv.box((0, 28, 13), (32, 30, 16), mt('wood', vox.rows(4)))
408+ return cv
409+
410+
411+def p_fences():
412+ cv = fence_cv()
413+ finish('fence_x', cv)
414+ cv2 = Cv(32, 32, 22)
415+ cv2.m.v = np.ascontiguousarray(cv.m.v.transpose(1, 0, 2))
416+ finish('fence_y', cv2)
417+
418+
419+def p_lamp():
420+ cv = Cv(32, 32, 94)
421+ iron = mt('slate')
422+ cv.cyl((16, 16, 0), (16, 16, 4), 3.6, iron)
423+ cv.cyl((16, 16, 4), (16, 16, 8), 2.4, iron)
424+ cv.cyl((16, 16, 8), (16, 16, 76), 1.2, iron)
425+ cv.cyl((16, 16, 76), (16, 16, 78), 2.2, iron)
426+ cv.box((11, 11, 78), (21, 21, 80), iron)
427+ cv.box((12, 12, 80), (20, 20, 88), mt('window', None, True))
428+ for x, y in ((12, 12), (20, 12), (12, 20), (20, 20)):
429+ cv.cyl((x, y, 80), (x, y, 88), 0.7, iron)
430+ cv.box((9, 9, 88), (23, 23, 90), iron)
431+ cv.box((12, 12, 90), (20, 20, 92), iron)
432+ cv.cyl((16, 16, 92), (16, 16, 94), 0.9, iron)
433+ finish('lamp', cv)
434+
435+
436+def p_well():
437+ cv = Cv(32, 32, 46)
438+ cv.cyl((16, 16, 0), (16, 16, 12), 9.5, mt('stone', vox.bricks(4, 8)))
439+ cv.cyl((16, 16, 8), (16, 16, 13), 7.0, 0)
440+ cv.cyl((16, 16, 7), (16, 16, 8), 6.5, mt('water'))
441+ cv.box((6, 15, 12), (8, 17, 32), mt('wood'))
442+ cv.box((24, 15, 12), (26, 17, 32), mt('wood'))
443+ cv.cyl((6, 16, 24), (26, 16, 24), 1.0, mt('wood_dark'))
444+ cv.gable(4, 6, 28, 26, 30, 38, 'x', mt('wood_dark', vox.rows(3)), 1)
445+ finish('well', cv)
446+
447+
448+def p_bench():
449+ cv = Cv(32, 32, 26)
450+ cv.box((4, 11, 11), (28, 21, 13), mt('wood', vox.planks(3, 2)))
451+ cv.box((4, 11, 0), (6, 21, 11), mt('wood_dark'))
452+ cv.box((26, 11, 0), (28, 21, 11), mt('wood_dark'))
453+ cv.box((4, 9, 13), (28, 11, 22), mt('wood', vox.rows(4)))
454+ finish('bench', cv)
455+
456+
457+def p_table():
458+ cv = Cv(32, 32, 24)
459+ cv.box((7, 9, 17), (25, 23, 19), mt('wood', vox.planks(4, 2)))
460+ cv.cyl((16, 16, 0), (16, 16, 17), 1.6, mt('wood_dark'))
461+ cv.cyl((16, 16, 0), (16, 16, 1), 6.0, mt('wood_dark'))
462+ for x in (5, 27):
463+ cv.cyl((x, 16, 0), (x, 16, 9), 3.0, mt('wood'))
464+ cv.cyl((x, 16, 9), (x, 16, 10), 3.4, mt('wood_dark'))
465+ finish('table', cv)
466+
467+
468+def p_signpost():
469+ cv = Cv(32, 32, 34)
470+ cv.box((15, 15, 0), (17, 17, 34), mt('wood_dark'))
471+ cv.box((17, 14, 22), (28, 18, 27), mt('wood', vox.rows(4)))
472+ cv.box((4, 14, 12), (15, 18, 17), mt('wood', vox.rows(4)))
473+ finish('signpost', cv)
474+
475+
476+def p_stall():
477+ cv = Cv(64, 32, 42)
478+ for x in (2, 59):
479+ for y in (2, 26):
480+ cv.box((x, y, 0), (x + 3, y + 3, 33), mt('wood_dark'))
481+ cv.box((5, 6, 10), (59, 24, 15), mt('wood', vox.planks(4, 2)))
482+ cv.box((12, 10, 15), (20, 20, 20), mt('cloth_cream', weave))
483+ cv.box((0, 0, 33), (64, 30, 36), mt('cloth_wine'))
484+ cream = mt('cloth_cream')
485+ for x in range(64):
486+ if (x // 8) % 2:
487+ cv.m.v[x, 0:30, 33:36] = cream
488+ finish('stall', cv)
489+
490+
491+def p_coalpile():
492+ cv = Cv(32, 32, 20)
493+ coal = mt('coal', coal_pat)
494+ cv.ell((16, 16, 0), (14, 12, 9), coal)
495+ cv.ell((9, 20, 0), (7, 6, 6), coal)
496+ cv.ell((23, 10, 0), (6, 6, 5), coal)
497+ finish('coalpile', cv)
498+
499+
500+def p_slag():
501+ cv = Cv(64, 64, 34)
502+ m = mt(SLAG, slag_pat)
503+ cv.ell((32, 32, 0), (28, 25, 15), m)
504+ cv.ell((14, 44, 0), (10, 9, 8), m)
505+ cv.ell((50, 14, 0), (9, 10, 8), m)
506+ finish('slag', cv)
507+
508+
509+def p_tub():
510+ cv = Cv(32, 32, 26)
511+ cv.box((5, 9, 6), (27, 23, 18), mt('slate'))
512+ cv.box((5, 9, 17), (27, 23, 19), mt('metal'))
513+ cv.box((7, 11, 19), (25, 21, 22), mt('coal', coal_pat))
514+ for x in (8, 24):
515+ for y in (11, 20):
516+ cv.cyl((x, y - 0.5, 5), (x, y + 1.5, 5), 3.0, mt('metal'))
517+ finish('tub', cv)
518+
519+
520+def p_flowers(i):
521+ rng = np.random.default_rng(3 + i)
522+ cv = Cv(32, 32, 6)
523+ cv.box((2, 2, 0), (30, 30, 4), mt('dirt', sprinkle(70 + i, 0.1, 1)))
524+ cols = [mt('cloth_wine'), mt('cloth_cream'), mt('window')] if i == 0 else [mt('cloth_navy'), mt('cloth_cream'), mt('cloth_wine')]
525+ leaf = mt('grass')
526+ for _ in range(70):
527+ x, y = rng.integers(3, 29, 2)
528+ cv.m.v[x, y, 4] = leaf
529+ for _ in range(26):
530+ x, y = rng.integers(3, 29, 2)
531+ cv.m.v[x, y, 4] = leaf
532+ cv.m.v[x, y, 5] = cols[rng.integers(3)]
533+ finish(f'flowers{i}', cv)
534+
535+
536+def p_bush(i):
537+ cv = Cv(32, 32, 24)
538+ leaf = mt('foliage' if i == 0 else 'foliage_dark', leaf_pat(130 + i))
539+ for x, y, z, r in ((16, 16, 9, 9), (10, 14, 7, 6), (22, 17, 7, 6), (15, 22, 6, 5)):
540+ cv.ell((x, y, z), (r, r, r * 0.8), leaf)
541+ finish(f'bush{i}', cv)
542+
543+
544+def p_rock(i):
545+ cv = Cv(32, 32, 16)
546+ m = mt('stone', rock_pat(140 + i))
547+ if i == 0:
548+ cv.ell((16, 16, 6), (10, 8, 6.5), m)
549+ else:
550+ cv.ell((12, 14, 5), (8, 7, 5.5), m)
551+ cv.ell((22, 20, 3.5), (6, 5, 3.5), m)
552+ finish(f'rock{i}', cv)
553+
554+
555+def p_grave():
556+ cv = Cv(32, 32, 22)
557+ cv.ell((16, 16, 0), (12, 9, 2.5), mt('mud', mud_pat(160)))
558+ cv.box((12, 13, 0), (20, 19, 4), mt('stone_dark'))
559+ head = mt('stone', cross_pat)
560+ cv.box((12, 14, 4), (20, 18, 15), head)
561+ cv.ell((16, 16, 15), (4, 2, 3.5), head)
562+ finish('grave', cv)
563+
564+
565+def p_campfire():
566+ cv = Cv(32, 32, 8)
567+ stone = mt('stone', rock_pat(150))
568+ cv.ell((16, 16, 0.5), (4, 4, 1), mt('coal'))
569+ for k in range(12):
570+ a = 2 * math.pi * k / 12
571+ cv.ell((16 + 9 * math.cos(a), 16 + 9 * math.sin(a), 1.5), (3.2, 2.8, 2.0), stone)
572+ cv.cyl((8, 12, 2.5), (24, 20, 2.5), 1.6, mt('bark'))
573+ cv.cyl((8, 20, 2.5), (24, 12, 2.5), 1.6, mt('bark'))
574+ finish('campfire', cv)
575+
576+
577+def p_flame(i):
578+ cv = Cv(32, 32, 22)
579+ ms = [mt([c] * 4, None, True) for c in ((255, 120, 30), (255, 170, 50), (255, 226, 120), (255, 250, 210))]
580+ gx, gy, gz = np.meshgrid(np.arange(32) + 0.5, np.arange(32) + 0.5, np.arange(22) + 0.5, indexing='ij')
581+ ph = 1.9 * i
582+ cxf = 16 + 0.7 * np.sin(gz * 0.5 + ph) * gz / 22
583+ cyf = 16 + 0.5 * np.cos(gz * 0.4 + ph) * gz / 22
584+ r = 5.6 * np.clip(1 - gz / 22, 0, 1) ** 0.55 * (1 + 0.2 * np.sin(gz * 1.1 + 2 * ph)) + 0.4
585+ d = np.hypot(gx - cxf, gy - cyf) / r
586+ v = cv.m.v
587+ v[d < 1] = ms[0]
588+ v[d < 0.65] = ms[1]
589+ v[d < 0.35] = ms[2]
590+ v[(d < 0.5) & (gz > 13)] = ms[3]
591+ finish(f'flame{i}', cv, outline=False)
592+
593+
594+def p_tent():
595+ cv = Cv(64, 32, 44)
596+ canvas = mt('canvas', vox.rows(6))
597+ cv.gable(4, 3, 60, 29, 0, 40, 'x', canvas)
598+ cv.m.v[26:38, 18:29, 0:15] = 0
599+ cv.m.v[26:38, 12:18, 0:15] = mt('cloth_black')
600+ cv.cap((4, 16, 41), (60, 16, 41), 0.9, mt('wood'))
601+ leather = mt('leather')
602+ cv.cap((20, 16, 40), (14, 1, 0), 0.5, leather)
603+ cv.cap((44, 16, 40), (50, 1, 0), 0.5, leather)
604+ finish('tent', cv)
605+
606+
607+def tree_cv():
608+ return Cv(128, 128, 176, (48, 48))
609+
610+
611+def p_oak(i):
612+ rng = np.random.default_rng(200 + i)
613+ cv = tree_cv()
614+ bark = mt('bark', bark_pat(210 + i))
615+ cv.cap((16, 16, 0), (16, 16, 62), 3.4, bark)
616+ for _ in range(5):
617+ a = rng.uniform(0, 2 * math.pi)
618+ cv.cap((16, 16, 48 + rng.uniform(0, 10)), (16 + 24 * math.cos(a), 16 + 24 * math.sin(a), 92 + rng.uniform(0, 14)), 2.0, bark)
619+ light = mt('foliage', leaf_pat(220 + i))
620+ dark = mt('foliage_dark', leaf_pat(230 + i))
621+ for _ in range(14 + 4 * i):
622+ a = rng.uniform(0, 2 * math.pi)
623+ r = 28 * math.sqrt(rng.uniform())
624+ rad = rng.uniform(12, 18)
625+ c = (16 + r * math.cos(a), 16 + r * math.sin(a), 102 + rng.normal(0, 12))
626+ cv.ell(c, (rad, rad, rad * 0.85), light if rng.random() < 0.6 else dark)
627+ finish(f'oak{i}', cv)
628+
629+
630+def p_birch():
631+ rng = np.random.default_rng(301)
632+ cv = tree_cv()
633+ cv.cap((16, 16, 0), (16, 16, 95), 2.3, mt(BIRCH, birch_pat))
634+ light = mt('foliage')
635+ dark = mt('foliage_dark')
636+ for _ in range(34):
637+ a = rng.uniform(0, 2 * math.pi)
638+ r = 22 * math.sqrt(rng.uniform())
639+ rad = rng.uniform(6, 10)
640+ c = (16 + r * math.cos(a), 16 + r * math.sin(a), 110 + rng.normal(0, 14))
641+ cv.ell(c, (rad, rad, rad * 1.1), light if rng.random() < 0.7 else dark)
642+ finish('birch', cv)
643+
644+
645+def p_pine():
646+ cv = tree_cv()
647+ cv.cap((16, 16, 0), (16, 16, 110), 2.6, mt('bark'))
648+ dark = mt('foliage_dark', leaf_pat(402))
649+ for t in range(8):
650+ r = 36 - 4.6 * t
651+ cv.ell((16, 16, 24 + 15 * t), (r, r, 5.5 + 0.3 * (7 - t)), dark)
652+ cv.cap((16, 16, 120), (16, 16, 148), 1.8, dark)
653+ finish('pine', cv)
654+
655+
656+def p_dead():
657+ rng = np.random.default_rng(501)
658+ cv = tree_cv()
659+ bark = mt('bark', bark_pat(502))
660+
661+ def br(p, d, L, r, depth):
662+ q = p + d * L
663+ cv.cap(p, q, r, bark)
664+ if depth > 0:
665+ for _ in range(int(rng.integers(2, 4))):
666+ nd = d + rng.normal(0, 0.8, 3)
667+ nd /= np.linalg.norm(nd)
668+ br(q, nd, L * 0.68, r * 0.7, depth - 1)
669+ br(np.array([16.0, 16.0, 0.0]), np.array([0.0, 0.0, 1.0]), 46, 3.0, 4)
670+ finish('dead', cv)
671+
672+
673+def small():
674+ n = 12
675+ yy, xx = np.mgrid[0:n, 0:n] + 0.5
676+ a = np.zeros((n, n))
677+ for dx, dy, r in ((-1.8, 0.8, 4.2), (1.6, -0.6, 4.6), (0.0, 2.2, 3.6), (0.0, -1.8, 3.2)):
678+ d = np.hypot(xx - n / 2 - dx, yy - n / 2 - dy) / r
679+ a = np.maximum(a, np.clip(1 - d, 0, 1) ** 0.6)
680+ g = (120 + 60 * a).astype(np.uint8)
681+ add('puff', Image.fromarray(np.dstack([g, g, g, (a * 230).astype(np.uint8)])), (n // 2, n // 2))
682+
683+ W, H = 96, 48
684+ yy, xx = np.mgrid[0:H, 0:W] + 0.5
685+ d = np.hypot((xx - W / 2) / (W / 2), (yy - H / 2) / (H / 2))
686+ al = np.clip(1 - d, 0, 1) ** 2
687+ rgba = np.dstack([np.full((H, W), 255.0), np.full((H, W), 236.0), np.full((H, W), 190.0), al * 255]).astype(np.uint8)
688+ add('light', Image.fromarray(rgba), (W // 2, H // 2))
689+
690+ e = np.zeros((1, 5, 4), np.uint8)
691+ e[0, 0] = e[0, 3] = (255, 214, 40, 255)
692+ add('eyes', Image.fromarray(e), (2, 0))
693+
694+
695+def props():
696+ p_crate()
697+ p_crates()
698+ p_barrel()
699+ p_barrels()
700+ p_sack()
701+ p_sacks()
702+ p_bale()
703+ p_haystack()
704+ p_logs()
705+ p_fences()
706+ p_lamp()
707+ p_well()
708+ p_bench()
709+ p_table()
710+ p_signpost()
711+ p_stall()
712+ p_coalpile()
713+ p_slag()
714+ p_tub()
715+ p_flowers(0)
716+ p_flowers(1)
717+ p_bush(0)
718+ p_bush(1)
719+ p_rock(0)
720+ p_rock(1)
721+ p_grave()
722+ p_campfire()
723+ for i in range(4):
724+ p_flame(i)
725+ p_tent()
726+ for i in range(3):
727+ p_oak(i)
728+ p_birch()
729+ p_pine()
730+ p_dead()
731+ small()
732+
733+
734+def save_scaled(img, path, k=2):
735+ bg = Image.new('RGBA', img.size, BG)
736+ bg.alpha_composite(img.convert('RGBA'))
737+ bg.resize((bg.width * k, bg.height * k), Image.NEAREST).save(path)
738+
739+
740+def tile_block(names):
741+ cv = Image.new('RGBA', (260, 150), BG)
742+ for s in range(7):
743+ for i in range(4):
744+ j = s - i
745+ if not 0 <= j < 4:
746+ continue
747+ img, org = RES[names[(i + j) % len(names)]]
748+ cv.alpha_composite(img, (130 + 32 * (i - j) - org[0], 8 + 16 * (i + j) - org[1]))
749+ return cv
750+
751+
752+def preview():
753+ os.makedirs(PREVIEW, exist_ok=True)
754+ items = list(RES.values())
755+ rows = [items[k:k + 9] for k in range(0, len(items), 9)]
756+ out, _, _, _ = vox.atlas(rows)
757+ save_scaled(out, os.path.join(PREVIEW, 'sheet.png'))
758+ fams = [
759+ ['grass0', 'grass1', 'grass2', 'grass3'],
760+ ['road0', 'road1', 'road2', 'road3'],
761+ ['cobble0', 'cobble1', 'cobble2', 'cobble3'],
762+ ['flag0', 'flag1', 'flag2', 'flag3'],
763+ ['soot0', 'soot1', 'soot2', 'soot3'],
764+ ['mud0', 'mud1'],
765+ ['farmland0', 'farmland1'],
766+ ['water0', 'water1'],
767+ ['planks'],
768+ ['rail_x'],
769+ ['rail_y'],
770+ ]
771+ per = 6
772+ sheet = Image.new('RGBA', (260 * per, 150 * ((len(fams) + per - 1) // per)), BG)
773+ for k, names in enumerate(fams):
774+ sheet.paste(tile_block(names), ((k % per) * 260, (k // per) * 150))
775+ save_scaled(sheet, os.path.join(PREVIEW, 'tiles4.png'))
776+
777+
778+def main():
779+ tiles()
780+ props()
781+ preview()
782+
783+
784+if __name__ == '__main__':
785+ main()
tools/gen_sprites.pyadded+14 -0
@@ -0,0 +1,14 @@
1+import json, glob, os
2+
3+root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
4+out = ['#![allow(dead_code)]', '', 'pub struct Spr {', ' pub path: &\'static str,', ' pub size: (f32, f32),', ' pub origin: (f32, f32),', ' pub foot: (i32, i32),', ' pub smoke: &\'static [(f32, f32)],', ' pub cell: (u32, u32),', ' pub grid: (u32, u32),', ' pub glow: Option<&\'static str>,', '}', '']
5+for f in sorted(glob.glob(os.path.join(root, 'tools/manifest/*.json'))):
6+ for name, e in sorted(json.load(open(f)).items()):
7+ w, h = e['size']
8+ ox, oy = e['origin']
9+ cell = e.get('cell') or [w, h]
10+ grid = e.get('grid') or [1, 1]
11+ sm = ', '.join(f'({dx:.1f}, {dy:.1f})' for dx, dy in e.get('smoke', []))
12+ glow = f'Some("gfx/{name}_e.png")' if e.get('glow') else 'None'
13+ out.append(f'pub const {name.upper()}: Spr = Spr {{ path: "gfx/{name}.png", size: ({w:.1f}, {h:.1f}), origin: ({ox:.1f}, {oy:.1f}), foot: ({e["foot"][0]}, {e["foot"][1]}), smoke: &[{sm}], cell: ({cell[0]}, {cell[1]}), grid: ({grid[0]}, {grid[1]}), glow: {glow} }};')
14+open(os.path.join(root, 'src/sprites.rs'), 'w').write('\n'.join(out) + '\n')
tools/manifest/buildings.jsonadded+432 -0
@@ -0,0 +1,432 @@
1+{
2+ "a_home": {
3+ "size": [
4+ 188,
5+ 190
6+ ],
7+ "origin": [
8+ 78,
9+ 108
10+ ],
11+ "foot": [
12+ 3,
13+ 2
14+ ],
15+ "smoke": [
16+ [
17+ 92,
18+ 168.0
19+ ]
20+ ],
21+ "cell": null,
22+ "grid": null,
23+ "glow": true
24+ },
25+ "a_post": {
26+ "size": [
27+ 188,
28+ 186
29+ ],
30+ "origin": [
31+ 78,
32+ 104
33+ ],
34+ "foot": [
35+ 3,
36+ 2
37+ ],
38+ "smoke": [
39+ [
40+ 96,
41+ 162.0
42+ ]
43+ ],
44+ "cell": null,
45+ "grid": null,
46+ "glow": true
47+ },
48+ "a_shop": {
49+ "size": [
50+ 218,
51+ 195
52+ ],
53+ "origin": [
54+ 77,
55+ 97
56+ ],
57+ "foot": [
58+ 4,
59+ 2
60+ ],
61+ "smoke": [
62+ [
63+ 164,
64+ 112.0
65+ ]
66+ ],
67+ "cell": null,
68+ "grid": null,
69+ "glow": true
70+ },
71+ "a_inn": {
72+ "size": [
73+ 220,
74+ 273
75+ ],
76+ "origin": [
77+ 78,
78+ 175
79+ ],
80+ "foot": [
81+ 4,
82+ 2
83+ ],
84+ "smoke": [
85+ [
86+ -16,
87+ 338.0
88+ ],
89+ [
90+ 144,
91+ 258.0
92+ ]
93+ ],
94+ "cell": null,
95+ "grid": null,
96+ "glow": true
97+ },
98+ "a_school": {
99+ "size": [
100+ 188,
101+ 188
102+ ],
103+ "origin": [
104+ 78,
105+ 106
106+ ],
107+ "foot": [
108+ 3,
109+ 2
110+ ],
111+ "smoke": [],
112+ "cell": null,
113+ "grid": null,
114+ "glow": true
115+ },
116+ "a_cottage1": {
117+ "size": [
118+ 186,
119+ 200
120+ ],
121+ "origin": [
122+ 77,
123+ 118
124+ ],
125+ "foot": [
126+ 3,
127+ 2
128+ ],
129+ "smoke": [
130+ [
131+ 68,
132+ 224.0
133+ ]
134+ ],
135+ "cell": null,
136+ "grid": null,
137+ "glow": true
138+ },
139+ "a_cottage2": {
140+ "size": [
141+ 188,
142+ 197
143+ ],
144+ "origin": [
145+ 78,
146+ 115
147+ ],
148+ "foot": [
149+ 3,
150+ 2
151+ ],
152+ "smoke": [
153+ [
154+ -32,
155+ 218.0
156+ ]
157+ ],
158+ "cell": null,
159+ "grid": null,
160+ "glow": true
161+ },
162+ "a_barn": {
163+ "size": [
164+ 156,
165+ 204
166+ ],
167+ "origin": [
168+ 78,
169+ 138
170+ ],
171+ "foot": [
172+ 2,
173+ 2
174+ ],
175+ "smoke": [],
176+ "cell": null,
177+ "grid": null,
178+ "glow": false
179+ },
180+ "m_mill": {
181+ "size": [
182+ 324,
183+ 420
184+ ],
185+ "origin": [
186+ 109,
187+ 274
188+ ],
189+ "foot": [
190+ 6,
191+ 3
192+ ],
193+ "smoke": [
194+ [
195+ 36,
196+ 534.0
197+ ]
198+ ],
199+ "cell": null,
200+ "grid": null,
201+ "glow": true
202+ },
203+ "m_terrace": {
204+ "size": [
205+ 220,
206+ 255
207+ ],
208+ "origin": [
209+ 78,
210+ 157
211+ ],
212+ "foot": [
213+ 4,
214+ 2
215+ ],
216+ "smoke": [
217+ [
218+ -32,
219+ 302.0
220+ ],
221+ [
222+ 32,
223+ 270.0
224+ ],
225+ [
226+ 96,
227+ 238.0
228+ ],
229+ [
230+ 160,
231+ 206.0
232+ ]
233+ ],
234+ "cell": null,
235+ "grid": null,
236+ "glow": true
237+ },
238+ "m_shop": {
239+ "size": [
240+ 186,
241+ 251
242+ ],
243+ "origin": [
244+ 77,
245+ 169
246+ ],
247+ "foot": [
248+ 3,
249+ 2
250+ ],
251+ "smoke": [
252+ [
253+ 100,
254+ 288.0
255+ ]
256+ ],
257+ "cell": null,
258+ "grid": null,
259+ "glow": true
260+ },
261+ "m_inn": {
262+ "size": [
263+ 220,
264+ 259
265+ ],
266+ "origin": [
267+ 78,
268+ 161
269+ ],
270+ "foot": [
271+ 4,
272+ 2
273+ ],
274+ "smoke": [
275+ [
276+ -24,
277+ 310.0
278+ ],
279+ [
280+ 152,
281+ 222.0
282+ ]
283+ ],
284+ "cell": null,
285+ "grid": null,
286+ "glow": true
287+ },
288+ "m_warehouse": {
289+ "size": [
290+ 186,
291+ 289
292+ ],
293+ "origin": [
294+ 77,
295+ 207
296+ ],
297+ "foot": [
298+ 3,
299+ 2
300+ ],
301+ "smoke": [],
302+ "cell": null,
303+ "grid": null,
304+ "glow": true
305+ },
306+ "c_headframe": {
307+ "size": [
308+ 148,
309+ 285
310+ ],
311+ "origin": [
312+ 74,
313+ 199
314+ ],
315+ "foot": [
316+ 3,
317+ 3
318+ ],
319+ "smoke": [],
320+ "cell": null,
321+ "grid": null,
322+ "glow": false
323+ },
324+ "c_engine": {
325+ "size": [
326+ 191,
327+ 302
328+ ],
329+ "origin": [
330+ 77,
331+ 220
332+ ],
333+ "foot": [
334+ 3,
335+ 2
336+ ],
337+ "smoke": [
338+ [
339+ 192,
340+ 424.0
341+ ]
342+ ],
343+ "cell": null,
344+ "grid": null,
345+ "glow": false
346+ },
347+ "c_row": {
348+ "size": [
349+ 218,
350+ 231
351+ ],
352+ "origin": [
353+ 77,
354+ 133
355+ ],
356+ "foot": [
357+ 4,
358+ 2
359+ ],
360+ "smoke": [
361+ [
362+ -32,
363+ 254.0
364+ ],
365+ [
366+ 32,
367+ 222.0
368+ ],
369+ [
370+ 96,
371+ 190.0
372+ ],
373+ [
374+ 160,
375+ 158.0
376+ ]
377+ ],
378+ "cell": null,
379+ "grid": null,
380+ "glow": false
381+ },
382+ "c_pawn": {
383+ "size": [
384+ 186,
385+ 185
386+ ],
387+ "origin": [
388+ 77,
389+ 103
390+ ],
391+ "foot": [
392+ 3,
393+ 2
394+ ],
395+ "smoke": [
396+ [
397+ 96,
398+ 158.0
399+ ]
400+ ],
401+ "cell": null,
402+ "grid": null,
403+ "glow": false
404+ },
405+ "c_inn": {
406+ "size": [
407+ 220,
408+ 249
409+ ],
410+ "origin": [
411+ 78,
412+ 151
413+ ],
414+ "foot": [
415+ 4,
416+ 2
417+ ],
418+ "smoke": [
419+ [
420+ -16,
421+ 290.0
422+ ],
423+ [
424+ 144,
425+ 210.0
426+ ]
427+ ],
428+ "cell": null,
429+ "grid": null,
430+ "glow": true
431+ }
432+}
\ No newline at end of file
tools/manifest/chars.jsonadded+338 -0
@@ -0,0 +1,338 @@
1+{
2+ "player": {
3+ "size": [
4+ 414,
5+ 1608
6+ ],
7+ "origin": [
8+ 23,
9+ 55
10+ ],
11+ "foot": [
12+ 1,
13+ 1
14+ ],
15+ "smoke": [],
16+ "cell": [
17+ 46,
18+ 67
19+ ],
20+ "grid": [
21+ 9,
22+ 24
23+ ],
24+ "glow": false
25+ },
26+ "gent": {
27+ "size": [
28+ 414,
29+ 1728
30+ ],
31+ "origin": [
32+ 23,
33+ 60
34+ ],
35+ "foot": [
36+ 1,
37+ 1
38+ ],
39+ "smoke": [],
40+ "cell": [
41+ 46,
42+ 72
43+ ],
44+ "grid": [
45+ 9,
46+ 24
47+ ],
48+ "glow": false
49+ },
50+ "grocer": {
51+ "size": [
52+ 414,
53+ 1560
54+ ],
55+ "origin": [
56+ 23,
57+ 53
58+ ],
59+ "foot": [
60+ 1,
61+ 1
62+ ],
63+ "smoke": [],
64+ "cell": [
65+ 46,
66+ 65
67+ ],
68+ "grid": [
69+ 9,
70+ 24
71+ ],
72+ "glow": false
73+ },
74+ "woman": {
75+ "size": [
76+ 396,
77+ 1488
78+ ],
79+ "origin": [
80+ 22,
81+ 53
82+ ],
83+ "foot": [
84+ 1,
85+ 1
86+ ],
87+ "smoke": [],
88+ "cell": [
89+ 44,
90+ 62
91+ ],
92+ "grid": [
93+ 9,
94+ 24
95+ ],
96+ "glow": false
97+ },
98+ "barmaid": {
99+ "size": [
100+ 396,
101+ 1488
102+ ],
103+ "origin": [
104+ 22,
105+ 53
106+ ],
107+ "foot": [
108+ 1,
109+ 1
110+ ],
111+ "smoke": [],
112+ "cell": [
113+ 44,
114+ 62
115+ ],
116+ "grid": [
117+ 9,
118+ 24
119+ ],
120+ "glow": false
121+ },
122+ "teacher": {
123+ "size": [
124+ 414,
125+ 1560
126+ ],
127+ "origin": [
128+ 23,
129+ 53
130+ ],
131+ "foot": [
132+ 1,
133+ 1
134+ ],
135+ "smoke": [],
136+ "cell": [
137+ 46,
138+ 65
139+ ],
140+ "grid": [
141+ 9,
142+ 24
143+ ],
144+ "glow": false
145+ },
146+ "old": {
147+ "size": [
148+ 414,
149+ 1560
150+ ],
151+ "origin": [
152+ 23,
153+ 55
154+ ],
155+ "foot": [
156+ 1,
157+ 1
158+ ],
159+ "smoke": [],
160+ "cell": [
161+ 46,
162+ 65
163+ ],
164+ "grid": [
165+ 9,
166+ 24
167+ ],
168+ "glow": false
169+ },
170+ "worker": {
171+ "size": [
172+ 414,
173+ 1608
174+ ],
175+ "origin": [
176+ 23,
177+ 55
178+ ],
179+ "foot": [
180+ 1,
181+ 1
182+ ],
183+ "smoke": [],
184+ "cell": [
185+ 46,
186+ 67
187+ ],
188+ "grid": [
189+ 9,
190+ 24
191+ ],
192+ "glow": false
193+ },
194+ "miner": {
195+ "size": [
196+ 414,
197+ 1560
198+ ],
199+ "origin": [
200+ 23,
201+ 53
202+ ],
203+ "foot": [
204+ 1,
205+ 1
206+ ],
207+ "smoke": [],
208+ "cell": [
209+ 46,
210+ 65
211+ ],
212+ "grid": [
213+ 9,
214+ 24
215+ ],
216+ "glow": false
217+ },
218+ "peddler": {
219+ "size": [
220+ 414,
221+ 1560
222+ ],
223+ "origin": [
224+ 23,
225+ 53
226+ ],
227+ "foot": [
228+ 1,
229+ 1
230+ ],
231+ "smoke": [],
232+ "cell": [
233+ 46,
234+ 65
235+ ],
236+ "grid": [
237+ 9,
238+ 24
239+ ],
240+ "glow": false
241+ },
242+ "bandit": {
243+ "size": [
244+ 414,
245+ 1560
246+ ],
247+ "origin": [
248+ 23,
249+ 53
250+ ],
251+ "foot": [
252+ 1,
253+ 1
254+ ],
255+ "smoke": [],
256+ "cell": [
257+ 46,
258+ 65
259+ ],
260+ "grid": [
261+ 9,
262+ 24
263+ ],
264+ "glow": false
265+ },
266+ "boy": {
267+ "size": [
268+ 288,
269+ 1104
270+ ],
271+ "origin": [
272+ 16,
273+ 37
274+ ],
275+ "foot": [
276+ 1,
277+ 1
278+ ],
279+ "smoke": [],
280+ "cell": [
281+ 32,
282+ 46
283+ ],
284+ "grid": [
285+ 9,
286+ 24
287+ ],
288+ "glow": false
289+ },
290+ "wolf": {
291+ "size": [
292+ 546,
293+ 432
294+ ],
295+ "origin": [
296+ 39,
297+ 40
298+ ],
299+ "foot": [
300+ 1,
301+ 1
302+ ],
303+ "smoke": [],
304+ "cell": [
305+ 78,
306+ 54
307+ ],
308+ "grid": [
309+ 7,
310+ 8
311+ ],
312+ "glow": false
313+ },
314+ "cart": {
315+ "size": [
316+ 248,
317+ 816
318+ ],
319+ "origin": [
320+ 31,
321+ 41
322+ ],
323+ "foot": [
324+ 1,
325+ 1
326+ ],
327+ "smoke": [],
328+ "cell": [
329+ 62,
330+ 51
331+ ],
332+ "grid": [
333+ 4,
334+ 16
335+ ],
336+ "glow": false
337+ }
338+}
\ No newline at end of file
tools/manifest/env.jsonadded+1280 -0
@@ -0,0 +1,1280 @@
1+{
2+ "grass0": {
3+ "size": [
4+ 64,
5+ 33
6+ ],
7+ "origin": [
8+ 32,
9+ 1
10+ ],
11+ "foot": [
12+ 1,
13+ 1
14+ ],
15+ "smoke": [],
16+ "cell": null,
17+ "grid": null,
18+ "glow": false
19+ },
20+ "road0": {
21+ "size": [
22+ 64,
23+ 33
24+ ],
25+ "origin": [
26+ 32,
27+ 1
28+ ],
29+ "foot": [
30+ 1,
31+ 1
32+ ],
33+ "smoke": [],
34+ "cell": null,
35+ "grid": null,
36+ "glow": false
37+ },
38+ "soot0": {
39+ "size": [
40+ 64,
41+ 33
42+ ],
43+ "origin": [
44+ 32,
45+ 1
46+ ],
47+ "foot": [
48+ 1,
49+ 1
50+ ],
51+ "smoke": [],
52+ "cell": null,
53+ "grid": null,
54+ "glow": false
55+ },
56+ "grass1": {
57+ "size": [
58+ 64,
59+ 33
60+ ],
61+ "origin": [
62+ 32,
63+ 1
64+ ],
65+ "foot": [
66+ 1,
67+ 1
68+ ],
69+ "smoke": [],
70+ "cell": null,
71+ "grid": null,
72+ "glow": false
73+ },
74+ "road1": {
75+ "size": [
76+ 64,
77+ 33
78+ ],
79+ "origin": [
80+ 32,
81+ 1
82+ ],
83+ "foot": [
84+ 1,
85+ 1
86+ ],
87+ "smoke": [],
88+ "cell": null,
89+ "grid": null,
90+ "glow": false
91+ },
92+ "soot1": {
93+ "size": [
94+ 64,
95+ 33
96+ ],
97+ "origin": [
98+ 32,
99+ 1
100+ ],
101+ "foot": [
102+ 1,
103+ 1
104+ ],
105+ "smoke": [],
106+ "cell": null,
107+ "grid": null,
108+ "glow": false
109+ },
110+ "grass2": {
111+ "size": [
112+ 64,
113+ 33
114+ ],
115+ "origin": [
116+ 32,
117+ 1
118+ ],
119+ "foot": [
120+ 1,
121+ 1
122+ ],
123+ "smoke": [],
124+ "cell": null,
125+ "grid": null,
126+ "glow": false
127+ },
128+ "road2": {
129+ "size": [
130+ 64,
131+ 33
132+ ],
133+ "origin": [
134+ 32,
135+ 1
136+ ],
137+ "foot": [
138+ 1,
139+ 1
140+ ],
141+ "smoke": [],
142+ "cell": null,
143+ "grid": null,
144+ "glow": false
145+ },
146+ "soot2": {
147+ "size": [
148+ 64,
149+ 33
150+ ],
151+ "origin": [
152+ 32,
153+ 1
154+ ],
155+ "foot": [
156+ 1,
157+ 1
158+ ],
159+ "smoke": [],
160+ "cell": null,
161+ "grid": null,
162+ "glow": false
163+ },
164+ "grass3": {
165+ "size": [
166+ 64,
167+ 33
168+ ],
169+ "origin": [
170+ 32,
171+ 1
172+ ],
173+ "foot": [
174+ 1,
175+ 1
176+ ],
177+ "smoke": [],
178+ "cell": null,
179+ "grid": null,
180+ "glow": false
181+ },
182+ "road3": {
183+ "size": [
184+ 64,
185+ 33
186+ ],
187+ "origin": [
188+ 32,
189+ 1
190+ ],
191+ "foot": [
192+ 1,
193+ 1
194+ ],
195+ "smoke": [],
196+ "cell": null,
197+ "grid": null,
198+ "glow": false
199+ },
200+ "soot3": {
201+ "size": [
202+ 64,
203+ 33
204+ ],
205+ "origin": [
206+ 32,
207+ 1
208+ ],
209+ "foot": [
210+ 1,
211+ 1
212+ ],
213+ "smoke": [],
214+ "cell": null,
215+ "grid": null,
216+ "glow": false
217+ },
218+ "cobble0": {
219+ "size": [
220+ 64,
221+ 33
222+ ],
223+ "origin": [
224+ 32,
225+ 1
226+ ],
227+ "foot": [
228+ 1,
229+ 1
230+ ],
231+ "smoke": [],
232+ "cell": null,
233+ "grid": null,
234+ "glow": false
235+ },
236+ "cobble1": {
237+ "size": [
238+ 64,
239+ 33
240+ ],
241+ "origin": [
242+ 32,
243+ 1
244+ ],
245+ "foot": [
246+ 1,
247+ 1
248+ ],
249+ "smoke": [],
250+ "cell": null,
251+ "grid": null,
252+ "glow": false
253+ },
254+ "cobble2": {
255+ "size": [
256+ 64,
257+ 33
258+ ],
259+ "origin": [
260+ 32,
261+ 1
262+ ],
263+ "foot": [
264+ 1,
265+ 1
266+ ],
267+ "smoke": [],
268+ "cell": null,
269+ "grid": null,
270+ "glow": false
271+ },
272+ "cobble3": {
273+ "size": [
274+ 64,
275+ 33
276+ ],
277+ "origin": [
278+ 32,
279+ 1
280+ ],
281+ "foot": [
282+ 1,
283+ 1
284+ ],
285+ "smoke": [],
286+ "cell": null,
287+ "grid": null,
288+ "glow": false
289+ },
290+ "flag0": {
291+ "size": [
292+ 64,
293+ 33
294+ ],
295+ "origin": [
296+ 32,
297+ 1
298+ ],
299+ "foot": [
300+ 1,
301+ 1
302+ ],
303+ "smoke": [],
304+ "cell": null,
305+ "grid": null,
306+ "glow": false
307+ },
308+ "flag1": {
309+ "size": [
310+ 64,
311+ 33
312+ ],
313+ "origin": [
314+ 32,
315+ 1
316+ ],
317+ "foot": [
318+ 1,
319+ 1
320+ ],
321+ "smoke": [],
322+ "cell": null,
323+ "grid": null,
324+ "glow": false
325+ },
326+ "flag2": {
327+ "size": [
328+ 64,
329+ 33
330+ ],
331+ "origin": [
332+ 32,
333+ 1
334+ ],
335+ "foot": [
336+ 1,
337+ 1
338+ ],
339+ "smoke": [],
340+ "cell": null,
341+ "grid": null,
342+ "glow": false
343+ },
344+ "flag3": {
345+ "size": [
346+ 64,
347+ 33
348+ ],
349+ "origin": [
350+ 32,
351+ 1
352+ ],
353+ "foot": [
354+ 1,
355+ 1
356+ ],
357+ "smoke": [],
358+ "cell": null,
359+ "grid": null,
360+ "glow": false
361+ },
362+ "mud0": {
363+ "size": [
364+ 64,
365+ 33
366+ ],
367+ "origin": [
368+ 32,
369+ 1
370+ ],
371+ "foot": [
372+ 1,
373+ 1
374+ ],
375+ "smoke": [],
376+ "cell": null,
377+ "grid": null,
378+ "glow": false
379+ },
380+ "mud1": {
381+ "size": [
382+ 64,
383+ 33
384+ ],
385+ "origin": [
386+ 32,
387+ 1
388+ ],
389+ "foot": [
390+ 1,
391+ 1
392+ ],
393+ "smoke": [],
394+ "cell": null,
395+ "grid": null,
396+ "glow": false
397+ },
398+ "farmland0": {
399+ "size": [
400+ 64,
401+ 34
402+ ],
403+ "origin": [
404+ 32,
405+ 2
406+ ],
407+ "foot": [
408+ 1,
409+ 1
410+ ],
411+ "smoke": [],
412+ "cell": null,
413+ "grid": null,
414+ "glow": false
415+ },
416+ "farmland1": {
417+ "size": [
418+ 64,
419+ 34
420+ ],
421+ "origin": [
422+ 32,
423+ 2
424+ ],
425+ "foot": [
426+ 1,
427+ 1
428+ ],
429+ "smoke": [],
430+ "cell": null,
431+ "grid": null,
432+ "glow": false
433+ },
434+ "water0": {
435+ "size": [
436+ 64,
437+ 33
438+ ],
439+ "origin": [
440+ 32,
441+ 1
442+ ],
443+ "foot": [
444+ 1,
445+ 1
446+ ],
447+ "smoke": [],
448+ "cell": null,
449+ "grid": null,
450+ "glow": false
451+ },
452+ "water1": {
453+ "size": [
454+ 64,
455+ 33
456+ ],
457+ "origin": [
458+ 32,
459+ 1
460+ ],
461+ "foot": [
462+ 1,
463+ 1
464+ ],
465+ "smoke": [],
466+ "cell": null,
467+ "grid": null,
468+ "glow": false
469+ },
470+ "planks": {
471+ "size": [
472+ 64,
473+ 33
474+ ],
475+ "origin": [
476+ 32,
477+ 1
478+ ],
479+ "foot": [
480+ 1,
481+ 1
482+ ],
483+ "smoke": [],
484+ "cell": null,
485+ "grid": null,
486+ "glow": false
487+ },
488+ "rail_x": {
489+ "size": [
490+ 64,
491+ 33
492+ ],
493+ "origin": [
494+ 32,
495+ 1
496+ ],
497+ "foot": [
498+ 1,
499+ 1
500+ ],
501+ "smoke": [],
502+ "cell": null,
503+ "grid": null,
504+ "glow": false
505+ },
506+ "rail_y": {
507+ "size": [
508+ 64,
509+ 33
510+ ],
511+ "origin": [
512+ 32,
513+ 1
514+ ],
515+ "foot": [
516+ 1,
517+ 1
518+ ],
519+ "smoke": [],
520+ "cell": null,
521+ "grid": null,
522+ "glow": false
523+ },
524+ "crate": {
525+ "size": [
526+ 48,
527+ 40
528+ ],
529+ "origin": [
530+ 24,
531+ 11
532+ ],
533+ "foot": [
534+ 1,
535+ 1
536+ ],
537+ "smoke": [],
538+ "cell": null,
539+ "grid": null,
540+ "glow": false
541+ },
542+ "crates": {
543+ "size": [
544+ 36,
545+ 50
546+ ],
547+ "origin": [
548+ 18,
549+ 19
550+ ],
551+ "foot": [
552+ 1,
553+ 1
554+ ],
555+ "smoke": [],
556+ "cell": null,
557+ "grid": null,
558+ "glow": false
559+ },
560+ "barrel": {
561+ "size": [
562+ 26,
563+ 30
564+ ],
565+ "origin": [
566+ 13,
567+ 11
568+ ],
569+ "foot": [
570+ 1,
571+ 1
572+ ],
573+ "smoke": [],
574+ "cell": null,
575+ "grid": null,
576+ "glow": false
577+ },
578+ "barrels": {
579+ "size": [
580+ 46,
581+ 41
582+ ],
583+ "origin": [
584+ 20,
585+ 18
586+ ],
587+ "foot": [
588+ 1,
589+ 1
590+ ],
591+ "smoke": [],
592+ "cell": null,
593+ "grid": null,
594+ "glow": false
595+ },
596+ "sack": {
597+ "size": [
598+ 26,
599+ 23
600+ ],
601+ "origin": [
602+ 13,
603+ 3
604+ ],
605+ "foot": [
606+ 1,
607+ 1
608+ ],
609+ "smoke": [],
610+ "cell": null,
611+ "grid": null,
612+ "glow": false
613+ },
614+ "sacks": {
615+ "size": [
616+ 43,
617+ 32
618+ ],
619+ "origin": [
620+ 18,
621+ 10
622+ ],
623+ "foot": [
624+ 1,
625+ 1
626+ ],
627+ "smoke": [],
628+ "cell": null,
629+ "grid": null,
630+ "glow": false
631+ },
632+ "bale": {
633+ "size": [
634+ 48,
635+ 41
636+ ],
637+ "origin": [
638+ 24,
639+ 12
640+ ],
641+ "foot": [
642+ 1,
643+ 1
644+ ],
645+ "smoke": [],
646+ "cell": null,
647+ "grid": null,
648+ "glow": false
649+ },
650+ "haystack": {
651+ "size": [
652+ 44,
653+ 31
654+ ],
655+ "origin": [
656+ 22,
657+ 3
658+ ],
659+ "foot": [
660+ 1,
661+ 1
662+ ],
663+ "smoke": [],
664+ "cell": null,
665+ "grid": null,
666+ "glow": false
667+ },
668+ "logs": {
669+ "size": [
670+ 59,
671+ 42
672+ ],
673+ "origin": [
674+ 30,
675+ 13
676+ ],
677+ "foot": [
678+ 1,
679+ 1
680+ ],
681+ "smoke": [],
682+ "cell": null,
683+ "grid": null,
684+ "glow": false
685+ },
686+ "fence_x": {
687+ "size": [
688+ 39,
689+ 35
690+ ],
691+ "origin": [
692+ 33,
693+ 8
694+ ],
695+ "foot": [
696+ 1,
697+ 1
698+ ],
699+ "smoke": [],
700+ "cell": null,
701+ "grid": null,
702+ "glow": false
703+ },
704+ "fence_y": {
705+ "size": [
706+ 39,
707+ 35
708+ ],
709+ "origin": [
710+ 6,
711+ 8
712+ ],
713+ "foot": [
714+ 1,
715+ 1
716+ ],
717+ "smoke": [],
718+ "cell": null,
719+ "grid": null,
720+ "glow": false
721+ },
722+ "lamp": {
723+ "size": [
724+ 32,
725+ 104
726+ ],
727+ "origin": [
728+ 16,
729+ 83
730+ ],
731+ "foot": [
732+ 1,
733+ 1
734+ ],
735+ "smoke": [],
736+ "cell": null,
737+ "grid": null,
738+ "glow": true
739+ },
740+ "well": {
741+ "size": [
742+ 48,
743+ 56
744+ ],
745+ "origin": [
746+ 24,
747+ 31
748+ ],
749+ "foot": [
750+ 1,
751+ 1
752+ ],
753+ "smoke": [],
754+ "cell": null,
755+ "grid": null,
756+ "glow": false
757+ },
758+ "bench": {
759+ "size": [
760+ 40,
761+ 43
762+ ],
763+ "origin": [
764+ 19,
765+ 17
766+ ],
767+ "foot": [
768+ 1,
769+ 1
770+ ],
771+ "smoke": [],
772+ "cell": null,
773+ "grid": null,
774+ "glow": false
775+ },
776+ "table": {
777+ "size": [
778+ 36,
779+ 39
780+ ],
781+ "origin": [
782+ 18,
783+ 13
784+ ],
785+ "foot": [
786+ 1,
787+ 1
788+ ],
789+ "smoke": [],
790+ "cell": null,
791+ "grid": null,
792+ "glow": false
793+ },
794+ "signpost": {
795+ "size": [
796+ 32,
797+ 40
798+ ],
799+ "origin": [
800+ 16,
801+ 21
802+ ],
803+ "foot": [
804+ 1,
805+ 1
806+ ],
807+ "smoke": [],
808+ "cell": null,
809+ "grid": null,
810+ "glow": false
811+ },
812+ "stall": {
813+ "size": [
814+ 97,
815+ 85
816+ ],
817+ "origin": [
818+ 32,
819+ 38
820+ ],
821+ "foot": [
822+ 1,
823+ 1
824+ ],
825+ "smoke": [],
826+ "cell": null,
827+ "grid": null,
828+ "glow": false
829+ },
830+ "coalpile": {
831+ "size": [
832+ 47,
833+ 26
834+ ],
835+ "origin": [
836+ 23,
837+ -1
838+ ],
839+ "foot": [
840+ 1,
841+ 1
842+ ],
843+ "smoke": [],
844+ "cell": null,
845+ "grid": null,
846+ "glow": false
847+ },
848+ "slag": {
849+ "size": [
850+ 98,
851+ 48
852+ ],
853+ "origin": [
854+ 46,
855+ -5
856+ ],
857+ "foot": [
858+ 1,
859+ 1
860+ ],
861+ "smoke": [],
862+ "cell": null,
863+ "grid": null,
864+ "glow": false
865+ },
866+ "tub": {
867+ "size": [
868+ 40,
869+ 39
870+ ],
871+ "origin": [
872+ 20,
873+ 15
874+ ],
875+ "foot": [
876+ 1,
877+ 1
878+ ],
879+ "smoke": [],
880+ "cell": null,
881+ "grid": null,
882+ "glow": false
883+ },
884+ "flowers0": {
885+ "size": [
886+ 60,
887+ 36
888+ ],
889+ "origin": [
890+ 30,
891+ 4
892+ ],
893+ "foot": [
894+ 1,
895+ 1
896+ ],
897+ "smoke": [],
898+ "cell": null,
899+ "grid": null,
900+ "glow": false
901+ },
902+ "flowers1": {
903+ "size": [
904+ 60,
905+ 36
906+ ],
907+ "origin": [
908+ 30,
909+ 4
910+ ],
911+ "foot": [
912+ 1,
913+ 1
914+ ],
915+ "smoke": [],
916+ "cell": null,
917+ "grid": null,
918+ "glow": false
919+ },
920+ "bush0": {
921+ "size": [
922+ 33,
923+ 26
924+ ],
925+ "origin": [
926+ 17,
927+ 5
928+ ],
929+ "foot": [
930+ 1,
931+ 1
932+ ],
933+ "smoke": [],
934+ "cell": null,
935+ "grid": null,
936+ "glow": false
937+ },
938+ "bush1": {
939+ "size": [
940+ 33,
941+ 26
942+ ],
943+ "origin": [
944+ 17,
945+ 5
946+ ],
947+ "foot": [
948+ 1,
949+ 1
950+ ],
951+ "smoke": [],
952+ "cell": null,
953+ "grid": null,
954+ "glow": false
955+ },
956+ "rock0": {
957+ "size": [
958+ 30,
959+ 24
960+ ],
961+ "origin": [
962+ 15,
963+ 2
964+ ],
965+ "foot": [
966+ 1,
967+ 1
968+ ],
969+ "smoke": [],
970+ "cell": null,
971+ "grid": null,
972+ "glow": false
973+ },
974+ "rock1": {
975+ "size": [
976+ 27,
977+ 27
978+ ],
979+ "origin": [
980+ 15,
981+ 2
982+ ],
983+ "foot": [
984+ 1,
985+ 1
986+ ],
987+ "smoke": [],
988+ "cell": null,
989+ "grid": null,
990+ "glow": false
991+ },
992+ "grave": {
993+ "size": [
994+ 34,
995+ 31
996+ ],
997+ "origin": [
998+ 17,
999+ 6
1000+ ],
1001+ "foot": [
1002+ 1,
1003+ 1
1004+ ],
1005+ "smoke": [],
1006+ "cell": null,
1007+ "grid": null,
1008+ "glow": false
1009+ },
1010+ "campfire": {
1011+ "size": [
1012+ 38,
1013+ 23
1014+ ],
1015+ "origin": [
1016+ 19,
1017+ -3
1018+ ],
1019+ "foot": [
1020+ 1,
1021+ 1
1022+ ],
1023+ "smoke": [],
1024+ "cell": null,
1025+ "grid": null,
1026+ "glow": false
1027+ },
1028+ "flame0": {
1029+ "size": [
1030+ 22,
1031+ 30
1032+ ],
1033+ "origin": [
1034+ 11,
1035+ 8
1036+ ],
1037+ "foot": [
1038+ 1,
1039+ 1
1040+ ],
1041+ "smoke": [],
1042+ "cell": null,
1043+ "grid": null,
1044+ "glow": true
1045+ },
1046+ "flame1": {
1047+ "size": [
1048+ 22,
1049+ 28
1050+ ],
1051+ "origin": [
1052+ 11,
1053+ 8
1054+ ],
1055+ "foot": [
1056+ 1,
1057+ 1
1058+ ],
1059+ "smoke": [],
1060+ "cell": null,
1061+ "grid": null,
1062+ "glow": true
1063+ },
1064+ "flame2": {
1065+ "size": [
1066+ 22,
1067+ 29
1068+ ],
1069+ "origin": [
1070+ 11,
1071+ 7
1072+ ],
1073+ "foot": [
1074+ 1,
1075+ 1
1076+ ],
1077+ "smoke": [],
1078+ "cell": null,
1079+ "grid": null,
1080+ "glow": true
1081+ },
1082+ "flame3": {
1083+ "size": [
1084+ 22,
1085+ 29
1086+ ],
1087+ "origin": [
1088+ 11,
1089+ 8
1090+ ],
1091+ "foot": [
1092+ 1,
1093+ 1
1094+ ],
1095+ "smoke": [],
1096+ "cell": null,
1097+ "grid": null,
1098+ "glow": true
1099+ },
1100+ "tent": {
1101+ "size": [
1102+ 86,
1103+ 81
1104+ ],
1105+ "origin": [
1106+ 27,
1107+ 35
1108+ ],
1109+ "foot": [
1110+ 1,
1111+ 1
1112+ ],
1113+ "smoke": [],
1114+ "cell": null,
1115+ "grid": null,
1116+ "glow": false
1117+ },
1118+ "oak0": {
1119+ "size": [
1120+ 101,
1121+ 147
1122+ ],
1123+ "origin": [
1124+ 55,
1125+ 127
1126+ ],
1127+ "foot": [
1128+ 1,
1129+ 1
1130+ ],
1131+ "smoke": [],
1132+ "cell": null,
1133+ "grid": null,
1134+ "glow": false
1135+ },
1136+ "oak1": {
1137+ "size": [
1138+ 108,
1139+ 164
1140+ ],
1141+ "origin": [
1142+ 55,
1143+ 144
1144+ ],
1145+ "foot": [
1146+ 1,
1147+ 1
1148+ ],
1149+ "smoke": [],
1150+ "cell": null,
1151+ "grid": null,
1152+ "glow": false
1153+ },
1154+ "oak2": {
1155+ "size": [
1156+ 107,
1157+ 175
1158+ ],
1159+ "origin": [
1160+ 49,
1161+ 155
1162+ ],
1163+ "foot": [
1164+ 1,
1165+ 1
1166+ ],
1167+ "smoke": [],
1168+ "cell": null,
1169+ "grid": null,
1170+ "glow": false
1171+ },
1172+ "birch": {
1173+ "size": [
1174+ 78,
1175+ 146
1176+ ],
1177+ "origin": [
1178+ 41,
1179+ 126
1180+ ],
1181+ "foot": [
1182+ 1,
1183+ 1
1184+ ],
1185+ "smoke": [],
1186+ "cell": null,
1187+ "grid": null,
1188+ "glow": false
1189+ },
1190+ "pine": {
1191+ "size": [
1192+ 106,
1193+ 158
1194+ ],
1195+ "origin": [
1196+ 53,
1197+ 137
1198+ ],
1199+ "foot": [
1200+ 1,
1201+ 1
1202+ ],
1203+ "smoke": [],
1204+ "cell": null,
1205+ "grid": null,
1206+ "glow": false
1207+ },
1208+ "dead": {
1209+ "size": [
1210+ 158,
1211+ 123
1212+ ],
1213+ "origin": [
1214+ 102,
1215+ 103
1216+ ],
1217+ "foot": [
1218+ 1,
1219+ 1
1220+ ],
1221+ "smoke": [],
1222+ "cell": null,
1223+ "grid": null,
1224+ "glow": false
1225+ },
1226+ "puff": {
1227+ "size": [
1228+ 12,
1229+ 12
1230+ ],
1231+ "origin": [
1232+ 6,
1233+ 6
1234+ ],
1235+ "foot": [
1236+ 1,
1237+ 1
1238+ ],
1239+ "smoke": [],
1240+ "cell": null,
1241+ "grid": null,
1242+ "glow": false
1243+ },
1244+ "light": {
1245+ "size": [
1246+ 96,
1247+ 48
1248+ ],
1249+ "origin": [
1250+ 48,
1251+ 24
1252+ ],
1253+ "foot": [
1254+ 1,
1255+ 1
1256+ ],
1257+ "smoke": [],
1258+ "cell": null,
1259+ "grid": null,
1260+ "glow": false
1261+ },
1262+ "eyes": {
1263+ "size": [
1264+ 5,
1265+ 1
1266+ ],
1267+ "origin": [
1268+ 2,
1269+ 0
1270+ ],
1271+ "foot": [
1272+ 1,
1273+ 1
1274+ ],
1275+ "smoke": [],
1276+ "cell": null,
1277+ "grid": null,
1278+ "glow": false
1279+ }
1280+}
\ No newline at end of file
tools/rec.shadded+8 -0
@@ -0,0 +1,8 @@
1+#!/bin/sh
2+cd "$(dirname "$0")/.."
3+cargo build --release -q || exit 1
4+OUT="${1:-demo.mp4}"
5+BEVY_ASSET_ROOT="$PWD" timeout ${TIMEOUT:-1200} ./target/release/courier --demo --record "$OUT.video.mp4" || exit 1
6+./target/release/mixdown "$OUT.video.mp4" "$PWD/assets" "$OUT.mix.mp4" || exit 1
7+ffmpeg -v error -y -i "$OUT.mix.mp4" -c:v copy -af loudnorm=I=-18:TP=-2 -c:a aac -b:a 160k "$OUT" || exit 1
8+rm -f "$OUT.mix.mp4" "$OUT.video.mp4" "$OUT.video.mp4.cues"
tools/vox.pyadded+364 -0
@@ -0,0 +1,364 @@
1+import json
2+import math
3+import os
4+
5+import numpy as np
6+from PIL import Image
7+
8+ROOT = '/home/tahinli/Documents/Code/Rust/courier'
9+GFX = os.path.join(ROOT, 'assets', 'gfx')
10+MANIFEST = os.path.join(ROOT, 'tools', 'manifest')
11+OUTLINE_RGB = np.array([27, 20, 32], float)
12+_U = np.uint64
13+_MASK64 = (1 << 64) - 1
14+_MATS = [None]
15+
16+P = {
17+ 'grass': [(40, 62, 48), (62, 92, 56), (88, 118, 68), (120, 146, 84)],
18+ 'grass_dry': [(70, 62, 40), (104, 92, 52), (136, 122, 70), (166, 150, 96)],
19+ 'dirt': [(52, 40, 34), (84, 64, 48), (116, 92, 66), (146, 120, 88)],
20+ 'mud': [(40, 34, 32), (64, 54, 46), (90, 76, 62), (118, 100, 80)],
21+ 'cobble': [(54, 56, 62), (84, 84, 88), (114, 112, 112), (142, 136, 128)],
22+ 'stone': [(86, 88, 96), (122, 120, 118), (156, 150, 140), (186, 178, 164)],
23+ 'stone_dark': [(38, 38, 44), (62, 60, 64), (90, 86, 84), (118, 110, 104)],
24+ 'brick': [(92, 38, 34), (124, 54, 44), (152, 78, 58), (178, 108, 76)],
25+ 'brick_dark': [(56, 28, 30), (80, 40, 38), (106, 56, 48), (130, 76, 62)],
26+ 'plaster': [(176, 166, 150), (198, 190, 172), (218, 210, 190), (232, 226, 206)],
27+ 'thatch': [(110, 84, 44), (146, 114, 58), (178, 146, 80), (204, 176, 108)],
28+ 'wood': [(70, 46, 32), (104, 70, 44), (136, 98, 62), (164, 124, 80)],
29+ 'wood_dark': [(42, 30, 26), (62, 44, 36), (86, 62, 46), (110, 82, 58)],
30+ 'slate': [(56, 62, 72), (78, 84, 96), (102, 108, 118), (126, 128, 136)],
31+ 'coal': [(20, 20, 24), (36, 36, 42), (54, 52, 58), (74, 70, 74)],
32+ 'water': [(30, 56, 72), (44, 80, 100), (64, 108, 126), (92, 138, 150)],
33+ 'foliage': [(34, 66, 46), (52, 94, 60), (76, 122, 72), (104, 148, 88)],
34+ 'foliage_dark': [(26, 46, 40), (38, 66, 52), (54, 90, 62), (74, 112, 76)],
35+ 'bark': [(44, 34, 30), (64, 50, 40), (88, 70, 54), (114, 92, 70)],
36+ 'skin': [(120, 78, 62), (164, 112, 88), (200, 146, 116), (224, 176, 144)],
37+ 'hair_brown': [(44, 30, 24), (70, 48, 34), (98, 70, 46), (124, 94, 64)],
38+ 'hair_black': [(18, 16, 20), (30, 28, 34), (46, 44, 50), (64, 62, 68)],
39+ 'hair_gray': [(90, 88, 94), (124, 122, 126), (156, 154, 156), (186, 184, 184)],
40+ 'cloth_brown': [(60, 40, 30), (88, 60, 42), (118, 84, 58), (146, 108, 76)],
41+ 'cloth_navy': [(24, 32, 52), (36, 48, 74), (54, 70, 100), (78, 96, 128)],
42+ 'cloth_green': [(30, 48, 38), (44, 70, 54), (64, 96, 74), (90, 122, 96)],
43+ 'cloth_wine': [(54, 22, 32), (82, 34, 44), (110, 52, 60), (138, 76, 80)],
44+ 'cloth_gray': [(56, 58, 66), (84, 86, 94), (112, 114, 120), (140, 142, 146)],
45+ 'cloth_black': [(18, 18, 24), (30, 30, 38), (46, 46, 54), (66, 64, 72)],
46+ 'cloth_cream': [(150, 136, 112), (180, 168, 140), (206, 196, 168), (226, 218, 192)],
47+ 'leather': [(36, 24, 20), (60, 40, 30), (90, 62, 44), (118, 86, 60)],
48+ 'metal': [(44, 50, 58), (74, 82, 92), (108, 116, 124), (146, 152, 158)],
49+ 'brass': [(92, 70, 34), (128, 100, 50), (164, 136, 72), (198, 170, 100)],
50+ 'window': [(214, 156, 64), (240, 196, 96), (252, 224, 140)],
51+ 'canvas': [(120, 106, 84), (152, 138, 110), (180, 168, 140), (206, 196, 166)],
52+ 'fire': [(160, 48, 24), (220, 96, 32), (246, 160, 48), (255, 220, 110)],
53+}
54+
55+
56+def mat(ramp, pattern=None, emissive=False):
57+ assert 3 <= len(ramp) <= 6
58+ _MATS.append((np.array(ramp, np.int64), pattern, bool(emissive)))
59+ return len(_MATS) - 1
60+
61+
62+def hash3(cx, cy, cz, seed=0):
63+ h = np.asarray(cx, np.int64).astype(_U) * _U(0x9E3779B97F4A7C15)
64+ h ^= np.asarray(cy, np.int64).astype(_U) * _U(0xC2B2AE3D27D4EB4F)
65+ h ^= np.asarray(cz, np.int64).astype(_U) * _U(0x165667B19E3779F9)
66+ h ^= _U((seed * 0x27D4EB2F165667C5) & _MASK64)
67+ h ^= h >> _U(31)
68+ h *= _U(0xBF58476D1CE4E5B9)
69+ h ^= h >> _U(29)
70+ h *= _U(0x94D049BB133111EB)
71+ h ^= h >> _U(32)
72+ return (h >> _U(11)).astype(np.float64) / 9007199254740992.0
73+
74+
75+def noise(amount=1, seed=0):
76+ def f(cx, cy, cz, face):
77+ return np.floor(hash3(cx, cy, cz, seed) * (2 * amount + 1)).astype(np.int64) - amount
78+ return f
79+
80+
81+def rows(h=4):
82+ def f(cx, cy, cz, face):
83+ return np.where(np.asarray(cz) % h == 0, -1, 0)
84+ return f
85+
86+
87+def bricks(h=4, w=12):
88+ def f(cx, cy, cz, face):
89+ cx, cy, cz, face = (np.asarray(a, np.int64) for a in (cx, cy, cz, face))
90+ along = np.where(face == 1, cx, cy)
91+ course = cz // h
92+ off = along + (course & 1) * (w // 2)
93+ mortar = (cz % h == 0) | (off % w == 0)
94+ var = np.floor(hash3(off // w, course, face, 5) * 3).astype(np.int64) - 1
95+ return np.where(mortar, 1, var)
96+ return f
97+
98+
99+def planks(w=6, axis=2):
100+ def f(cx, cy, cz, face):
101+ c = [np.asarray(a, np.int64) for a in (cx, cy, cz)]
102+ face = np.asarray(face, np.int64)
103+ s = np.zeros(c[0].shape, np.int64)
104+ for fa in range(3):
105+ k = [i for i in range(3) if i not in (axis, fa)][0]
106+ s = np.where(face == fa, c[k], s)
107+ var = np.floor(hash3(s // w, face, axis, 9) * 3).astype(np.int64) - 1
108+ return np.where(s % w == 0, -1, var)
109+ return f
110+
111+
112+class Model:
113+ def __init__(self, sx, sy, sz):
114+ self.v = np.zeros((sx, sy, sz), np.uint8)
115+
116+ def _fill(self, lo, hi, fn, m):
117+ sl = []
118+ for a in range(3):
119+ i0 = max(0, math.floor(lo[a]) - 1)
120+ i1 = min(self.v.shape[a], math.ceil(hi[a]) + 1)
121+ if i1 <= i0:
122+ return
123+ sl.append(slice(i0, i1))
124+ X, Y, Z = [np.arange(s.start, s.stop) + 0.5 for s in sl]
125+ mask = fn(X[:, None, None], Y[None, :, None], Z[None, None, :])
126+ sub = self.v[sl[0], sl[1], sl[2]]
127+ sub[np.broadcast_to(mask, sub.shape)] = m
128+
129+ def box(self, x0, y0, z0, x1, y1, z1, m):
130+ def fn(X, Y, Z):
131+ return (X >= x0) & (X <= x1) & (Y >= y0) & (Y <= y1) & (Z >= z0) & (Z <= z1)
132+ self._fill((x0, y0, z0), (x1, y1, z1), fn, m)
133+
134+ def obox(self, cx, cy, cz, hx, hy, hz, yaw, m):
135+ c, s = math.cos(yaw), math.sin(yaw)
136+ R = math.hypot(hx, hy)
137+
138+ def fn(X, Y, Z):
139+ dx = X - cx
140+ dy = Y - cy
141+ lx = dx * c + dy * s
142+ ly = dy * c - dx * s
143+ return (np.abs(lx) <= hx) & (np.abs(ly) <= hy) & (np.abs(Z - cz) <= hz)
144+ self._fill((cx - R, cy - R, cz - hz), (cx + R, cy + R, cz + hz), fn, m)
145+
146+ def ellipsoid(self, cx, cy, cz, rx, ry, rz, m):
147+ def fn(X, Y, Z):
148+ return ((X - cx) / rx) ** 2 + ((Y - cy) / ry) ** 2 + ((Z - cz) / rz) ** 2 <= 1
149+ self._fill((cx - rx, cy - ry, cz - rz), (cx + rx, cy + ry, cz + rz), fn, m)
150+
151+ def capsule(self, a, b, r, m):
152+ a = np.asarray(a, float)
153+ ab = np.asarray(b, float) - a
154+ L2 = max(float(ab @ ab), 1e-12)
155+
156+ def fn(X, Y, Z):
157+ px, py, pz = X - a[0], Y - a[1], Z - a[2]
158+ t = np.clip((px * ab[0] + py * ab[1] + pz * ab[2]) / L2, 0, 1)
159+ dx, dy, dz = px - t * ab[0], py - t * ab[1], pz - t * ab[2]
160+ return dx * dx + dy * dy + dz * dz <= r * r
161+ lo = np.minimum(a, a + ab) - r
162+ hi = np.maximum(a, a + ab) + r
163+ self._fill(lo, hi, fn, m)
164+
165+ def cylinder(self, a, b, r, m):
166+ a = np.asarray(a, float)
167+ ab = np.asarray(b, float) - a
168+ L = float(np.linalg.norm(ab))
169+ u = ab / max(L, 1e-12)
170+
171+ def fn(X, Y, Z):
172+ px, py, pz = X - a[0], Y - a[1], Z - a[2]
173+ along = px * u[0] + py * u[1] + pz * u[2]
174+ d2 = px * px + py * py + pz * pz - along * along
175+ return (along >= 0) & (along <= L) & (d2 <= r * r)
176+ lo = np.minimum(a, a + ab) - r
177+ hi = np.maximum(a, a + ab) + r
178+ self._fill(lo, hi, fn, m)
179+
180+ def gable(self, x0, y0, x1, y1, z0, z1, axis, m, overhang=0):
181+ o = overhang
182+ if axis == 'x':
183+ a0, a1, b0, b1, ca, cb = x0, x1, y0, y1, 0, 1
184+ else:
185+ a0, a1, b0, b1, ca, cb = y0, y1, x0, x1, 1, 0
186+ bc = (b0 + b1) / 2
187+ hw = (b1 - b0) / 2
188+
189+ def fn(X, Y, Z):
190+ pos = (X, Y)
191+ A = pos[ca]
192+ B = pos[cb]
193+ d = np.abs(B - bc) / hw
194+ h = z0 + (z1 - z0) * (1 - np.minimum(d, 1))
195+ return (A >= a0 - o) & (A <= a1 + o) & (d <= 1 + o / hw) & (Z >= z0) & (Z <= h)
196+ self._fill((x0 - o, y0 - o, z0), (x1 + o, y1 + o, z1), fn, m)
197+
198+ def paint(self, fn, m):
199+ ix, iy, iz = np.nonzero(self.v)
200+ sel = np.broadcast_to(fn(ix + 0.5, iy + 0.5, iz + 0.5), ix.shape)
201+ self.v[ix[sel], iy[sel], iz[sel]] = m
202+
203+
204+def render(model, outline=True, edges=True):
205+ v = model.v
206+ sx, sy, sz = v.shape
207+ W = sx + sy
208+ H = int(math.ceil((sx + sy) / 2 + sz))
209+ U, V = np.meshgrid(np.arange(W) - sy + 0.5, np.arange(H) - sz + 0.5)
210+ bounds = np.stack([2 * sx - U, 2 * sy + U, 2 * (sz + V)])
211+ face = np.argmin(bounds, axis=0).reshape(-1)
212+ s0 = bounds.min(axis=0)
213+ lo = np.maximum(np.maximum(-U, U), 2 * V)
214+ idx = np.flatnonzero((s0 >= lo).reshape(-1))
215+ P0 = np.stack([(s0 + U) / 2, (s0 - U) / 2, s0 / 2 - V], -1).reshape(-1, 3)
216+ p = P0[idx]
217+ f = face[idx]
218+ dims = np.array(v.shape)
219+ hit_mat = np.zeros(H * W, np.uint8)
220+ hit_face = np.zeros(H * W, np.int64)
221+ hit_cell = np.zeros((H * W, 3), np.int64)
222+ for _ in range(4 * (sx + sy + sz) + 8):
223+ if not idx.size:
224+ break
225+ c = np.floor(p - 1e-6).astype(np.int64)
226+ inside = (c >= 0).all(1)
227+ cc = np.clip(c, 0, dims - 1)
228+ mt = v[cc[:, 0], cc[:, 1], cc[:, 2]]
229+ occ = inside & (mt > 0)
230+ hi_ = idx[occ]
231+ hit_mat[hi_] = mt[occ]
232+ hit_face[hi_] = f[occ]
233+ hit_cell[hi_] = c[occ]
234+ go = inside & ~occ
235+ idx, p, c = idx[go], p[go], c[go]
236+ d = p - c
237+ t = d.min(1)
238+ f = d.argmin(1)
239+ p = p - t[:, None]
240+
241+ M = (hit_mat > 0).reshape(H, W)
242+ mat_img = hit_mat.reshape(H, W)
243+ face_img = hit_face.reshape(H, W)
244+ cell_img = hit_cell.reshape(H, W, 3)
245+ D = cell_img.sum(2)
246+
247+ Mr = np.zeros_like(M)
248+ Mb = np.zeros_like(M)
249+ Dr = np.zeros_like(D)
250+ Db = np.zeros_like(D)
251+ Mr[:, :-1] = M[:, 1:]
252+ Dr[:, :-1] = D[:, 1:]
253+ Mb[:-1, :] = M[1:, :]
254+ Db[:-1, :] = D[1:, :]
255+ edge = M & (~Mr | (np.abs(D - Dr) > 4) | ~Mb | (np.abs(D - Db) > 4))
256+
257+ shade = np.zeros((H, W), np.int64)
258+ emis = np.zeros((H, W), bool)
259+ glass = np.zeros((H, W), bool)
260+ lens = np.zeros((H, W), np.int64)
261+ rgb = np.zeros((H, W, 3))
262+ mids = np.unique(mat_img[M])
263+ for mid in mids:
264+ ramp, pat, em = _MATS[mid]
265+ sel = mat_img == mid
266+ fa = face_img[sel]
267+ L = len(ramp)
268+ base = np.where(fa == 2, L - 2, np.where(fa == 1, L - 3, L - 4))
269+ if pat is not None:
270+ cl = cell_img[sel]
271+ base = base + pat(cl[:, 0], cl[:, 1], cl[:, 2], fa)
272+ shade[sel] = base
273+ emis[sel] = em
274+ glass[sel] = em and len(ramp) == len(P['window']) and bool(np.all(ramp == np.array(P['window'])))
275+ lens[sel] = L
276+ shade = shade - (edge if edges else 0)
277+ for mid in mids:
278+ ramp = _MATS[mid][0]
279+ sel = mat_img == mid
280+ idx_ = np.clip(shade[sel], 0, len(ramp) - 1)
281+ rgb[sel] = ramp[idx_]
282+
283+ Hc, Wc = H + 2, W + 2
284+ img = np.zeros((Hc, Wc, 4), np.uint8)
285+ img[1:-1, 1:-1, :3] = np.round(rgb).astype(np.uint8)
286+ img[1:-1, 1:-1, 3] = M * 255
287+
288+ if outline:
289+ A = img[..., 3] > 0
290+ col = img[..., :3].astype(float)
291+ out = np.zeros_like(col)
292+ got = np.zeros((Hc, Wc), bool)
293+ for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
294+ nA = np.roll(A, (dy, dx), (0, 1))
295+ nC = np.roll(col, (dy, dx), (0, 1))
296+ take = nA & ~A & ~got
297+ out[take] = 0.35 * nC[take] + 0.65 * OUTLINE_RGB
298+ got |= take
299+ img[got, :3] = np.round(out[got]).astype(np.uint8)
300+ img[got, 3] = 255
301+
302+ em_img = None
303+ E = np.zeros((Hc, Wc), bool)
304+ E[1:-1, 1:-1] = emis & M
305+ ys, xs = np.nonzero(img[..., 3])
306+ x0, x1 = max(int(xs.min()) - 1, 0), min(int(xs.max()) + 2, Wc)
307+ y0, y1 = max(int(ys.min()) - 1, 0), min(int(ys.max()) + 2, Hc)
308+ if E.any():
309+ em = np.zeros_like(img)
310+ em[E] = img[E]
311+ em_img = Image.fromarray(em[y0:y1, x0:x1])
312+ G = np.zeros((Hc, Wc), bool)
313+ G[1:-1, 1:-1] = glass & M
314+ img[G, :3] = np.round(img[G, :3] * 0.22 + np.array([34, 40, 52]) * 0.78).astype(np.uint8)
315+ origin = (sy + 1 - x0, sz + 1 - y0)
316+ return Image.fromarray(img[y0:y1, x0:x1]), em_img, origin
317+
318+
319+def project(x, y, z, origin):
320+ return origin[0] + (x - y), origin[1] + (x + y) / 2 - z
321+
322+
323+def smoke_offset(px, py, origin):
324+ return ((px - origin[0]) * 2, -(py - origin[1]) * 2)
325+
326+
327+def save(name, img, origin, foot=(1, 1), smoke=(), cell=None, grid=None, emissive=None, group='misc'):
328+ os.makedirs(GFX, exist_ok=True)
329+ os.makedirs(MANIFEST, exist_ok=True)
330+ img.save(os.path.join(GFX, name + '.png'))
331+ if emissive is not None:
332+ emissive.save(os.path.join(GFX, name + '_e.png'))
333+ path = os.path.join(MANIFEST, group + '.json')
334+ data = {}
335+ if os.path.exists(path):
336+ with open(path) as fh:
337+ data = json.load(fh)
338+ data[name] = {
339+ 'size': list(img.size),
340+ 'origin': [int(origin[0]), int(origin[1])],
341+ 'foot': list(foot),
342+ 'smoke': [list(s) for s in smoke],
343+ 'cell': list(cell) if cell is not None else None,
344+ 'grid': list(grid) if grid is not None else None,
345+ 'glow': emissive is not None,
346+ }
347+ with open(path, 'w') as fh:
348+ json.dump(data, fh, indent=2)
349+
350+
351+def atlas(frames_rows):
352+ frames = [fr for row in frames_rows for fr in row]
353+ L = max(o[0] for _, o in frames)
354+ T = max(o[1] for _, o in frames)
355+ R = max(img.size[0] - o[0] for img, o in frames)
356+ B = max(img.size[1] - o[1] for img, o in frames)
357+ cw, ch = L + R, T + B
358+ cols = max(len(r) for r in frames_rows)
359+ rows_n = len(frames_rows)
360+ out = Image.new('RGBA', (cols * cw, rows_n * ch), (0, 0, 0, 0))
361+ for j, row in enumerate(frames_rows):
362+ for i, (img, o) in enumerate(row):
363+ out.paste(img, (i * cw + L - o[0], j * ch + T - o[1]))
364+ return out, (cw, ch), (cols, rows_n), (L, T)
tools/vox_test.pyadded+88 -0
@@ -0,0 +1,88 @@
1+import os
2+import sys
3+import time
4+
5+sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
6+from vox import *
7+from PIL import Image
8+
9+OUT = '/tmp/claude-1000/-home-tahinli-Documents-Code-Rust/edd994b8-9b3e-47f3-95c7-9404536bd326/scratchpad/vt'
10+
11+
12+def save_pair(name, img):
13+ img.save(os.path.join(OUT, name + '.png'))
14+ img.resize((img.width * 4, img.height * 4), Image.NEAREST).save(os.path.join(OUT, name + '_x4.png'))
15+
16+
17+def house():
18+ o, W, D, H = 4, 96, 64, 70
19+ fy, fx = o + D, o + W
20+ t0 = time.perf_counter()
21+ m = Model(W + 2 * o, D + 2 * o, 112)
22+ plaster = mat(P['plaster'], noise(1, 2))
23+ wood = mat(P['wood'], noise(1, 3))
24+ pane = mat(P['window'], emissive=True)
25+ door = mat(P['wood_dark'], planks(4, 2))
26+ thatch = mat(P['thatch'], noise(1, 4))
27+ brick = mat(P['brick'], bricks(4, 12))
28+ m.box(o, o, 0, fx, fy, H, plaster)
29+ m.paint(lambda x, y, z: ((y > fy - 1) & (((x - o) % 24 < 2) | (z % 35 < 2))
30+ | (x > fx - 1) & (((y - o) % 24 < 2) | (z % 35 < 2))) & (z < H), wood)
31+ for x0, x1 in ((o + 10, o + 20), (o + 62, o + 72)):
32+ m.box(x0, fy - 2, 30, x1, fy, 44, 0)
33+ m.box(x0 + 1, fy - 2, 31, x1 - 1, fy - 1, 43, pane)
34+ for y0, y1 in ((o + 14, o + 24), (o + 38, o + 48)):
35+ m.box(fx - 2, y0, 30, fx, y1, 44, 0)
36+ m.box(fx - 2, y0 + 1, 31, fx - 1, y1 - 1, 43, pane)
37+ m.box(o + 40, fy - 2, 0, o + 50, fy, 26, 0)
38+ m.box(o + 40, fy - 2, 0, o + 50, fy - 1, 26, door)
39+ m.gable(o, o, fx, fy, H, 100, 'x', thatch, overhang=4)
40+ m.box(o + 60, o + 8, 60, o + 70, o + 14, 106, brick)
41+ t1 = time.perf_counter()
42+ img, em, org = render(m)
43+ t2 = time.perf_counter()
44+ save_pair('house', img)
45+ if em is not None:
46+ save_pair('house_e', em)
47+ print('house grid %s build %.3fs render %.3fs origin %s' % (m.v.shape, t1 - t0, t2 - t1, org))
48+
49+
50+def figure():
51+ t0 = time.perf_counter()
52+ m = Model(40, 40, 60)
53+ navy = mat(P['cloth_navy'], noise(1, 5))
54+ coat = mat(P['cloth_brown'], noise(1, 6))
55+ skin = mat(P['skin'])
56+ black = mat(P['cloth_black'], noise(1, 7))
57+ m.capsule((16, 20, 22), (16, 20, 3), 2.4, navy)
58+ m.capsule((24, 20, 22), (24, 20, 3), 2.4, navy)
59+ m.ellipsoid(20, 20, 33, 6, 4, 10, coat)
60+ m.capsule((13, 20, 40), (9, 20, 26), 2.2, coat)
61+ m.capsule((27, 20, 40), (31, 20, 26), 2.2, coat)
62+ m.capsule((20, 20, 40), (20, 20, 46), 1.8, skin)
63+ m.ellipsoid(20, 20, 48, 4.2, 4.2, 4.6, skin)
64+ m.cylinder((20, 20, 53), (20, 20, 54), 7, black)
65+ m.cylinder((20, 20, 54), (20, 20, 59), 4.6, black)
66+ t1 = time.perf_counter()
67+ img, em, org = render(m)
68+ t2 = time.perf_counter()
69+ save_pair('figure', img)
70+ print('figure grid %s build %.3fs render %.3fs origin %s' % (m.v.shape, t1 - t0, t2 - t1, org))
71+
72+
73+def grass():
74+ t0 = time.perf_counter()
75+ m = Model(64, 64, 2)
76+ m.box(0, 0, 0, 64, 64, 2, mat(P['grass'], noise(1, 8)))
77+ t1 = time.perf_counter()
78+ img, em, org = render(m)
79+ t2 = time.perf_counter()
80+ save_pair('grass', img)
81+ print('grass grid %s build %.3fs render %.3fs origin %s' % (m.v.shape, t1 - t0, t2 - t1, org))
82+
83+
84+if __name__ == '__main__':
85+ os.makedirs(OUT, exist_ok=True)
86+ house()
87+ figure()
88+ grass()
tools/web.shadded+14 -0
@@ -0,0 +1,14 @@
1+#!/usr/bin/env bash
2+set -euo pipefail
3+cd "$(dirname "$0")/.."
4+
5+cargo build --profile web --target wasm32-unknown-unknown --bin courier
6+wasm-bindgen --target web --no-typescript --out-dir dist --out-name courier target/wasm32-unknown-unknown/web/courier.wasm
7+
8+if command -v wasm-opt >/dev/null 2>&1; then
9+ wasm-opt -Os --strip-debug --strip-producers --enable-bulk-memory --enable-nontrapping-float-to-int -o dist/courier_bg.wasm dist/courier_bg.wasm
10+fi
11+
12+cp web/index.html dist/
13+mkdir -p dist/assets
14+cp -r assets/. dist/assets/
web/index.htmladded+30 -0
@@ -0,0 +1,30 @@
1+<!DOCTYPE html>
2+<html lang="en">
3+<head>
4+<meta charset="utf-8">
5+<meta name="viewport" content="width=device-width, initial-scale=1">
6+<title>Courier</title>
7+<style>
8+html, body { margin: 0; height: 100%; background: #000; overflow: hidden; }
9+body { display: flex; flex-direction: column; align-items: center; justify-content: center; }
10+#wrap { position: relative; width: min(100vw, calc(100vh * 16 / 9)); aspect-ratio: 16 / 9; }
11+#game { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
12+#start { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #000; color: #ccc; font: 1.2rem monospace; cursor: pointer; }
13+#hint { margin-top: 0.5rem; color: #666; font: 0.8rem monospace; white-space: nowrap; }
14+</style>
15+</head>
16+<body>
17+<div id="wrap">
18+<canvas id="game"></canvas>
19+<div id="start">Click to start</div>
20+</div>
21+<div id="hint">WASD move · E talk · Shift travel · C camp · F eat · L lantern · Tab bag · 1-5 choose</div>
22+<script type="module">
23+import init from './courier.js';
24+document.getElementById('start').addEventListener('click', (e) => {
25+ e.currentTarget.remove();
26+ init();
27+}, { once: true });
28+</script>
29+</body>
30+</html>