diff --git a/.claude/.gdignore b/.claude/.gdignore new file mode 100644 index 0000000..e69de29 diff --git a/assets/cards/additional-core.png b/assets/cards/additional-core.png index 07d111f..5d892c6 100644 Binary files a/assets/cards/additional-core.png and b/assets/cards/additional-core.png differ diff --git a/assets/cards/back-carbon-nanobots.png b/assets/cards/back-carbon-nanobots.png new file mode 100644 index 0000000..6129cb9 Binary files /dev/null and b/assets/cards/back-carbon-nanobots.png differ diff --git a/assets/cards/back-carbon-nanobots.png.import b/assets/cards/back-carbon-nanobots.png.import new file mode 100644 index 0000000..ca266cf --- /dev/null +++ b/assets/cards/back-carbon-nanobots.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://7hxoyggb46gj" +path="res://.godot/imported/back-carbon-nanobots.png-e99722f00b0c552d3e86904f50f38eaa.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/cards/back-carbon-nanobots.png" +dest_files=["res://.godot/imported/back-carbon-nanobots.png-e99722f00b0c552d3e86904f50f38eaa.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/cards/bit-rot.png b/assets/cards/bit-rot.png index 69a87c6..3b1a073 100644 Binary files a/assets/cards/bit-rot.png and b/assets/cards/bit-rot.png differ diff --git a/assets/cards/bloatware.png b/assets/cards/bloatware.png index eba43f2..166d058 100644 Binary files a/assets/cards/bloatware.png and b/assets/cards/bloatware.png differ diff --git a/assets/cards/bug-injector.png b/assets/cards/bug-injector.png index b52def9..77d607e 100644 Binary files a/assets/cards/bug-injector.png and b/assets/cards/bug-injector.png differ diff --git a/assets/cards/compatibility-layer.png b/assets/cards/compatibility-layer.png index 11c26a2..f5ad7e1 100644 Binary files a/assets/cards/compatibility-layer.png and b/assets/cards/compatibility-layer.png differ diff --git a/assets/cards/cooling-system.png b/assets/cards/cooling-system.png index 9d2e2c0..36b4b8b 100644 Binary files a/assets/cards/cooling-system.png and b/assets/cards/cooling-system.png differ diff --git a/assets/cards/dedicated-gpu.png b/assets/cards/dedicated-gpu.png index aeb52a8..f54f255 100644 Binary files a/assets/cards/dedicated-gpu.png and b/assets/cards/dedicated-gpu.png differ diff --git a/assets/cards/desynchronization.png b/assets/cards/desynchronization.png index 7c50367..f7e2916 100644 Binary files a/assets/cards/desynchronization.png and b/assets/cards/desynchronization.png differ diff --git a/assets/cards/diagnostic-module.png b/assets/cards/diagnostic-module.png index 92ac8f4..d0d26fc 100644 Binary files a/assets/cards/diagnostic-module.png and b/assets/cards/diagnostic-module.png differ diff --git a/assets/cards/drive-by-download.png b/assets/cards/drive-by-download.png index 7527ccd..b190d4f 100644 Binary files a/assets/cards/drive-by-download.png and b/assets/cards/drive-by-download.png differ diff --git a/assets/cards/ecc-memory.png b/assets/cards/ecc-memory.png index aba28da..5b4fa13 100644 Binary files a/assets/cards/ecc-memory.png and b/assets/cards/ecc-memory.png differ diff --git a/assets/cards/error-correction.png b/assets/cards/error-correction.png index 6d70382..82c0d2d 100644 Binary files a/assets/cards/error-correction.png and b/assets/cards/error-correction.png differ diff --git a/assets/cards/execute-data-siphon.png b/assets/cards/execute-data-siphon.png index 587c84a..21cb3d9 100644 Binary files a/assets/cards/execute-data-siphon.png and b/assets/cards/execute-data-siphon.png differ diff --git a/assets/cards/execute-defragment.png b/assets/cards/execute-defragment.png index f188652..4f0a31d 100644 Binary files a/assets/cards/execute-defragment.png and b/assets/cards/execute-defragment.png differ diff --git a/assets/cards/execute-disconnect.png b/assets/cards/execute-disconnect.png index 4e1869c..379c725 100644 Binary files a/assets/cards/execute-disconnect.png and b/assets/cards/execute-disconnect.png differ diff --git a/assets/cards/execute-emergency-shutdown.png b/assets/cards/execute-emergency-shutdown.png index dc5e858..2118b92 100644 Binary files a/assets/cards/execute-emergency-shutdown.png and b/assets/cards/execute-emergency-shutdown.png differ diff --git a/assets/cards/execute-force-reboot.png b/assets/cards/execute-force-reboot.png index f787555..2fdbc1c 100644 Binary files a/assets/cards/execute-force-reboot.png and b/assets/cards/execute-force-reboot.png differ diff --git a/assets/cards/execute-fork.png b/assets/cards/execute-fork.png index 5c1f192..06d228d 100644 Binary files a/assets/cards/execute-fork.png and b/assets/cards/execute-fork.png differ diff --git a/assets/cards/execute-fuzz.png b/assets/cards/execute-fuzz.png index 63cee05..e330396 100644 Binary files a/assets/cards/execute-fuzz.png and b/assets/cards/execute-fuzz.png differ diff --git a/assets/cards/execute-hard-reset.png b/assets/cards/execute-hard-reset.png index 4e98123..712bf14 100644 Binary files a/assets/cards/execute-hard-reset.png and b/assets/cards/execute-hard-reset.png differ diff --git a/assets/cards/execute-kill-process.png b/assets/cards/execute-kill-process.png index f6b4f8c..b9395b3 100644 Binary files a/assets/cards/execute-kill-process.png and b/assets/cards/execute-kill-process.png differ diff --git a/assets/cards/execute-lag-spike.png b/assets/cards/execute-lag-spike.png index 9f1416f..e31c02c 100644 Binary files a/assets/cards/execute-lag-spike.png and b/assets/cards/execute-lag-spike.png differ diff --git a/assets/cards/execute-memory-dump.png b/assets/cards/execute-memory-dump.png index bc3f54b..34469fb 100644 Binary files a/assets/cards/execute-memory-dump.png and b/assets/cards/execute-memory-dump.png differ diff --git a/assets/cards/execute-override.png b/assets/cards/execute-override.png index 1a129b5..ed8073c 100644 Binary files a/assets/cards/execute-override.png and b/assets/cards/execute-override.png differ diff --git a/assets/cards/execute-packet-flood.png b/assets/cards/execute-packet-flood.png index 93764a5..0866436 100644 Binary files a/assets/cards/execute-packet-flood.png and b/assets/cards/execute-packet-flood.png differ diff --git a/assets/cards/execute-ping-sweep.png b/assets/cards/execute-ping-sweep.png index c7f1703..f9b2f74 100644 Binary files a/assets/cards/execute-ping-sweep.png and b/assets/cards/execute-ping-sweep.png differ diff --git a/assets/cards/execute-port-scan.png b/assets/cards/execute-port-scan.png index 1396602..cf7513c 100644 Binary files a/assets/cards/execute-port-scan.png and b/assets/cards/execute-port-scan.png differ diff --git a/assets/cards/execute-process-clone.png b/assets/cards/execute-process-clone.png index 933ce6d..438424a 100644 Binary files a/assets/cards/execute-process-clone.png and b/assets/cards/execute-process-clone.png differ diff --git a/assets/cards/execute-purge.png b/assets/cards/execute-purge.png index 0589a57..35024f0 100644 Binary files a/assets/cards/execute-purge.png and b/assets/cards/execute-purge.png differ diff --git a/assets/cards/execute-quarantine.png b/assets/cards/execute-quarantine.png index a7ceabf..6472979 100644 Binary files a/assets/cards/execute-quarantine.png and b/assets/cards/execute-quarantine.png differ diff --git a/assets/cards/execute-remote-access.png b/assets/cards/execute-remote-access.png index eebdb3b..a306db5 100644 Binary files a/assets/cards/execute-remote-access.png and b/assets/cards/execute-remote-access.png differ diff --git a/assets/cards/execute-rollback.png b/assets/cards/execute-rollback.png index 76fec9f..4bf09cf 100644 Binary files a/assets/cards/execute-rollback.png and b/assets/cards/execute-rollback.png differ diff --git a/assets/cards/execute-root-access.png b/assets/cards/execute-root-access.png index 9b337ea..6525dd4 100644 Binary files a/assets/cards/execute-root-access.png and b/assets/cards/execute-root-access.png differ diff --git a/assets/cards/execute-sabotage.png b/assets/cards/execute-sabotage.png index e3669ef..4159f98 100644 Binary files a/assets/cards/execute-sabotage.png and b/assets/cards/execute-sabotage.png differ diff --git a/assets/cards/execute-segfault.png b/assets/cards/execute-segfault.png index ca4e92b..b213d7f 100644 Binary files a/assets/cards/execute-segfault.png and b/assets/cards/execute-segfault.png differ diff --git a/assets/cards/execute-snapshot-restore.png b/assets/cards/execute-snapshot-restore.png index d409b46..aa315bc 100644 Binary files a/assets/cards/execute-snapshot-restore.png and b/assets/cards/execute-snapshot-restore.png differ diff --git a/assets/cards/execute-snapshot.png b/assets/cards/execute-snapshot.png index ea86a83..edd957c 100644 Binary files a/assets/cards/execute-snapshot.png and b/assets/cards/execute-snapshot.png differ diff --git a/assets/cards/execute-trace-route.png b/assets/cards/execute-trace-route.png index 2a1f4db..bf192e0 100644 Binary files a/assets/cards/execute-trace-route.png and b/assets/cards/execute-trace-route.png differ diff --git a/assets/cards/exploit-kit.png b/assets/cards/exploit-kit.png index 660427f..8119a8c 100644 Binary files a/assets/cards/exploit-kit.png and b/assets/cards/exploit-kit.png differ diff --git a/assets/cards/failover.png b/assets/cards/failover.png index f0f1bc6..0495873 100644 Binary files a/assets/cards/failover.png and b/assets/cards/failover.png differ diff --git a/assets/cards/false-positive.png b/assets/cards/false-positive.png index 98f4e42..2e1255e 100644 Binary files a/assets/cards/false-positive.png and b/assets/cards/false-positive.png differ diff --git a/assets/cards/firewall-appliance.png b/assets/cards/firewall-appliance.png index 5f64775..e4d37b5 100644 Binary files a/assets/cards/firewall-appliance.png and b/assets/cards/firewall-appliance.png differ diff --git a/assets/cards/fragmentation.png b/assets/cards/fragmentation.png index 0035d92..70a55bb 100644 Binary files a/assets/cards/fragmentation.png and b/assets/cards/fragmentation.png differ diff --git a/assets/cards/front-carbon-nanobots.png b/assets/cards/front-carbon-nanobots.png new file mode 100644 index 0000000..c85059e Binary files /dev/null and b/assets/cards/front-carbon-nanobots.png differ diff --git a/assets/cards/front-carbon-nanobots.png.import b/assets/cards/front-carbon-nanobots.png.import new file mode 100644 index 0000000..9cc47a9 --- /dev/null +++ b/assets/cards/front-carbon-nanobots.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bboaq7coenuqu" +path="res://.godot/imported/front-carbon-nanobots.png-575b942f6f2b3b6b741edcf67c81958c.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/cards/front-carbon-nanobots.png" +dest_files=["res://.godot/imported/front-carbon-nanobots.png-575b942f6f2b3b6b741edcf67c81958c.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/cards/garbage-collection.png b/assets/cards/garbage-collection.png index ad5ab2e..3210381 100644 Binary files a/assets/cards/garbage-collection.png and b/assets/cards/garbage-collection.png differ diff --git a/assets/cards/ghost-process.png b/assets/cards/ghost-process.png index f5671c5..a82337f 100644 Binary files a/assets/cards/ghost-process.png and b/assets/cards/ghost-process.png differ diff --git a/assets/cards/hardware-sandbox.png b/assets/cards/hardware-sandbox.png index 0854f76..6b385d1 100644 Binary files a/assets/cards/hardware-sandbox.png and b/assets/cards/hardware-sandbox.png differ diff --git a/assets/cards/heap-corruption.png b/assets/cards/heap-corruption.png index e3ea7fe..7028906 100644 Binary files a/assets/cards/heap-corruption.png and b/assets/cards/heap-corruption.png differ diff --git a/assets/cards/heat-sink.png b/assets/cards/heat-sink.png index d68b4cb..ddbe2aa 100644 Binary files a/assets/cards/heat-sink.png and b/assets/cards/heat-sink.png differ diff --git a/assets/cards/hot-patch.png b/assets/cards/hot-patch.png index 4007a28..633c2b0 100644 Binary files a/assets/cards/hot-patch.png and b/assets/cards/hot-patch.png differ diff --git a/assets/cards/hot-swap-bay.png b/assets/cards/hot-swap-bay.png index ece1048..7998435 100644 Binary files a/assets/cards/hot-swap-bay.png and b/assets/cards/hot-swap-bay.png differ diff --git a/assets/cards/hotfix.png b/assets/cards/hotfix.png index 9925023..e8e1cc9 100644 Binary files a/assets/cards/hotfix.png and b/assets/cards/hotfix.png differ diff --git a/assets/cards/infinite-loop.png b/assets/cards/infinite-loop.png index ffd052c..62655c8 100644 Binary files a/assets/cards/infinite-loop.png and b/assets/cards/infinite-loop.png differ diff --git a/assets/cards/keylogger.png b/assets/cards/keylogger.png index aac1a8d..0eeb4dc 100644 Binary files a/assets/cards/keylogger.png and b/assets/cards/keylogger.png differ diff --git a/assets/cards/latency-spike.png b/assets/cards/latency-spike.png index 7e15719..8a71153 100644 Binary files a/assets/cards/latency-spike.png and b/assets/cards/latency-spike.png differ diff --git a/assets/cards/memory-parasite.png b/assets/cards/memory-parasite.png index 881853e..25352f5 100644 Binary files a/assets/cards/memory-parasite.png and b/assets/cards/memory-parasite.png differ diff --git a/assets/cards/mirror-site.png b/assets/cards/mirror-site.png index bcda9b8..e350a6c 100644 Binary files a/assets/cards/mirror-site.png and b/assets/cards/mirror-site.png differ diff --git a/assets/cards/network-interface-upgrade.png b/assets/cards/network-interface-upgrade.png index a3fa153..356f105 100644 Binary files a/assets/cards/network-interface-upgrade.png and b/assets/cards/network-interface-upgrade.png differ diff --git a/assets/cards/null-pointer.png b/assets/cards/null-pointer.png index 868705f..0ed6db9 100644 Binary files a/assets/cards/null-pointer.png and b/assets/cards/null-pointer.png differ diff --git a/assets/cards/overclocked-cpu.png b/assets/cards/overclocked-cpu.png index f9ce37b..c28a267 100644 Binary files a/assets/cards/overclocked-cpu.png and b/assets/cards/overclocked-cpu.png differ diff --git a/assets/cards/overflow-error.png b/assets/cards/overflow-error.png index 797061e..6a0f068 100644 Binary files a/assets/cards/overflow-error.png and b/assets/cards/overflow-error.png differ diff --git a/assets/cards/packet-accelerator.png b/assets/cards/packet-accelerator.png index e3eed88..222858f 100644 Binary files a/assets/cards/packet-accelerator.png and b/assets/cards/packet-accelerator.png differ diff --git a/assets/cards/packet-loss.png b/assets/cards/packet-loss.png index ac13241..ec5e5de 100644 Binary files a/assets/cards/packet-loss.png and b/assets/cards/packet-loss.png differ diff --git a/assets/cards/packet-sniffer.png b/assets/cards/packet-sniffer.png index 1f29b00..3134100 100644 Binary files a/assets/cards/packet-sniffer.png and b/assets/cards/packet-sniffer.png differ diff --git a/assets/cards/payload-injector.png b/assets/cards/payload-injector.png index b3954e4..b2300b9 100644 Binary files a/assets/cards/payload-injector.png and b/assets/cards/payload-injector.png differ diff --git a/assets/cards/payload-module.png b/assets/cards/payload-module.png index c21c3d7..0d17a0c 100644 Binary files a/assets/cards/payload-module.png and b/assets/cards/payload-module.png differ diff --git a/assets/cards/persistent-infection.png b/assets/cards/persistent-infection.png index a37daef..9714cfe 100644 Binary files a/assets/cards/persistent-infection.png and b/assets/cards/persistent-infection.png differ diff --git a/assets/cards/proxy-relay.png b/assets/cards/proxy-relay.png index 30ec076..aef022d 100644 Binary files a/assets/cards/proxy-relay.png and b/assets/cards/proxy-relay.png differ diff --git a/assets/cards/quantum-coprocessor.png b/assets/cards/quantum-coprocessor.png index ca27b7e..68947f7 100644 Binary files a/assets/cards/quantum-coprocessor.png and b/assets/cards/quantum-coprocessor.png differ diff --git a/assets/cards/race-condition.png b/assets/cards/race-condition.png index 50a5f0f..20269dc 100644 Binary files a/assets/cards/race-condition.png and b/assets/cards/race-condition.png differ diff --git a/assets/cards/raid-array.png b/assets/cards/raid-array.png index 28be164..2843137 100644 Binary files a/assets/cards/raid-array.png and b/assets/cards/raid-array.png differ diff --git a/assets/cards/ram-expansion.png b/assets/cards/ram-expansion.png index f81120c..d2e5a8e 100644 Binary files a/assets/cards/ram-expansion.png and b/assets/cards/ram-expansion.png differ diff --git a/assets/cards/recursive-infection.png b/assets/cards/recursive-infection.png index ebae163..f2447fa 100644 Binary files a/assets/cards/recursive-infection.png and b/assets/cards/recursive-infection.png differ diff --git a/assets/cards/redundant-power-supply.png b/assets/cards/redundant-power-supply.png index e7c90d1..1e741ac 100644 Binary files a/assets/cards/redundant-power-supply.png and b/assets/cards/redundant-power-supply.png differ diff --git a/assets/cards/replication-routine.png b/assets/cards/replication-routine.png index fca5ebe..e2d501b 100644 Binary files a/assets/cards/replication-routine.png and b/assets/cards/replication-routine.png differ diff --git a/assets/cards/resource-leech.png b/assets/cards/resource-leech.png index 2e7ed8e..94d38aa 100644 Binary files a/assets/cards/resource-leech.png and b/assets/cards/resource-leech.png differ diff --git a/assets/cards/rollback-routine.png b/assets/cards/rollback-routine.png index 204578e..9130a05 100644 Binary files a/assets/cards/rollback-routine.png and b/assets/cards/rollback-routine.png differ diff --git a/assets/cards/rootkit.png b/assets/cards/rootkit.png index c6f135f..4be2ca7 100644 Binary files a/assets/cards/rootkit.png and b/assets/cards/rootkit.png differ diff --git a/assets/cards/sandbox-mode.png b/assets/cards/sandbox-mode.png index 892ec4d..f57a944 100644 Binary files a/assets/cards/sandbox-mode.png and b/assets/cards/sandbox-mode.png differ diff --git a/assets/cards/segmentation-fault.png b/assets/cards/segmentation-fault.png index 2438ce2..79396fe 100644 Binary files a/assets/cards/segmentation-fault.png and b/assets/cards/segmentation-fault.png differ diff --git a/assets/cards/session-hijack.png b/assets/cards/session-hijack.png index 14026bc..1d06503 100644 Binary files a/assets/cards/session-hijack.png and b/assets/cards/session-hijack.png differ diff --git a/assets/cards/solid-state-cache.png b/assets/cards/solid-state-cache.png index ca04263..c6f5d76 100644 Binary files a/assets/cards/solid-state-cache.png and b/assets/cards/solid-state-cache.png differ diff --git a/assets/cards/spoofed-mac.png b/assets/cards/spoofed-mac.png index 0045097..4f5dc23 100644 Binary files a/assets/cards/spoofed-mac.png and b/assets/cards/spoofed-mac.png differ diff --git a/assets/cards/stack-overflow.png b/assets/cards/stack-overflow.png index facd758..3e40188 100644 Binary files a/assets/cards/stack-overflow.png and b/assets/cards/stack-overflow.png differ diff --git a/assets/cards/stock-rice.png b/assets/cards/stock-rice.png index 1323f02..d9e516f 100644 Binary files a/assets/cards/stock-rice.png and b/assets/cards/stock-rice.png differ diff --git a/assets/cards/surge-protector.png b/assets/cards/surge-protector.png index 92951e5..a5bf82c 100644 Binary files a/assets/cards/surge-protector.png and b/assets/cards/surge-protector.png differ diff --git a/assets/cards/tunnel.png b/assets/cards/tunnel.png index cc641d8..d6b8031 100644 Binary files a/assets/cards/tunnel.png and b/assets/cards/tunnel.png differ diff --git a/assets/cards/undefined-behavior.png b/assets/cards/undefined-behavior.png index 7eaa92a..a7d49d4 100644 Binary files a/assets/cards/undefined-behavior.png and b/assets/cards/undefined-behavior.png differ diff --git a/assets/cards/unhandled-exception.png b/assets/cards/unhandled-exception.png index e997657..599c9df 100644 Binary files a/assets/cards/unhandled-exception.png and b/assets/cards/unhandled-exception.png differ diff --git a/assets/cards/uptime-monitor.png b/assets/cards/uptime-monitor.png index 4d3d787..fe48091 100644 Binary files a/assets/cards/uptime-monitor.png and b/assets/cards/uptime-monitor.png differ diff --git a/assets/cards/version-control.png b/assets/cards/version-control.png index 041ed26..714c37a 100644 Binary files a/assets/cards/version-control.png and b/assets/cards/version-control.png differ diff --git a/assets/cards/visual-artifact.png b/assets/cards/visual-artifact.png index ed8a07a..ee1d616 100644 Binary files a/assets/cards/visual-artifact.png and b/assets/cards/visual-artifact.png differ diff --git a/assets/cards/warm-standby.png b/assets/cards/warm-standby.png index aa18f60..ec7220f 100644 Binary files a/assets/cards/warm-standby.png and b/assets/cards/warm-standby.png differ diff --git a/assets/cards/watchdog-timer.png b/assets/cards/watchdog-timer.png index 0d068d5..f7144aa 100644 Binary files a/assets/cards/watchdog-timer.png and b/assets/cards/watchdog-timer.png differ diff --git a/assets/cards/worm-protocol.png b/assets/cards/worm-protocol.png index fa016d7..b07fd0a 100644 Binary files a/assets/cards/worm-protocol.png and b/assets/cards/worm-protocol.png differ diff --git a/assets/cards/zero-day.png b/assets/cards/zero-day.png index 4dceeb3..8d7696c 100644 Binary files a/assets/cards/zero-day.png and b/assets/cards/zero-day.png differ diff --git a/assets/fonts/JetBrainsMono.ttf b/assets/fonts/JetBrainsMono.ttf new file mode 100644 index 0000000..aa310be Binary files /dev/null and b/assets/fonts/JetBrainsMono.ttf differ diff --git a/assets/fonts/JetBrainsMono.ttf.import b/assets/fonts/JetBrainsMono.ttf.import new file mode 100644 index 0000000..9716013 --- /dev/null +++ b/assets/fonts/JetBrainsMono.ttf.import @@ -0,0 +1,36 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://xws34dcsoext" +path="res://.godot/imported/JetBrainsMono.ttf-8687b3ef53786600db7b41962d23a6bd.fontdata" + +[deps] + +source_file="res://assets/fonts/JetBrainsMono.ttf" +dest_files=["res://.godot/imported/JetBrainsMono.ttf-8687b3ef53786600db7b41962d23a6bd.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +disable_embedded_bitmaps=true +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +modulate_color_glyphs=false +hinting=3 +subpixel_positioning=4 +keep_rounding_remainders=true +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/assets/fonts/OFL-JetBrainsMono.txt b/assets/fonts/OFL-JetBrainsMono.txt new file mode 100644 index 0000000..821a3da --- /dev/null +++ b/assets/fonts/OFL-JetBrainsMono.txt @@ -0,0 +1,93 @@ +Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: https://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/OFL-Orbitron.txt b/assets/fonts/OFL-Orbitron.txt new file mode 100644 index 0000000..91ede45 --- /dev/null +++ b/assets/fonts/OFL-Orbitron.txt @@ -0,0 +1,93 @@ +Copyright 2018 The Orbitron Project Authors (https://github.com/theleagueof/orbitron), with Reserved Font Name: "Orbitron" + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/assets/fonts/Orbitron.ttf b/assets/fonts/Orbitron.ttf new file mode 100644 index 0000000..1fc54ce Binary files /dev/null and b/assets/fonts/Orbitron.ttf differ diff --git a/assets/fonts/Orbitron.ttf.import b/assets/fonts/Orbitron.ttf.import new file mode 100644 index 0000000..e3a66c4 --- /dev/null +++ b/assets/fonts/Orbitron.ttf.import @@ -0,0 +1,36 @@ +[remap] + +importer="font_data_dynamic" +type="FontFile" +uid="uid://deqgf8gws0psp" +path="res://.godot/imported/Orbitron.ttf-4aa5bef4a915ff1c3ef70d74e72864ce.fontdata" + +[deps] + +source_file="res://assets/fonts/Orbitron.ttf" +dest_files=["res://.godot/imported/Orbitron.ttf-4aa5bef4a915ff1c3ef70d74e72864ce.fontdata"] + +[params] + +Rendering=null +antialiasing=1 +generate_mipmaps=false +disable_embedded_bitmaps=true +multichannel_signed_distance_field=false +msdf_pixel_range=8 +msdf_size=48 +allow_system_fallback=true +force_autohinter=false +modulate_color_glyphs=false +hinting=3 +subpixel_positioning=4 +keep_rounding_remainders=true +oversampling=0.0 +Fallbacks=null +fallbacks=[] +Compress=null +compress=true +preload=[] +language_support={} +script_support={} +opentype_features={} diff --git a/engine/cards/anomalies.gd b/engine/cards/anomalies.gd index a19bc50..efa527e 100644 --- a/engine/cards/anomalies.gd +++ b/engine/cards/anomalies.gd @@ -159,7 +159,9 @@ static func _beta_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> v static func _code_zero_resolve(s: Dictionary, _item: Dictionary, src: Dictionary) -> void: var foes := State.opponents_in_combat(s, src.ref) for r in foes: + var counters := State.counters_of(State.anomaly(s, r)) State.anomaly(s, r).infection += 1 + State.emit_counters(s, r, counters) State.fired(s, "Code Zero", src.controller) var names := ", ".join(foes.map(func(r): return "%s (%d)" % [State.anomaly_name(s, r), State.infection_of(State.anomaly(s, r))])) State.say(s, "Patient Zero infects %s." % names) @@ -184,7 +186,7 @@ static func _leaker_resolve(s: Dictionary, _item: Dictionary, src: Dictionary) - static func _leaker_discard(s: Dictionary, data: Dictionary, card: Variant) -> void: var p: int = data.ref.player if State.remove_from(s.players[State.other(p)].hand, card): - State.to_discard(s, card) + State.to_discard(s, card, "hand", "discarded") State.say(s, "Exfiltrate: %s discards %s." % [State.player_name(State.other(p)), State.name_of(s, card)]) if State.anomaly(s, data.ref).breachedTurn == s.turn: Flow.draw_cards(s, p, 1) @@ -209,14 +211,16 @@ static func _backup_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> if av.at == null or av.damage == 0: return var healed := mini(3, av.damage) + var counters := State.counters_of(av) av.damage -= healed + State.emit_counters(s, src.ref, counters) State.fired(s, "Backup Machine", p) State.say(s, "Restore Point heals %d damage on %s." % [healed, State.anomaly_name(s, src.ref)]) return var card: int = item.args.card if not State.remove_from(s.players[p].discard, card): return - State.to_hand(s, card) + State.to_hand(s, card, "discard") State.fired(s, "Backup Machine", p) State.say(s, "Restore Point returns %s to %s's hand." % [State.name_of(s, card), State.player_name(p)]) if State.def_of(s, card).kind != "hardware" or Query.slots_free(s, src.ref) <= 0: @@ -237,7 +241,7 @@ static func _backup_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> static func _backup_install(s: Dictionary, data: Dictionary, yes: Variant) -> void: if not yes or State.anomaly(s, data.ref).at == null or not s.players[data.ref.player].hand.has(data.card): return - s.players[data.ref.player].bandwidth -= data.cost + State.add_bandwidth(s, data.ref.player, -data.cost) s.stats.bandwidthOnCards[data.ref.player] += data.cost HardwareCards.attach_hardware(s, data.card, data.ref) State.say(s, "%s is installed on %s." % [State.name_of(s, data.card), State.anomaly_name(s, data.ref)]) @@ -266,6 +270,8 @@ static func _bits_resolve(s: Dictionary, item: Dictionary, src: Dictionary) -> v for v in before: after.append(State.roll_die(s) if v <= k else v) c.dice[key] = after + if State.has_events(s): + State.emit(s, {"k": "rerolled", "ref": src.ref.duplicate(), "dice": after.duplicate()}) State.fired(s, "Broken Bits", src.controller) var rerolled := before.filter(func(v): return v <= k).size() State.say(s, "Bit Flip rerolls %d dice: [%s] → [%s]." % [rerolled, ",".join(before.map(func(v): return str(v))), ",".join(after.map(func(v): return str(v)))]) diff --git a/engine/cards/executions.gd b/engine/cards/executions.gd index d14f317..b350738 100644 --- a/engine/cards/executions.gd +++ b/engine/cards/executions.gd @@ -247,7 +247,7 @@ static func _sabotage_resolve(s: Dictionary, item: Dictionary) -> void: State.fired(s, item.name, item.player) if item.args.mode == "destroy": State.uninstall_hardware(s, hw) - State.to_discard(s, hw) + State.to_discard(s, hw, "worn", "destroyed") State.stat(s, "hardwareLost", owner.player) State.say(s, "Sabotage destroys %s." % State.name_of(s, hw)) HardwareCards.shed_hardware(s, owner) @@ -400,7 +400,7 @@ static func _dump_discard(s: Dictionary, data: Dictionary, _value: Variant) -> v static func _dump_drop(s: Dictionary, data: Dictionary, card: Variant) -> void: if State.remove_from(s.players[data.player].hand, card): - State.to_discard(s, card) + State.to_discard(s, card, "hand", "discarded") # Rollback @@ -421,7 +421,7 @@ static func _rollback_resolve(s: Dictionary, item: Dictionary) -> void: var wearer = State.wearer_of(s, card) if State.uninstall_program(s, card) == null and State.uninstall_hardware(s, card) == null: return - State.to_hand(s, card) + State.to_hand(s, card, "worn" if wearer != null else "play") State.fired(s, item.name, item.player) State.say(s, "Rollback returns %s to %s's hand." % [State.name_of(s, card), State.player_name(State.owner_of(s, card))]) if wearer != null: @@ -565,8 +565,10 @@ static func _purge_resolve(s: Dictionary, item: Dictionary) -> void: var here := CardUtil.mine(s, item.player, loc) for r in here: var av := State.anomaly(s, r) + var counters := State.counters_of(av) av.infection = 0 av.permanentInfection = 0 + State.emit_counters(s, r, counters) av.mods = av.mods.filter(func(m): return m.cores >= 0 or m.by == item.player) av.rootedUntil = 0 av.disabledUntil = 0 @@ -591,7 +593,7 @@ static func _reset_resolve(s: Dictionary, item: Dictionary) -> void: var back: Array = item.args.cards.filter(func(id): return State.program_location(s, id) == item.target) for id in back: State.uninstall_program(s, id) - State.to_hand(s, id) + State.to_hand(s, id, "play") var gain: int = back.size() * (1 + item.power) State.gain_bandwidth(s, item.player, gain) State.fired(s, item.name, item.player) diff --git a/engine/cards/hardware.gd b/engine/cards/hardware.gd index 244cdec..a187b2e 100644 --- a/engine/cards/hardware.gd +++ b/engine/cards/hardware.gd @@ -35,7 +35,7 @@ static func shed_hardware(s: Dictionary, r: Dictionary) -> void: hw = list[i] break State.uninstall_hardware(s, hw) - State.to_discard(s, hw) + State.to_discard(s, hw, "worn", "shed") State.stat(s, "hardwareLost", r.player) State.say(s, "%s is out of Expansion Slots and discards %s." % [State.anomaly_name(s, r), State.name_of(s, hw)]) @@ -57,6 +57,7 @@ static func _wearing(wearer: Variant, r: Dictionary) -> bool: static func attach_hardware(s: Dictionary, card: int, r: Dictionary) -> void: State.remove_from(s.players[r.player].hand, card) State.anomaly(s, r).hardware.append(card) + State.emit_install(s, card, "anomaly:%d:%d" % [r.player, r.slot]) s.cards[card].installedTurn = s.turn State.stat(s, "hardwareInstalled", r.player) State.played(s, State.name_of(s, card), r.player) @@ -264,7 +265,7 @@ static func _raid_defeated(s: Dictionary, _hw: int, ev: Dictionary) -> bool: static func _raid_keep(s: Dictionary, data: Dictionary, keep: Variant) -> void: if keep: - s.players[data.ref.player].bandwidth -= data.cost + State.add_bandwidth(s, data.ref.player, -data.cost) State.stat(s, "bandwidthOnCards", data.ref.player, data.cost) State.fired(s, "RAID Array", data.ref.player) Flow.knock_out(s, data.ref, data.loc, data.role, keep) @@ -366,7 +367,7 @@ static func _hot_swap_resolve(s: Dictionary, item: Dictionary, src: Dictionary) if not Query.slots_fit(s, r, out_card, into): return State.uninstall_hardware(s, out_card) - State.to_hand(s, out_card) + State.to_hand(s, out_card, "worn") attach_hardware(s, into, r) State.fired(s, "Hot-Swap Bay", src.controller) State.say(s, "Hot-Swap Bay swaps %s for %s on %s." % [State.name_of(s, out_card), State.name_of(s, into), State.anomaly_name(s, r)]) diff --git a/engine/cards/programs.gd b/engine/cards/programs.gd index fd6e9a6..c8bb73d 100644 --- a/engine/cards/programs.gd +++ b/engine/cards/programs.gd @@ -38,10 +38,10 @@ static func destroy_program(s: Dictionary, id: int) -> void: for x in here: if x.name == "Version Control": State.fired(s, "Version Control", owner) - State.to_hand(s, id) + State.to_hand(s, id, "play") State.say(s, "Version Control: %s returns to %s's hand." % [State.name_of(s, id), State.player_name(owner)]) return - State.to_discard(s, id) + State.to_discard(s, id, "play", "destroyed") State.say(s, "%s is destroyed." % State.name_of(s, id)) @@ -50,6 +50,7 @@ static func _install_free(s: Dictionary, card: int, at: String) -> void: var p := State.owner_of(s, card) State.remove_from(s.players[p].hand, card) s.locations[at].programs.append(card) + State.emit_install(s, card, "loc:" + at) s.cards[card].installedTurn = s.turn State.stat(s, "programsInstalled", p) State.played(s, State.name_of(s, card), p) @@ -91,6 +92,7 @@ static func _latest_penalty(s: Dictionary, av: Dictionary) -> Variant: static func _remove_negative(s: Dictionary, r: Dictionary, what: String) -> void: var av := State.anomaly(s, r) + var counters := State.counters_of(av) if what == "infection": av.infection -= 1 elif what == "bug": @@ -106,6 +108,7 @@ static func _remove_negative(s: Dictionary, r: Dictionary, what: String) -> void elif what.begins_with("mod:"): var seq := what.substr(4).to_int() av.mods = av.mods.filter(func(m): return m.seq != seq) + State.emit_counters(s, r, counters) static func scripts() -> Dictionary: @@ -575,7 +578,7 @@ static func _packet_loss_breach(s: Dictionary, src: Dictionary, ev: Dictionary) return var card: int = hand[Rng.rand_int(s.rng, hand.size())] State.remove_from(hand, card) - State.to_discard(s, card) + State.to_discard(s, card, "hand", "discarded") State.fired(s, "Packet Loss", src.controller) State.say(s, "Packet Loss: %s discards %s at random." % [State.player_name(ev.ref.player), State.name_of(s, card)]) @@ -678,7 +681,7 @@ static func _garbage_resolve(s: Dictionary, item: Dictionary, src: Dictionary) - if State.program_location(s, card) != src.at: return State.uninstall_program(s, card) - State.to_discard(s, card) + State.to_discard(s, card, "play", "sacrificed") State.stat(s, "programsLost", src.controller) State.gain_bandwidth(s, src.controller, State.def_of(s, card).bandwidth) State.fired(s, "Garbage Collection", src.controller) @@ -705,7 +708,7 @@ static func _version_captured(s: Dictionary, src: Dictionary, ev: Dictionary) -> static func _version_save(s: Dictionary, _data: Variant, card: Variant) -> void: if State.uninstall_program(s, card) == null: return - State.to_hand(s, card) + State.to_hand(s, card, "play") State.fired(s, "Version Control", State.owner_of(s, card)) State.say(s, "Version Control returns %s to %s's hand." % [State.name_of(s, card), State.player_name(State.owner_of(s, card))]) diff --git a/engine/cards/servers.gd b/engine/cards/servers.gd index aec114a..d2c75d0 100644 --- a/engine/cards/servers.gd +++ b/engine/cards/servers.gd @@ -189,6 +189,7 @@ static func _callable_redraw(s: Dictionary, data: Dictionary, again: Variant) -> if not State.remove_from(pl.hand, data.card): return pl.deck.append(data.card) + State.emit_pile(s, data.card, "deck", "hand") State.fired(s, "Callable Server", data.player) Flow.draw_now(s, data.player) s.stats.cardsDrawn[data.player] -= 1 diff --git a/engine/cards/util.gd b/engine/cards/util.gd index 4c64a54..4444ee7 100644 --- a/engine/cards/util.gd +++ b/engine/cards/util.gd @@ -39,7 +39,9 @@ static func add_bugs(s: Dictionary, r: Dictionary, n: int, source: String, by: i State.say(s, "ECC Memory blocks %s's Bug counters on %s." % [source, State.anomaly_name(s, r)]) State.fired(s, "ECC Memory", r.player) return false + var counters := State.counters_of(State.anomaly(s, r)) State.anomaly(s, r).bugs += n + State.emit_counters(s, r, counters) State.fired(s, source, by) State.say(s, "%s: %s gets %d Bug counter%s (%d total)." % [source, State.anomaly_name(s, r), n, "" if n == 1 else "s", State.anomaly(s, r).bugs]) return true @@ -47,10 +49,12 @@ static func add_bugs(s: Dictionary, r: Dictionary, n: int, source: String, by: i static func infect(s: Dictionary, r: Dictionary, n: int, source: String, by: int, permanent := false) -> void: var av := State.anomaly(s, r) + var counters := State.counters_of(av) if permanent: av.permanentInfection += n else: av.infection += n + State.emit_counters(s, r, counters) State.fired(s, source, by) State.say(s, "%s: %s gets %s %sInfection counter%s (%d total)." % [source, State.anomaly_name(s, r), "an" if n == 1 else str(n), "permanent " if permanent else "", "" if n == 1 else "s", av.infection + av.permanentInfection]) diff --git a/engine/engine.gd b/engine/engine.gd index 15bb839..2707d92 100644 --- a/engine/engine.gd +++ b/engine/engine.gd @@ -104,8 +104,9 @@ static func _new_anomaly(card: int, face_up: bool, copy_of: Variant) -> Dictiona } -## Starts a game from {pool, decks: [deck, deck], seed, rules?, log?}. A deck is {anomalies, servers, -## main}, lists of card names. Returns null (and records an error) if a deck is illegal. +## Starts a game from {pool, decks: [deck, deck], seed, rules?, log?, events?}. A deck is {anomalies, +## servers, main}, lists of card names. Returns null (and records an error) if a deck is illegal. +## With `events`, the game also keeps s.events for the table to act out (State.emit). static func create_game(o: Dictionary) -> Variant: var pool: Dictionary = o.pool var decks: Array = o.decks @@ -146,6 +147,7 @@ static func create_game(o: Dictionary) -> Variant: "stats": _new_stats(), "cardUse": {}, "log": [] if o.get("log", false) else null, + "events": [] if o.get("events", false) else null, } var add := func(card_name: String, owner: int) -> int: s.defs[card_name] = _with_price(pool.by_name[card_name], rules) @@ -175,13 +177,17 @@ static func create_game(o: Dictionary) -> Variant: "anomalies": avs, "unlockedLevel": 1, }) + for i in 4: + if avs[i].faceUp: + State.emit(s, {"k": "flipped", "ref": State.ref(p, i + 1)}) for p in 2: var me: Dictionary = s.players[p] var start: Dictionary = s.locations[GameMap.START_LOC[p]] var server: int = me.serverPile.pop_front() start.owner = p start.server = server - me.bandwidth = rules.startingBandwidth + CardScripts.of(s.cards[server].name).get("bandwidthOnPlace", 0) + State.emit_install(s, server, "loc:" + GameMap.START_LOC[p]) + State.add_bandwidth(s, p, rules.startingBandwidth + CardScripts.of(s.cards[server].name).get("bandwidthOnPlace", 0)) State.played(s, s.cards[server].name, p) for i in rules.openingHand: Flow.draw_now(s, p) @@ -190,9 +196,14 @@ static func create_game(o: Dictionary) -> Variant: s.active = s.firstPlayer var p2 := State.other(s.firstPlayer) var second: Dictionary = s.players[p2] - second.bandwidth += rules.secondPlayer.bandwidth - for av in second.anomalies.slice(0, rules.startingAnomalies + rules.secondPlayer.anomalies): + State.add_bandwidth(s, p2, rules.secondPlayer.bandwidth) + var opening: Array = second.anomalies.slice(0, rules.startingAnomalies + rules.secondPlayer.anomalies) + for i in opening.size(): + var av: Dictionary = opening[i] + var was: bool = av.faceUp av.faceUp = av.card >= 0 + if av.faceUp and not was: + State.emit(s, {"k": "flipped", "ref": State.ref(p2, i + 1)}) for i in rules.secondPlayer.cards: Flow.draw_now(s, p2) if rules.secondPlayer.locations > 0: @@ -201,11 +212,13 @@ static func create_game(o: Dictionary) -> Variant: var L: Dictionary = s.locations[GameMap.other_end(line, GameMap.START_LOC[p2])] L.owner = p2 L.server = second.serverPile.pop_front() + State.emit_install(s, L.server, "loc:" + GameMap.other_end(line, GameMap.START_LOC[p2])) State.played(s, s.cards[L.server].name, p2) s.stats.cardsDrawn = [0, 0] State.say(s, "%s goes first." % State.player_name(s.firstPlayer), {"tag": "game", "player": s.firstPlayer}) _begin_turn(s, not rules.firstTurn.draw) run(s) + State.reconcile_bandwidth(s, [0, 0], 0) return s @@ -218,6 +231,7 @@ static func _begin_turn(s: Dictionary, skip_draw: bool) -> void: return s.turn += 1 s.clock = State.start_of(s.turn) + State.emit(s, {"k": "turn", "turn": s.turn, "p": s.active}) # Command rule: a player's turn is their commands in a round, so its refreshes come at the first. var fresh: bool = not cmd or State.first_command(s, s.turn) if not cmd or State.round_of(s, s.turn) != State.round_of(s, s.turn - 1): @@ -260,7 +274,7 @@ static func _end_turn(s: Dictionary) -> void: var until = s.cards[hw].get("pushedUntil") if until != null and not State.running(s, until): State.remove_from(av.hardware, hw) - State.to_discard(s, hw) + State.to_discard(s, hw, "worn", "expired") State.say(s, "%s (Push Update) is discarded." % State.name_of(s, hw)) _tidy(s) s.active = State.commander_of(s, s.turn + 1) if s.rules.commands.on else State.other(s.active) @@ -727,6 +741,11 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> var p: int = decider(s) var me: Dictionary = s.players[p] var who := State.player_name(p) + var events_from := -1 + var bandwidth_before := [] + if State.has_events(s): + events_from = s.events.size() + bandwidth_before = [s.players[0].bandwidth, s.players[1].bandwidth] match a.type: "end": @@ -752,9 +771,11 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> "buyAnomaly": var price: int = anomaly_for_sale(s, p).price var av: Dictionary = me.anomalies[a.slot - 1] - me.bandwidth -= price + State.add_bandwidth(s, p, -price) State.stat(s, "bandwidthOnAnomalies", p, price) State.stat(s, "anomaliesBought", p) + if not av.faceUp: + State.emit(s, {"k": "flipped", "ref": State.ref(p, a.slot)}) av.faceUp = true State.say(s, "%s buys Anomaly %d: %s (-%d Gb, now %d)." % [who, a.slot, State.name_of(s, av.card), price, me.bandwidth], {"tag": "card", "player": p}) "recruit": @@ -763,18 +784,19 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> if av.card >= 0: Flow.retire_anomaly(s, State.ref(p, a.slot)) State.remove_from(me.hand, a.card) - me.bandwidth -= cost + State.add_bandwidth(s, p, -cost) State.stat(s, "bandwidthOnCards", p, cost) State.stat(s, "anomaliesRecruited", p) State.played(s, State.name_of(s, a.card), p) av.merge(_new_anomaly(a.card, true, null), true) me.anomalies[a.slot + 3].card = a.card + State.emit(s, {"k": "flipped", "ref": State.ref(p, a.slot)}) State.say(s, "%s recruits %s as Anomaly %d (-%d Gb, now %d)." % [who, State.name_of(s, a.card), a.slot, cost, me.bandwidth], {"tag": "card", "player": p}) "salvage": var gain: int = State.def_of(s, a.card).bandwidth State.remove_from(me.hand, a.card) - State.to_discard(s, a.card) - me.bandwidth += gain + State.to_discard(s, a.card, "hand", "salvage") + State.add_bandwidth(s, p, gain) State.stat(s, "bandwidthFromSalvage", p, gain) State.stat(s, "cardsSalvaged", p) State.say(s, "%s salvages %s (+%d Gb, now %d)." % [who, State.name_of(s, a.card), gain, me.bandwidth], {"tag": "card", "player": p}) @@ -784,6 +806,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> var text := "%s places %s on %s." % [who, State.anomaly_name(s, r), a.to] if av.at == null \ else "%s moves %s %s → %s." % [who, State.anomaly_name(s, r), av.at, a.to] State.say(s, text, {"tag": "move", "player": p, "loc": a.to, "ref": r}) + State.emit_moved(s, r, av.at, a.to) av.at = a.to av.placed = true "recall": @@ -806,15 +829,17 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> "clearFirewall": var level: int = s.firewalls[a.line] var cost := State.firewall_cost(s, level) - me.bandwidth -= cost + State.add_bandwidth(s, p, -cost) State.stat(s, "bandwidthOnFirewalls", p, cost) s.firewalls.erase(a.line) + State.emit(s, {"k": "firewall", "line": a.line, "from": level, "to": 0, "p": p}) State.stat(s, "firewallsCleared", p) State.say(s, "%s clears the Lv %d Firewall on %s (-%d Gb)." % [who, level, a.line, cost], {"tag": "firewall", "player": p}) "firewall": var before: int = s.firewalls.get(a.line, 0) var cost := Query.pay(s, {"kind": "firewall", "player": p, "line": a.line, "level": a.level}, "bandwidthOnFirewalls") s.firewalls[a.line] = a.level + State.emit(s, {"k": "firewall", "line": a.line, "from": before, "to": a.level, "p": p}) State.stat(s, "firewallsUpgraded" if before else "firewallsPlaced", p) var text := "%s upgrades the Firewall on %s to Lv %d (-%d Gb)." % [who, a.line, a.level, cost] if before \ else "%s places a Lv %d Firewall on %s (-%d Gb)." % [who, a.level, a.line, cost] @@ -824,6 +849,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> var cost := Query.pay(s, {"kind": "hardware", "player": p, "card": a.card, "ref": r, "at": State.anomaly(s, r).at}, "bandwidthOnCards") State.remove_from(me.hand, a.card) State.anomaly(s, r).hardware.append(a.card) + State.emit_install(s, a.card, "anomaly:%d:%d" % [r.player, r.slot]) s.cards[a.card].installedTurn = s.turn State.stat(s, "hardwareInstalled", p) State.played(s, State.name_of(s, a.card), p) @@ -834,6 +860,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> var cost := Query.pay(s, {"kind": "program", "player": p, "card": a.card, "at": a.at}, "bandwidthOnCards") State.remove_from(me.hand, a.card) s.locations[a.at].programs.append(a.card) + State.emit_install(s, a.card, "loc:" + a.at) s.cards[a.card].installedTurn = s.turn State.stat(s, "programsInstalled", p) State.played(s, State.name_of(s, a.card), p) @@ -850,6 +877,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> "from": a.from, "power": execution_power(s, p, a.from), } s.stack.append(item) + State.emit(s, {"k": "stack", "p": p, "card": a.card, "name": card_name, "kind": "execution"}) if item.power > 0: State.fired(s, "Dedicated GPU", p) State.stat(s, "executionsPlayed", p) @@ -863,7 +891,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> "activate": var src: Dictionary = ability_source(s, a.card, a.name) var cost := ability_cost(s, src) + _extra_cost(s, src, a.args) - me.bandwidth -= cost + State.add_bandwidth(s, p, -cost) State.stat(s, "bandwidthOnAbilities", p, cost) if src.kind == "hardware": HardwareCards.use_hardware(s, src.id) @@ -871,6 +899,7 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> State.mark_used(s, ability_key(src)) var label: String = "%s (%s)" % [State.def_of(s, src.id).ability.name, src.name] if src.kind == "anomaly" else src.name s.stack.append({"kind": "ability", "player": p, "card": src.id, "name": src.name, "target": null, "args": a.args, "from": null, "power": 0}) + State.emit(s, {"k": "stack", "p": p, "card": src.id, "name": src.name, "kind": "ability"}) State.stat(s, "abilitiesUsed", p) if src.kind == "anomaly": State.played(s, src.name, p) @@ -878,6 +907,8 @@ static func apply_action(s: Dictionary, a: Dictionary, legal: Variant = null) -> State.say(s, "%s uses %s%s." % [who, label, paid], {"tag": "card", "player": p, "loc": src.at, "ref": src.get("ref")}) _respond_to(s, p, s.stack.size() - 1) run(s) + if events_from >= 0: + State.reconcile_bandwidth(s, bandwidth_before, events_from) return true @@ -954,7 +985,7 @@ static func _resolve_top(s: Dictionary) -> void: var item: Dictionary = s.stack.pop_back() var script := CardScripts.of(item.name) if item.kind == "execution": - State.to_discard(s, item.card) + State.to_discard(s, item.card, "stack", "played") for src in Query.sources(s): var sc := CardScripts.of(src.name) if sc.has("negates") and sc.negates.call(s, src, item): @@ -1043,6 +1074,7 @@ static func view_for(s: Dictionary, p: int) -> Dictionary: var view := s.duplicate() view.rng = {"s": 0} view.log = null + view.events = null view.players = players view.choice = choice view.combat = combat diff --git a/engine/flow.gd b/engine/flow.gd index cade509..d5da070 100644 --- a/engine/flow.gd +++ b/engine/flow.gd @@ -28,6 +28,7 @@ static func draw_now(s: Dictionary, p: int) -> Variant: var card: int = pl.deck.pop_front() pl.hand.append(card) State.stat(s, "cardsDrawn", p) + State.emit(s, {"k": "drew", "p": p, "card": card}) return card @@ -49,16 +50,21 @@ static func _clear_status(av: Dictionary) -> void: av.damage = 0 -## A copy leaves play. It has no Hardware of its own. -static func remove_copy(s: Dictionary, r: Dictionary) -> void: +## A copy leaves play. It has no Hardware of its own. `recalled` is false when a defeat already +## told the events. +static func remove_copy(s: Dictionary, r: Dictionary, recalled := true) -> void: var cp := State.anomaly(s, r) if cp.at == null: return State.say(s, "%s is removed." % State.anomaly_name(s, r), {"tag": "move", "player": r.player, "ref": r}) + var counters := State.counters_of(cp) + if recalled: + State.emit_moved(s, r, cp.at, null) _clear_status(cp) cp.permanentInfection = 0 cp.at = null cp.faceUp = false + State.emit_counters(s, r, counters) drop_from_combat(s, r) @@ -70,11 +76,11 @@ static func retire_anomaly(s: Dictionary, r: Dictionary) -> void: if not av.hardware.is_empty(): State.stat(s, "hardwareLost", r.player, av.hardware.size()) for hw in av.hardware: - State.to_discard(s, hw) + State.to_discard(s, hw, "worn", "retired") var from := " from %s" % av.at if av.at else "" State.say(s, "%s retires %s%s." % [State.player_name(r.player), State.anomaly_name(s, r), from], {"tag": "card", "player": r.player, "ref": r}) drop_from_combat(s, r) - State.to_discard(s, av.card) + State.to_discard(s, av.card, "slot", "retired") State.stat(s, "anomaliesRetired", r.player) @@ -84,18 +90,22 @@ static func knock_out(s: Dictionary, r: Dictionary, loc: String, role: String, k var av := State.anomaly(s, r) if av.at == null: return + if State.has_events(s): + State.emit(s, {"k": "destroyed", "ref": r.duplicate(), "loc": av.at}) if State.is_copy(r): - remove_copy(s, r) + remove_copy(s, r, false) else: if not keep_hardware and not av.hardware.is_empty(): var names := ", ".join(av.hardware.map(func(h): return State.name_of(s, h))) State.say(s, "%s loses %s." % [State.player_name(r.player), names], {"tag": "combat", "player": r.player, "ref": r, "loc": loc}) State.stat(s, "hardwareLost", r.player, av.hardware.size()) for hw in av.hardware: - State.to_discard(s, hw) + State.to_discard(s, hw, "worn", "destroyed") av.hardware = [] + var counters := State.counters_of(av) _clear_status(av) av.at = null + State.emit_counters(s, r, counters) State.say(s, "%s returns to its slot." % State.anomaly_name(s, r), {"tag": "combat", "player": r.player, "ref": r, "loc": loc}) remove_copy(s, State.copy_of(r)) State.stat(s, "anomaliesDestroyed", r.player) @@ -112,9 +122,12 @@ static func recall_anomaly(s: Dictionary, r: Dictionary) -> void: var healed: int = av.damage var healing := ", healing %d damage" % healed if healed else "" State.say(s, "%s recalls %s from %s to its slot%s." % [State.player_name(r.player), State.anomaly_name(s, r), av.at, healing], {"tag": "move", "player": r.player, "ref": r, "loc": av.at}) + var counters := State.counters_of(av) + State.emit_moved(s, r, av.at, null) _clear_status(av) av.at = null av.placed = true + State.emit_counters(s, r, counters) remove_copy(s, State.copy_of(r)) State.stat(s, "recalls", r.player) @@ -123,6 +136,8 @@ static func recall_anomaly(s: Dictionary, r: Dictionary) -> void: static func create_copy(s: Dictionary, original: Dictionary, to: String) -> void: var r := State.copy_of(original) var cp := State.anomaly(s, r) + var was = cp.at + var counters := State.counters_of(cp) cp.merge({ "card": State.anomaly(s, original).card, "faceUp": true, @@ -141,6 +156,8 @@ static func create_copy(s: Dictionary, original: Dictionary, to: String) -> void "breachedTurn": 0, "createdTurn": s.turn, }, true) + State.emit_moved(s, r, was, to) + State.emit_counters(s, r, counters) State.say(s, "%s creates %s on %s." % [State.player_name(r.player), State.anomaly_name(s, r), to], {"tag": "card", "player": r.player, "ref": r, "loc": to}) @@ -148,6 +165,7 @@ static func create_copy(s: Dictionary, original: Dictionary, to: String) -> void static func move_anomaly(s: Dictionary, r: Dictionary, to: String) -> void: var av := State.anomaly(s, r) State.say(s, "%s moves %s → %s." % [State.anomaly_name(s, r), av.at, to], {"tag": "move", "player": r.player, "ref": r, "loc": to}) + State.emit_moved(s, r, av.at, to) av.at = to @@ -225,6 +243,8 @@ static func _roll_all(s: Dictionary, c: Dictionary) -> void: break c.ties += 1 c.rolled = true + if State.has_events(s): + State.emit(s, {"k": "rolled", "loc": c.loc, "dice": c.dice.duplicate(true)}) # --------------------------------------------------------------------------------------------- @@ -241,6 +261,8 @@ static func damage_anomaly(s: Dictionary, r: Dictionary, n: int) -> bool: if av.at == null or n <= 0: return false av.damage += n + if State.has_events(s): + State.emit(s, {"k": "damaged", "ref": r.duplicate(), "amount": n, "loc": av.at}) var dead: bool = av.damage >= Query.health_of(s, r) var how := " and is destroyed" if dead else " (%s)" % health_text(s, r) State.say(s, "%s takes %d damage%s." % [State.anomaly_name(s, r), n, how], {"tag": "combat", "player": r.player, "ref": r, "amount": n, "loc": av.at}) @@ -327,6 +349,7 @@ static func sync_dice(s: Dictionary, c: Dictionary) -> void: for r in State.fighters_of(c): var key := State.ref_key(r) var dice: Array = c.dice.get(key, []) + var before := dice.duplicate() if State.has_events(s) else [] var want := Query.cores_of(s, Query.fighter_of(s, r)) while dice.size() < want: dice.append(State.roll_die(s)) @@ -334,6 +357,8 @@ static func sync_dice(s: Dictionary, c: Dictionary) -> void: dice.sort() dice.resize(want) c.dice[key] = dice + if State.has_events(s) and dice != before: + State.emit(s, {"k": "rerolled", "ref": r.duplicate(), "dice": dice.duplicate()}) ## Current dice totals {atk, def}, after syncing to Core changes. @@ -407,6 +432,9 @@ static func _run_stage(s: Dictionary, c: Dictionary, stage: String) -> void: var hp := func(r): return ", %s" % health_text(s, r) if s.rules.health.on else "" var defs := " and ".join(c.defenders.map(func(d): return "%s%s" % [State.anomaly_name(s, d), hp.call(d)])) State.say(s, "Combat at %s: %s (%d Cores, from %s%s) vs %s (%d Cores)." % [c.loc, State.anomaly_name(s, c.attacker), sides.atk, c.origin, hp.call(c.attacker), defs, sides.def], {"tag": "combat", "player": c.attacker.player, "loc": c.loc, "ref": c.attacker}) + if State.has_events(s): + State.emit(s, {"k": "combat", "id": c.id, "loc": c.loc, "attacker": c.attacker.duplicate(), + "defenders": c.defenders.map(func(d): return d.duplicate()), "kind": c.kind}) Query.emit(s, "onCombatStart", null) return if stage == "roll": @@ -497,16 +525,22 @@ static func capture_main(s: Dictionary, r: Dictionary, loc: String, how: String) if State.anomaly(s, r).at == null or State.controls(s, p, loc): return var previous = L.owner + State.emit_moved(s, r, State.anomaly(s, r).at, loc) + if State.has_events(s): + State.emit(s, {"k": "captured", "loc": loc, "p": p, "from": previous}) if L.server != null: State.reset_card(s, L.server) s.players[s.cards[L.server].owner].serverPile.append(L.server) + State.emit_pile(s, L.server, "serverPile", "play") if previous != null and not L.programs.is_empty(): State.stat(s, "programsLost", previous, L.programs.size()) for prog in L.programs: - State.to_discard(s, prog) + State.to_discard(s, prog, "play", "captured") L.programs = [] L.owner = p L.server = me.serverPile.pop_front() if not me.serverPile.is_empty() else null + if L.server != null: + State.emit_install(s, L.server, "loc:" + loc) State.anomaly(s, r).at = loc var level := GameMap.level_for(p, loc) @@ -528,6 +562,7 @@ static func capture_main(s: Dictionary, r: Dictionary, loc: String, how: String) if i < level and not av.faceUp: av.faceUp = true av.unlockedTurn = s.turn + State.emit(s, {"k": "flipped", "ref": State.ref(p, i + 1)}) State.say(s, "%s unlocks Anomaly %d: %s." % [State.player_name(p), i + 1, State.name_of(s, av.card)], {"tag": "capture", "player": p, "loc": loc}) if State.grid_count(s, p) >= s.rules.winLocations: s.over = true diff --git a/engine/query.gd b/engine/query.gd index 82d89bf..6594fcb 100644 --- a/engine/query.gd +++ b/engine/query.gd @@ -356,7 +356,7 @@ static func pay(s: Dictionary, payment: Dictionary, stat_key: String) -> int: var cost := maxi(0, n) if cost > s.players[payment.player].bandwidth: Util.fail("Can't afford %d Gb" % cost) - s.players[payment.player].bandwidth -= cost + State.add_bandwidth(s, payment.player, -cost) State.stat(s, stat_key, payment.player, cost) for src in touched: var sc := CardScripts.of(src.name) diff --git a/engine/state.gd b/engine/state.gd index d2bdac5..5a2307d 100644 --- a/engine/state.gd +++ b/engine/state.gd @@ -65,6 +65,58 @@ static func say(s: Dictionary, msg: String, meta := {}) -> void: s.log.append(line) +## Records what just happened for the table to act out (godot-plan.md §3): `ev` is {k: kind, ...}. +## Only a game made with `events` keeps them; TS has no events, so they stay out of conformance. +static func emit(s: Dictionary, ev: Dictionary) -> void: + var events = s.get("events") + if events != null: + events.append(ev) + + +## Whether this game records events, to skip building ones nobody keeps. +static func has_events(s: Dictionary) -> bool: + return s.get("events") != null + + +## Events from index `from` as `viewer` may see them: copies, with cards they can't see as -1 (the +## other player's draws, and cards the other player takes into hand from a hidden pile). +static func events_for(s: Dictionary, viewer: int, from := 0) -> Array: + var out := [] + var events = s.get("events") + if events == null: + return out + for i in range(maxi(0, from), events.size()): + var ev: Dictionary = events[i].duplicate(true) + var theirs: bool = ev.get("p", viewer) != viewer + if theirs and (ev.k == "drew" or (ev.k == "hand" and ev.get("from") in ["deck", "serverPile", ""])): + ev.card = -1 + elif theirs and ev.k == "pile" and ev.get("from") == "hand": + ev.card = -1 + out.append(ev) + return out + + +## Folded Bandwidth events must equal the Bandwidth: when a change slipped past the helpers, one more +## event makes up the difference. `before` is each player's Bandwidth at event `from`. Counted in +## event_fixes, which tests expect to stay 0. +static var event_fixes := 0 + + +static func reconcile_bandwidth(s: Dictionary, before: Array, from: int) -> void: + var events = s.get("events") + if events == null: + return + var have := before.duplicate() + for i in range(from, events.size()): + var ev: Dictionary = events[i] + if ev.k == "bandwidth": + have[ev.p] = ev.to + for p in 2: + if have[p] != s.players[p].bandwidth: + event_fixes += 1 + emit(s, {"k": "bandwidth", "p": p, "from": have[p], "to": s.players[p].bandwidth}) + + ## The play-by-play as `viewer` may read it, or every line in full for null. static func log_for(s: Dictionary, viewer: Variant) -> Array: var out := [] @@ -374,14 +426,60 @@ static func reset_card(s: Dictionary, id: int) -> void: c.erase("pushedUntil") -static func to_discard(s: Dictionary, id: int) -> void: +## `from` and `why` only describe the move for events: from "hand", "play" (a location's Server or +## Program), "worn" (Hardware), "stack", "slot" or "deck"; why "salvage", "played", "destroyed", +## "captured", "discarded", …. +static func to_discard(s: Dictionary, id: int, from := "", why := "") -> void: reset_card(s, id) s.players[owner_of(s, id)].discard.append(id) + if has_events(s): + emit(s, {"k": "discard", "p": owner_of(s, id), "card": id, "from": from, "why": why}) -static func to_hand(s: Dictionary, id: int) -> void: +static func to_hand(s: Dictionary, id: int, from := "") -> void: reset_card(s, id) s.players[owner_of(s, id)].hand.append(id) + if has_events(s): + emit(s, {"k": "hand", "p": owner_of(s, id), "card": id, "from": from}) + + +## A Server, Program or Hardware card arriving on a location ("loc:C2") or an Anomaly +## ("anomaly:0:1"), for events. +static func emit_install(s: Dictionary, id: int, at: String) -> void: + if has_events(s): + emit(s, {"k": "install", "p": owner_of(s, id), "card": id, "at": at}) + + +## A card going into its owner's deck or Server pile ("deck", "serverPile"), for events. +static func emit_pile(s: Dictionary, id: int, zone: String, from: String) -> void: + if has_events(s): + emit(s, {"k": "pile", "p": owner_of(s, id), "card": id, "zone": zone, "from": from}) + + +static func emit_moved(s: Dictionary, r: Dictionary, from: Variant, to: Variant) -> void: + if not has_events(s) or from == to: + return + if from == null: + emit(s, {"k": "placed", "ref": r.duplicate(), "loc": to}) + elif to == null: + emit(s, {"k": "recalled", "ref": r.duplicate(), "from": from}) + else: + emit(s, {"k": "moved", "ref": r.duplicate(), "from": from, "to": to}) + + +## The counters an Anomaly shows, for "counter" events: take them before a change and pass them to +## emit_counters after it. +static func counters_of(av: Dictionary) -> Dictionary: + return {"infection": infection_of(av), "bugs": av.bugs, "damage": av.damage} + + +static func emit_counters(s: Dictionary, r: Dictionary, before: Dictionary) -> void: + if not has_events(s): + return + var now := counters_of(anomaly(s, r)) + for what in now: + if now[what] != before[what]: + emit(s, {"k": "counter", "ref": r.duplicate(), "what": what, "from": before[what], "to": now[what]}) static func remove_from(list: Array, id: int) -> bool: @@ -417,10 +515,18 @@ static func program_location(s: Dictionary, id: int) -> Variant: static func gain_bandwidth(s: Dictionary, p: int, n: int, key := "bandwidthFromEffects") -> void: if n <= 0: return - s.players[p].bandwidth += n + add_bandwidth(s, p, n) stat(s, key, p, n) +## Changes a player's Bandwidth by `n` (negative to spend), with its event. No stats. +static func add_bandwidth(s: Dictionary, p: int, n: int) -> void: + var before: int = s.players[p].bandwidth + s.players[p].bandwidth = before + n + if n != 0 and has_events(s): + emit(s, {"k": "bandwidth", "p": p, "from": before, "to": before + n}) + + # --------------------------------------------------------------------------------------------- # Tasks and choices diff --git a/gameplay-plan.md b/gameplay-plan.md new file mode 100644 index 0000000..a630ba6 --- /dev/null +++ b/gameplay-plan.md @@ -0,0 +1,254 @@ +# Gameplay Plan: Files TCG Table and Presentation + +_Prepared 2026-10-01 from `gameplay.md`, against the Godot project in `files-game/`._ + +Companion document: **`ui-plan.md`**, which owns the shared design foundation (tokens, fonts, the +chamfered StyleBox, the panel-geometry constant). **Its Phase 0 is a prerequisite for everything +here** — read §2–3 of that document first. + +## 1. Why + +`godot-plan.md` §10 records M1 (engine), M2 (table slice) and M3 (all Set 1 cards + greedy bot) as +done and conformance-clean — 1,100 traces, 1.68 M steps matching the TypeScript reference exactly. +What is not done is **M4 Presentation**. `gameplay.md` is, almost line for line, a request to build +M4 with the art direction settled. + +Three concrete problems: + +- **Cards are unreadable, measurably.** The hand renders at ~**153 × 215 px** on screen + (`HAND_DISTANCE = 9.0`, fov 45, at the 1600 × 900 base), and the inspector renders a 750 × 1050 + card face into a **150 × 210** `TextureRect`. They are the same size, which is why neither works. + `godot-plan.md` §4 promises *"Hovering a card shows it large (right-click pins it)"* — never + built; right-click is Cancel. +- **The world is a physical tabletop, not cyberspace.** A suede-fabric playmat on a 64 × 1 × 52 + dark-wood table. The cards are a chamfered neon HUD. The two do not look related. +- **Nothing is animated.** There are **five tween calls in the whole project**: `Card3D.glide()` + and `GameTable._place_camera()`. One generic 0.28 s glide serves draw, play and discard alike. + Damage and capture pop-ups are fired by **regex-matching log text** in + `scenes/game.gd:_pop_new_lines()` — so every reworded log line is a silently broken animation. + There is no engine event stream, so the table cannot know what actually happened. + +**Outcome:** a table that reads as cyberspace, a hand you can actually read, firewalls that look +like hardware, and a game that acts itself out. + +## 2. Decisions taken + +| Question | Decision | +| --- | --- | +| World look | **Keep the 3D tabletop** — `playmat.glb`, seat/top camera, `Card3D`. Restyle the surface to dark glass with a neon grid inlay, black void + grid horizon, chamfered tiles. | +| Card legibility | Enlarge the 2D inspector **and** add a hand-focus mode. | +| Firewalls | Procedural RJ45 port with emissive LEDs. No custom model. | +| Animation | Port `s.events` per `godot-plan.md` §3 with a presenter queue. | +| Owner colours | Keep Okabe–Ito `#56b4e9` / `#e69f00`; add a stripe/dot pattern cue; cyan is chrome only. | + +Colours used below come from `ui-plan.md` §2. The ones this plan needs: `bg #05080a`, +`accent #22d3ee`, `accent_dk #0e6b78`, owner `#56b4e9` / `#e69f00`, and a **22 px-at-750 px +chamfer**, i.e. ~3 % of the shorter edge. + +The cards already use a gold **edge connector** bus to mean *"hardware plugs in here"* — so +firewalls-as-ethernet-ports (§B4) extends an established visual vocabulary rather than inventing one. + +## 3. The work + +### B1. The cyberspace table + +`GameTable._build_room()` (`table/game_table.gd:101-146`) builds a `WorldEnvironment` with bg +`Color(0.035, 0.035, 0.045)`, ambient 0.85, filmic tonemap and **glow already enabled** at +intensity 0.4 / HDR threshold 1.2 — the bloom foundation exists. Plus a sun at energy 1.35 and a +64 × 1 × 52 dark-wood `BoxMesh` table top under the mat. + +- Black void background with a neon-blue grid horizon; drop or sink the wood table top. +- Replace `assets/playmat.tres` with a dark-glass grid material. **The swap is contained:** that + `.tres` is a `StandardMaterial3D` bound in exactly one place — + `table/playmat.tscn`'s `surface_material_override/0` on `Plane_003`. Point a new `ShaderMaterial` + + `playmat.gdshader` at that one line and the mat's look becomes a shader parameter rather than a + texture. The three suede maps (~3.5 MB) fall out of use. +- The old material carries `uv1_scale (2.284, 1.903, 1)` and `uv1_offset (0.908, 0, 0)`. Derive + the grid spacing from `BoardLayout.MAT_SIZE` (18.288 × 15.24) and the tile pitch instead, so the + grid **lines up with the locations** rather than with the old UVs. +- Raise glow once emission is the primary light source. + +### B2. Chamfer the location tiles + +`tile.gdshader` is a 29-line rounded-rect SDF with `radius = 0.2` and `instance uniform` +`fill_color` / `edge_color` / `glow` already in place. + +Swapping the rounded-rect SDF for a **chamfered octagon SDF** is roughly a five-line change that +instantly matches the cards' chamfer across all 15 locations **and** all 14 printed card spots, +which share the same shader. **This is the highest ratio of visual payoff to diff size in either +plan — do it first.** + +Add the **stripe/dot owner pattern** here too, as one more instance uniform. That is what lets +owner identity survive beside cyan chrome (`ui-plan.md` §2). + +On the "large play spaces" note in `gameplay.md`: tiles are ~`5.53 × 2.06` units, about **4.3 cards +wide**. Keeping that footprint was accepted. Integrating it means making the tile read as a +*socket* — chamfered frame, corner ticks, microtext label, dim interior — rather than a grey slab. + +### B3. Make the cards readable + +Three levers, all already instrumented: + +1. **The inspector.** `ui/hud.gd:189-194` is a `150 × 210` `TextureRect` fed by `Hud._art()` + (`:624-628`, cached in `_art_cache`). Grow it substantially; let the text panel scroll beside or + below it. Pure reuse — the full-resolution 750 × 1050 face is already loaded. +2. **Hand focus mode.** `GameTable._layout_hand()` (`:837-864`) lays the hand as a flat row + parented to the `Camera3D`. Add a mode — mouse to the bottom edge, or a held key — that expands + the hand into a large, legible 2D row drawn from the same textures, clickable, carrying the + salvage chip from `ui-plan.md` §A6. Reuse `Hud._art()`. +3. **Hover lift already exists** (`:837`, `y += CARD_SIZE.y * 0.42`). Keep it as the at-rest cue. + +Also fix the at-rest case: `HAND_SHOWN = 0.62` behind a 150 px bottom panel reserve is why only a +sliver shows. Retune `HAND_SHOWN` and `HAND_DISTANCE` (`:21-22`) once `ui-plan.md` §0.4 lands — +not before, since the reserve is one of the numbers that moves. + +### B4. Firewalls as RJ45 ports + +`_make_gate()` (`table/game_table.gd:249-291`) builds a `PlaneMesh` diamond plus a `BoxMesh` wall +(`1 × 1 × 0.14`). `_sync_gates()` (`:461-484`) scales it by level (`h = 0.22 + 0.2 * level`), tints +it from `FIREWALL_COLORS`, and pins a `"Lv N"` 2D tag. + +Replace with a procedural socket: a chamfered port body on the gateway, **emissive LEDs encoding +the level**, and a plug-in animation on place or upgrade. Scale reference: 1 unit = 5 cm, a card is +1.27 × 1.778 units, the gateway diamond is 0.34 × 0.34. + +Two engine facts constrain the design: + +- **Max level is `rules.firewallCost.size()`**, not a hardcoded 3 (`engine/engine.gd:619`; costs + default `[2, 4, 8]`). `FIREWALL_COLORS` hardcodes three entries and `_sync_gates` clamps with + `mini(...)`. Drive the LED count from the rules instead, or a rule variant silently caps the display. +- **Firewalls have no HP.** They are only placed, upgraded, or cleared for cost + (`engine/engine.gd:811-817`), and clearing is a *purchase* available to either player — there is + no free removal. So there is no damage state to show. The animation vocabulary is + **plug in / swap up / unplug**, not break. + +Keep it legible in both the seat and top-down views; the LEDs are the level readout in top-down, +where the port body foreshortens away. + +### B5. Engine events and the presenter + +The foundation for every animation. Specified in `godot-plan.md` §3 and never ported — §10 +confirms *"Not ported yet: engine events for animation (M4)"*. + +- The engine appends **`s.events`**: `drew, moved, placed, combat started, rolled, rerolled, + damaged, destroyed, captured, Firewall changed, Bandwidth changed, counter changed`. Most zone + changes already funnel through helpers in `engine/state.gd` (`to_hand`, `to_discard`, + `gain_bandwidth` at `:417`, `say` at `:58`), so emission lands in a handful of places. +- Filter per player via `events_for(s, p)`, mirroring what `State.log_for` already does for the log. +- A new presenter plays them **in order**, then snaps the table to `view_for(s, you)`. That + ordering is the safety invariant from §3: *a missed or mis-drawn animation never leaves the table + showing the wrong state.* It composes cleanly with `GameTable.sync()` being an idempotent + full-resync and `Card3D.glide()` early-returning on an unchanged goal. +- This **retires `scenes/game.gd:_pop_new_lines()`** (`:137-164`), which infers animations by + substring-matching log text (`" captures "`, `" wins the roll"`, `"Tie,"`, `"destroyed"`) plus a + regex. + +> **Conformance hazard — the one thing that will bite.** `tests/conformance.gd` fingerprints the +> state through `_body()` (`:230-235`), which shallow-duplicates and erases `defs` and `log`. +> Adding an `events` key changes that hash and **fails all 1,100 traces at once**. `_compare()` +> (`:211`) also runs the *decider's view* through the same `_body()`, so the leak would hit twice. +> +> **The whole fix is one line** — add `b.erase("events")` to `_body()`. That covers the state md5 +> and the view md5 together and leaves the per-line log check alone. `godot-plan.md` §3 already +> rules that events "stay out of conformance, because TS doesn't have them". **Do it in the same +> commit that adds the key.** + +### B6. The animation language + +`gameplay.md` asks for flashy, warped speed trails on a **rush in → slow hold/drift → rush out** +curve. The current state: five tween calls total — `Card3D.glide()` (`GLIDE_TIME = 0.28`, +`TRANS_CUBIC`/`EASE_OUT`) and `GameTable._place_camera()` (0.45 s, `EASE_IN_OUT`). No particles +anywhere, no `AnimationPlayer`. + +Build the curve as a reusable helper beside the presenter, driving: card movement **per event kind** +(a draw should not look like a discard), firewall plug-in, capture, damage, and the log drawer from +`ui-plan.md` §A3. + +Speed trails suit the existing `card.gdshader`, which already carries `instance uniform highlight` +(rgb + strength) and a rim-glow term — flashes and trails can ride those **without duplicating +materials**, which is the constraint `godot-plan.md` §4 sets for card rendering. + +> **Pacing is a real risk, not a detail.** A game asks each player ~367 decisions and opens ~43 +> response windows. `godot-plan.md` §4 requires an animation-speed setting **including instant**, +> and a click that skips the current animation. `Card3D.instant` — a static kill-switch set by +> `tests/table_smoke.gd:46` — already exists and must keep working, or the UI test hangs. + +## 4. Order + +``` +ui-plan Phase 0 (prerequisite) + │ + ├──▶ B2 ──▶ B1 (cheap visual direction first) + │ + ├──▶ B3 ──▶ ui-plan A6 (inspector + hand row carry the salvage chip) + │ + └──▶ B5 ──▶ B6 ──▶ B4 + └──▶ ui-plan A5 (bandwidth delta) +``` + +1. **`ui-plan.md` Phase 0 first, always.** +2. **B2 then B1.** The chamfered tile SDF is a five-line change that sets the visual direction + before the heavier world and material work. +3. **B5 before B6.** Events gate every real animation. +4. **B4 last of the 3D work** — most self-contained, and it benefits from B6's vocabulary. + +**Hazards.** +- Doing **B6 before B5** means writing animations against log-string matching, then rewriting them. +- Adding **`s.events` without the `_body()` strip** fails all 1,100 traces simultaneously. +- Retuning **`HAND_SHOWN` before `ui-plan.md` §0.4** means tuning against a panel reserve that is + about to change. + +## 5. Verification + +Custom harness — no GUT, no gdUnit4. Each test is a standalone `extends SceneTree` script run via +`--script`, passing on exit code plus `Util.errors` being empty. + +Godot is **not on `PATH`** here. It is 4.7.2 stable at +`/Applications/Godot.app/Contents/MacOS/Godot`, matching the project's 4.7 target. + +```sh +export GODOT=/Applications/Godot.app/Contents/MacOS/Godot +cd /Users/forrestchurch/Trog-Chamber/files-game + +# Run this FIRST — see the note below. +"$GODOT" --headless --import + +# Rules unchanged. THE gate for B5. tests/traces/ is gitignored and currently empty: +tools/make_traces.sh # needs the TS sim; SIM env points at files-tcg/sim +"$GODOT" --headless --script res://tests/conformance.gd -- --check + +"$GODOT" --headless --script res://tests/table_smoke.gd -- --games 20 +"$GODOT" --headless --script res://tests/smoke.gd -- --games 50 +"$GODOT" --headless --script res://tests/bot_speed.gd # bot must stay off the main thread + +# Look harness — needs a display, so no --headless. +"$GODOT" --script res://tests/screenshot.gd -- --out /tmp/shot.png +"$GODOT" --script res://tests/screenshot.gd -- --top --out /tmp/shot-top.png +``` + +> **Import before testing.** `.godot/` is gitignored and this checkout's `.godot/imported/` holds +> 13 entries with **no entry for `card.glb` or `playmat.glb`**. Unimported, `$Model` resolves to +> `null` and `Card3D._ready()` (`table/card_3d.gd:70`) throws on every card spawned; +> `tests/table_smoke.gd` then reports a meaningless *"35 unreachable move kinds"*, because picking +> needs collision bodies that `_ready()` never added. That number is an artifact, not a +> reachability bug — do not go hunting it. The pass covers 274 card PNGs plus two `.glb`s. +> +> `tests/smoke.gd` is green as of writing: 20/20 games clean in 37 s. + +Compare screenshots against `20261001_171420.png` (the current state) and the card faces in +`files-game/assets/cards/` (the target). Then play a full game and confirm: the hand is legible at +rest **and** in focus mode; a firewall plugs in and shows its level; a draw does not look like a +discard; captures and damage read without the log; and the animation-speed setting still has a +working **instant** option. + +**Guardrails.** +- `camelCase` dictionary keys and action-type strings are the TypeScript wire format + (`s.firewalls`, `installHardware`, `bandwidthFromSalvage`). Renaming any fails every trace. + Do not tidy them. +- `tests/table_smoke.gd` reaches into `scenes/game.gd` privates (`_play`, `_select`, `_paused`, + `moves`) and `GameTable.screen_point_for`. Restructuring `game.gd` breaks the only automated UI + test — keep those names. +- `scenes/game.gd` must not call `Odds` while the bot thinks; its static caches are unlocked. +- Keep `Card3D.instant` working as a global animation kill-switch. +- `engine/` and `match/` use **no nodes or scenes** (`godot-plan.md` §3) so they run headless, on + the bot thread, and later on a PvP server. The presenter in B5 must live outside them. diff --git a/godot-plan.md b/godot-plan.md index df94e44..e4e600e 100644 --- a/godot-plan.md +++ b/godot-plan.md @@ -423,3 +423,40 @@ The sizes are relative. M1 shows how fast TypeScript ports to GDScript, so firm Every move was reachable in 50 games across both seats, at 16:9 and square screens, with the bot on its thread or not. - **Fonts.** The 2D text and tags use the system's DejaVu fonts for now; the release font is M4. + +**2026-10-01: the look, the menu and the show** (M4 Presentation, M5's start screen), from +`gameplay-plan.md` and `ui-plan.md`. + +- **Design system** (`ui/style.gd`, `Style`). The print templates' tokens (cyan `#22d3ee` chrome, + Okabe–Ito owners), the two vendored OFL fonts in `assets/fonts/` (Orbitron for display, JetBrains + Mono for everything else), the one `Theme`, and the panel geometry that the HUD, the camera fit, + the hand and `screen_point_for` all read. `ui/chamfer_box.gd` (`ChamferBox`) is the chamfered + StyleBox with glow and corner ticks; `ui/scanlines.gdshader` is the CRT overlay. +- **HUD** (`ui/hud.gd`). A status strip per player with a Bandwidth bar (`ui/bandwidth_bar.gd`: + 0–20 Gb, ticks at the Firewall costs, a ghost to what salvaging the hand reaches, a glow past 20); + the log as a terminal drawer on `` ` ``; combat as a transient readout over the table; the + inspector with the card large and a salvage chip; a hand-focus row on Tab or the bottom edge. +- **Menu** (`scenes/menu.tscn`). The new main scene, over the same grid world. `SceneRouter` + carries the game and settings into `scenes/game.tscn`, which still deals a game when opened + directly (tests, the editor). Settings persist in `user://settings.cfg` (`GameSettings`), + including the animation speed (Slow, Normal, Fast, Instant). +- **Table.** Cyberspace: a void grid floor, a dark-glass mat whose grid follows the board pitch + (`table/playmat.gdshader`, `table/void_grid.gdshader`), chamfered socket tiles with a stripe + (South) or dot (North) owner pattern, gateways as RJ45 ports (`table/firewall_port.gd`: a plug with + one LED per Firewall level in the rules), a Bandwidth strip on each player's edge of the mat, and + Executions held beside the table while they wait on the stack. +- **Engine events.** The engine records `s.events` when a game is created with `"events": true` + (`State.emit`, filtered by `State.events_for`). Conformance runs with them on and strips them + from the fingerprint: `main` (1,000 games) and `labels` (100) still match at every step. + `tests/events.gd` folds the events back up and checks the result against the state after every + action. +- **The show** (`present/`). `Presenter` turns each change's events into a timeline: how each card + travels (draw, reveal, slam, move, discard, destroy) and cues for pop-ups, capture flashes, the + turn banner and Bandwidth pulses. The table still snaps to the view in the same sync, so a missed + animation never shows a wrong state. `Motion` holds the rush-in, drift, rush-out curve every + animation uses, and the speed setting. Cards leave short speed trails. A click or Space skips + the show; the bot waits for it to end. `tests/present_smoke.gd` plays whole games with the + animations on. This retires the old log-text pop-ups. +- **Tests.** `tests/table_smoke.gd --threaded` was restarting its first game every frame when + the bot moved first. Fixed. `tests/screenshot.gd` gained `--focus`, `--terminal`, `--combat`, + `--zoom` and `--at`, and `tests/menu_screenshot.gd` renders the title screen. diff --git a/match/local_match.gd b/match/local_match.gd index 04e5b9e..2ecf1b7 100644 --- a/match/local_match.gd +++ b/match/local_match.gd @@ -50,7 +50,7 @@ func _init(card_pool: Dictionary, match_setup: Dictionary, the_bot: Object, opts options = DEFAULT_OPTIONS.duplicate() options.merge(opts, true) bot = the_bot - s = RulesEngine.create_game({"pool": pool, "decks": setup.decks, "seed": setup.seed, "rules": rules, "log": true}) + s = RulesEngine.create_game({"pool": pool, "decks": setup.decks, "seed": setup.seed, "rules": rules, "log": true, "events": true}) _settle() @@ -125,6 +125,16 @@ func log_lines() -> Array: return out +## How many events the game has recorded (see State.emit): pass it to events_since() later. +func event_count() -> int: + return s.events.size() if s.events != null else 0 + + +## Events from index `from` on, as you may see them (State.events_for). Copies. +func events_since(from: int) -> Array: + return State.events_for(s, human, from) + + ## The current or latest combat, or null. func combat() -> Variant: return combats.back() if not combats.is_empty() else null diff --git a/present/motion.gd b/present/motion.gd new file mode 100644 index 0000000..c8dec5b --- /dev/null +++ b/present/motion.gd @@ -0,0 +1,68 @@ +class_name Motion +## The animation language (gameplay-plan.md §B6): things rush in, hold or drift slowly, then rush +## out. Every animation in the game takes its timing from here, so the speed setting (and the +## tests' instant switch, Card3D.instant) reach all of them. + +## Multiplies every duration; 0 is instant. Set from the animation-speed setting. +static var speed_scale := 1.0 + + +static func instant() -> bool: + return speed_scale <= 0.0 or Card3D.instant + + +## `t` seconds at the current speed. +static func secs(t: float) -> float: + return 0.0 if instant() else t * speed_scale + + +## Rush to `to`: a fast start and a soft landing. +static func rush_in(tw: Tween, obj: Object, prop: NodePath, to: Variant, t: float) -> PropertyTweener: + return tw.tween_property(obj, prop, to, secs(t)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT) + + +## Drift slowly to `to`, easing at both ends: the hold between two rushes. +static func drift(tw: Tween, obj: Object, prop: NodePath, to: Variant, t: float) -> PropertyTweener: + return tw.tween_property(obj, prop, to, secs(t)).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT) + + +## Rush away to `to`: a slow start that snaps at the end. +static func rush_out(tw: Tween, obj: Object, prop: NodePath, to: Variant, t: float) -> PropertyTweener: + return tw.tween_property(obj, prop, to, secs(t)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_IN) + + +## The whole curve on one property: rush to `hold_a`, drift to `hold_b`, rush out to `to`. +static func rush_hold_rush(tw: Tween, obj: Object, prop: NodePath, hold_a: Variant, hold_b: Variant, to: Variant, + t_in := 0.18, t_hold := 0.45, t_out := 0.16) -> void: + rush_in(tw, obj, prop, hold_a, t_in) + drift(tw, obj, prop, hold_b, t_hold) + rush_out(tw, obj, prop, to, t_out) + + +## The curve as a function, for things driven by hand (shaders, pop-ups): progress `u` (0–1) of an +## animation whose middle `hold` share is the drift. Returns how far along the path it is (0–1): +## it covers `reach` of the way during the rush in, and the rest in the rush out. +static func curve(u: float, hold := 0.5, reach := 0.86) -> float: + u = clampf(u, 0.0, 1.0) + var a := (1.0 - hold) / 2.0 + if u < a: + var k := u / a + return reach * (1.0 - pow(2.0, -10.0 * k)) / (1.0 - pow(2.0, -10.0)) + if u < a + hold: + var k := (u - a) / hold + return reach + (1.0 - reach) * 0.25 * (0.5 - 0.5 * cos(PI * k)) + var k := (u - a - hold) / a + var from := reach + (1.0 - reach) * 0.25 + return from + (1.0 - from) * pow(2.0, 10.0 * (k - 1.0)) + + +## How strong a streak behind something moving on the curve should be at progress `u`: high in +## the rushes, low in the hold. +static func streak(u: float, hold := 0.5) -> float: + u = clampf(u, 0.0, 1.0) + var a := (1.0 - hold) / 2.0 + if u < a: + return 1.0 - u / a * 0.6 + if u < a + hold: + return 0.15 + return 0.4 + 0.6 * (u - a - hold) / a diff --git a/present/motion.gd.uid b/present/motion.gd.uid new file mode 100644 index 0000000..b151ecc --- /dev/null +++ b/present/motion.gd.uid @@ -0,0 +1 @@ +uid://c7kpegf65ne4o diff --git a/present/presenter.gd b/present/presenter.gd new file mode 100644 index 0000000..f30dbbe --- /dev/null +++ b/present/presenter.gd @@ -0,0 +1,264 @@ +class_name Presenter +extends Node +## Acts the game out (gameplay-plan.md §B5). Each change to the match comes with the engine's +## events for it (s.events, filtered for you); the presenter lays them out on a timeline, one beat +## after another, and turns them into how cards travel (motion styles the table applies in its +## next sync) and cues that need the new positions (pop-ups, flashes, the turn banner). +## +## The table still snaps to the view in that sync: every card's goal is its real spot, and the +## events only choose the way there and when. So a missed or misdrawn animation can never leave +## the table showing the wrong state (godot-plan.md §3). This lives outside engine/ and match/, +## which use no nodes. + +## Seconds each kind of event holds the timeline at normal speed before the next one starts. +## Kinds that come in runs (draws, discards) have short beats, so a run fans out. +const BEATS := { + "turn": 0.3, "drew": 0.11, "hand": 0.1, "discard": 0.16, "install": 0.42, "placed": 0.34, + "moved": 0.4, "recalled": 0.32, "flipped": 0.28, "combat": 0.32, "rolled": 0.62, "rerolled": 0.5, + "damaged": 0.3, "destroyed": 0.45, "captured": 0.5, "firewall": 0.55, "bandwidth": 0.0, "counter": 0.12, + "stack": 0.75, "pile": 0.12, +} +## An opponent's card held up for you to read takes longer than your own. +const REVEAL_BEAT := 0.85 +## The longest one change may take; longer ones are squeezed to fit. +const MAX_BATCH := 3.4 +## Extra time after the last beat for its animation to land. +const TAIL := 0.45 + +var table: GameTable +var hud: Hud +## When the show for the last change ends, in engine seconds. +var _until := 0.0 +## Cues waiting for the sync: Callables taking no arguments. +var _cues: Array[Callable] = [] + + +## Before the table syncs to `after`: plans the show for `events` (as `me` sees them). `before` is +## the view the table shows now ({} for a new game). +func stage(events: Array, before: Dictionary, after: Dictionary, me: int) -> void: + _cues = [] + if events.is_empty() or Motion.instant(): + return + var plan := [] + var t := 0.0 + for ev in events: + var beat: float = BEATS.get(ev.k, 0.0) + if (ev.k == "install" or ev.k == "discard") and ev.get("p", me) != me and _from_hidden(ev): + beat = REVEAL_BEAT + plan.append({"ev": ev, "at": t}) + t += beat + var squeeze := 1.0 if t <= MAX_BATCH else MAX_BATCH / t + var bot_draws: Array[float] = [] + # What earlier events in this change did, for the later ones: cards that went on the stack, + # Anomalies destroyed. + var seen := {"stacked": {}, "destroyed": {}} + for step in plan: + var at: float = step.at * squeeze + _stage_one(step.ev, at, before, after, me, bot_draws, seen) + _deal_bot_hand(before, after, me, bot_draws) + _until = Time.get_ticks_msec() / 1000.0 + Motion.secs(t * squeeze + TAIL) + + +## Whether `ev` brings out a card the viewer couldn't see: from a hand or the deck. +static func _from_hidden(ev: Dictionary) -> bool: + var from: String = ev.get("from", "hand") + return from in ["hand", "deck", ""] + + +func _stage_one(ev: Dictionary, at: float, before: Dictionary, after: Dictionary, me: int, bot_draws: Array[float], seen: Dictionary) -> void: + var motions := table.motions + match ev.k: + "drew": + if ev.p == me and ev.card >= 0: + motions["card:%d" % ev.card] = {"style": "draw", "delay": at} + else: + bot_draws.append(at) + "discard": + var key := "card:%d" % ev.card + if ev.card < 0: + return + var from: String = ev.get("from", "") + if ev.get("why", "") == "destroyed": + motions[key] = {"style": "destroy", "delay": at} + elif ev.p != me and (_from_hidden(ev) or (from == "stack" and seen.stacked.has(ev.card))): + # A card of theirs you hadn't seen: held up for you to read on its way. + motions[key] = {"style": "reveal", "delay": at, "p": ev.p, "from": "deck" if from == "deck" else "hand", "color": Style.OWNER[ev.p]} + else: + var spec := {"style": "discard", "delay": at} + if ev.get("from", "") == "deck": + spec.merge({"p": ev.p, "from": "deck"}) + motions[key] = spec + "stack": + # An Execution played: up in front of you, then beside the table until it resolves. + if ev.get("kind", "") == "execution" and ev.card >= 0: + seen.stacked[ev.card] = true + var spec := {"style": "stack", "delay": at, "color": Style.OWNER[ev.p]} + if ev.p != me: + spec.merge({"p": ev.p, "from": "hand"}) + motions["card:%d" % ev.card] = spec + "pile": + # Back into a hidden pile (a Server going home, a card shuffled in). + if ev.card >= 0: + motions["card:%d" % ev.card] = {"style": "leave", "delay": at, "p": ev.p, "to": ev.zone} + "install": + if ev.card < 0: + return + var key := "card:%d" % ev.card + var d: Dictionary = after.defs.get(State.name_of(after, ev.card), {}) if ev.card < after.cards.size() else {} + if d.get("kind", "") == "server": + motions[key] = {"style": "slam", "delay": at, "p": ev.p, "from": "serverPile"} + elif ev.p != me: + motions[key] = {"style": "reveal", "delay": at, "p": ev.p, "from": "hand", "color": Style.OWNER[ev.p]} + else: + motions[key] = {"style": "slam", "delay": at} + "placed", "moved", "recalled", "flipped": + var key := Moves.anomaly_key(ev.ref) + motions[key] = {"style": "move", "delay": at, "color": Style.OWNER[ev.ref.player]} + # Its Hardware rides along, just behind. + if after.players[ev.ref.player].anomalies.size() >= ev.ref.slot: + for id in State.hardware_of(after, ev.ref): + motions["card:%d" % id] = {"style": "move", "delay": at + 0.04, "color": Style.OWNER[ev.ref.player]} + if ev.k == "flipped": + _cue(func(): table.flash_card(key, Style.ACCENT, at + 0.2)) + "destroyed": + var key := Moves.anomaly_key(ev.ref) + seen.destroyed[key] = true + motions[key] = {"style": "destroy", "delay": at} + var loc = ev.get("loc") + _cue(func(): + var w = table.anchor_of(Moves.loc_key(loc)) if loc != null else table.anchor_of(key) + if w != null: + table.pop_text(w, "DESTROYED", Style.BAD, at, 24)) + "combat": + _cue(func(): + var w = table.anchor_of(Moves.loc_key(ev.loc)) + if w != null: + table.pop_text(w, "// COMBAT", Style.ATTACK, at, 22)) + "rolled": + for rk in ev.dice: + var dice: Array = ev.dice[rk] + if dice.is_empty(): + continue + var parts: PackedStringArray = rk.split(":") + var key := "anomaly:%s:%s" % [parts[0], parts[1]] if parts.size() == 2 else "" + var owner := int(parts[0]) if parts.size() == 2 else me + var text := "⚄ %s = %d" % [" ".join(dice.map(func(x): return str(x))), Util.sum(dice)] + _cue(func(): + var w = table.anchor_of(key) + if w == null: + w = table.anchor_of(Moves.loc_key(ev.loc)) + if w != null: + table.pop_text(w + Vector3(0, 0.3, 0), text, Style.OWNER[owner].lightened(0.3), at, 20) + table.flash_card(key, Style.OWNER[owner], at)) + "rerolled": + var key := Moves.anomaly_key(ev.ref) + var text := "REROLL ⚄ %s" % " ".join(ev.dice.map(func(x): return str(x))) + _cue(func(): + var w = table.anchor_of(key) + if w != null: + table.pop_text(w + Vector3(0, 0.3, 0), text, Style.WARN, at, 20)) + "damaged": + var key := Moves.anomaly_key(ev.ref) + var r: Dictionary = ev.ref + var amount: int = ev.amount + var loc = ev.get("loc") + _cue(func(): + table.pop_damage(r, amount, false, loc, at) + table.flash_card(key, Style.BAD, at)) + "captured": + var loc: String = ev.loc + var p: int = ev.p + _cue(func(): + table.flash_capture(loc, p, at) + var w = table.anchor_of(Moves.loc_key(loc)) + if w != null: + table.pop_text(w, "%s TAKES %s" % [State.player_name(p).to_upper(), loc], Style.OWNER[p].lightened(0.25), at + 0.1, 22)) + "firewall": + table.gate_delays[ev.line] = at + var to: int = ev.to + var line: String = ev.line + _cue(func(): + var w = table.anchor_of("gate:" + line) + if w != null: + var text := "FIREWALL CLEARED" if to == 0 else "FIREWALL LV %d" % to + table.pop_text(w + Vector3(0, 0.4, 0), text, Style.firewall_color(maxi(1, to), after.rules.firewallCost.size()), at + 0.45, 18)) + "bandwidth": + var delta: int = ev.to - ev.from + if delta != 0: + var p: int = ev.p + if not table.bandwidth_delays.has(p): + table.bandwidth_delays[p] = at + _cue(func(): hud.pulse_bandwidth(p, delta, at)) + "counter": + var key := Moves.anomaly_key(ev.ref) + var what: String = ev.get("what", "") + var delta: int = ev.to - ev.from + var text := "" + var color: Color = Style.CLASS_ACCENT.G + if what == "damage": + # Damage itself pops when dealt; a counter going down is a heal, unless the Anomaly + # was just destroyed and is being reset. + if delta < 0 and not seen.destroyed.has(key): + text = "+%d HEAL" % -delta + color = Style.TYPE_ACCENT.server + elif delta != 0: + text = "%+d %s" % [delta, {"infection": "☣", "bugs": "✱"}.get(what, "•")] + if text != "": + _cue(func(): + var w = table.anchor_of(key) + if w != null: + table.pop_text(w + Vector3(0, 0.2, 0), text, color, at, 18)) + "turn": + var p: int = ev.p + var turn: int = ev.turn + var title := "YOUR COMMAND" if p == me else "%s'S COMMAND" % State.player_name(p).to_upper() + var sub := "ROUND %d · COMMAND %d" % [State.round_of(after, turn), turn] if after.rules.commands.on else "TURN %d" % turn + _cue(func(): hud.banner(title, sub, Style.OWNER[p], at)) + + +## The bot's hand is face-down placeholders by position: the new ones are dealt off its deck, at +## the times its draws came. +func _deal_bot_hand(before: Dictionary, after: Dictionary, me: int, bot_draws: Array[float]) -> void: + if before.is_empty(): + return + var p := State.other(me) + var n0: int = mini(before.players[p].hand.size(), GameTable.BOT_HAND_SHOWN) + var n1: int = mini(after.players[p].hand.size(), GameTable.BOT_HAND_SHOWN) + for i in range(n0, n1): + var j := i - n0 + var at: float = bot_draws[j] if j < bot_draws.size() else 0.0 + table.motions["bothand:%d:%d" % [p, i]] = {"style": "deal", "delay": at, "p": p, "from": "deck"} + + +func _cue(fn: Callable) -> void: + _cues.append(fn) + + +## After the table's sync: the cues, which read the new positions. +func run() -> void: + var cues := _cues + _cues = [] + for fn in cues: + fn.call() + + +## Whether a show is playing. +func busy() -> bool: + if Motion.instant(): + return false + return Time.get_ticks_msec() / 1000.0 < _until or table.animating() + + +## Seconds until the planned show ends (0 when none is playing). +func time_left() -> float: + if Motion.instant(): + return 0.0 + return maxf(0.0, _until - Time.get_ticks_msec() / 1000.0) + + +## Skips to the end of the show. +func skip() -> void: + _until = 0.0 + _cues = [] + table.finish_animations() + hud.finish_banner() diff --git a/present/presenter.gd.uid b/present/presenter.gd.uid new file mode 100644 index 0000000..d81a2cf --- /dev/null +++ b/present/presenter.gd.uid @@ -0,0 +1 @@ +uid://cjjv056maonj2 diff --git a/present/trail.gdshader b/present/trail.gdshader new file mode 100644 index 0000000..6f3339b --- /dev/null +++ b/present/trail.gdshader @@ -0,0 +1,18 @@ +shader_type spatial; +render_mode blend_add, unshaded, cull_disabled, depth_draw_never, shadows_disabled; + +// A speed-trail ghost (gameplay-plan.md §B6): a soft card-shaped glow a card leaves behind while it +// rushes, fading fast. Every ghost shares this material; the fade and color are per instance, so +// trails never duplicate materials. + +uniform float energy = 0.9; +instance uniform vec4 tint : source_color = vec4(0.133, 0.827, 0.933, 1.0); +instance uniform float fade = 1.0; + +void fragment() { + vec2 p = abs(UV - 0.5) * 2.0; + float edge = max(p.x, p.y); + // Bright at the rim, faint inside: an afterimage of the card's frame. + float a = (1.0 - smoothstep(0.82, 1.0, edge)) * (0.22 + 0.78 * smoothstep(0.55, 0.96, edge)); + ALBEDO = tint.rgb * energy * a * fade; +} diff --git a/present/trail.gdshader.uid b/present/trail.gdshader.uid new file mode 100644 index 0000000..d1a601d --- /dev/null +++ b/present/trail.gdshader.uid @@ -0,0 +1 @@ +uid://i0ievq6wjbpv diff --git a/project.godot b/project.godot index a0cec0c..3e43c33 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Files TCG" -run/main_scene="res://scenes/game.tscn" +run/main_scene="res://scenes/menu.tscn" config/features=PackedStringArray("4.7", "Forward Plus") config/icon="res://icon.svg" diff --git a/scenes/game.gd b/scenes/game.gd index 5273a53..43b2547 100644 --- a/scenes/game.gd +++ b/scenes/game.gd @@ -11,7 +11,8 @@ var pool: Dictionary var match_: LocalMatch var table: GameTable var hud: Hud -var settings := {"stops": "combat", "autoSkip": true, "checkInvariants": false, "botDelay": 0.45} +var presenter: Presenter +var settings := GameSettings.DEFAULTS.duplicate() ## The picked source key, or "". var selected := "" @@ -22,9 +23,10 @@ var _bot_thought := {} var _bot_wait := 0.0 var _paused := false var _hover_seen := {} -var _combat_seen := 0 -## Log lines already turned into table pop-ups. -var _log_seen := 0 +## What the mouse is over in the hand-focus row, which wins over the table's hover while open. +var _hand_hover := {} +## Engine events already acted out by the presenter. +var _events_seen := 0 func _ready() -> void: @@ -33,6 +35,10 @@ func _ready() -> void: add_child(table) hud = Hud.new() add_child(hud) + presenter = Presenter.new() + presenter.table = table + presenter.hud = hud + add_child(presenter) hud.set_settings(settings) hud.move_chosen.connect(_play) hud.source_picked.connect(func(key): _select(key)) @@ -41,14 +47,29 @@ func _ready() -> void: hud.view_toggled.connect(func(): table.toggle_view()) hud.new_game_requested.connect(start_game) hud.settings_changed.connect(_on_settings) + hud.menu_requested.connect(_to_menu) + hud.hand_hovered.connect(func(info): _hand_hover = info) + hud.hand_picked.connect(_pick) + hud.hand_focus_changed.connect(func(open): + if not open: + _hand_hover = {} + table.set_hand_tucked(open)) + # From the menu, the router brings the game and saved settings. Opened directly (the editor, + # tests), it deals a game from --seed or a random seed with the default settings. + var routed := SceneRouter.take() + if routed.has("settings"): + settings = routed.settings.duplicate() + hud.set_settings(settings) + Motion.speed_scale = GameSettings.anim_scale(settings) + if routed.has("game"): + start_game(routed.game) + return var args := OS.get_cmdline_user_args() var seed := randi_range(1, 999999) var i := args.find("--seed") if i >= 0 and i + 1 < args.size(): seed = int(args[i + 1]) start_game({"seed": seed, "human": 0, "style": "greedy"}) - if args.find("--seed") < 0: - hud.show_start({"seed": seed, "cancel": true}) ## Starts a game from {seed, human, style}. @@ -65,9 +86,10 @@ func start_game(opts: Dictionary) -> void: match_.changed.connect(_on_changed) selected = "" _moves_version = -1 - _combat_seen = 0 _bot_wait = 0.0 - _log_seen = match_.log_lines().size() + # From 0, so the opening deal plays out. + _events_seen = 0 + presenter.skip() hud.reset_for_new_game() table.set_seat(match_.human, true) _on_changed() @@ -75,10 +97,17 @@ func start_game(opts: Dictionary) -> void: func _on_settings(s: Dictionary) -> void: settings = s + Motion.speed_scale = GameSettings.anim_scale(s) + GameSettings.save(s) if match_ != null and _bot_task < 0: match_.set_options({"stops": s.stops, "autoSkip": s.autoSkip, "checkInvariants": s.checkInvariants}) +func _to_menu(screen: String) -> void: + _join_bot() + SceneRouter.to_menu(screen) + + # --------------------------------------------------------------------------------------------- # The bot @@ -91,13 +120,14 @@ func _process(delta: float) -> void: _bot_task = -1 _bot_wait = 0.0 match_.bot_apply(_bot_thought) - elif not _paused and not match_.is_over() and match_.bot_to_act() and not hud.modal_open(): + elif not _paused and not match_.is_over() and match_.bot_to_act() and not hud.modal_open() and not presenter.busy(): _bot_wait += delta if _bot_wait >= settings.botDelay: var m := match_ _bot_task = WorkerThreadPool.add_task(func(): _bot_thought = m.bot_think(), false, "bot") - if table.hovered != _hover_seen: - _hover_seen = table.hovered.duplicate() + var hover: Dictionary = _hand_hover if hud.hand_focus_open() else table.hovered + if hover != _hover_seen: + _hover_seen = hover.duplicate() _inspect(_hover_seen) _refresh() @@ -124,57 +154,14 @@ func _on_changed() -> void: if selected != "" and not moves.any(func(mv): return mv.source == selected): selected = "" hud.hide_popover() - var c = match_.combat() - if c != null and c.id != _combat_seen: - _combat_seen = c.id - hud.show_combat_tab() + # The show for this change: the presenter plans it before the table syncs, then cues what + # needs the new positions. + # A new game starts from nothing, not from the last game's table. + var before := table.shown_view() if _events_seen > 0 else {} + presenter.stage(match_.events_since(_events_seen), before, match_.view(), match_.human) + _events_seen = match_.event_count() _refresh() - _pop_new_lines() - - -## Shows what the newest log lines did on the table: damage, roll results, captures. Several from -## one move come one after another; after a long run of moves at once, only the last few show. -func _pop_new_lines() -> void: - var lines := match_.log_lines() - var pops := [] - for i in range(_log_seen, lines.size()): - var l: Dictionary = lines[i] - var loc = l.get("loc") - if loc == null or not BoardLayout.at.has(loc): - continue - var at: Vector3 = BoardLayout.at[loc] - var p = l.get("player") - var color: Color = GameTable.OWNER_COLORS[p].lightened(0.3) if p != null else Color("#d7dee6") - if l.get("ref") != null and l.get("amount") != null: - pops.append(func(delay): table.pop_damage(l.ref, l.amount, l.text.contains("destroyed"), loc, delay)) - elif l.get("tag") == "capture" and l.text.contains(" captures "): - pops.append(func(delay): - table.flash_capture(loc, p) - table.pop_text(at, "%s takes %s" % [State.player_name(p), loc], color, delay)) - elif l.get("tag") == "combat" and l.text.contains(" wins the roll"): - var t := _roll_score(l.text) - pops.append(func(delay): table.pop_text(at, "%s wins %s" % [State.player_name(p), t], color, delay)) - elif l.get("tag") == "combat" and l.text.begins_with("Tie,"): - pops.append(func(delay): table.pop_text(at, "Stalemate", color, delay)) - elif l.get("tag") == "combat" and l.text.contains(" ends: "): - pops.append(func(delay): table.pop_text(at, "Combat ends", Color("#ffb454"), delay)) - _log_seen = lines.size() - pops = pops.slice(maxi(0, pops.size() - 5)) - for i in pops.size(): - pops[i].call(i * 0.45) - - -static var _roll_re := RegEx.create_from_string("wins the roll, (\\d+) to (\\d+)") - - -## "14–7" from "North wins the roll, 7 to 14: 7 damage.", the winner's total first. -static func _roll_score(text: String) -> String: - var m := _roll_re.search(text) - if m == null: - return "" - var a := int(m.get_string(1)) - var b := int(m.get_string(2)) - return "%d–%d" % [maxi(a, b), mini(a, b)] + presenter.run() func _refresh() -> void: @@ -182,7 +169,7 @@ func _refresh() -> void: var marks := _marks(v) table.sync(v, marks) hud.refresh({"match": match_, "view": v, "moves": moves, "selected": selected, "marks": marks, - "thinking": _thinking(), "paused": _paused, "preview": _preview(v)}) + "thinking": _thinking(), "paused": _paused, "preview": _preview(v), "show_left": presenter.time_left()}) ## How each key glows: the combat, your sources, and the selected source's targets. @@ -204,6 +191,11 @@ func _marks(v: Dictionary) -> Dictionary: for mv in moves: if mv.source == selected and mv.target != "none": marks[mv.target] = "attack" if mv.action.type == "attack" else "target" + # Its defenders glow too: clicking one attacks where it stands (see _hits_on). + if mv.action.type == "attack": + for r in State.anomalies_at(v, mv.action.to): + if not marks.has(Moves.anomaly_key(r)): + marks[Moves.anomaly_key(r)] = "attack" return marks @@ -211,8 +203,8 @@ func _marks(v: Dictionary) -> Dictionary: func _preview(v: Dictionary) -> String: if selected == "" or _thinking() or _hover_seen.is_empty(): return "" - for mv in moves: - if mv.source == selected and mv.target == _hover_seen.key and mv.action.type == "attack": + for mv in _hits_on(_hover_seen.key): + if mv.action.type == "attack": var me := match_.human var from = State.anomaly(v, State.ref(me, mv.action.slot)).at var to: String = mv.action.to @@ -260,14 +252,15 @@ func _inspect(h: Dictionary) -> void: var pl: Dictionary = v.players[int(parts[1])] text = "[b]%s's %s[/b]\n%d cards in hand, %d in the deck, %d Servers in the pile, %d in the discard pile." % [ State.player_name(int(parts[1])), parts[2], pl.hand.size(), pl.deck.size(), pl.serverPile.size(), pl.discard.size()] - hud.inspect({"art": card, "text": text}) + hud.inspect({"art": card, "text": text, "key": key}) static func _card_info(v: Dictionary, card: String) -> String: var d: Dictionary = v.defs.get(card, {}) if d.is_empty(): return "[b]%s[/b]" % card - var out := "[b]%s[/b]\n[color=#7d8a97]%s%s · %d Gb[/color]" % [d.name, d.kind.capitalize(), " (%s)" % d.type if d.type != "" else "", d.bandwidth] + var type := " · %s" % Style.CLASS_NAMES.get(d.type, d.type) if d.type != "" else "" + var out := "[b]%s[/b]\n[color=%s]%s%s · %d Gb[/color]" % [d.name, Style.hex(Style.card_accent(d)), d.kind.capitalize(), type, d.bandwidth] if d.kind == "anomaly": out += "\n%d Cores · %d Health · %d Expansion Slots" % [d.cores, d.health, d.slots] if d.text != "": @@ -342,7 +335,7 @@ func _pick(key: String, at: Vector2) -> void: if match_.human_to_act() and v.choice != null: return if selected != "": - var hits := moves.filter(func(mv): return mv.source == selected and mv.target == key) + var hits := _hits_on(key) if hits.size() == 1: _play(hits[0]) return @@ -355,11 +348,35 @@ func _pick(key: String, at: Vector2) -> void: _select(key) +## The selected source's moves onto `key`. An Anomaly on the board that isn't one of your sources +## also stands for its location: its card covers most of the tile, so clicking the defender you +## want to attack attacks its location. +func _hits_on(key: String) -> Array: + var hits := moves.filter(func(mv): return mv.source == selected and mv.target == key) + if not hits.is_empty() or moves.any(func(mv): return mv.source == key): + return hits + var r = Moves.ref_of_key(key) + var v := match_.view() + if r == null or r.slot > v.players[r.player].anomalies.size(): + return hits + var at = State.anomaly(v, r).at + if at == null: + return hits + return moves.filter(func(mv): return mv.source == selected and mv.target == Moves.loc_key(at)) + + func _unhandled_input(e: InputEvent) -> void: if match_ == null: return if e is InputEventMouseButton and e.pressed: if e.button_index == MOUSE_BUTTON_LEFT: + # A click while the game acts itself out skips to the end of the show. On your + # decision it still picks what's under the mouse: the show is of moves already made, + # and a click on your attacker or its target shouldn't be lost to it. + if presenter.busy(): + presenter.skip() + if not match_.human_to_act(): + return _pick(table.hovered.get("key", "none"), e.position) elif e.button_index == MOUSE_BUTTON_RIGHT: _cancel() @@ -377,10 +394,22 @@ func _unhandled_input(e: InputEvent) -> void: return match e.keycode: KEY_ESCAPE: - if hud.modal_open() and match_.view().choice == null and not match_.is_over(): + if hud.hand_focus_open(): + hud.set_hand_focus(false) + elif hud.drawer_open() and not hud.modal_open(): + hud.set_drawer(false) + elif hud.modal_open() and match_.view().choice == null and not match_.is_over(): hud.close_modal() _cancel() + KEY_TAB: + if not hud.modal_open(): + hud.toggle_hand_focus() + KEY_QUOTELEFT: + hud.toggle_drawer() KEY_SPACE: + if presenter.busy(): + presenter.skip() + return var v := match_.view() if v.choice == null and not hud.modal_open(): for t in ["pass", "end"]: diff --git a/scenes/menu.gd b/scenes/menu.gd new file mode 100644 index 0000000..d4bd931 --- /dev/null +++ b/scenes/menu.gd @@ -0,0 +1,254 @@ +extends Node +## The title screen (ui-plan.md §A2): the logo over the same black-and-grid world as the table, +## with START (to the new-game screen), SETTINGS and QUIT, and slots for the deck builder (M6), +## multiplayer and accounts (M8). The game itself starts through SceneRouter. + +## Slots for what later milestones add: shown, but not clickable yet. +const LATER := [["DECK BUILDER", "M6"], ["MULTIPLAYER", "M8"], ["ACCOUNT", "M8"]] + +var settings: Dictionary +var _camera: Camera3D +var _floor: ShaderMaterial +var _cards: Array[Node3D] = [] +var _title: Control +var _setup: Control +var _modal: Control +var _time := 0.0 + + +func _ready() -> void: + settings = GameSettings.load_saved() + Motion.speed_scale = GameSettings.anim_scale(settings) + _build_world() + var layer := CanvasLayer.new() + add_child(layer) + var root := Control.new() + root.theme = Style.theme() + root.set_anchors_preset(Control.PRESET_FULL_RECT) + root.mouse_filter = Control.MOUSE_FILTER_IGNORE + layer.add_child(root) + root.add_child(_vignette()) + _title = _build_title() + root.add_child(_title) + _setup = _build_setup() + root.add_child(_setup) + root.add_child(_footer()) + _modal = Control.new() + _modal.set_anchors_preset(Control.PRESET_FULL_RECT) + _modal.visible = false + root.add_child(_modal) + var routed := SceneRouter.take() + _show(_setup if routed.get("screen", "") == "setup" else _title, true) + + +# --------------------------------------------------------------------------------------------- +# The world behind the menu + +func _build_world() -> void: + add_child(GameTable.make_environment()) + var sun := DirectionalLight3D.new() + sun.light_color = Color(0.9, 0.95, 1.0) + sun.light_energy = 1.1 + add_child(sun) + sun.look_at_from_position(Vector3(4, 12, 10), Vector3.ZERO, Vector3.UP) + var ground := GameTable.make_floor(900.0) + _floor = ground.material_override + _floor.set_shader_parameter("fade_from", 20.0) + _floor.set_shader_parameter("fade_to", 190.0) + _floor.set_shader_parameter("energy", 0.42) + _floor.set_shader_parameter("pitch", Vector2(2.96, 2.18)) + add_child(ground) + _camera = Camera3D.new() + _camera.fov = 52.0 + _camera.far = 400.0 + add_child(_camera) + _camera.current = true + _camera.position = Vector3(0, 3.2, 14) + _camera.look_at(Vector3(0, 1.4, -30), Vector3.UP) + # A few cards adrift over the grid, to the right of the menu. + var scene: PackedScene = load("res://table/card_3d.tscn") + var faces := ["Code Zero", "Pingable Server", "Hotfix"] + var spots := [Vector3(3.3, 2.3, 5.2), Vector3(6.9, 3.1, 0.8), Vector3(11.0, 2.5, -4.6)] + for i in faces.size(): + var c: Node3D = scene.instantiate() + c.card_name = faces[i] + add_child(c) + c.set_meta("base", spots[i]) + c.set_meta("phase", i * 1.7) + c.scale = Vector3.ONE * 1.6 + _cards.append(c) + + +func _process(delta: float) -> void: + _time += delta + # Fly slowly over the grid: slide the grid toward the camera. + _floor.set_shader_parameter("origin", Vector2(0.0, fmod(_time * 1.4, 2.18))) + for c in _cards: + var base: Vector3 = c.get_meta("base") + var ph: float = c.get_meta("phase") + c.position = base + Vector3(0, sin(_time * 0.6 + ph) * 0.18, 0) + c.rotation = Vector3(PI / 2 - 0.35 + sin(_time * 0.3 + ph) * 0.08, -0.5 + sin(_time * 0.25 + ph) * 0.25, 0.12) + + +# --------------------------------------------------------------------------------------------- +# Screens + +func _vignette() -> TextureRect: + var t := TextureRect.new() + t.mouse_filter = Control.MOUSE_FILTER_IGNORE + t.set_anchors_preset(Control.PRESET_FULL_RECT) + var g := Gradient.new() + g.set_color(0, Color(Style.BG, 0.94)) + g.set_color(1, Color(Style.BG, 0.0)) + g.add_point(0.45, Color(Style.BG, 0.7)) + var gt := GradientTexture2D.new() + gt.gradient = g + gt.fill_from = Vector2(0, 0) + gt.fill_to = Vector2(1, 0) + gt.width = 128 + gt.height = 4 + t.texture = gt + t.expand_mode = TextureRect.EXPAND_IGNORE_SIZE + t.stretch_mode = TextureRect.STRETCH_SCALE + return t + + +func _build_title() -> Control: + var box := VBoxContainer.new() + box.anchor_top = 0.5 + box.anchor_bottom = 0.5 + box.offset_left = 110 + box.offset_top = -270 + box.add_theme_constant_override("separation", 12) + box.add_child(_logo()) + var spacer := Control.new() + spacer.custom_minimum_size = Vector2(0, 26) + box.add_child(spacer) + box.add_child(_menu_button("START", func(): _show(_setup))) + for item in LATER: + var b := _menu_button("%s" % item[0], func(): pass) + b.disabled = true + b.tooltip_text = "Coming in %s." % item[1] + var row := HBoxContainer.new() + row.add_theme_constant_override("separation", 10) + row.add_child(b) + var tag := Widgets.label("// %s" % item[1], "Micro") + tag.size_flags_vertical = Control.SIZE_SHRINK_CENTER + row.add_child(tag) + box.add_child(row) + box.add_child(_menu_button("SETTINGS", _show_settings)) + box.add_child(_menu_button("QUIT", func(): get_tree().quit())) + return box + + +func _logo() -> Control: + var v := VBoxContainer.new() + v.add_theme_constant_override("separation", 2) + var logo := RichTextLabel.new() + logo.bbcode_enabled = true + logo.fit_content = true + logo.scroll_active = false + logo.autowrap_mode = TextServer.AUTOWRAP_OFF + logo.mouse_filter = Control.MOUSE_FILTER_IGNORE + logo.custom_minimum_size = Vector2(620, 0) + logo.add_theme_font_override("normal_font", Style.display_font(900)) + logo.add_theme_font_size_override("normal_font_size", 76) + logo.add_theme_color_override("font_shadow_color", Color(Style.ACCENT, 0.55)) + logo.add_theme_constant_override("shadow_outline_size", 18) + logo.add_theme_constant_override("shadow_offset_x", 0) + logo.add_theme_constant_override("shadow_offset_y", 0) + logo.text = "[color=%s]FILES[/color][color=%s]//[/color][color=%s]TCG[/color]" % [ + Style.hex(Style.ACCENT), Style.hex(Style.ACCENT_DK), Style.hex(Style.SCREEN)] + v.add_child(logo) + var sub := Widgets.label("// A TRADING CARD GAME OF ANOMALIES, SERVERS AND FIREWALLS · SET 1", "Muted") + sub.add_theme_font_size_override("font_size", 13) + v.add_child(sub) + return v + + +func _menu_button(text: String, fn: Callable) -> Button: + var b := Widgets.button(text, fn, "BigButton") + b.custom_minimum_size = Vector2(340, 0) + b.alignment = HORIZONTAL_ALIGNMENT_LEFT + return b + + +func _build_setup() -> Control: + var center := CenterContainer.new() + center.set_anchors_preset(Control.PRESET_FULL_RECT) + center.mouse_filter = Control.MOUSE_FILTER_IGNORE + var pc := PanelContainer.new() + pc.custom_minimum_size = Vector2(560, 0) + var box := Style.chamfer_box(Style.ACCENT, Color(Style.BG, 0.9), 1.5, 16.0, 16.0) + box.ticks = true + box.set_content_margin_all(24) + pc.add_theme_stylebox_override("panel", box) + center.add_child(pc) + var v := VBoxContainer.new() + v.add_theme_constant_override("separation", 12) + pc.add_child(v) + v.add_child(Widgets.label("round@files:~$ ./new-game --vs bot", "Micro")) + v.add_child(Widgets.heading("NEW GAME")) + v.add_child(Widgets.muted("Both decks are dealt at random from Set 1, from the seed.")) + Widgets.start_form(v, {"seed": randi_range(1, 999999)}, func(opts): SceneRouter.to_game(opts, settings), + func(): _show(_title)) + return center + + +func _footer() -> Label: + var l := Widgets.label("round@files:~$ ./files-tcg · v0.1 · Godot %s" % Engine.get_version_info().string, "Micro") + l.anchor_top = 1.0 + l.anchor_bottom = 1.0 + l.offset_left = 24 + l.offset_top = -30 + return l + + +## Shows one screen, rushing it in. +func _show(screen: Control, instant := false) -> void: + for s in [_title, _setup]: + s.visible = s == screen + if instant or Motion.instant(): + screen.modulate.a = 1.0 + return + screen.modulate.a = 0.0 + var tw := create_tween() + Motion.rush_in(tw, screen, "modulate:a", 1.0, 0.35) + + +func _show_settings() -> void: + for c in _modal.get_children(): + c.queue_free() + var dim := ColorRect.new() + dim.color = Color(Style.BG, 0.6) + dim.set_anchors_preset(Control.PRESET_FULL_RECT) + _modal.add_child(dim) + _modal.add_child(Widgets.scanlines(0.1)) + var center := CenterContainer.new() + center.set_anchors_preset(Control.PRESET_FULL_RECT) + _modal.add_child(center) + var pc := PanelContainer.new() + pc.custom_minimum_size = Vector2(520, 0) + var box := Style.chamfer_box(Style.ACCENT, Color(Style.BG, 0.93), 1.5, 16.0, 16.0) + box.ticks = true + box.set_content_margin_all(20) + pc.add_theme_stylebox_override("panel", box) + center.add_child(pc) + var v := VBoxContainer.new() + v.add_theme_constant_override("separation", 10) + pc.add_child(v) + v.add_child(Widgets.heading("SETTINGS")) + Widgets.settings_form(v, settings, func(out): + settings = out + GameSettings.save(out) + Motion.speed_scale = GameSettings.anim_scale(out) + _modal.visible = false) + _modal.visible = true + + +func _unhandled_input(e: InputEvent) -> void: + if e is InputEventKey and e.pressed and not e.echo and e.keycode == KEY_ESCAPE: + if _modal.visible: + _modal.visible = false + elif _setup.visible: + _show(_title) diff --git a/scenes/menu.gd.uid b/scenes/menu.gd.uid new file mode 100644 index 0000000..f121daa --- /dev/null +++ b/scenes/menu.gd.uid @@ -0,0 +1 @@ +uid://blhshidutfacv diff --git a/scenes/menu.tscn b/scenes/menu.tscn new file mode 100644 index 0000000..b52cd62 --- /dev/null +++ b/scenes/menu.tscn @@ -0,0 +1,6 @@ +[gd_scene format=3] + +[ext_resource type="Script" path="res://scenes/menu.gd" id="1_menu"] + +[node name="Menu" type="Node"] +script = ExtResource("1_menu") diff --git a/scenes/scene_router.gd b/scenes/scene_router.gd new file mode 100644 index 0000000..1f77103 --- /dev/null +++ b/scenes/scene_router.gd @@ -0,0 +1,33 @@ +class_name SceneRouter +## Moves between the menu and a game (the project's only scene changes), carrying what the next +## scene needs in `args`. + +const MENU := "res://scenes/menu.tscn" +const GAME := "res://scenes/game.tscn" + +## What the scene being entered should start with, e.g. {game: {seed, human, style}, settings}. +## The scene takes it with take(). +static var args := {} + + +## Opens a game with `opts` ({seed, human, style}) and `settings`. +static func to_game(opts: Dictionary, settings: Dictionary) -> void: + args = {"game": opts, "settings": settings} + _tree().change_scene_to_file.call_deferred(GAME) + + +## Back to the menu; `screen` is "" for the title or "setup" for the new-game screen. +static func to_menu(screen := "") -> void: + args = {"screen": screen} + _tree().change_scene_to_file.call_deferred(MENU) + + +## The args left for this scene, cleared so a reload doesn't reuse them. +static func take() -> Dictionary: + var out := args + args = {} + return out + + +static func _tree() -> SceneTree: + return Engine.get_main_loop() as SceneTree diff --git a/scenes/scene_router.gd.uid b/scenes/scene_router.gd.uid new file mode 100644 index 0000000..0c0954b --- /dev/null +++ b/scenes/scene_router.gd.uid @@ -0,0 +1 @@ +uid://cyrdo7nvlfwrg diff --git a/table/bandwidth_strip.gd b/table/bandwidth_strip.gd new file mode 100644 index 0000000..78c6160 --- /dev/null +++ b/table/bandwidth_strip.gd @@ -0,0 +1,120 @@ +class_name BandwidthStrip +extends Node3D +## A player's Bandwidth as a neon loading bar along their edge of the mat (ui-plan.md §A5), +## mirrored small in the HUD (BandwidthBar). Bandwidth has no cap, so the scale is fixed: 20 cells +## of 1 Gb, with ticks at the Firewall costs, and the whole bar glows past 20 instead of clipping. +## For you, dimmer cells run on to what salvaging your hand could reach. +## +## Local axes: x runs along the bar (0 Gb at -x, as its owner sees it), z toward its owner. + +const CELLS := 20 +const LENGTH := 11.0 +const CELL_DEPTH := 0.34 +const LED_SHADER := preload("res://table/led.gdshader") + +static var _material: ShaderMaterial + +var color := Color("#56b4e9") +var gb := 0 +var reach := 0 +var _cells: Array[MeshInstance3D] = [] +var _ticks: Array[Label3D] = [] +var _value: Label3D +var _shown := 0.0 +var _tween: Tween +var _pulse := 0.0 + + +func _ready() -> void: + if _material == null: + _material = ShaderMaterial.new() + _material.shader = LED_SHADER + var step := LENGTH / CELLS + var mesh := BoxMesh.new() + mesh.size = Vector3(step * 0.8, 0.03, CELL_DEPTH) + for i in CELLS: + var c := MeshInstance3D.new() + c.mesh = mesh + c.material_override = _material + c.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF + c.position = Vector3(-LENGTH / 2.0 + step * (i + 0.5), 0.015, 0) + add_child(c) + _cells.append(c) + var title := _label("BANDWIDTH", 40, Style.MUTED) + title.position = Vector3(-LENGTH / 2.0 - 0.15, 0.01, 0) + title.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + _value = _label("0 Gb", 64, color) + _value.position = Vector3(LENGTH / 2.0 + 0.2, 0.01, 0) + _value.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT + _draw() + + +func _label(text: String, size: int, c: Color) -> Label3D: + var l := Label3D.new() + l.text = text + l.font = Style.body_font(700) + l.font_size = size + l.pixel_size = 0.004 + l.rotation.x = -PI / 2 + l.modulate = c + l.outline_size = 0 + add_child(l) + return l + + +## The Firewall costs, marked under the bar. +func set_ticks(costs: Array) -> void: + for t in _ticks: + t.queue_free() + _ticks = [] + var step := LENGTH / CELLS + for cost in costs: + if cost <= 0 or cost >= CELLS: + continue + var t := _label(str(cost), 30, Color(Style.SCREEN, 0.6)) + t.position = Vector3(-LENGTH / 2.0 + step * cost, 0.01, CELL_DEPTH / 2.0 + 0.14) + _ticks.append(t) + + +## Shows `value` Gb (and the ghost to `reach_to`), filling cell by cell on the motion curve after +## `delay` seconds. +func set_value(value: int, reach_to: int, c: Color, delay := 0.0) -> void: + color = c + reach = maxi(reach_to, value) + _value.modulate = c + _value.text = "%d Gb" % value + if value == gb: + _draw() + return + gb = value + if _tween != null: + _tween.kill() + if Motion.instant() or not is_inside_tree(): + _shown = value + _draw() + return + _tween = create_tween() + if delay > 0.0: + _tween.tween_interval(Motion.secs(delay)) + _tween.tween_method(func(x): + _shown = x + _draw(), _shown, float(value), Motion.secs(0.6)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT) + + +func _process(delta: float) -> void: + if gb > CELLS: + _pulse = fmod(_pulse + delta, 2.0) + _draw() + + +func _draw() -> void: + var lit := roundi(_shown) + var over := gb > CELLS + var k := 0.5 + 0.5 * sin(_pulse * PI) + for i in _cells.size(): + var v := Color(0, 0, 0, 0) + if i < lit: + v = Color(color.lerp(Color.WHITE, 0.2 * float(i) / CELLS), 2.6 + k * 1.4 if over else 1.7) + elif i < reach: + v = Color(color, 0.09) + _cells[i].set_instance_shader_parameter("led", v) diff --git a/table/bandwidth_strip.gd.uid b/table/bandwidth_strip.gd.uid new file mode 100644 index 0000000..4af30fc --- /dev/null +++ b/table/bandwidth_strip.gd.uid @@ -0,0 +1 @@ +uid://bvwmfdyl1pyqc diff --git a/table/card.gdshader b/table/card.gdshader index 40dbcc9..b918d98 100644 --- a/table/card.gdshader +++ b/table/card.gdshader @@ -17,6 +17,8 @@ uniform bool rim_glow = true; // rgb is the color, a the strength. instance uniform vec4 highlight : source_color = vec4(0.0); +// A brief flash on top of the highlight (hits, reveals, rushes); Card3D fades it out. +instance uniform vec4 flash : source_color = vec4(0.0); // 0 is normal, 1 dark gray: disabled Hardware and Programs. instance uniform float dim = 0.0; @@ -36,5 +38,5 @@ void fragment() { float border = min(min(uv.x, 1.0 - uv.x), min(uv.y, 1.0 - uv.y)); glow = mix(0.12, 1.6, 1.0 - smoothstep(0.0, 0.07, border)); } - EMISSION = highlight.rgb * highlight.a * glow; + EMISSION = highlight.rgb * highlight.a * glow + flash.rgb * flash.a * (0.35 + glow); } diff --git a/table/card_3d.gd b/table/card_3d.gd index 7e89dff..3ae74e1 100644 --- a/table/card_3d.gd +++ b/table/card_3d.gd @@ -11,8 +11,16 @@ const BACK := 1 const EDGE := 2 ## Half the card's thickness: a card at this height lies on the table. const REST_HEIGHT := 0.005 -## Seconds a card takes to slide to a new spot. -const GLIDE_TIME := 0.28 +## Seconds a card takes to slide to a new spot (at normal speed; see Motion). +const GLIDE_TIME := 0.26 +## Speed trails: ghosts left per unit moved, how fast a card must move to leave them, how long one +## lasts. +const TRAIL_DENSITY := 2.5 +const TRAIL_MIN_SPEED := 10.0 +const TRAIL_LIFE := 0.15 +## Most ghosts a card keeps at once. +const TRAIL_MAX := 14 +const TRAIL_SHADER := preload("res://present/trail.gdshader") ## Every card jumps instead of sliding (for tests). static var instant := false @@ -61,15 +69,28 @@ var pick_key := "": var _mesh: MeshInstance3D var _body: StaticBody3D var _tween: Tween +var _flash_tween: Tween +var _flash := Color(0, 0, 0, 0) +## Speed trail: whether one is on, its color, where the card was last frame, and the live ghosts. +var _trail := false +var _trail_color := Color("#22d3ee") +var _trail_from := Vector3.ZERO +var _ghosts: Array = [] +static var _ghost_mesh: PlaneMesh +static var _ghost_material: ShaderMaterial ## Where the last glide was headed, so an unchanged target doesn't restart it. var _goal := Transform3D() var _goal_set := false +## On its way out of sight (into a hidden pile): freed when it gets there. +var _leaving := false func _ready() -> void: _mesh = $Model.find_children("*", "MeshInstance3D")[0] _apply_materials() _apply_uniforms() + # Only while a trail is on or fading (see _process). + set_process(false) if not Engine.is_editor_hint(): _body = StaticBody3D.new() var shape := CollisionShape3D.new() @@ -101,11 +122,140 @@ func glide(xf: Transform3D, instant := false) -> void: _goal_set = true if _tween != null: _tween.kill() - if instant or Card3D.instant or not is_inside_tree(): + if instant or Motion.instant() or not is_inside_tree(): transform = xf return - _tween = create_tween().set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT) - _tween.tween_property(self, "transform", xf, GLIDE_TIME) + _tween = create_tween() + Motion.rush_in(_tween, self, "transform", xf, GLIDE_TIME) + + +## Sends the card along `path` (transforms in its parent's space, the goal last) on the motion +## curve (gameplay-plan.md §B6): it starts at path[0], rushes to path[1], drifts to path[2] and +## rushes out to the goal. Shorter paths skip the drift. `times` are each leg's seconds, `delay` +## waits first (at path[0]), and `trail` leaves a speed trail in the rushes. +func travel(path: Array, times: Array, delay := 0.0, trail := true, color := Color("#22d3ee"), leave := false) -> void: + var goal: Transform3D = path.back() + _goal = goal + _goal_set = true + _leaving = leave + if _tween != null: + _tween.kill() + if Motion.instant() or not is_inside_tree(): + transform = goal + if leave: + queue_free() + return + transform = path[0] + _tween = create_tween() + if delay > 0.0: + _tween.tween_interval(Motion.secs(delay)) + _tween.tween_callback(func(): _start_trail(trail, color)) + var legs := path.size() - 1 + for i in legs: + var t: float = times[mini(i, times.size() - 1)] + if legs >= 3 and i == 1: + Motion.drift(_tween, self, "transform", path[i + 1], t) + elif i == legs - 1 and legs > 1: + Motion.rush_out(_tween, self, "transform", path[i + 1], t) + else: + Motion.rush_in(_tween, self, "transform", path[i + 1], t) + _tween.tween_callback(func(): _trail = false) + if leave: + _tween.tween_callback(queue_free) + + +## Whether the card is still on its way somewhere. +func moving() -> bool: + return _tween != null and _tween.is_valid() and _tween.is_running() + + +## Jumps to where the card is headed (skipping its animation). +func finish() -> void: + if moving(): + _tween.kill() + transform = _goal + _trail = false + if _leaving: + queue_free() + if _flash_tween != null: + _flash_tween.kill() + _set_flash(Color(0, 0, 0, 0)) + + +## A flash of `color` that fades out over `t` seconds, after `delay`. +func flash(color: Color, t := 0.5, delay := 0.0) -> void: + if Motion.instant() or not is_inside_tree(): + return + if _flash_tween != null: + _flash_tween.kill() + _flash_tween = create_tween() + if delay > 0.0: + _flash_tween.tween_interval(Motion.secs(delay)) + _flash_tween.tween_method(_set_flash, Color(color, 2.2), Color(color, 0.0), Motion.secs(t)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT) + + +func _set_flash(c: Color) -> void: + _flash = c + if _mesh != null: + _mesh.set_instance_shader_parameter("flash", c) + + +func _start_trail(on: bool, color: Color) -> void: + _trail = on + _trail_color = color + _trail_from = position + if on: + set_process(true) + + +## Leaves ghosts along the way while the card rushes, and fades the old ones. +func _process(delta: float) -> void: + if Engine.is_editor_hint(): + return + if _trail and get_parent() != null: + var step := position - _trail_from + var dist := step.length() + if delta > 0.0 and dist / delta >= TRAIL_MIN_SPEED: + var n := mini(3, ceili(dist * TRAIL_DENSITY)) + for i in n: + _spawn_ghost(_trail_from.lerp(position, float(i + 1) / n), float(i + 1) / n) + _trail_from = position + var now := Time.get_ticks_msec() / 1000.0 + while not _ghosts.is_empty() and now - _ghosts[0].born > TRAIL_LIFE: + _ghosts.pop_front().node.queue_free() + for g in _ghosts: + var k: float = 1.0 - (now - g.born) / TRAIL_LIFE + (g.node as GeometryInstance3D).set_instance_shader_parameter("fade", k * k * g.strength) + if not _trail and _ghosts.is_empty(): + set_process(false) + + +func _spawn_ghost(at: Vector3, strength: float) -> void: + if _ghost_mesh == null: + _ghost_mesh = PlaneMesh.new() + _ghost_mesh.size = Vector2(1.27, 1.778) + _ghost_material = ShaderMaterial.new() + _ghost_material.shader = TRAIL_SHADER + var g := MeshInstance3D.new() + g.mesh = _ghost_mesh + g.material_override = _ghost_material + g.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF + get_parent().add_child(g) + g.transform = Transform3D(transform.basis, at) + g.set_instance_shader_parameter("tint", _trail_color) + g.set_instance_shader_parameter("fade", strength) + # Cards held near the camera (your hand) leave fainter ghosts: they're large on screen. + var near := 0.35 if get_parent() is Node3D and get_parent().get_parent() is Camera3D else 1.0 + _ghosts.append({"node": g, "born": Time.get_ticks_msec() / 1000.0, "strength": (0.15 + 0.35 * strength) * near}) + if _ghosts.size() > TRAIL_MAX: + _ghosts.pop_front().node.queue_free() + + +func _exit_tree() -> void: + for g in _ghosts: + if is_instance_valid(g.node): + g.node.queue_free() + _ghosts = [] func _apply_materials() -> void: @@ -121,3 +271,4 @@ func _apply_uniforms() -> void: return _mesh.set_instance_shader_parameter("highlight", highlight) _mesh.set_instance_shader_parameter("dim", dim) + _mesh.set_instance_shader_parameter("flash", _flash) diff --git a/table/firewall_port.gd b/table/firewall_port.gd new file mode 100644 index 0000000..1a802e9 --- /dev/null +++ b/table/firewall_port.gd @@ -0,0 +1,272 @@ +class_name FirewallPort +extends Node3D +## A gateway as an ethernet port (gameplay-plan.md §B4): a socket printed on the mat, and a +## Firewall as a plug seated in it, with gold contacts (the cards' edge-connector motif: hardware +## plugs in here) and a row of LEDs, one per Firewall level the rules allow, lit up to its level. +## Firewalls have no Health, so the animations are plug in, swap up and unplug. +## +## Local axes: z runs along the line through the gateway, x across it. + +const TILE_SHADER := preload("res://table/tile.gdshader") +const LED_SHADER := preload("res://table/led.gdshader") +const SOCKET := Vector2(0.62, 0.46) +const PLUG := Vector3(0.52, 0.2, 0.36) +const LED_SIZE := 0.1 +const LED_STEP := 0.17 +## Where the plug sits seated, and where it comes in from. +const SEATED := Vector3(0, PLUG.y / 2.0 + 0.004, 0) +const ABOVE := Vector3(0, 1.5, 0.25) + +static var _socket_material: ShaderMaterial +static var _led_material: ShaderMaterial +static var _housing_material: StandardMaterial3D +static var _clip_material: StandardMaterial3D +static var _gold_material: StandardMaterial3D + +## The level shown (0: no Firewall) and how many LEDs there are. +var level := 0 +var levels := 3 +var _socket: MeshInstance3D +var _tab: MeshInstance3D +var _plug: Node3D +var _leds: Array[MeshInstance3D] = [] +var _tween: Tween +var _glow_tween: Tween +var _mark := Color(0, 0, 0, 0) +var _glow := 0.0 + + +func _ready() -> void: + # A bit larger than life, so the LEDs read from across the table and in the top view. + scale = Vector3.ONE * 1.3 + _make_materials() + _socket = _decal(SOCKET, 0.06) + _socket.position.y = 0.005 + # The latch slot, on the socket's far side. + _tab = _decal(Vector2(0.24, 0.1), 0.025) + _tab.position = Vector3(0, 0.005, SOCKET.y / 2.0 + 0.04) + _plug = Node3D.new() + _plug.name = "Plug" + _plug.visible = false + add_child(_plug) + _plug.add_child(_box(PLUG, Vector3.ZERO, _housing_material)) + _plug.add_child(_box(Vector3(0.2, 0.05, 0.16), Vector3(0, PLUG.y / 2.0 + 0.02, PLUG.z / 2.0 - 0.07), _clip_material)) + for i in 8: + var x := (i - 3.5) * 0.052 + _plug.add_child(_box(Vector3(0.03, 0.012, 0.1), Vector3(x, PLUG.y / 2.0 + 0.006, -PLUG.z / 2.0 + 0.06), _gold_material)) + _build_leds() + _apply_socket() + + +func _make_materials() -> void: + if _socket_material != null: + return + _socket_material = ShaderMaterial.new() + _socket_material.shader = TILE_SHADER + _socket_material.set_shader_parameter("size", SOCKET) + _socket_material.set_shader_parameter("chamfer", 0.06) + _socket_material.set_shader_parameter("edge_width", 0.03) + _socket_material.set_shader_parameter("inner_line", 0.6) + _socket_material.render_priority = 0 + _led_material = ShaderMaterial.new() + _led_material.shader = LED_SHADER + _housing_material = StandardMaterial3D.new() + _housing_material.albedo_color = Color(0.05, 0.13, 0.15, 0.78) + _housing_material.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA + _housing_material.roughness = 0.12 + _housing_material.metallic_specular = 0.8 + _housing_material.rim_enabled = true + _housing_material.rim = 0.6 + _housing_material.emission_enabled = true + _housing_material.emission = Style.ACCENT_DK + _housing_material.emission_energy_multiplier = 0.6 + _clip_material = StandardMaterial3D.new() + _clip_material.albedo_color = Color(0.03, 0.06, 0.07) + _clip_material.roughness = 0.3 + _gold_material = StandardMaterial3D.new() + _gold_material.albedo_color = Color("#ffd24a") + _gold_material.metallic = 1.0 + _gold_material.roughness = 0.25 + _gold_material.emission_enabled = true + _gold_material.emission = Color("#ffb02e") + _gold_material.emission_energy_multiplier = 0.12 + + +## A flat chamfered decal on the mat, drawn with the tile shader. +func _decal(size: Vector2, chamfer: float) -> MeshInstance3D: + var m := MeshInstance3D.new() + var plane := PlaneMesh.new() + plane.size = size + m.mesh = plane + var mat: ShaderMaterial = _socket_material + if size != SOCKET: + mat = _socket_material.duplicate() + mat.set_shader_parameter("size", size) + mat.set_shader_parameter("chamfer", chamfer) + mat.set_shader_parameter("inner_line", 0.0) + m.material_override = mat + m.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF + add_child(m) + return m + + +func _box(size: Vector3, at: Vector3, mat: Material) -> MeshInstance3D: + var m := MeshInstance3D.new() + var b := BoxMesh.new() + b.size = size + m.mesh = b + m.material_override = mat + m.position = at + return m + + +func _build_leds() -> void: + for l in _leds: + l.queue_free() + _leds = [] + var mesh := BoxMesh.new() + mesh.size = Vector3(LED_SIZE, 0.035, LED_SIZE) + for i in levels: + var led := MeshInstance3D.new() + led.mesh = mesh + led.material_override = _led_material + led.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF + led.position = Vector3((i - (levels - 1) / 2.0) * LED_STEP, PLUG.y / 2.0 + 0.018, 0.02) + _plug.add_child(led) + _leds.append(led) + _light(level, false) + + +## Shows Firewall `to` (0 for none) out of `max_levels`, animating from the shown level after +## `delay` seconds unless `animate` is false. +func set_level(to: int, max_levels: int, animate := true, delay := 0.0) -> void: + if max_levels != levels: + levels = maxi(1, max_levels) + _build_leds() + if to == level: + return + var from := level + level = to + if _tween != null: + _tween.kill() + if not animate or Motion.instant() or not is_inside_tree(): + _plug.visible = to > 0 + _plug.position = SEATED + _plug.scale = Vector3.ONE + _light(to, false) + return + _tween = create_tween() + if delay > 0.0: + _tween.tween_interval(Motion.secs(delay)) + if from == 0: + _plug_in() + elif to == 0: + _unplug() + else: + _swap(to > from) + + +## The plug rushes in from above, hangs over the socket while it lines up, and snaps in; then +## the LEDs come on one by one. +func _plug_in() -> void: + _tween.tween_callback(func(): + _plug.visible = true + _plug.scale = Vector3.ONE + _plug.position = ABOVE + _plug.rotation = Vector3(0.5, 0.35, 0) + _light(0, false)) + var tw := _tween + tw.set_parallel(false) + Motion.rush_in(tw, _plug, "position", Vector3(0, 0.42, 0.02), 0.22) + tw.parallel() + Motion.rush_in(tw, _plug, "rotation", Vector3(0.08, 0, 0), 0.22) + Motion.drift(tw, _plug, "position", Vector3(0, 0.34, 0), 0.28) + tw.parallel() + Motion.drift(tw, _plug, "rotation", Vector3.ZERO, 0.28) + Motion.rush_out(tw, _plug, "position", SEATED, 0.1) + tw.tween_callback(func(): pulse(Style.firewall_color(level, levels), 2.6)) + for i in level: + tw.tween_callback(_light.bind(i + 1, true)) + tw.tween_interval(Motion.secs(0.08)) + + +## Up a level: the plug lifts a little and reseats, and the new LEDs flash on. Down: they go out. +func _swap(up: bool) -> void: + var tw := _tween + Motion.rush_in(tw, _plug, "position", SEATED + Vector3(0, 0.14, 0), 0.12) + Motion.rush_out(tw, _plug, "position", SEATED, 0.1) + tw.tween_callback(func(): + _light(level, true) + if up: + pulse(Style.firewall_color(level, levels), 2.0)) + + +## Cleared: the LEDs go out, the plug lifts out of the socket and away. +func _unplug() -> void: + var tw := _tween + tw.tween_callback(_light.bind(0, true)) + Motion.rush_in(tw, _plug, "position", SEATED + Vector3(0, 0.3, 0), 0.16) + Motion.drift(tw, _plug, "position", SEATED + Vector3(0, 0.42, 0), 0.22) + Motion.rush_out(tw, _plug, "position", ABOVE, 0.18) + tw.parallel() + Motion.rush_out(tw, _plug, "scale", Vector3.ONE * 0.4, 0.18) + tw.tween_callback(func(): _plug.visible = false) + + +## Lights the first `n` LEDs in the level's color; the rest stay dark. +func _light(n: int, flash: bool) -> void: + var c := Style.firewall_color(maxi(1, level), levels) + for i in _leds.size(): + var on := i < n + _leds[i].set_instance_shader_parameter("led", Color(c, 3.4 if flash and i == n - 1 else 1.7) if on else Color(0.12, 0.16, 0.17, 0.0)) + + +## A glow around the socket that fades out: a Firewall going in, or the gateway being picked. +func pulse(color: Color, strength: float) -> void: + if _glow_tween != null: + _glow_tween.kill() + _glow = strength + _mark = color + _apply_socket() + if Motion.instant(): + _glow = 0.0 + _apply_socket() + return + _glow_tween = create_tween() + _glow_tween.tween_method(func(g): + _glow = g + _apply_socket(), strength, 0.0, Motion.secs(0.7)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT) + + +## Highlights the socket for a mark (a legal source or target), or clears it. +func set_mark(color: Color, strength: float) -> void: + _mark = color + _glow = strength + _apply_socket() + + +func _apply_socket() -> void: + if _socket == null: + return + var edge := Color(Style.ACCENT, 0.75) if level == 0 else Color(Style.firewall_color(level, levels), 0.9) + if _glow > 0.0: + edge = _mark + for d in [_socket, _tab]: + d.set_instance_shader_parameter("fill_color", Color(Style.BG, 0.92)) + d.set_instance_shader_parameter("edge_color", edge) + d.set_instance_shader_parameter("glow", _glow) + + +## Whether an animation is playing. +func busy() -> bool: + return _tween != null and _tween.is_valid() and _tween.is_running() + + +func finish() -> void: + if busy(): + _tween.kill() + _plug.visible = level > 0 + _plug.position = SEATED + _plug.rotation = Vector3.ZERO + _plug.scale = Vector3.ONE + _light(level, false) diff --git a/table/firewall_port.gd.uid b/table/firewall_port.gd.uid new file mode 100644 index 0000000..662aa98 --- /dev/null +++ b/table/firewall_port.gd.uid @@ -0,0 +1 @@ +uid://ctear1vm5qj3 diff --git a/table/game_table.gd b/table/game_table.gd index 6eab22a..a8905b2 100644 --- a/table/game_table.gd +++ b/table/game_table.gd @@ -7,25 +7,13 @@ extends Node3D const CARD_SCENE := preload("res://table/card_3d.tscn") const PLAYMAT_SCENE := preload("res://table/playmat.tscn") const TILE_SHADER := preload("res://table/tile.gdshader") +const VOID_SHADER := preload("res://table/void_grid.gdshader") -## Okabe–Ito sky blue and orange, as in the browser app: they stay apart for color-blind players. -const OWNER_COLORS: Array[Color] = [Color("#56b4e9"), Color("#e69f00")] -const MARK_COLORS := { - "source": Color("#2de2c4"), "respond": Color("#ffb454"), "selected": Color("#ffffff"), - "target": Color("#2de2c4"), "attack": Color("#ff5c7a"), "fight": Color("#ff5c7a"), -} -const MARK_STRENGTH := {"source": 1.0, "respond": 1.2, "selected": 2.0, "target": 1.5, "attack": 1.8, "fight": 1.2} -const FIREWALL_COLORS: Array[Color] = [Color("#ffb454"), Color("#ff7a45"), Color("#ff3d3d")] +## Colors come from Style (ui-plan.md §0.1): owners, marks and the chrome. ## Your hand, held in front of the camera: distance and how much of a card shows at the bottom. -const HAND_DISTANCE := 9.0 -const HAND_SHOWN := 0.62 -## Screen space the 2D panels cover, in pixels at the 1600 × 900 base size. The camera fits the -## mat into what's left. -const PANEL_LEFT := 300.0 -const PANEL_RIGHT := 345.0 -const PANEL_TOP := 48.0 -const PANEL_BOTTOM := 150.0 +const HAND_DISTANCE := 8.2 +const HAND_SHOWN := 0.74 ## Hardware peeks out from under its wearer by this much each. const HARDWARE_PEEK := 0.3 const PROGRAM_STEP := 0.42 @@ -34,7 +22,15 @@ const BOT_HAND_SHOWN := 14 const POP_TIME := 2.2 const FLASH_TIME := 1.4 ## Pop-ups showing at once; a new one past this drops the oldest. -const MAX_POPS := 6 +const MAX_POPS := 8 +## How each motion style moves a card (see _path_for): seconds for each leg of the curve. +const PATH_TIMES := { + "move": [0.2, 0.3, 0.16], "slam": [0.18, 0.12, 0.09], "reveal": [0.24, 0.7, 0.2], + "discard": [0.13, 0.2, 0.16], "destroy": [0.12, 0.34, 0.18], "draw": [0.22, 0.34, 0.18], + "deal": [0.2, 0.18], "stack": [0.24, 0.6, 0.2], +} +## How far in front of the camera a revealed card is held up. +const REVEAL_DISTANCE := 5.2 var camera: Camera3D ## The player sitting at the table (whose hand is held up, whose side the camera is on). @@ -48,19 +44,24 @@ var _hand_root: Node3D var _board: Node3D var _cards_root: Node3D var _tile_material: ShaderMaterial +var _mat: Node3D +var _floor_material: ShaderMaterial var _tiles := {} var _gates := {} var _lines := {} var _cards := {} var _piles := {} var _hover_body: Object = null -## Your hand's cards in hand order. +## Your hand's cards in hand order, and the Executions waiting on the stack, oldest first. var _hand_order: Array[Card3D] = [] +var _stack_order: Array[Card3D] = [] var _zoom := 1.0 +## Your hand drops out of sight while the HUD's hand-focus row shows it instead. +var _hand_tucked := false var _cam_tween: Tween var _view: Dictionary = {} -var _font: SystemFont -var _tag_font: SystemFont +var _font: Font +var _tag_font: Font var _overlay: Control ## 2D readouts pinned to points on the table: key → {box, label, world, used}. var _tags := {} @@ -69,13 +70,19 @@ var _pops: Array = [] ## Tiles pulsing after a capture: location → {color, born}. var _flashes := {} var _last_marks := {} +## Set by the presenter just before a sync, used by it once: how a card should get to its new spot +## (node key → {style, delay, p, from}), and when each gateway's Firewall should change (line → +## seconds). Anything without one just glides. +var motions := {} +var gate_delays := {} +## Seconds before each player's Bandwidth bar on the mat moves (player → seconds); also the presenter's. +var bandwidth_delays := {} +var _strips: Array[BandwidthStrip] = [] func _ready() -> void: - _font = SystemFont.new() - _font.font_names = PackedStringArray(["DejaVu Sans", "Noto Sans", "sans-serif"]) - _tag_font = SystemFont.new() - _tag_font.font_names = PackedStringArray(["DejaVu Sans Mono", "Adwaita Mono", "monospace"]) + _font = Style.body_font(600) + _tag_font = Style.body_font(500) _build_room() var layer := CanvasLayer.new() layer.layer = 0 @@ -99,41 +106,21 @@ func _ready() -> void: # Building func _build_room() -> void: - var env := Environment.new() - env.background_mode = Environment.BG_COLOR - env.background_color = Color(0.035, 0.035, 0.045) - env.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR - env.ambient_light_color = Color(0.72, 0.75, 0.82) - env.ambient_light_energy = 0.85 - env.tonemap_mode = Environment.TONE_MAPPER_FILMIC - env.glow_enabled = true - env.glow_intensity = 0.4 - env.glow_hdr_threshold = 1.2 - var we := WorldEnvironment.new() - we.environment = env - add_child(we) - + add_child(make_environment()) var sun := DirectionalLight3D.new() - sun.light_color = Color(0.9, 0.87, 0.82) - sun.light_energy = 1.35 + sun.light_color = Color(0.9, 0.95, 1.0) + sun.light_energy = 1.2 sun.shadow_enabled = true + sun.shadow_opacity = 0.7 sun.directional_shadow_max_distance = 60.0 add_child(sun) sun.look_at_from_position(Vector3(6, 20, 9), Vector3.ZERO, Vector3.UP) + var ground := make_floor() + _floor_material = ground.material_override + add_child(ground) - # The table under the mat: dark wood. - var top := MeshInstance3D.new() - var box := BoxMesh.new() - box.size = Vector3(64, 1, 52) - top.mesh = box - var wood := StandardMaterial3D.new() - wood.albedo_color = Color(0.16, 0.105, 0.07) - wood.roughness = 0.62 - top.material_override = wood - top.position = Vector3(0, -0.6, 0) - add_child(top) - - add_child(PLAYMAT_SCENE.instantiate()) + _mat = PLAYMAT_SCENE.instantiate() + add_child(_mat) camera = Camera3D.new() camera.fov = 45.0 @@ -147,6 +134,7 @@ func _build_room() -> void: func _build_board() -> void: BoardLayout.update() + _fit_grid() _tile_material = ShaderMaterial.new() _tile_material.shader = TILE_SHADER _tile_material.set_shader_parameter("size", BoardLayout.tile_size) @@ -154,8 +142,9 @@ func _build_board() -> void: var plane := PlaneMesh.new() plane.size = BoardLayout.tile_size + # The lines between locations, as dim circuit traces. var line_material := StandardMaterial3D.new() - line_material.albedo_color = Color(0.85, 0.88, 0.92, 0.32) + line_material.albedo_color = Color(Style.ACCENT, 0.42) line_material.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA line_material.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED line_material.render_priority = -2 @@ -187,8 +176,9 @@ func _build_board() -> void: spot_material.shader = TILE_SHADER var spot_size := BoardLayout.CARD_SIZE + Vector2(0.14, 0.14) spot_material.set_shader_parameter("size", spot_size) - spot_material.set_shader_parameter("radius", 0.1) - spot_material.set_shader_parameter("edge_width", 0.04) + spot_material.set_shader_parameter("chamfer", BoardLayout.CARD_SIZE.x * Style.CHAMFER_RATIO * 2.0) + spot_material.set_shader_parameter("edge_width", 0.035) + spot_material.set_shader_parameter("inner_line", 0.0) spot_material.render_priority = -1 var spot_plane := PlaneMesh.new() spot_plane.size = spot_size @@ -202,9 +192,9 @@ func _build_board() -> void: for i in spots.size(): var at: Vector3 = spots[i] # The spot's name, printed in the gap between it and the first row. - var name := _flat_label(34) + var name := _flat_label(30) name.text = names[i] - name.modulate = Color(OWNER_COLORS[p], 0.75) + name.modulate = Color(Style.OWNER[p], 0.8) name.rotation.y = BoardLayout.yaw_for(p) var inward := -1.0 if p == 0 else 1.0 name.position = Vector3(at.x, 0.004, at.z + inward * (BoardLayout.CARD_SIZE.y / 2 + 0.17)) @@ -215,8 +205,18 @@ func _build_board() -> void: m.position = Vector3(at.x, 0.003, at.z) m.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF _board.add_child(m) - m.set_instance_shader_parameter("fill_color", Color(OWNER_COLORS[p], 0.06)) - m.set_instance_shader_parameter("edge_color", Color(OWNER_COLORS[p], 0.5)) + m.set_instance_shader_parameter("fill_color", Color(Style.OWNER[p] * 0.18, 0.55)) + m.set_instance_shader_parameter("edge_color", Color(Style.OWNER[p], 0.6)) + m.set_instance_shader_parameter("pattern", 1.0 + p) + + # Each player's Bandwidth bar, just off their edge of the mat. + for p in [0, 1]: + var strip := BandwidthStrip.new() + var toward := 1.0 if p == 0 else -1.0 + strip.position = Vector3(0, -0.1, toward * (BoardLayout.MAT_SIZE.y / 2.0 + 0.36)) + strip.rotation.y = BoardLayout.yaw_for(p) + _board.add_child(strip) + _strips.append(strip) for loc in GameMap.LOCATIONS: var tile := MeshInstance3D.new() @@ -233,12 +233,69 @@ func _build_board() -> void: body.add_child(shape) body.set_meta("key", Moves.loc_key(loc)) tile.add_child(body) - var label := _flat_label(64) - label.position = BoardLayout.at[loc] + Vector3(BoardLayout.tile_size.x / 2 - 1.0, 0.004, 0) + # The location's id as microtext in the socket's corner. + var label := _flat_label(58) + label.horizontal_alignment = HORIZONTAL_ALIGNMENT_RIGHT + label.vertical_alignment = VERTICAL_ALIGNMENT_TOP + label.modulate = Color(Style.SECONDARY, 0.85) _board.add_child(label) _tiles[loc] = {"mesh": tile, "label": label} +## Cyberspace (gameplay-plan.md §B1): a black void with a cool, even light so the cards stay +## readable; neon emission is what blooms. The menu uses it too, so both read as one world. +static func make_environment() -> WorldEnvironment: + var env := Environment.new() + env.background_mode = Environment.BG_COLOR + env.background_color = Color("#010304") + env.ambient_light_source = Environment.AMBIENT_SOURCE_COLOR + env.ambient_light_color = Color(0.66, 0.76, 0.86) + env.ambient_light_energy = 0.8 + env.tonemap_mode = Environment.TONE_MAPPER_FILMIC + env.glow_enabled = true + env.glow_intensity = 0.75 + env.glow_strength = 1.05 + env.glow_bloom = 0.0 + env.glow_hdr_threshold = 1.1 + env.glow_blend_mode = Environment.GLOW_BLEND_MODE_ADDITIVE + for i in 7: + env.set_glow_level(i, [0.0, 1.0, 1.0, 0.7, 0.5, 0.0, 0.0][i]) + var we := WorldEnvironment.new() + we.environment = env + return we + + +## The floor under the mat: the neon grid running out into the void. +static func make_floor(size := 240.0) -> MeshInstance3D: + var ground := MeshInstance3D.new() + var plane := PlaneMesh.new() + plane.size = Vector2(size, size) + ground.mesh = plane + var m := ShaderMaterial.new() + m.shader = VOID_SHADER + m.render_priority = -4 + ground.material_override = m + ground.position = Vector3(0, -0.14, 0) + ground.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF + return ground + + +## Lines the mat's and floor's grids up with the locations: half a column pitch across and a row +## pitch deep, crossing between the rows. +func _fit_grid() -> void: + var pitch := Vector2(BoardLayout.col_pitch / 2.0, BoardLayout.row_pitch) + var origin := Vector2(0, BoardLayout.row_pitch / 2.0) + var mats: Array = [_floor_material] + for mi in _mat.find_children("*", "MeshInstance3D", true, false): + var m: Material = (mi as MeshInstance3D).get_surface_override_material(0) + if m is ShaderMaterial: + mats.append(m) + for m in mats: + m.set_shader_parameter("pitch", pitch) + m.set_shader_parameter("origin", origin) + m.set_shader_parameter("half_size", BoardLayout.MAT_SIZE / 2.0) + + ## How far along d (from a tile's centre) the segment leaves a tile of half-size `half`. static func _exit_t(d: Vector3, half: Vector2) -> float: var tx := INF if is_zero_approx(d.x) else half.x / absf(d.x) @@ -248,37 +305,10 @@ static func _exit_t(d: Vector3, half: Vector2) -> float: func _make_gate(line: Dictionary, yaw: float) -> Dictionary: var at := BoardLayout.line_mid(line) - var diamond := MeshInstance3D.new() - var dm := PlaneMesh.new() - dm.size = Vector2(0.34, 0.34) - diamond.mesh = dm - var mat := StandardMaterial3D.new() - mat.albedo_color = Color(0.85, 0.88, 0.92, 0.55) - mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA - mat.emission_enabled = true - mat.emission = Color.BLACK - mat.render_priority = -1 - diamond.material_override = mat - diamond.position = at + Vector3(0, 0.004, 0) - diamond.rotation.y = PI / 4 - diamond.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF - _board.add_child(diamond) - - var wall := MeshInstance3D.new() - var wm := BoxMesh.new() - wm.size = Vector3(1.0, 1.0, 0.14) - wall.mesh = wm - var wall_mat := StandardMaterial3D.new() - wall_mat.albedo_color = FIREWALL_COLORS[0] - wall_mat.emission_enabled = true - wall_mat.emission = FIREWALL_COLORS[0] - wall_mat.emission_energy_multiplier = 0.35 - wall_mat.roughness = 0.4 - wall.material_override = wall_mat - wall.position = at - wall.rotation.y = yaw - wall.visible = false - _board.add_child(wall) + var port := FirewallPort.new() + port.position = at + port.rotation.y = yaw + _board.add_child(port) var body := StaticBody3D.new() var shape := CollisionShape3D.new() var bs := BoxShape3D.new() @@ -288,7 +318,7 @@ func _make_gate(line: Dictionary, yaw: float) -> Dictionary: body.position = at + Vector3(0, 0.2, 0) body.set_meta("key", Moves.gate_key(line.id)) _board.add_child(body) - return {"diamond": diamond, "mat": mat, "wall": wall, "wall_mat": wall_mat, "at": at} + return {"port": port, "at": at} func _flat_label(size: int) -> Label3D: @@ -297,7 +327,7 @@ func _flat_label(size: int) -> Label3D: l.font_size = size l.pixel_size = 0.004 l.rotation.x = -PI / 2 - l.modulate = Color(0.85, 0.88, 0.92, 0.8) + l.modulate = Color(Style.SECONDARY, 0.8) l.outline_size = 0 l.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER return l @@ -339,9 +369,7 @@ func _place_camera(instant: bool) -> void: func _fit_camera() -> Transform3D: var side := 1.0 if me == 0 else -1.0 var vp := get_viewport().get_visible_rect().size - var sx := vp.x / 1600.0 - var sy := vp.y / 900.0 - var region := Rect2(PANEL_LEFT * sx, PANEL_TOP * sy, vp.x - (PANEL_LEFT + PANEL_RIGHT) * sx, vp.y - (PANEL_TOP + PANEL_BOTTOM) * sy) + var region := Style.table_region(vp) var hx := BoardLayout.MAT_SIZE.x / 2 var hz := BoardLayout.MAT_SIZE.y / 2 var points := [Vector3(-hx, 0, -hz), Vector3(hx, 0, -hz), Vector3(-hx, 0, hz), Vector3(hx, 0, hz), @@ -412,8 +440,13 @@ func _is_hand_body(body: Object) -> bool: # --------------------------------------------------------------------------------------------- # Syncing to a view +## The view the table shows now ({} before the first sync). +func shown_view() -> Dictionary: + return _view + + ## Snaps the table to `view` (as seen by `me`), with `marks` from key to a mark name (see -## MARK_COLORS). +## Style.MARK). func sync(v: Dictionary, marks: Dictionary) -> void: _view = v _last_marks = marks @@ -421,11 +454,22 @@ func sync(v: Dictionary, marks: Dictionary) -> void: _tags[k].used = false _sync_tiles(v, marks) _sync_gates(v, marks) + for p in [0, 1]: + var pl: Dictionary = v.players[p] + if _strips[p].get_meta("ticks", []) != v.rules.firewallCost: + _strips[p].set_ticks(v.rules.firewallCost) + _strips[p].set_meta("ticks", v.rules.firewallCost) + var reach := Query.reachable_bandwidth(v, p) if p == me else int(pl.bandwidth) + _strips[p].set_value(pl.bandwidth, reach, Style.OWNER[p], bandwidth_delays.get(p, 0.0)) + bandwidth_delays = {} var want := {} _want_board_cards(v, want) _want_zones(v, want) + _want_stack(v, want) _apply_cards(want, marks) _layout_hand() + _layout_stack() + motions = {} for k in _tags.keys(): if not _tags[k].used: _tags[k].box.queue_free() @@ -437,51 +481,49 @@ func _sync_tiles(v: Dictionary, marks: Dictionary) -> void: for loc in GameMap.LOCATIONS: var tile: MeshInstance3D = _tiles[loc].mesh var owner = v.locations[loc].owner - var fill := Color(1, 1, 1, 0.018) - var edge := Color(0.82, 0.85, 0.9, 0.4) + # An open socket is dim chrome; a held one takes its owner's color and pattern. + var fill := Color(Style.BG, 0.62) + var edge := Color(Style.ACCENT, 0.5) if owner != null: - fill = Color(OWNER_COLORS[owner], 0.075) - edge = Color(OWNER_COLORS[owner], 0.85) + fill = Color(Style.OWNER[owner] * 0.2, 0.72) + edge = Color(Style.OWNER[owner], 0.9) + tile.set_instance_shader_parameter("pattern", 0.0 if owner == null else 1.0 + owner) var glow := 0.0 var mark = marks.get(Moves.loc_key(loc)) if mark != null: - edge = MARK_COLORS[mark] - glow = MARK_STRENGTH[mark] + edge = Style.MARK[mark] + glow = Style.MARK_STRENGTH[mark] tile.set_instance_shader_parameter("fill_color", fill) tile.set_instance_shader_parameter("edge_color", edge) tile.set_instance_shader_parameter("glow", glow) var label: Label3D = _tiles[loc].label if GameMap.is_start(loc): - label.text = "%s · %s" % [loc, "your start" if loc == GameMap.START_LOC[me] else "start"] + label.text = "%s · %s" % [loc, "YOUR START" if loc == GameMap.START_LOC[me] else "START"] else: - label.text = "%s · Lv %d" % [loc, GameMap.level_for(me, loc)] + label.text = "%s · LV %d" % [loc, GameMap.level_for(me, loc)] + # In the socket's far right corner as you sit. + var toward := 1.0 if me == 0 else -1.0 + var half := BoardLayout.tile_size / 2.0 - Vector2(0.28, 0.16) + label.position = BoardLayout.at[loc] + Vector3(half.x * toward, 0.004, -half.y * toward) label.rotation.y = 0.0 if me == 0 else PI func _sync_gates(v: Dictionary, marks: Dictionary) -> void: + # The LED count comes from the rules, so a longer Firewall cost list shows every level. + var levels: int = v.rules.firewallCost.size() for line_id in _gates: var g: Dictionary = _gates[line_id] var level: int = v.firewalls.get(line_id, 0) + var port: FirewallPort = g.port + port.set_level(level, levels, true, gate_delays.get(line_id, 0.0)) var mark = marks.get(Moves.gate_key(line_id)) - var mat: StandardMaterial3D = g.mat if mark != null: - mat.albedo_color = MARK_COLORS[mark] - mat.emission = MARK_COLORS[mark] * MARK_STRENGTH[mark] - else: - mat.albedo_color = Color(0.85, 0.88, 0.92, 0.55) if level == 0 else Color(FIREWALL_COLORS[level - 1], 0.9) - mat.emission = Color.BLACK - var wall: MeshInstance3D = g.wall - wall.visible = level > 0 - if level > 0: - var h := 0.22 + 0.2 * level - wall.scale = Vector3(1, h, 1) - wall.position.y = h / 2.0 - var c := FIREWALL_COLORS[mini(level, FIREWALL_COLORS.size()) - 1] - g.wall_mat.albedo_color = c - g.wall_mat.emission = c - _tag("gate:" + line_id, "Lv %d" % level, c.lightened(0.3), g.at + Vector3(0, h + 0.1, 0), true) + port.set_mark(Style.MARK[mark], Style.MARK_STRENGTH[mark]) + elif not port.busy(): + port.set_mark(Color(0, 0, 0, 0), 0.0) var seg: MeshInstance3D = _lines[line_id] seg.transparency = 0.6 if level > 0 else 0.0 + gate_delays = {} ## Cards on the mat: Servers, Programs, Anomalies in play and their Hardware. @@ -584,6 +626,14 @@ func _want_zones(v: Dictionary, want: Dictionary) -> void: "yaw": yaw, "face_down": true, "key": "pile:%d:hand" % p} +## Executions waiting on the stack, held up beside the table until they resolve: their card is in +## no zone meanwhile. Not clickable, so they never cover a click on the board. +func _want_stack(v: Dictionary, want: Dictionary) -> void: + for it in v.stack: + if it.kind == "execution" and it.get("card", -1) >= 0: + want["card:%d" % it.card] = {"name": State.name_of(v, it.card), "held": "stack", "key": ""} + + ## A pile: a block as tall as the count, with its top card on it (face up for the discard). func _want_pile(p: int, zone: String, count: int, top: int, want: Dictionary) -> void: var spot := BoardLayout.zone_spot(p, zone) @@ -621,9 +671,20 @@ func _make_pile(spot: Vector3) -> Dictionary: ## Creates, moves and removes Card3Ds to match `want` (node key → spot). func _apply_cards(want: Dictionary, marks: Dictionary) -> void: _hand_order = [] + _stack_order = [] for key in _cards.keys(): if not want.has(key): - _cards[key].queue_free() + var card: Card3D = _cards[key] + var spec: Dictionary = motions.get(key, {}) + if spec.get("style", "") == "leave": + # Back into a hidden pile: it goes there, then it's gone. + if card.get_parent() != _cards_root: + card.reparent(_cards_root, true) + card.pick_key = "" + var goal := _zone_xf(spec.get("p", me), spec.get("to", "deck")) + card.travel(_path_for(card, goal, {"style": "discard"}, false), PATH_TIMES.discard, spec.get("delay", 0.0), true, Style.ACCENT, true) + else: + card.queue_free() _cards.erase(key) for key in want: var w: Dictionary = want[key] @@ -632,7 +693,8 @@ func _apply_cards(want: Dictionary, marks: Dictionary) -> void: if fresh: card = CARD_SCENE.instantiate() _cards[key] = card - var parent: Node = _hand_root if w.get("hand", false) else _cards_root + var held: bool = w.get("hand", false) or w.has("held") + var parent: Node = _hand_root if held else _cards_root if card.get_parent() != parent: if card.get_parent() == null: parent.add_child(card) @@ -641,24 +703,125 @@ func _apply_cards(want: Dictionary, marks: Dictionary) -> void: card.set_shadows(parent != _hand_root) card.card_name = w.name card.pick_key = w.key + card.set_meta("node_key", key) if w.get("hand", false): _hand_order.append(card) + elif w.get("held", "") == "stack": + _stack_order.append(card) card.dim = w.get("dim", 0.0) var mark = marks.get(w.key) if not w.key.begins_with("loc:") else null # Only the card a hand key names glows, and only an Anomaly's own card, not its Hardware. if mark != null and w.key.begins_with("anomaly:") and key != w.key: mark = null - var strength: float = MARK_STRENGTH[mark] * (0.55 if w.get("hand", false) else 1.0) if mark != null else 0.0 - card.highlight = Color(MARK_COLORS[mark], strength) if mark != null else Color(0, 0, 0, 0) - if not w.get("hand", false): + var strength: float = Style.MARK_STRENGTH[mark] * (0.55 if w.get("hand", false) else 1.0) if mark != null else 0.0 + card.highlight = Color(Style.MARK[mark], strength) if mark != null else Color(0, 0, 0, 0) + if not held: var basis := Basis.from_euler(Vector3(0, w.yaw, PI if w.get("face_down", false) else 0.0)) var xf := Transform3D(basis, w.pos) - if fresh: - card.transform = xf - card.glide(xf, fresh) + var spec: Dictionary = motions.get(key, {}) + if not spec.is_empty(): + var style: String = spec.style + card.travel(_path_for(card, xf, spec, fresh), PATH_TIMES.get(style, PATH_TIMES.move), spec.get("delay", 0.0), + true, spec.get("color", Style.ACCENT)) + if style == "destroy": + card.flash(Style.BAD, 0.6, spec.get("delay", 0.0)) + else: + if fresh: + card.transform = xf + card.glide(xf, fresh) _sync_badge(key, w) +## The way a card travels to `goal` (world space) for a motion spec. See PATH_TIMES for timing. +func _path_for(card: Card3D, goal: Transform3D, spec: Dictionary, fresh: bool) -> Array: + var start := goal if fresh else card.global_transform + if spec.get("from", "") != "": + start = _zone_xf(spec.get("p", me), spec.from) + var up := Vector3.UP + match spec.style: + "slam": + # Straight over its spot, then down hard. + var over := Transform3D(goal.basis, goal.origin + up * 1.5) + return [start, over, over.translated(-up * 0.25), goal] + "reveal": + # Up in front of you, face up, held there to read, then down to its spot. + var show := _present_xf() + return [start, show, show.translated(camera.global_transform.basis.z * 0.3), goal] + "discard", "destroy": + var rise := Transform3D(start.basis, start.origin + up * 0.7) + return [start, rise, Transform3D(goal.basis, goal.origin + up * 0.9), goal] + "deal": + return [start, Transform3D(goal.basis, start.origin.lerp(goal.origin, 0.5) + up * 0.8), goal] + # "move": lift off, drift over the destination, set down. + var lift := Transform3D(start.basis, start.origin.lerp(goal.origin, 0.2) + up * 1.3) + return [start, lift, Transform3D(goal.basis, goal.origin + up * 0.8), goal] + + +## Where a card held up for you to read sits: in front of the camera, upright. +func _present_xf() -> Transform3D: + return camera.global_transform * Transform3D(Basis(Vector3.RIGHT, PI / 2), Vector3(0, 0.45, -REVEAL_DISTANCE)) + + +## The top of player `p`'s pile `zone` ("deck", "serverPile", "discard", "hand"), face down, in +## world space. Your own "hand" is the held hand in front of the camera. +func _zone_xf(p: int, zone: String) -> Transform3D: + if zone == "hand" and p == me: + var half_h := HAND_DISTANCE * tan(deg_to_rad(camera.fov / 2.0)) + return camera.global_transform * Transform3D(Basis(Vector3.RIGHT, PI / 2), Vector3(0, -half_h, -HAND_DISTANCE)) + if zone == "play": + zone = "hand" + var count := 1 + if not _view.is_empty() and _view.players[p].has(zone): + count = maxi(1, _view.players[p][zone].size()) + var h := (count - 1) * BoardLayout.LAYER + BoardLayout.CARD_Y if zone != "hand" else BoardLayout.CARD_Y + return Transform3D(Basis.from_euler(Vector3(0, BoardLayout.yaw_for(p), PI)), BoardLayout.zone_spot(p, zone) + Vector3(0, h, 0)) + + +## A table point for a key ("anomaly:…", "card:…", "loc:…"): the card now, or the location. +func anchor_of(key: String) -> Variant: + var c: Card3D = _cards.get(key) + if c != null and is_instance_valid(c): + return c.global_position + if key.begins_with("loc:") and BoardLayout.at.has(key.substr(4)): + return BoardLayout.at[key.substr(4)] + if key.begins_with("gate:") and _gates.has(key.substr(5)): + return _gates[key.substr(5)].at + return null + + +## A flash on the card at node key `key`. +func flash_card(key: String, color: Color, delay := 0.0) -> void: + var c: Card3D = _cards.get(key) + if c != null and is_instance_valid(c): + c.flash(color, 0.55, delay) + + +## Whether anything on the table is still moving. +func animating() -> bool: + for k in _cards: + if is_instance_valid(_cards[k]) and _cards[k].moving(): + return true + for g in _gates.values(): + if g.port.busy(): + return true + return false + + +## Jumps every animation to its end (a click skips the show). +func finish_animations() -> void: + for k in _cards: + if is_instance_valid(_cards[k]): + _cards[k].finish() + for g in _gates.values(): + g.port.finish() + for pop in _pops: + pop.label.queue_free() + _pops = [] + _flashes = {} + if not _view.is_empty(): + _sync_tiles(_view, _last_marks) + + ## A readout under an Anomaly: Cores, Health and status. func _sync_badge(key: String, w: Dictionary) -> void: if not w.get("badge", false): @@ -668,7 +831,7 @@ func _sync_badge(key: String, w: Dictionary) -> void: return var toward := 1.0 if me == 0 else -1.0 var card: Card3D = _cards[key] - _tag(key, badge_text(_view, r), OWNER_COLORS[r.player].lightened(0.3), Vector3(0, 0.05, 0.72 * toward), false, card) + _tag(key, badge_text(_view, r), Style.OWNER[r.player].lightened(0.3), Vector3(0, 0.05, 0.72 * toward), false, card) ## Shows `text` in a small 2D box pinned under the table point `world`, or with `follow`, at @@ -679,9 +842,7 @@ func _tag(key: String, text: String, color: Color, world: Vector3, above := fals if t.is_empty(): var box := PanelContainer.new() box.mouse_filter = Control.MOUSE_FILTER_IGNORE - var sb := StyleBoxFlat.new() - sb.bg_color = Color(0.02, 0.03, 0.04, 0.78) - sb.set_corner_radius_all(4) + var sb := Style.chamfer_box(Color(color, 0.45), Color(Style.BG, 0.82), 1.0, 0.0, 4.0) sb.content_margin_left = 5 sb.content_margin_right = 5 sb.content_margin_top = 1 @@ -695,7 +856,10 @@ func _tag(key: String, text: String, color: Color, world: Vector3, above := fals t = {"box": box, "label": label} _tags[key] = t t.label.text = text - t.label.add_theme_color_override("font_color", color) + # Only on a change: an override restyles the label, which reshapes its text. + if t.get("color") != color: + t.color = color + t.label.add_theme_color_override("font_color", color) t.world = world t.above = above t.used = true @@ -723,7 +887,7 @@ func pop_damage(r: Dictionary, amount: int, destroyed: bool, loc: Variant, delay world = BoardLayout.at[loc] else: return - pop_text(world, "−%d%s" % [amount, " destroyed" if destroyed else ""], Color("#ff6b6b"), delay, 26) + pop_text(world, "−%d%s" % [amount, " destroyed" if destroyed else ""], Style.BAD, delay, 26) ## A short message rising from a table point, e.g. who won a roll. @@ -740,13 +904,13 @@ func pop_text(world: Vector3, text: String, color: Color, delay := 0.0, size := _overlay.add_child(label) while _pops.size() >= MAX_POPS: _pops.pop_front().label.queue_free() - _pops.append({"label": label, "world": world, "born": Time.get_ticks_msec() + int(delay * 1000)}) + _pops.append({"label": label, "world": world, "born": Time.get_ticks_msec() + int(Motion.secs(delay) * 1000)}) -## The location at `loc` pulses in its new owner's color. -func flash_capture(loc: String, p: int) -> void: - if _tiles.has(loc): - _flashes[loc] = {"color": OWNER_COLORS[p], "born": Time.get_ticks_msec()} +## The location at `loc` pulses in its new owner's color, after `delay` seconds. +func flash_capture(loc: String, p: int, delay := 0.0) -> void: + if _tiles.has(loc) and not Motion.instant(): + _flashes[loc] = {"color": Style.OWNER[p], "born": Time.get_ticks_msec() + int(Motion.secs(delay) * 1000)} func _place_pops() -> void: @@ -776,6 +940,8 @@ func _pulse_tiles() -> void: var f: Dictionary = _flashes[loc] var age: float = (now - f.born) / 1000.0 var tile: MeshInstance3D = _tiles[loc].mesh + if age < 0.0: + continue if age > FLASH_TIME: _flashes.erase(loc) _sync_tiles(_view, _last_marks) @@ -833,6 +999,46 @@ static func badge_text(v: Dictionary, r: Dictionary) -> String: return " ".join(parts) +## Lays out the Executions on the stack at the right of the table, newest in front. One that +## just went on is held up in the middle for you to read first. +func _layout_stack() -> void: + var n := _stack_order.size() + if n == 0: + return + var vp := get_viewport().get_visible_rect().size + var d := HAND_DISTANCE + 2.2 + var half_h := d * tan(deg_to_rad(camera.fov / 2.0)) + var half_w := half_h * vp.x / vp.y + var region := Style.table_region(vp) + var right := half_w - 2.0 * half_w * (vp.x - region.end.x) / vp.x - BoardLayout.CARD_SIZE.x * 0.8 + for i in n: + var c: Card3D = _stack_order[i] + if not is_instance_valid(c) or c.is_queued_for_deletion(): + continue + var tilt := Basis(Vector3.RIGHT, PI / 2).rotated(Vector3.BACK, 0.06 - 0.05 * i) + var xf := Transform3D(tilt, Vector3(right - i * 0.6, half_h * 0.25 - i * 0.18, -d + i * 0.02)) + var spec: Dictionary = motions.get(c.get_meta("node_key", ""), {}) + if spec.get("style", "") == "stack": + var start := c.transform + if spec.get("from", "") != "": + start = camera.global_transform.affine_inverse() * _zone_xf(spec.get("p", me), spec.from) + var show := Transform3D(Basis(Vector3.RIGHT, PI / 2), Vector3(0, 0.45, -REVEAL_DISTANCE)) + c.travel([start, show, show.translated(Vector3(0, 0, 0.25)), xf], PATH_TIMES.stack, spec.get("delay", 0.0), + true, spec.get("color", Style.ACCENT)) + continue + if not c.has_goal(): + c.transform = xf + c.glide(xf) + + +## Drops your held hand out of sight (true) or brings it back. +func set_hand_tucked(on: bool) -> void: + if on == _hand_tucked: + return + _hand_tucked = on + _layout_hand() + + ## Lays out your hand in front of the camera, the hovered card lifted. func _layout_hand() -> void: var cards := _hand_order.filter(func(c): return is_instance_valid(c) and not c.is_queued_for_deletion()) @@ -842,9 +1048,10 @@ func _layout_hand() -> void: var vp := get_viewport().get_visible_rect().size var half_h := HAND_DISTANCE * tan(deg_to_rad(camera.fov / 2.0)) var half_w := half_h * vp.x / vp.y - # Keep clear of the side panels (see the HUD): 300 px on the left, 340 on the right. - var left := -half_w + 2.0 * half_w * 300.0 / vp.x + BoardLayout.CARD_SIZE.x / 2 - var right := half_w - 2.0 * half_w * 340.0 / vp.x - BoardLayout.CARD_SIZE.x / 2 + # Keep clear of the side panels (Style's panel geometry, as the HUD draws them). + var region := Style.table_region(vp) + var left := -half_w + 2.0 * half_w * region.position.x / vp.x + BoardLayout.CARD_SIZE.x / 2 + var right := half_w - 2.0 * half_w * (vp.x - region.end.x) / vp.x - BoardLayout.CARD_SIZE.x / 2 var step := 1.34 if n == 1 else minf(1.34, (right - left) / (n - 1)) var mid := (left + right) / 2.0 var y0 := -half_h + BoardLayout.CARD_SIZE.y * (HAND_SHOWN - 0.5) @@ -856,8 +1063,17 @@ func _layout_hand() -> void: var y := y0 + (BoardLayout.CARD_SIZE.y * 0.42 if lift else 0.0) if c.highlight.a > 0 and not lift: y += 0.12 + if _hand_tucked: + y = -half_h - BoardLayout.CARD_SIZE.y var pos := Vector3(x, y, -HAND_DISTANCE + i * 0.004 + (0.25 if lift else 0.0)) var xf := Transform3D(Basis(Vector3.RIGHT, PI / 2), pos) + var spec: Dictionary = motions.get(c.get_meta("node_key", ""), {}) + if spec.get("style", "") == "draw": + # Drawn: off the deck, held up to you, then into the hand. + var deck := camera.global_transform.affine_inverse() * _zone_xf(me, "deck") + var hold := Transform3D(Basis(Vector3.RIGHT, PI / 2), Vector3(x * 0.45, -0.25, -REVEAL_DISTANCE - 0.3)) + c.travel([deck, hold, hold.translated(Vector3(0, 0.06, 0.25)), xf], PATH_TIMES.draw, spec.get("delay", 0.0)) + continue if not c.has_goal(): # A card just drawn comes up from below. c.transform = xf.translated(Vector3(0, -2.5, 0)) @@ -868,8 +1084,7 @@ func _layout_hand() -> void: ## Tries spots across each object with that key and raycasts each, as a click would. For tests. func screen_point_for(key: String) -> Variant: var vp := get_viewport().get_visible_rect().size - var sx := vp.x / 1600.0 - var region := Rect2(PANEL_LEFT * sx, PANEL_TOP * vp.y / 900.0, vp.x - (PANEL_LEFT + PANEL_RIGHT) * sx, vp.y) + var region := Style.table_region(vp, 0.0) var points := [] var grid := func(xf: Transform3D, half: Vector2, y: float) -> void: for fz in [0.0, -0.6, 0.6, -0.85, 0.85]: diff --git a/table/led.gdshader b/table/led.gdshader new file mode 100644 index 0000000..f17a24b --- /dev/null +++ b/table/led.gdshader @@ -0,0 +1,15 @@ +shader_type spatial; +render_mode blend_mix, unshaded, shadows_disabled; + +// A Firewall LED (gameplay-plan.md §B4). One material for every LED; each one's color and how +// brightly it's lit (a, past 1 for bloom; 0 is off) are instance uniforms. + +instance uniform vec4 led : source_color = vec4(0.12, 0.16, 0.17, 0.0); + +void fragment() { + vec2 p = abs(UV - 0.5) * 2.0; + float core = 1.0 - smoothstep(0.35, 1.0, max(p.x, p.y)); + vec3 off = vec3(0.05, 0.07, 0.075); + // Brightness follows a: a ghost (a < 0.5) is a dim tint, a lit LED (a ≥ 1.5) blooms at its core. + ALBEDO = led.a > 0.0 ? off + led.rgb * (0.1 + led.a * (0.45 + 0.55 * core)) : off; +} diff --git a/table/led.gdshader.uid b/table/led.gdshader.uid new file mode 100644 index 0000000..f4b5487 --- /dev/null +++ b/table/led.gdshader.uid @@ -0,0 +1 @@ +uid://kkh8crvwgaaw diff --git a/table/playmat.gdshader b/table/playmat.gdshader new file mode 100644 index 0000000..ff923e3 --- /dev/null +++ b/table/playmat.gdshader @@ -0,0 +1,56 @@ +shader_type spatial; +render_mode blend_mix, cull_back, diffuse_burley, specular_schlick_ggx; + +// The playmat as dark glass with a neon grid inlay (gameplay-plan.md §B1). The grid is drawn in +// world space from the board layout (GameTable sets `pitch` and `origin` from BoardLayout), so its +// lines run between the locations instead of along the mat's UVs. The mat's edge is a neon rim. + +uniform vec3 glass_color : source_color = vec3(0.010, 0.020, 0.026); +uniform float roughness : hint_range(0.0, 1.0) = 0.3; +uniform vec4 line_color : source_color = vec4(0.133, 0.827, 0.933, 1.0); +// Major grid: half a column pitch across, a row pitch deep; origin is a major crossing. +uniform vec2 pitch = vec2(2.96, 2.18); +uniform vec2 origin = vec2(0.0, 1.09); +// Minor lines per major cell. +uniform float minor = 4.0; +uniform float major_width = 0.018; +uniform float minor_width = 0.008; +uniform float major_energy = 1.25; +uniform float minor_energy = 0.28; +// Half the mat's size, for the rim. +uniform vec2 half_size = vec2(9.144, 7.62); +uniform float rim_energy = 2.6; + +varying vec3 world_pos; +varying vec3 world_normal; + +void vertex() { + world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz; + world_normal = normalize((MODEL_MATRIX * vec4(NORMAL, 0.0)).xyz); +} + +float grid_line(vec2 p, vec2 cell, float width) { + vec2 g = abs(fract(p / cell + 0.5) - 0.5) * cell; + vec2 aa = fwidth(p) * 1.25; + vec2 l = 1.0 - smoothstep(vec2(width) - aa, vec2(width) + aa, g); + return max(l.x, l.y); +} + +void fragment() { + vec2 p = world_pos.xz - origin; + float top = step(0.5, world_normal.y); + float major_l = grid_line(p, pitch, major_width); + float minor_l = grid_line(p, pitch / minor, minor_width) * (1.0 - major_l); + float edge_d = min(half_size.x - abs(world_pos.x), half_size.y - abs(world_pos.z)); + float rim = 1.0 - smoothstep(0.0, 0.07, edge_d); + float band = (1.0 - smoothstep(0.0, 0.9, edge_d)) * 0.22; + ALBEDO = glass_color; + ROUGHNESS = roughness; + METALLIC = 0.25; + SPECULAR = 0.4; + vec3 e = line_color.rgb * (major_l * major_energy + minor_l * minor_energy) * top; + e += line_color.rgb * (rim * rim_energy + band * top); + // The sides are all rim. + e += line_color.rgb * (1.0 - top) * 0.9; + EMISSION = e; +} diff --git a/table/playmat.gdshader.uid b/table/playmat.gdshader.uid new file mode 100644 index 0000000..b01de45 --- /dev/null +++ b/table/playmat.gdshader.uid @@ -0,0 +1 @@ +uid://ctbq24wo6c522 diff --git a/table/playmat.tscn b/table/playmat.tscn index 582a7a2..6575e6f 100644 --- a/table/playmat.tscn +++ b/table/playmat.tscn @@ -1,7 +1,7 @@ [gd_scene format=3] [ext_resource type="PackedScene" uid="uid://dx42gyxom1dlb" path="res://assets/playmat.glb" id="1_model"] -[ext_resource type="Material" uid="uid://br7tudxocdqc5" path="res://assets/playmat.tres" id="2_fabric"] +[ext_resource type="Material" path="res://table/playmat_glass.tres" id="2_glass"] [node name="Playmat" type="Node3D"] @@ -9,6 +9,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.021875, 0) [node name="Plane_003" parent="Model" index="0"] -surface_material_override/0 = ExtResource("2_fabric") +surface_material_override/0 = ExtResource("2_glass") [editable path="Model"] diff --git a/table/playmat_glass.tres b/table/playmat_glass.tres new file mode 100644 index 0000000..3cba462 --- /dev/null +++ b/table/playmat_glass.tres @@ -0,0 +1,7 @@ +[gd_resource type="ShaderMaterial" format=3] + +[ext_resource type="Shader" path="res://table/playmat.gdshader" id="1_shader"] + +[resource] +render_priority = -3 +shader = ExtResource("1_shader") diff --git a/table/tile.gdshader b/table/tile.gdshader index 9b3fbc0..7fc1e39 100644 --- a/table/tile.gdshader +++ b/table/tile.gdshader @@ -1,28 +1,72 @@ shader_type spatial; render_mode blend_mix, depth_draw_opaque, cull_disabled, shadows_disabled, unshaded; -// A location printed on the playmat: a rounded rectangle with a tinted fill and an edge line. -// One material serves every tile; the owner tint and glow are instance uniforms. +// A location printed on the playmat, drawn as a socket in the cards' style (gameplay-plan.md §B2): +// a chamfered octagon like the cards' frames, a dim interior, an inset second line, brighter ticks +// on the chamfers and the owner's pattern (stripes for South, dots for North) as a cue beside the +// color. One material serves every tile and every printed card spot; the owner tint, pattern and +// glow are instance uniforms. uniform vec2 size = vec2(5.6, 2.05); -uniform float radius = 0.2; +// The corner cut, in world units. +uniform float chamfer = 0.22; uniform float edge_width = 0.07; +// The faint second line inside the edge, as a fraction of the edge's alpha; 0 for none. +uniform float inner_line = 0.45; +// Pattern pitch and size, in world units. +uniform float stripe_pitch = 0.3; +uniform float dot_pitch = 0.32; instance uniform vec4 fill_color : source_color = vec4(1.0, 1.0, 1.0, 0.06); instance uniform vec4 edge_color : source_color = vec4(1.0, 1.0, 1.0, 0.45); // Highlights (legal targets, the combat) light up the edge. instance uniform float glow = 0.0; +// The owner's pattern: 0 none, 1 stripes (South), 2 dots (North). +instance uniform float pattern = 0.0; + +// Signed distance to a chamfered rectangle: exact inside, which is all the bands need. +float sd_octagon(vec2 p, vec2 half_size, float c, out bool on_chamfer) { + vec2 q = abs(p); + float box = max(q.x - half_size.x, q.y - half_size.y); + float diag = (q.x + q.y - (half_size.x + half_size.y - c)) * 0.70710678; + on_chamfer = diag > box; + return max(box, diag); +} void fragment() { vec2 p = (UV - 0.5) * size; - vec2 q = abs(p) - (size * 0.5 - vec2(radius)); - float d = length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - radius; + bool on_chamfer; + float d = sd_octagon(p, size * 0.5, chamfer, on_chamfer); if (d > 0.0) { discard; } + float px = fwidth(d); float w = edge_width * (1.0 + glow * 0.8); - float edge = 1.0 - smoothstep(w * 0.5, w, -d); - vec4 c = mix(fill_color, edge_color, edge); + // The chamfers carry a thicker tick, like the corner ticks on the cards. + float ew = on_chamfer ? w * 1.9 : w; + float edge = 1.0 - smoothstep(ew - px, ew + px, -d); + float inner_d = abs(-d - w * 2.6); + float inner = (1.0 - smoothstep(w * 0.18 - px, w * 0.18 + px, inner_d)) * inner_line; + + vec4 fill = fill_color; + if (pattern > 0.5) { + float on = 0.0; + if (pattern < 1.5) { + float t = fract((p.x + p.y) / stripe_pitch); + float aa = fwidth((p.x + p.y) / stripe_pitch); + on = smoothstep(0.62 - aa, 0.62 + aa, t) * (1.0 - smoothstep(0.86 - aa, 0.86 + aa, t)); + } else { + vec2 cell = fract(p / dot_pitch) - 0.5; + float r = length(cell) * dot_pitch; + float aa = fwidth(r); + on = 1.0 - smoothstep(0.045 - aa, 0.045 + aa, r); + } + // Keep the pattern off the frame so the edge reads cleanly. + on *= smoothstep(w * 3.0, w * 4.5, -d); + fill = mix(fill, vec4(edge_color.rgb, max(fill.a, edge_color.a * 0.32)), on * 0.75); + } + vec4 c = mix(fill, edge_color, max(edge, inner * edge_color.a)); + c.a = max(c.a, fill.a); // Unshaded, so the print reads the same under any light; glow brightens the edge for bloom. ALBEDO = c.rgb * (1.0 + glow * edge * 1.5) + fill_color.rgb * glow * 0.1; ALPHA = c.a; diff --git a/table/void_grid.gdshader b/table/void_grid.gdshader new file mode 100644 index 0000000..46089d9 --- /dev/null +++ b/table/void_grid.gdshader @@ -0,0 +1,40 @@ +shader_type spatial; +render_mode blend_mix, unshaded, cull_disabled, shadows_disabled; + +// The floor of cyberspace under the playmat: a neon grid on black that fades into the void, with +// a slow scan ring running out from the table. It continues the mat's grid (same pitch, same +// origin), so the mat reads as a lit part of one floor. + +uniform vec4 line_color : source_color = vec4(0.133, 0.827, 0.933, 1.0); +uniform vec3 floor_color : source_color = vec3(0.004, 0.008, 0.011); +uniform vec2 pitch = vec2(2.96, 2.18); +uniform vec2 origin = vec2(0.0, 1.09); +uniform float width = 0.014; +uniform float energy = 0.3; +// The grid fades between these distances from the table's centre. +uniform float fade_from = 6.0; +uniform float fade_to = 48.0; +uniform float scan_speed = 9.0; +uniform float scan_period = 9.0; + +varying vec3 world_pos; + +void vertex() { + world_pos = (MODEL_MATRIX * vec4(VERTEX, 1.0)).xyz; +} + +void fragment() { + vec2 p = world_pos.xz - origin; + vec2 g = abs(fract(p / pitch + 0.5) - 0.5) * pitch; + vec2 aa = fwidth(p) * 1.5; + vec2 l = 1.0 - smoothstep(vec2(width) - aa, vec2(width) + aa, g); + float line = max(l.x, l.y); + float r = length(world_pos.xz); + float fade = 1.0 - smoothstep(fade_from, fade_to, r); + // Lines get thin far away; fade them by their screen size too so they don't shimmer. + fade *= clamp(1.2 - length(aa) * 3.0, 0.0, 1.0); + float ring_r = mod(TIME * scan_speed, scan_period * scan_speed); + float ring = exp(-pow((r - ring_r) / 1.6, 2.0)) * (1.0 - ring_r / (scan_period * scan_speed)); + float glow_floor = (1.0 - smoothstep(4.0, 22.0, r)) * 0.06; + ALBEDO = floor_color + line_color.rgb * (line * energy * (1.0 + ring * 1.6) * fade + glow_floor); +} diff --git a/table/void_grid.gdshader.uid b/table/void_grid.gdshader.uid new file mode 100644 index 0000000..6d97129 --- /dev/null +++ b/table/void_grid.gdshader.uid @@ -0,0 +1 @@ +uid://c84mmktgswpio diff --git a/tests/attack_click.gd b/tests/attack_click.gd new file mode 100644 index 0000000..2704c3e --- /dev/null +++ b/tests/attack_click.gd @@ -0,0 +1,103 @@ +extends SceneTree +## Plays games through the game scene, headless, with you driven by the greedy bot. Whenever it +## would attack, it does so by clicking instead: the attacker, then the middle of the target +## location, where the defenders' cards stand. Checks that the click attacks. +## +## godot --headless --script res://tests/attack_click.gd -- [--games N] [--seed N] + +var _game: Node +var _games := 4 +var _seed := 7 +var _played := 0 +var _hb := GreedyBot.new(GreedyBot.STYLES.greedy.params) +var _wait := -1 +var _attacks := 0 +var _on_defender := 0 +var _missed := 0 +var _began := false + + +func _init() -> void: + var args := OS.get_cmdline_user_args() + var i := 0 + while i < args.size(): + match args[i]: + "--games": + i += 1 + _games = int(args[i]) + "--seed": + i += 1 + _seed = int(args[i]) + i += 1 + Card3D.instant = true + _game = load("res://scenes/game.tscn").instantiate() + root.add_child.call_deferred(_game) + + +func _process(_d: float) -> bool: + if _game == null or not _game.is_node_ready(): + return false + if not _began: + _began = true + _new_game() + return false + if Engine.get_physics_frames() < _wait: + return false + var m: LocalMatch = _game.match_ + for n in 400: + if not Util.errors.is_empty(): + print("seed %d: engine error: %s" % [m.setup.seed, "; ".join(Util.errors)]) + return _finish(true) + if m.is_over(): + _played += 1 + if _played >= _games: + return _finish(false) + _new_game() + return false + if m.bot_to_act(): + m.bot_step() + continue + # Let physics catch up with the table before clicking it. + if _wait < 0: + _wait = Engine.get_physics_frames() + 2 + return false + _wait = -1 + var a: Dictionary = _hb.choose(RulesEngine.view_for(m.s, m.human), m.legal(), m.human) + if a.type == "attack": + _click_attack(m, a) + else: + m.act(a) + return false + return false + + +func _click_attack(m: LocalMatch, a: Dictionary) -> void: + var table: GameTable = _game.table + var mv: Dictionary = _game.moves.filter(func(x): return x.action == a)[0] + _attacks += 1 + _game._select(mv.source) + var sp := table.camera.unproject_position(BoardLayout.at[a.to] + Vector3(0, 0.01, 0)) + var key := table.key_at(sp) + if key.begins_with("anomaly:"): + _on_defender += 1 + var before := m.actions.size() + _game._pick(key, sp) + if _game.hud.popover_open(): + _game.hud.hide_popover() + if m.actions.size() == before: + _missed += 1 + print("seed %d: clicking %s (at %s's middle) didn't attack" % [m.setup.seed, key, a.to]) + m.act(a) + + +func _new_game() -> void: + _game._paused = true + _game.hud.close_modal() + _game.start_game({"seed": _seed + _played, "human": _played % 2, "style": "greedy"}) + Util.errors.clear() + + +func _finish(failed: bool) -> bool: + print("attack click: %d game(s), %d attacks clicked (%d on a defender's card), %d missed" % [_played, _attacks, _on_defender, _missed]) + quit(1 if failed or _missed > 0 else 0) + return false diff --git a/tests/conformance.gd b/tests/conformance.gd index bc53b5a..1c9ca06 100644 --- a/tests/conformance.gd +++ b/tests/conformance.gd @@ -149,7 +149,8 @@ func _check_game(t: Dictionary, index: Dictionary) -> Dictionary: if dealt != decks: return fail.call(0, "dealt different decks: %s vs TS %s" % [JSON.stringify(dealt), JSON.stringify(decks)]) - var s = RulesEngine.create_game({"pool": _pool, "decks": decks, "seed": seed, "rules": rules, "log": true}) + # With events on, so the run also shows that recording them leaves the rules alone. + var s = RulesEngine.create_game({"pool": _pool, "decks": decks, "seed": seed, "rules": rules, "log": true, "events": true}) if s == null or not Util.errors.is_empty(): return fail.call(0, "create_game failed: %s" % "; ".join(Util.errors)) var initial: Dictionary = t.initial @@ -226,11 +227,13 @@ func _compare(s: Dictionary, t: Dictionary, n: int, state_md5: String, log_md5: return "" -## The state as fingerprinted: without its card defs (fixed for the game) and log (checked by line). +## The state as fingerprinted: without its card defs (fixed for the game), log (checked by line) and +## events (TS has none, see godot-plan.md §3). func _body(s: Dictionary) -> Dictionary: var b := s.duplicate() b.erase("defs") b.erase("log") + b.erase("events") return b diff --git a/tests/events.gd b/tests/events.gd new file mode 100644 index 0000000..9d36fda --- /dev/null +++ b/tests/events.gd @@ -0,0 +1,342 @@ +extends SceneTree +## Plays random-vs-random games with events on (godot-plan.md §3) and checks after every action that +## the event stream, folded up from the start, gives the state: each player's Bandwidth, each +## gateway's Firewall, each location's owner, the zone of every card, where every Anomaly stands, +## which Anomalies are face up, and their counters. Every event's "from" must match the fold too, and +## the Bandwidth safety net (State.reconcile_bandwidth) must never be needed. +## +## godot --headless --script res://tests/events.gd -- [--games N] [--seed N] + +var _fold: Dictionary +var _seen := 0 +var _errors: Array[String] = [] + + +func _init() -> void: + var games := 30 + var first := 1 + var args := OS.get_cmdline_user_args() + var i := 0 + while i < args.size(): + match args[i]: + "--games": + i += 1 + games = int(args[i]) + "--seed": + i += 1 + first = int(args[i]) + i += 1 + var pool := Cards.load_cards() + var rules := Rules.defaults() + var started := Time.get_ticks_msec() + var failed := 0 + var steps := 0 + var events := 0 + var kinds := {} + State.event_fixes = 0 + for seed in range(first, first + games): + Util.errors.clear() + _errors = [] + var err := _play(pool, rules, seed) + if err == "" and not Util.errors.is_empty(): + err = "engine error: %s" % "; ".join(Util.errors) + if err == "" and State.event_fixes > 0: + err = "the Bandwidth safety net added %d event(s)" % State.event_fixes + if err != "": + failed += 1 + print("seed %d: %s" % [seed, err]) + State.event_fixes = 0 + continue + steps += _fold.steps + events += _seen + for k in _fold.kinds: + kinds[k] = kinds.get(k, 0) + _fold.kinds[k] + var secs := (Time.get_ticks_msec() - started) / 1000.0 + var counts := PackedStringArray() + var names := kinds.keys() + names.sort() + for k in names: + counts.append("%s %d" % [k, kinds[k]]) + print("events: %s" % ", ".join(counts)) + print("events: %d/%d games consistent (%d steps, %d events, %.1fs)" % [games - failed, games, steps, events, secs]) + var match_err := _check_match(pool, first) + if match_err != "": + failed += 1 + print("LocalMatch: %s" % match_err) + quit(0 if failed == 0 else 1) + + +## LocalMatch records events and hands out yours: the bot's draws hidden, yours shown. +func _check_match(pool: Dictionary, seed: int) -> String: + var rules := LocalMatch.rules_from([]) + var setup := {"seed": seed, "human": 0, "decks": LocalMatch.random_decks(pool, seed, rules), "rules": []} + var m := LocalMatch.new(pool, setup, RandomBot.new(seed)) + var you := RandomBot.new(seed + 1) + var from := m.event_count() + if from == 0: + return "no events after setup" + for n in 300: + if m.is_over(): + break + if m.bot_to_act(): + m.bot_step() + else: + m.act(you.choose(m.view(), m.legal(), m.human)) + var mine := m.events_since(from) + if mine.size() != m.event_count() - from: + return "events_since(%d) has %d events, expected %d" % [from, mine.size(), m.event_count() - from] + var drew := [0, 0] + for ev in mine: + if ev.k == "drew": + drew[ev.p] += 1 + if (ev.p == m.bot_side) != (ev.card == -1): + return "a draw shown to the wrong player: %s" % JSON.stringify(ev) + if drew[0] == 0 or drew[1] == 0: + return "no draws seen: %s" % str(drew) + return "" + + +## Plays one game, checking after every action. Returns "" or the first problem. +func _play(pool: Dictionary, rules: Dictionary, seed: int) -> String: + var decks := Play.deal(pool, seed, rules) + var s = RulesEngine.create_game({"pool": pool, "decks": decks, "seed": seed, "rules": rules, "log": true, "events": true}) + if s == null: + return "create_game failed" + _start_fold(s) + var err := _check(s, "setup") + if err != "": + return err + var random: Callable = Play.bots().random + var players := [random.call(seed * 2 + 1), random.call(seed * 2 + 2)] + var n := 0 + while not s.over: + n += 1 + if n > Play.MAX_ACTIONS: + return "didn't finish" + var p: int = RulesEngine.decider(s) + var legal := RulesEngine.legal_actions(s) + var view := RulesEngine.view_for(s, p) + if view.events != null: + return "view_for keeps the events" + var a: Dictionary = players[p].choose(view, legal, p) + if not RulesEngine.apply_action(s, a, legal): + return "illegal action" + _fold.steps += 1 + err = _check(s, "step %d (%s), turn %d" % [n, RulesEngine.action_key(a), s.turn]) + if err != "": + return err + return _check_views(s) + + +# --------------------------------------------------------------------------------------------- +# The fold + +func _start_fold(s: Dictionary) -> void: + _seen = 0 + var zone := {} + for c in s.cards: + var kind: String = s.defs[c.name].kind + zone[c.id] = "slot" if kind == "anomaly" else ("serverPile" if kind == "server" else "deck") + var owner := {} + # No event captures the starts; folding from them, any capture event must agree. + for loc in GameMap.START_LOC: + owner[loc] = GameMap.START_LOC.find(loc) + for loc in GameMap.LOCATIONS: + if not owner.has(loc): + owner[loc] = null + var at := {} + var face := {} + var counters := {} + for p in 2: + for slot in range(1, 9): + var k := "%d:%d" % [p, slot] + at[k] = null + counters[k] = {"infection": 0, "bugs": 0, "damage": 0} + if slot <= 4: + face[k] = false + _fold = {"bandwidth": [0, 0], "firewalls": {}, "owner": owner, "zone": zone, "at": at, "face": face, + "counters": counters, "turn": 0, "active": -1, "combats": {}, "steps": 0, "kinds": {}} + + +## Folds the new events, then compares the fold with the state. +func _check(s: Dictionary, where: String) -> String: + var events: Array = s.events + for i in range(_seen, events.size()): + var err := _apply(s, events[i]) + if err != "": + return "%s: event %d %s: %s" % [where, i, JSON.stringify(events[i]), err] + _seen = events.size() + var err := _compare(s) + return "" if err == "" else "%s: %s" % [where, err] + + +func _zone_matches(zone: String, from: String) -> bool: + return from != "" and (zone == from or zone.begins_with(from + ":")) + + +func _apply(s: Dictionary, ev: Dictionary) -> String: + var f := _fold + f.kinds[ev.k] = f.kinds.get(ev.k, 0) + 1 + var rk := func(r) -> String: return "%d:%d" % [r.player, r.slot] + match ev.k: + "turn": + if ev.turn != f.turn + 1: + return "turn %d after %d" % [ev.turn, f.turn] + f.turn = ev.turn + f.active = ev.p + "bandwidth": + if ev.from != f.bandwidth[ev.p]: + return "from %d, but the fold has %d" % [ev.from, f.bandwidth[ev.p]] + if ev.from == ev.to: + return "no change" + f.bandwidth[ev.p] = ev.to + "firewall": + if ev.from != f.firewalls.get(ev.line, 0): + return "from Lv %d, but the fold has %d" % [ev.from, f.firewalls.get(ev.line, 0)] + f.firewalls[ev.line] = ev.to + "captured": + if ev.from != f.owner[ev.loc]: + return "from %s, but the fold has %s" % [ev.from, f.owner[ev.loc]] + f.owner[ev.loc] = ev.p + "drew": + if f.zone[ev.card] != "deck": + return "drawn from %s" % f.zone[ev.card] + if s.cards[ev.card].owner != ev.p: + return "not the drawer's card" + f.zone[ev.card] = "hand" + "hand", "discard": + if not _zone_matches(f.zone[ev.card], ev.from): + return "from %s, but the fold has %s" % [ev.from, f.zone[ev.card]] + if s.cards[ev.card].owner != ev.p: + return "p isn't the owner" + f.zone[ev.card] = ev.k + if ev.k == "discard" and ev.why == "": + return "no why" + "pile": + if not _zone_matches(f.zone[ev.card], ev.from): + return "from %s, but the fold has %s" % [ev.from, f.zone[ev.card]] + f.zone[ev.card] = ev.zone + "install": + var was: String = f.zone[ev.card] + if was != "hand" and was != "serverPile": + return "installed from %s" % was + f.zone[ev.card] = ("play:" + ev.at.substr(4)) if ev.at.begins_with("loc:") else "worn:" + ev.at.substr(8) + "stack": + if ev.kind == "execution": + if f.zone[ev.card] != "hand": + return "played from %s" % f.zone[ev.card] + f.zone[ev.card] = "stack" + "placed": + if f.at[rk.call(ev.ref)] != null: + return "placed, but it stands on %s" % f.at[rk.call(ev.ref)] + f.at[rk.call(ev.ref)] = ev.loc + "moved": + if f.at[rk.call(ev.ref)] != ev.from: + return "moved from %s, but it stands on %s" % [ev.from, f.at[rk.call(ev.ref)]] + f.at[rk.call(ev.ref)] = ev.to + "recalled", "destroyed": + var from = ev.get("from", ev.get("loc")) + if from == null or f.at[rk.call(ev.ref)] != from: + return "left %s, but it stands on %s" % [from, f.at[rk.call(ev.ref)]] + f.at[rk.call(ev.ref)] = null + "flipped": + if f.face[rk.call(ev.ref)]: + return "already face up" + f.face[rk.call(ev.ref)] = true + "damaged": + if ev.amount <= 0 or f.at[rk.call(ev.ref)] == null: + return "bad damage" + f.counters[rk.call(ev.ref)].damage += ev.amount + "counter": + var c: Dictionary = f.counters[rk.call(ev.ref)] + if c[ev.what] != ev.from: + return "%s from %d, but the fold has %d" % [ev.what, ev.from, c[ev.what]] + c[ev.what] = ev.to + "combat": + if f.combats.has(ev.id): + return "combat %d twice" % ev.id + f.combats[ev.id] = ev.loc + "rolled": + if not f.combats.values().has(ev.loc): + return "a roll with no combat there" + "rerolled": + if ev.dice.is_empty() and s.combat == null: + return "a reroll with no combat" + _: + return "unknown kind" + return "" + + +## The state's zone for every card, in the fold's terms. +func _zones(s: Dictionary) -> Dictionary: + var out := {} + for p in 2: + var pl: Dictionary = s.players[p] + for zone in ["hand", "deck", "serverPile", "discard"]: + for id in pl[zone]: + out[id] = zone + for i in pl.anomalies.size(): + var av: Dictionary = pl.anomalies[i] + for hw in av.hardware: + out[hw] = "worn:%d:%d" % [p, i + 1] + if i < 4 and av.card >= 0: + out[av.card] = "slot" + for loc in s.locations: + var L: Dictionary = s.locations[loc] + if L.server != null: + out[L.server] = "play:" + loc + for id in L.programs: + out[id] = "play:" + loc + for item in s.stack: + if item.kind == "execution": + out[item.card] = "stack" + return out + + +func _compare(s: Dictionary) -> String: + var f := _fold + for p in 2: + if f.bandwidth[p] != s.players[p].bandwidth: + return "%s's Bandwidth folds to %d, is %d" % [State.player_name(p), f.bandwidth[p], s.players[p].bandwidth] + for line in GameMap.LINES: + if f.firewalls.get(line.id, 0) != s.firewalls.get(line.id, 0): + return "the Firewall on %s folds to %d, is %d" % [line.id, f.firewalls.get(line.id, 0), s.firewalls.get(line.id, 0)] + for loc in GameMap.LOCATIONS: + if f.owner[loc] != s.locations[loc].owner: + return "%s's owner folds to %s, is %s" % [loc, f.owner[loc], s.locations[loc].owner] + var zones := _zones(s) + for id in f.zone: + if f.zone[id] != zones.get(id, "?"): + return "%s (%d) folds to %s, is in %s" % [s.cards[id].name, id, f.zone[id], zones.get(id, "?")] + for p in 2: + for slot in range(1, 9): + var k := "%d:%d" % [p, slot] + var av: Dictionary = s.players[p].anomalies[slot - 1] + if f.at[k] != av.at: + return "Anomaly %s folds to %s, stands on %s" % [k, f.at[k], av.at] + if slot <= 4 and f.face[k] != av.faceUp: + return "Anomaly %s folds to face %s, is %s" % [k, "up" if f.face[k] else "down", "up" if av.faceUp else "down"] + var want := State.counters_of(av) + if f.counters[k] != want: + return "Anomaly %s's counters fold to %s, are %s" % [k, f.counters[k], want] + if f.turn != s.turn or (not s.over and f.active != s.active): + return "turn folds to %d (%d), is %d (%d)" % [f.turn, f.active, s.turn, s.active] + return "" + + +## Each player's events: the same stream, with the other player's draws hidden. +func _check_views(s: Dictionary) -> String: + for p in 2: + var mine := State.events_for(s, p) + if mine.size() != s.events.size(): + return "events_for(%d) has %d events of %d" % [p, mine.size(), s.events.size()] + for i in mine.size(): + var ev: Dictionary = mine[i] + var real: Dictionary = s.events[i] + if ev.k == "drew" and ev.p != p and ev.card != -1: + return "events_for(%d) shows the other player's draw" % p + if ev.k == "drew" and ev.p == p and ev.card != real.card: + return "events_for(%d) hides its own draw" % p + if not State.events_for(s, p, s.events.size()).is_empty(): + return "events_for from the end isn't empty" + return "" diff --git a/tests/events.gd.uid b/tests/events.gd.uid new file mode 100644 index 0000000..b0c7c4e --- /dev/null +++ b/tests/events.gd.uid @@ -0,0 +1 @@ +uid://dlcfd2ok4i5qh diff --git a/tests/menu_screenshot.gd b/tests/menu_screenshot.gd new file mode 100644 index 0000000..2207d6d --- /dev/null +++ b/tests/menu_screenshot.gd @@ -0,0 +1,37 @@ +extends SceneTree +## Renders the title screen and saves a screenshot. Needs a display (not --headless). +## +## godot --script res://tests/menu_screenshot.gd -- [--setup] [--out PATH] + +var _menu: Node +var _out := "/tmp/files-tcg-menu.png" +var _setup := false +var _frames := 0 + + +func _init() -> void: + var args := OS.get_cmdline_user_args() + var i := 0 + while i < args.size(): + match args[i]: + "--out": + i += 1 + _out = args[i] + "--setup": + _setup = true + i += 1 + DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_NO_FOCUS, true) + if _setup: + SceneRouter.args = {"screen": "setup"} + _menu = load("res://scenes/menu.tscn").instantiate() + _menu.set_process_unhandled_input(false) + root.add_child.call_deferred(_menu) + + +func _process(_delta: float) -> bool: + _frames += 1 + if _frames == 90: + root.get_viewport().get_texture().get_image().save_png(_out) + print("saved %s" % _out) + return true + return false diff --git a/tests/menu_screenshot.gd.uid b/tests/menu_screenshot.gd.uid new file mode 100644 index 0000000..df0f9ce --- /dev/null +++ b/tests/menu_screenshot.gd.uid @@ -0,0 +1 @@ +uid://bjawqnk48u86v diff --git a/tests/present_smoke.gd b/tests/present_smoke.gd new file mode 100644 index 0000000..e9153b8 --- /dev/null +++ b/tests/present_smoke.gd @@ -0,0 +1,109 @@ +extends SceneTree +## Plays whole games through the game scene with the animations on (sped up), so every engine +## event goes through the presenter and the table's motion paths in real frames. The bot runs on +## its thread as in play, and waits for each show to end; your moves are random picks made once +## the show is over. Fails on an engine error or a stuck game. +## +## godot --headless --script res://tests/present_smoke.gd -- [--games N] [--seed N] [--speed X] + +var _game: Node +var _games := 2 +var _seed := 1 +var _speed := 0.08 +var _played := 0 +var _moves := 0 +var _shows := 0 +var _events := 0 +var _rng := RandomNumberGenerator.new() +var _started := 0 +var _idle_frames := 0 +var _failed := false +var _frames := 0 + + +func _init() -> void: + var args := OS.get_cmdline_user_args() + var i := 0 + while i < args.size(): + match args[i]: + "--games": + i += 1 + _games = int(args[i]) + "--seed": + i += 1 + _seed = int(args[i]) + "--speed": + i += 1 + _speed = float(args[i]) + i += 1 + _rng.seed = _seed + _game = load("res://scenes/game.tscn").instantiate() + root.add_child.call_deferred(_game) + _started = Time.get_ticks_msec() + + +func _process(_delta: float) -> bool: + if _game == null or not _game.is_node_ready(): + return false + _frames += 1 + if _frames == 1: + Motion.speed_scale = _speed + _new_game() + return false + var m: LocalMatch = _game.match_ + if not Util.errors.is_empty(): + print("seed %d: engine error: %s" % [m.setup.seed, "; ".join(Util.errors)]) + _failed = true + return _finish() + if m.is_over(): + print("seed %d: %s after %d moves" % [m.setup.seed, Hud.status_line(m.view(), m), m.actions.size()]) + _played += 1 + if _played >= _games: + return _finish() + _new_game() + return false + var presenter: Presenter = _game.presenter + if presenter.busy(): + _idle_frames = 0 + return false + _idle_frames += 1 + if m.human_to_act() and _idle_frames > 1: + _idle_frames = 0 + var before := m.event_count() + _pick(m) + _events += m.event_count() - before + _shows += 1 + elif _idle_frames > 3000: + print("stuck: no move for 3000 frames (bot to act: %s)" % m.bot_to_act()) + _failed = true + return _finish() + return false + + +func _new_game() -> void: + _game.hud.close_modal() + _game.settings.botDelay = 0.0 + _game.start_game({"seed": _seed + _played, "human": _played % 2, "style": "greedy"}) + Util.errors.clear() + + +func _pick(_m: LocalMatch) -> void: + _moves += 1 + var moves: Array = _game.moves + if moves.is_empty(): + return + var others := moves.filter(func(mv): return mv.action.type not in ["end", "pass"]) + var pick: Dictionary + if not others.is_empty() and _rng.randf() < 0.65: + pick = others[_rng.randi() % others.size()] + else: + var stop := moves.filter(func(mv): return mv.action.type in ["end", "pass"]) + pick = stop[0] if not stop.is_empty() else moves[_rng.randi() % moves.size()] + _game._play(pick) + + +func _finish() -> bool: + var secs := (Time.get_ticks_msec() - _started) / 1000.0 + print("present smoke: %d game(s), %d of your moves, %d events shown, %d frames, %.1fs" % [_played, _moves, _events, _frames, secs]) + quit(1 if _failed else 0) + return false diff --git a/tests/present_smoke.gd.uid b/tests/present_smoke.gd.uid new file mode 100644 index 0000000..899d1dd --- /dev/null +++ b/tests/present_smoke.gd.uid @@ -0,0 +1 @@ +uid://bgdqoa1quiiuo diff --git a/tests/screenshot.gd b/tests/screenshot.gd index 4795d96..8d5610e 100644 --- a/tests/screenshot.gd +++ b/tests/screenshot.gd @@ -3,6 +3,13 @@ extends SceneTree ## display (not --headless). ## ## godot --script res://tests/screenshot.gd -- [--seed N] [--moves N] [--out PATH] [--top] [--north] [--select KEY|auto] +## [--focus [N]] [--terminal] [--frames N] [--at SECONDS] [--zoom X] [--combat] +## +## --combat keeps playing past --moves until a combat is under way at one of your decisions. +## --at takes the shot that many seconds after the moves are made instead of at a frame, to catch +## an animation part way (use with --disable-vsync, as a hidden window's frames can be throttled). +## +## --focus opens the hand-focus row, with its Nth card under the mouse; --terminal opens the log. var _game: Node var _seed := 1 @@ -12,6 +19,13 @@ var _top := false var _select := "" var _human := 0 var _frames := 0 +var _shot_at := 70 +var _focus := -2 +var _terminal := false +var _zoom := 1.0 +var _combat := false +var _at := -1.0 +var _dealt_at := 0 var _rng := RandomNumberGenerator.new() @@ -36,6 +50,24 @@ func _init() -> void: "--select": i += 1 _select = args[i] + "--focus": + _focus = -1 + if i + 1 < args.size() and args[i + 1].is_valid_int(): + i += 1 + _focus = int(args[i]) + "--terminal": + _terminal = true + "--frames": + i += 1 + _shot_at = int(args[i]) + "--zoom": + i += 1 + _zoom = float(args[i]) + "--combat": + _combat = true + "--at": + i += 1 + _at = float(args[i]) i += 1 _rng.seed = _seed # Don't take keyboard focus or clicks from whatever you're doing while it renders. @@ -55,7 +87,10 @@ func _process(_delta: float) -> bool: _game.start_game({"seed": _seed, "human": _human, "style": "greedy"}) var m: LocalMatch = _game.match_ var n := 0 - while n < _moves and not m.is_over(): + var in_combat := func() -> bool: + var c = m.combat() + return c != null and not c.done and m.human_to_act() + while (n < _moves or (_combat and not in_combat.call() and n < 4000)) and not m.is_over(): n += 1 if m.bot_to_act(): m.bot_step() @@ -68,8 +103,13 @@ func _process(_delta: float) -> bool: var stop := moves.filter(func(mv): return mv.action.type in ["end", "pass"]) _game._play(stop[0] if not stop.is_empty() else moves[0]) m.run_bot() + _dealt_at = Time.get_ticks_msec() + if _combat: + print("combat under way: %s" % in_combat.call()) if _top: _game.table.toggle_view() + if _zoom != 1.0: + _game.table.zoom(_zoom) if _select == "auto": # The first hand card with a targeted move. for mv in _game.moves: @@ -80,7 +120,15 @@ func _process(_delta: float) -> bool: _game._select(_select) var card := _select.substr(5) if _select.begins_with("hand:") else "" _game._inspect({"key": _select, "card": card}) - if _frames == 70: + if _frames == 4: + if _terminal: + _game.hud.set_drawer(true) + if _focus >= -1: + _game.hud.set_hand_focus(true) + if _frames == 30 and _focus >= 0: + _game.hud._hover_focus(_focus) + var due := _frames == _shot_at if _at < 0 else _frames > 2 and Time.get_ticks_msec() - _dealt_at >= _at * 1000 + if due: var img := root.get_viewport().get_texture().get_image() img.save_png(_out) print("saved %s" % _out) diff --git a/tests/table_smoke.gd b/tests/table_smoke.gd index 9748058..335d9b7 100644 --- a/tests/table_smoke.gd +++ b/tests/table_smoke.gd @@ -23,6 +23,7 @@ var _threaded := false ## The physics frame to wait for before the next check, so the bodies have moved with the cards. var _wait := -1 var _checks := 0 +var _began := false func _init() -> void: @@ -52,7 +53,9 @@ func _init() -> void: func _process(_delta: float) -> bool: if _game == null or not _game.is_node_ready(): return false - if _steps == 0 and _played == 0: + # Once: with --threaded, bot moves don't count as steps, so a step count can't tell. + if not _began: + _began = true _new_game() if Engine.get_physics_frames() < _wait: return false diff --git a/ui-plan.md b/ui-plan.md new file mode 100644 index 0000000..4123918 --- /dev/null +++ b/ui-plan.md @@ -0,0 +1,332 @@ +# UI Plan: Files TCG Interface Redesign + +_Prepared 2026-10-01 from `ui-thoughts.md`, against the Godot project in `files-game/`._ + +Companion document: **`gameplay-plan.md`** (the table look, firewalls, card zoom and animation). +This plan owns the **shared design foundation** that both depend on, so start here. + +## 1. Why + +`godot-plan.md` §10 records M1 (engine), M2 (table slice) and M3 (all Set 1 cards + greedy bot) as +done and conformance-clean — 1,100 traces, 1.68 M steps matching the TypeScript reference exactly. +What is not done is **M4 Presentation** and **M5's start screen**. `ui-thoughts.md` is, almost line +for line, a request to build M5's screens and M4's look, with the art direction now settled. + +The interface was built to prove the rules work, not to be looked at: + +- **Two duplicated colour palettes with the wrong accent.** `Hud.COLORS` (`ui/hud.gd:18-23`) and + `GameTable`'s set (`table/game_table.gd:12-18`) overlap, and the accent is **teal `#2de2c4`** + inherited from the browser app. The printed cards are **cyan `#22d3ee`**. +- **No fonts.** Every string is `SystemFont` DejaVu, built in three separate places. +- **Rounded corners.** `StyleBoxFlat` at `radius 5`; the cards are chamfered octagons. +- **No main menu.** `project.godot` boots straight to `scenes/game.tscn`, which deals a live board + and then opens the "New game" modal on top of it. +- **A busy right column.** Inspector, source menu, and a Log/Combat/Moves `TabContainer` stacked + in 340 px, with the log buried behind whichever tab was last focused. + +**Outcome:** an interface that reads as the same object as the cards — black, chamfered, neon cyan, +terminal-flavoured — with the log out of the way and Bandwidth legible at a glance. + +## 2. The design system already exists + +The print templates in `decks/files-deck-1/*.css` are the authoritative source. They are better +specified than anything we would invent, so this plan reuses them rather than restyling by eye. + +| Token | Value | Role | +| --- | --- | --- | +| `bg` | `#05080a` | screen black | +| `screen` | `#e6fbff` | primary text | +| `secondary` | `#a9d9e0` | secondary text | +| `muted` | `#6f8a90` | labels, microtext | +| `accent` | `#22d3ee` | **system chrome** — frames, buttons, grid, terminal | +| `accent_dk` | `#0e6b78` | dim borders, connectors | + +Per-type accents, for card-kind chips and badges: + +| Server | Hardware | Execution | Program | System | +| --- | --- | --- | --- | --- | +| `#39d353` | `#ffd24a` | `#ffb02e` | `#8b949e` | `#22d3ee` | + +Anomaly classes (the same V/B/G/P the card pool is organised by): + +| Virus | Bug | Glitch | Patch | +| --- | --- | --- | --- | +| `#3fb950` | `#ff5c5c` | `#d264ff` | `#4aa3ff` | + +Owner colours stay **Okabe–Ito** `#56b4e9` (South/you) and `#e69f00` (North/bot) — chosen so +colour-blind players can tell sides apart. Because chrome cyan now sits beside "your" blue, owner +identity gains a **second, non-colour cue**: a stripe fill for South and a dot fill for North, +drawn in `tile.gdshader` (see `gameplay-plan.md` §B2). The browser app used exactly this pattern +pair for the same reason. + +Shared geometry and effects, from the `.neon` rule every card template shares: + +- **Chamfer** 22 px on a 750 px card → **~3 % of the shorter edge**. Scale per widget. +- **Border** 2–3 px solid accent. +- **Glow** `0 0 16px accent, 0 0 6px accent, inset 0 0 18px rgba(0,0,0,0.55)`. +- **Scanlines** `repeating-linear-gradient(0deg, rgba(0,0,0,0.16) 0 2px, transparent 2px 4px)`. +- **Corner ticks** 30 × 3 px accent bars at 45° on the top chamfers. +- **Emphasis chips** filled accent, dark `#05080a` text, glow — never outlined-on-dark. +- **Terminal idiom** `//` section prefixes and a `round@files:` prompt line. +- **Motifs** the CPU-chip badge with pin notches (cost), the gold *edge connector* bus meaning + "hardware plugs in here", and rotated edge microtext. + +### Decisions taken + +| Question | Decision | +| --- | --- | +| Fonts | **Orbitron** (display: logo, menu, headings only) + **JetBrains Mono** (all body/HUD text) | +| Main menu | New `main_scene`, over the same black/grid world as the table | +| Right panel | Log → terminal drawer; Combat → transient centre overlay; Moves stays docked | +| Bandwidth bar | Fixed 0–20 Gb, ticks at 2/4/8, glow past 20, ghost segment for reachable Gb | +| Owner colours | Keep Okabe–Ito; add stripe/dot pattern cue; reserve cyan for chrome | + +## 3. Phase 0 — Shared foundation + +**Both plans style the same widgets with the same tokens. Build this once, first.** It is one new +file plus two mechanical edits, and everything in both documents depends on it. + +### 0.1 `ui/style.gd` — a new `class_name Style` static class + +The project has **zero autoloads** and 33 `class_name` statics, so a static class is the +house-consistent seam. It holds: + +- every token above as `const Color`; +- `Style.display_font()` / `Style.body_font()` returning the vendored `FontFile`s; +- `Style.chamfer_box(accent, fill, width, glow)` → the chamfered StyleBox (0.3); +- `Style.theme()` → the one `Theme`, replacing `Hud._make_theme()`; +- `Style.type_accent(kind)` and `Style.class_accent(type)` for card-kind and V/B/G/P colours. + +This retires **both** palettes: `Hud.COLORS` + `Hud.OWNER_HEX` (`ui/hud.gd:18-23`) and +`GameTable.OWNER_COLORS` / `MARK_COLORS` / `FIREWALL_COLORS` (`table/game_table.gd:12-18`). + +> `GameTable`'s own `CanvasLayer` Controls — tags at `:677`, pop-ups at `:730` — do **not** inherit +> the Hud theme and style themselves inline. A static class is reachable from both. That is the point. + +### 0.2 Fonts + +Vendor Orbitron and JetBrains Mono (both OFL) into `assets/fonts/`. **No font file exists in the +repo today**; all text is `SystemFont` DejaVu in three places — `ui/hud.gd:86-89`, +`GameTable._font` and `GameTable._tag_font` (`table/game_table.gd:75-78`). Route all three through +`Style`. + +Orbitron is **display only** — logo, menu, headings. It is a wide geometric face and will not hold +up in dense readouts. JetBrains Mono carries every HUD string; its metrics are the closest +shippable match to the cards' Consolas, which `godot-plan.md` M4 notes cannot ship. + +### 0.3 The chamfered StyleBox + +`Hud._box()` (`ui/hud.gd:105-115`) is a `StyleBoxFlat` factory using `set_corner_radius_all(5)` +that feeds *every* panel and every button state. `StyleBoxFlat` only does **rounded** corners — +there is no chamfer property — so the card look cannot be reached by configuring it. This is the +one genuinely novel piece of UI engineering in either plan. + +**Use a custom `StyleBox` subclass**: `ui/chamfer_box.gd`, `class_name ChamferBox extends StyleBox`, +overriding `_draw(to_canvas_item: RID, rect: Rect2)` and emitting the octagon through +`RenderingServer.canvas_item_add_polygon()` for the fill plus `canvas_item_add_polyline()` for the +accent border. Why: + +- A `StyleBox` is a `Resource`, so it drops into `Theme.set_stylebox()` and inherits to every + child — no per-node work, and `_box()`'s call sites keep their shape. +- Resolution-independent, and the chamfer is a property, so one class serves panels, buttons, + chips and the drawer at different scales. +- The **glow** is faked in the same `_draw`: emit two or three outward-expanded copies of the + octagon at decreasing alpha before the fill. Per-widget and controllable, unlike the viewport + Environment glow, which would bloom the entire HUD indiscriminately. +- **Corner ticks** are a few extra `canvas_item_add_line()` calls in the same pass. + +Rejected: `StyleBoxTexture` 9-patch needs an authored texture per accent colour (or `modulate` +gymnastics) and its corners do not rescale cleanly; a per-`Control` `ShaderMaterial` bypasses +`Theme` entirely and would need assigning at ~20 sites by hand. + +A `StyleBox` *cannot* carry a shader, so the **scanline overlay** is separate: a `CanvasItem` +`ShaderMaterial` on the terminal drawer and modal panels, layered over the chamfered box. The two +compose — frame from the StyleBox, texture from the shader. + +### 0.4 One panel-geometry source of truth + +The panel reserves are written in four places, and they **already disagree**: + +| Site | Left | Right | +| --- | --- | --- | +| `Hud.LEFT_W` / `RIGHT_W` (`ui/hud.gd:16-17`) — what is actually drawn | 300 | **340** | +| `GameTable.PANEL_LEFT` / `PANEL_RIGHT` (`table/game_table.gd:25-28`) | 300 | **345** | +| `_layout_hand()` (`table/game_table.gd:846-847`) — bare literals, ignores the consts | 300 | **340** | +| `screen_point_for()` (`:872`) and `_fit_camera()` (`:344`) — read `PANEL_*` | 300 | **345** | + +The camera fit and the click-reachability test reserve 345 px while the HUD draws 340 and the hand +lays out against 340: a live 5 px drift, harmless today only because nothing sits in the gap. + +Collapse all four onto one constant on `Style`, read by both `Hud` and `GameTable`, and delete the +literals at `:846-847`. `tests/table_smoke.gd` does **not** hardcode these — it calls +`GameTable.screen_point_for()`, so it inherits whichever number the table uses. That is why a +mismatch here surfaces as *"a legal move is not clickable"* rather than as a layout bug. + +**Every item in both plans moves these numbers** (bigger inspector, log drawer, bandwidth bar, hand +focus). Centralise before touching layout. + +## 4. The work + +### A1. Retheme the HUD + +Swap `Hud._make_theme()` for `Style.theme()` and `_box()` for chamfered boxes; accent moves +**teal `#2de2c4` → cyan `#22d3ee`**. + +Then two cleanup passes that are easy to miss and are exactly what will still look wrong if +skipped: + +- Remove the ~15 `add_theme_*_override` calls that only exist to patch the old theme — + `ui/hud.gd:121, 124, 128, 133, 157, 167, 183, 187, 200-201, 208, 452, 460, 656, 681, 707, 736`. +- Replace the **inline hex strings in BBCode** — `ui/hud.gd:202, 351, 361, 385, 393, 527, 529, + 533, 545, 560, 574, 579, 589, 598` — with `Style`-sourced values. These are string literals + inside `[color=#...]` tags and **silently ignore the theme**. + +### A2. Main menu + +No menu exists. `project.godot` sets `run/main_scene="res://scenes/game.tscn"`, and +`scenes/game.gd:_ready()` deals a live board and *then* opens the "New game" modal over it. There +is also no scene manager anywhere in the project — "New game" re-inits in place. + +Add `scenes/menu.tscn` + `menu.gd` as the new `main_scene`: logo in Orbitron, `START`, `SETTINGS`, +`QUIT`, over the black/grid background from `gameplay-plan.md` §B1 so the menu and the table read +as one world. START leads to the existing `Hud.show_start()` content (seed / side / bot style) as +a proper screen rather than a modal over a live game. + +Leave obvious slots for Deck Builder (M6), Account and Multiplayer (M8). + +This needs the project's **first scene transition** — add a small static `SceneRouter`, consistent +with 0.1, rather than scattering `change_scene_to_file` calls. + +### A3. The terminal log drawer + +`_log` is a `RichTextLabel` at tab 0 of `_tabs` (`ui/hud.gd:215-220`). Rebuild it as a bottom +drawer styled as a CRT console: scanline overlay, `round@files:` prompt line, `//` section +prefixes, monospace, **hidden by default**, toggled by **`` ` ``** and a tab handle, sliding on the +rush-in / hold / rush-out curve from `gameplay-plan.md` §B6. + +Combat and Moves must be handled in the same pass, because all three share that `TabContainer`: + +- **Combat** becomes a transient centre-screen readout during combat staging. Today + `scenes/game.gd:127-130` force-switches to the Combat tab on *every* combat — which is precisely + what would yank the drawer open all game. +- **Moves** stays docked in the right column. You click moves from it, so it cannot be hidden. + +### A4. Simplify the play screen + +With the log in the drawer and the inspector grown (`gameplay-plan.md` §B3), the right column +becomes **inspector → source menu → Moves**. + +The two left player panels (`ui/hud.gd:343-362`) currently carry the Bandwidth readout, a +`■■■□□□` location track, hand/deck/discard/Servers counts, and a row per Anomaly. The Bandwidth +half moves to the playmat bar (A5), so compress what remains into one chamfered status strip per +player. + +Keep the phase strip (`_steps`) and the two action buttons — those are the controls, not decoration. + +### A5. Bandwidth bar on the playmat + +A neon bar on the mat, mirrored small in the HUD. + +Bandwidth is a plain uncapped int (`s.players[p].bandwidth`) and the rules give it **no maximum**: +it carries over between commands and rounds. So the scale is invented — **fixed 0–20 Gb, tick +marks at the Firewall costs 2 / 4 / 8, glowing past 20 instead of clipping.** For grounding: card +costs run 3–9 Gb and players typically sit under 15. + +Behind the fill, a dimmer **ghost segment** shows `Query.reachable_bandwidth(s, p, except)` +(`engine/query.gd:370`) — current Gb plus the salvage value of your hand. That is the number that +answers "can I afford this?", and it is the same one the engine already uses for response windows. + +``` + BANDWIDTH + ████████░░░░░░▒▒▒▒▒▒▒▒░░░░░░░░ + 0 2 4 8 20 + ████ 7 Gb now ▒▒▒▒ 15 Gb reachable (+8 salvage) +``` + +Animating the delta needs the `Bandwidth changed` event from `gameplay-plan.md` §B5. Until that +lands the bar can only snap on `LocalMatch.changed`, which carries no arguments. + +### A6. Salvage on the hovered card + +Salvage has no affordance today. It reaches the UI only as a generic move in the Moves tab, in the +picked-source menu, and in the "Not enough Gb" choice modal (`ui/hud.gd:691-694`). It is also +**deliberately excluded from the glow marks** (`scenes/game.gd:199-201`) because it is *always* +legal — marking it would make every card in hand glow permanently. + +Add a `SALVAGE +N Gb` chip to the enlarged inspector and the hand-focus row, enabled by matching +the hovered `hand:` key against the salvage moves already in the move list. Keeping it +hover-scoped preserves the reason it was excluded from the marks: discoverable without lighting up +the whole hand. + +Rules note: salvage pays the card's **printed** Bandwidth and is legal whenever you must pay a +cost. The chip should read as a payment, not a discard. + +## 5. Order + +``` +0.1 tokens ─▶ 0.2 fonts ─▶ 0.3 chamfer box ─▶ 0.4 panel geometry + │ + ┌──────────────────────┴───────────┐ + ▼ ▼ + A1 ─▶ A3 ─▶ A4 ─▶ A2 gameplay-plan B2/B3 + │ │ + └──▶ A5 ◀── needs B5 ──────┘ + A6 ◀── needs B3 +``` + +1. **Phase 0 first, always.** +2. **A1, A3, A4 as one pass.** They rewrite the same `_build_right` / `_build_left` regions of + `ui/hud.gd`; doing them separately means restyling the right column twice. +3. **A2 after A1**, so the menu inherits the finished theme instead of being restyled later. +4. **A6 after `gameplay-plan.md` §B3** — the chip hangs off the enlarged inspector and hand row. +5. **A5 after §B5** for the animated delta; the static bar can land earlier. + +**Hazards.** Doing A4 or A5 before 0.4 silently breaks `tests/table_smoke.gd`, the camera fit and +the hand layout, in a way that presents as a picking bug rather than a layout one. + +## 6. Verification + +Custom harness — no GUT, no gdUnit4. Each test is a standalone `extends SceneTree` script run via +`--script`, passing on exit code plus `Util.errors` being empty. + +Godot is **not on `PATH`** here. It is 4.7.2 stable at +`/Applications/Godot.app/Contents/MacOS/Godot`, matching the project's 4.7 target. + +```sh +export GODOT=/Applications/Godot.app/Contents/MacOS/Godot +cd /Users/forrestchurch/Trog-Chamber/files-game + +# Run this FIRST — see the note below. +"$GODOT" --headless --import + +# Every legal move still clickable, clear of the redesigned panels. Both aspects. +"$GODOT" --headless --script res://tests/table_smoke.gd -- --games 20 +"$GODOT" --headless --script res://tests/table_smoke.gd -- --games 20 --threaded + +# Look harness — needs a display, so no --headless. +"$GODOT" --script res://tests/screenshot.gd -- --out /tmp/shot.png +"$GODOT" --script res://tests/screenshot.gd -- --top --out /tmp/shot-top.png +``` + +> **Import before testing.** `.godot/` is gitignored and this checkout's `.godot/imported/` holds +> 13 entries with **no entry for `card.glb` or `playmat.glb`**. Unimported, `$Model` resolves to +> `null` and `Card3D._ready()` (`table/card_3d.gd:70`) throws on every card spawned; +> `tests/table_smoke.gd` then reports a meaningless *"35 unreachable move kinds"*, because picking +> needs collision bodies that `_ready()` never added. That number is an artifact, not a +> reachability bug — do not go hunting it. The pass covers 274 card PNGs plus two `.glb`s. +> +> `tests/smoke.gd` is green as of writing: 20/20 games clean in 37 s. + +Compare screenshots against `20261001_171420.png` (the current state) and the card faces in +`files-game/assets/cards/` (the target). Then play a game and confirm: the terminal opens and +closes on `` ` ``, the bandwidth bar tracks captures / salvage / spending, the salvage chip appears +only when legal, and every modal is chamfered and readable. + +**Guardrails.** +- `tests/table_smoke.gd` reaches into `scenes/game.gd` privates (`_play`, `_select`, `_paused`, + `moves`) and `GameTable.screen_point_for`. Restructuring `game.gd` breaks the only automated UI + test — keep those names. +- `scenes/game.gd` must not call `Odds` while the bot thinks; its static caches are unlocked. New + readouts (odds on the bandwidth bar, the combat overlay) must respect this. +- `camelCase` dictionary keys are the TypeScript wire format (`bandwidthFromSalvage`). Renaming any + fails every conformance trace. Do not tidy them. diff --git a/ui/bandwidth_bar.gd b/ui/bandwidth_bar.gd new file mode 100644 index 0000000..78f774f --- /dev/null +++ b/ui/bandwidth_bar.gd @@ -0,0 +1,115 @@ +class_name BandwidthBar +extends Control +## A player's Bandwidth as a neon loading bar (ui-plan.md §A5). Bandwidth has no maximum, so the +## scale is fixed at 0–20 Gb with ticks at the Firewall costs, and the bar glows past 20 instead of +## clipping. Behind the fill, a dimmer ghost runs to what you could reach by salvaging your hand +## (Query.reachable_bandwidth): the number that answers "can I afford this?". + +const MAX_GB := 20 +const CELLS := 20 + +var color := Style.ACCENT: + set(value): + color = value + queue_redraw() +## Tick marks, in Gb: the Firewall costs. +var ticks: Array = [2, 4, 8]: + set(value): + ticks = value + queue_redraw() +## Show the numbers under the ticks. +var show_scale := false: + set(value): + show_scale = value + custom_minimum_size.y = 22.0 if value else 10.0 + queue_redraw() + +## The shown fill, eased toward the real value. +var shown := 0.0: + set(value): + shown = value + queue_redraw() +var gb := 0 +var reachable := 0 +var _tween: Tween +var _pulse := 0.0 + + +func _init() -> void: + custom_minimum_size = Vector2(120, 10) + mouse_filter = Control.MOUSE_FILTER_IGNORE + + +## Shows `value` Gb with the ghost at `reach`. Animates the change on the motion curve. +func set_bandwidth(value: int, reach: int, animate := true) -> void: + reachable = maxi(reach, value) + if value == gb and is_equal_approx(shown, value): + queue_redraw() + return + gb = value + if _tween != null: + _tween.kill() + if not animate or Motion.instant() or not is_inside_tree(): + shown = value + return + _tween = create_tween() + Motion.rush_in(_tween, self, "shown", float(value), 0.55) + + +func _process(delta: float) -> void: + if gb > MAX_GB: + _pulse = fmod(_pulse + delta, 2.0) + queue_redraw() + + +func _draw() -> void: + var bar_h := minf(size.y, 10.0) + var w := size.x + var cell := w / CELLS + var gap := maxf(1.0, cell * 0.14) + var dark := Color(color, 0.1) + var ghost := Color(color, 0.28) + for i in CELLS: + var x := i * cell + var r := Rect2(x + gap / 2.0, 0, cell - gap, bar_h) + var c := dark + if i + 1 <= roundi(shown): + # Brighter toward the head of the fill. + c = color.lerp(Color.WHITE, 0.25 * float(i) / CELLS) + elif i + 1 <= reachable: + c = ghost + draw_rect(r, c) + # A partial cell while the fill moves. + var frac := shown - floorf(shown) + if frac > 0.02 and shown < CELLS: + var i := int(floorf(shown)) + draw_rect(Rect2(i * cell + gap / 2.0, 0, (cell - gap) * frac, bar_h), color) + # The frame and the Firewall-cost ticks. + draw_rect(Rect2(0, -2, w, bar_h + 4), Color(color, 0.45), false, 1.0) + for t in ticks: + if t > 0 and t < MAX_GB: + var x: float = t * cell + draw_line(Vector2(x, -4), Vector2(x, bar_h + 4), Color(Style.SCREEN, 0.7), 1.0) + if show_scale: + _text(str(t), Vector2(x, bar_h + 14)) + if show_scale: + _text("0", Vector2(0, bar_h + 14), HORIZONTAL_ALIGNMENT_LEFT) + _text("20", Vector2(w, bar_h + 14), HORIZONTAL_ALIGNMENT_RIGHT) + # Past the scale: the bar glows instead of clipping. + if gb > MAX_GB: + var k := 0.5 + 0.5 * sin(_pulse * PI) + for g in 3: + var grow := 2.0 + g * 2.0 + draw_rect(Rect2(-grow, -2 - grow, w + grow * 2, bar_h + 4 + grow * 2), Color(color, (0.25 - g * 0.07) * (0.6 + 0.4 * k)), false, 2.0) + + +func _text(t: String, at: Vector2, align := HORIZONTAL_ALIGNMENT_CENTER) -> void: + var f := Style.body_font() + var fs := 10 + var tw := f.get_string_size(t, HORIZONTAL_ALIGNMENT_LEFT, -1, fs).x + var x := at.x - tw / 2.0 + if align == HORIZONTAL_ALIGNMENT_LEFT: + x = at.x + elif align == HORIZONTAL_ALIGNMENT_RIGHT: + x = at.x - tw + draw_string(f, Vector2(x, at.y), t, HORIZONTAL_ALIGNMENT_LEFT, -1, fs, Style.MUTED) diff --git a/ui/bandwidth_bar.gd.uid b/ui/bandwidth_bar.gd.uid new file mode 100644 index 0000000..8e6a17a --- /dev/null +++ b/ui/bandwidth_bar.gd.uid @@ -0,0 +1 @@ +uid://c50u7fnnf6kjs diff --git a/ui/chamfer_box.gd b/ui/chamfer_box.gd new file mode 100644 index 0000000..89c483d --- /dev/null +++ b/ui/chamfer_box.gd @@ -0,0 +1,147 @@ +@tool +class_name ChamferBox +extends StyleBox +## A panel with the cards' chamfered corners (ui-plan.md §0.3): the `.neon` frame of the print +## templates, an octagon with a fill, an accent border, an optional outer glow and the corner ticks +## on the top chamfers. StyleBoxFlat only rounds corners, so this draws the octagon itself. Being a +## StyleBox, it goes in a Theme like any other and serves panels, buttons and chips at any size. + +## Corners to cut, as a bitmask of these. The rest stay square. +const TOP_LEFT := 1 +const TOP_RIGHT := 2 +const BOTTOM_RIGHT := 4 +const BOTTOM_LEFT := 8 +const ALL := 15 + +@export var bg_color := Color(0, 0, 0, 0.8): + set(value): + bg_color = value + emit_changed() +@export var border_color := Color("#22d3ee"): + set(value): + border_color = value + emit_changed() +@export var border_width := 1.5: + set(value): + border_width = value + emit_changed() +## The cut, in pixels. Clamped to half the shorter side. +@export var chamfer := 8.0: + set(value): + chamfer = value + emit_changed() +@export_flags("Top left", "Top right", "Bottom right", "Bottom left") var corners := ALL: + set(value): + corners = value + emit_changed() +## How far the glow reaches past the border, in pixels; 0 for none. It takes the border's color. +@export var glow := 0.0: + set(value): + glow = value + emit_changed() +@export_range(0.0, 1.0) var glow_alpha := 0.35: + set(value): + glow_alpha = value + emit_changed() +## Thick accent bars along the top chamfers, like the cards' corner ticks. +@export var ticks := false: + set(value): + ticks = value + emit_changed() +## A stripe of border color down the left edge, this wide: owner panels and log prompts. +@export var left_bar := 0.0: + set(value): + left_bar = value + emit_changed() + + +func _init(fill := Color(0, 0, 0, 0.8), border := Color("#22d3ee"), width := 1.5, cut := 8.0) -> void: + bg_color = fill + border_color = border + border_width = width + chamfer = cut + set_content_margin_all(8) + content_margin_top = 6 + content_margin_bottom = 6 + + +## The octagon for `r`, clockwise from the top-left corner, cut by `c`. +func _outline(r: Rect2, c: float) -> PackedVector2Array: + c = clampf(c, 0.0, minf(r.size.x, r.size.y) / 2.0) + var x0 := r.position.x + var y0 := r.position.y + var x1 := r.end.x + var y1 := r.end.y + var pts := PackedVector2Array() + if corners & TOP_LEFT and c > 0: + pts.append_array([Vector2(x0, y0 + c), Vector2(x0 + c, y0)]) + else: + pts.append(Vector2(x0, y0)) + if corners & TOP_RIGHT and c > 0: + pts.append_array([Vector2(x1 - c, y0), Vector2(x1, y0 + c)]) + else: + pts.append(Vector2(x1, y0)) + if corners & BOTTOM_RIGHT and c > 0: + pts.append_array([Vector2(x1, y1 - c), Vector2(x1 - c, y1)]) + else: + pts.append(Vector2(x1, y1)) + if corners & BOTTOM_LEFT and c > 0: + pts.append_array([Vector2(x0 + c, y1), Vector2(x0, y1 - c)]) + else: + pts.append(Vector2(x0, y1)) + return pts + + +func _closed(pts: PackedVector2Array) -> PackedVector2Array: + var out := pts.duplicate() + out.append(pts[0]) + return out + + +func _draw(to_canvas_item: RID, rect: Rect2) -> void: + var rs := RenderingServer + if rect.size.x <= 1 or rect.size.y <= 1: + return + # The glow: rings outside the border, fading out. + if glow > 0.0 and border_color.a > 0.0: + var rings := 4 + var step := glow / rings + for i in rings: + var grow := step * (i + 0.5) + var k := 1.0 - float(i) / rings + var c := Color(border_color, border_color.a * glow_alpha * k * k) + var ring := _outline(rect.grow(grow), chamfer + grow * 0.414) + rs.canvas_item_add_polyline(to_canvas_item, _closed(ring), [c], step + 0.5, true) + var pts := _outline(rect, chamfer) + if bg_color.a > 0.0: + rs.canvas_item_add_polygon(to_canvas_item, pts, [bg_color]) + if left_bar > 0.0: + # The panel's own outline cut down to its left edge, so the chamfers cut the bar too. + var strip := PackedVector2Array([rect.position, rect.position + Vector2(left_bar, 0), + rect.position + Vector2(left_bar, rect.size.y), rect.position + Vector2(0, rect.size.y)]) + for bar in Geometry2D.intersect_polygons(pts, strip): + rs.canvas_item_add_polygon(to_canvas_item, bar, [border_color]) + if border_width > 0.0 and border_color.a > 0.0: + var inset := _outline(rect.grow(-border_width / 2.0), maxf(0.0, chamfer - border_width * 0.2)) + rs.canvas_item_add_polyline(to_canvas_item, _closed(inset), [border_color], border_width, true) + if ticks: + var c := clampf(chamfer, 0.0, minf(rect.size.x, rect.size.y) / 2.0) + var w := maxf(2.5, border_width * 2.0) + var tick := Color(border_color, minf(1.0, border_color.a * 1.4)) + if corners & TOP_LEFT: + rs.canvas_item_add_line(to_canvas_item, rect.position + Vector2(0, c), rect.position + Vector2(c, 0), tick, w, true) + if corners & TOP_RIGHT: + var tr := Vector2(rect.end.x, rect.position.y) + rs.canvas_item_add_line(to_canvas_item, tr + Vector2(-c, 0), tr + Vector2(0, c), tick, w, true) + + +func _get_draw_rect(rect: Rect2) -> Rect2: + return rect.grow(glow) + + +## A copy with other colors, for button states and chips. +func tinted(fill: Color, border: Color) -> ChamferBox: + var b: ChamferBox = duplicate() + b.bg_color = fill + b.border_color = border + return b diff --git a/ui/chamfer_box.gd.uid b/ui/chamfer_box.gd.uid new file mode 100644 index 0000000..e42cd6a --- /dev/null +++ b/ui/chamfer_box.gd.uid @@ -0,0 +1 @@ +uid://dqdsxifyvahdc diff --git a/ui/game_settings.gd b/ui/game_settings.gd new file mode 100644 index 0000000..c207484 --- /dev/null +++ b/ui/game_settings.gd @@ -0,0 +1,38 @@ +class_name GameSettings +## The player's settings, kept in user://settings.cfg between runs. The game scene only reads them +## when it's entered from the menu (see SceneRouter), so tests that open it directly always start +## from DEFAULTS. + +const PATH := "user://settings.cfg" +const DEFAULTS := {"stops": "combat", "autoSkip": true, "checkInvariants": false, "botDelay": 0.45, "anim": "normal"} +## Animation speeds: `scale` multiplies every animation's length; 0 is instant. +const ANIM_SPEEDS := { + "slow": {"label": "Slow", "scale": 1.6}, + "normal": {"label": "Normal", "scale": 1.0}, + "fast": {"label": "Fast", "scale": 0.5}, + "instant": {"label": "Instant", "scale": 0.0}, +} + + +static func load_saved() -> Dictionary: + var out := DEFAULTS.duplicate() + var cfg := ConfigFile.new() + if cfg.load(PATH) == OK: + for k in DEFAULTS: + var v = cfg.get_value("game", k, DEFAULTS[k]) + if typeof(v) == typeof(DEFAULTS[k]) or (DEFAULTS[k] is float and v is int): + out[k] = v + if not ANIM_SPEEDS.has(out.anim): + out.anim = DEFAULTS.anim + return out + + +static func save(settings: Dictionary) -> void: + var cfg := ConfigFile.new() + for k in DEFAULTS: + cfg.set_value("game", k, settings.get(k, DEFAULTS[k])) + cfg.save(PATH) + + +static func anim_scale(settings: Dictionary) -> float: + return ANIM_SPEEDS.get(settings.get("anim", "normal"), ANIM_SPEEDS.normal).scale diff --git a/ui/game_settings.gd.uid b/ui/game_settings.gd.uid new file mode 100644 index 0000000..92ee910 --- /dev/null +++ b/ui/game_settings.gd.uid @@ -0,0 +1 @@ +uid://b5g0pdocs00y0 diff --git a/ui/hud.gd b/ui/hud.gd index 450460c..b045e72 100644 --- a/ui/hud.gd +++ b/ui/hud.gd @@ -1,9 +1,10 @@ class_name Hud extends CanvasLayer -## The 2D layer over the table (godot-plan.md §4, "Anything with text is 2D"): the status bar, -## player panels, the action bar, prompts and menus, the card inspector, and the log, combat and -## move panels. It draws what Game hands it in refresh() and reports clicks as signals; it never -## builds an action. +## The 2D layer over the table (godot-plan.md §4, "Anything with text is 2D"): the status bar, a +## status strip per player, the action panel, the card inspector, the source menu and move list, +## the terminal log drawer, the combat readout, the hand-focus row and the dialogs. It draws what +## Game hands it in refresh() and reports clicks as signals; it never builds an action. Its look +## comes from Style (ui-plan.md §2–3). signal move_chosen(move: Dictionary) signal source_picked(key: String) @@ -12,15 +13,13 @@ signal end_command_pressed signal view_toggled signal new_game_requested(opts: Dictionary) signal settings_changed(settings: Dictionary) +## Back to the menu: "" for the title screen, "setup" for the new-game screen. +signal menu_requested(screen: String) +## The hand-focus row: the card under the mouse ({key, card}, or {} for none), and a click on one. +signal hand_hovered(info: Dictionary) +signal hand_picked(key: String, at: Vector2) +signal hand_focus_changed(open: bool) -const LEFT_W := 300 -const RIGHT_W := 340 -const COLORS := { - "bg": Color("#06090dE6"), "panel": Color("#0c1218EE"), "panel2": Color("#111a22"), "line": Color("#1e2a36"), - "text": Color("#d7dee6"), "muted": Color("#7d8a97"), "accent": Color("#2de2c4"), "warn": Color("#ffb454"), - "bad": Color("#ff6b6b"), "attack": Color("#ff5c7a"), -} -const OWNER_HEX: Array[String] = ["#56b4e9", "#e69f00"] const STEPS := [["deploy", "Deploy"], ["play", "Play"], ["attack", "Attack"], ["playAgain", "Play again"]] const STAT_LABELS := { "capturesUnowned": "Open locations captured", "capturesUndefended": "Undefended enemy locations captured", @@ -31,25 +30,37 @@ const STAT_LABELS := { "hardwareInstalled": "Hardware installed", "programsInstalled": "Programs installed", "executionsPlayed": "Executions played", "abilitiesUsed": "Abilities used", } +## The terminal drawer's height, at the base size. +const DRAWER_H := 290.0 +## Seconds the combat readout stays after a combat ends and its show has played out. +const COMBAT_LINGER := 2.5 +## Cards in the hand-focus row at the base size, and how much the one under the mouse grows. +const FOCUS_CARD := Vector2(192, 269) +const FOCUS_GROW := 1.5 +## Pixels from the bottom edge that open the hand-focus row. +const FOCUS_EDGE := 6.0 var theme: Theme var _root: Control var _status: Label var _stack: Label +## One per row of the left column, the opponent's first: {panel, box, title, side, turn, bar, gb, body, badge}. +var _strips: Array = [] var _banner_text: RichTextLabel -var _panels: Array[RichTextLabel] = [] -var _steps: Label +var _steps: RichTextLabel var _primary: Button var _end_command: Button +var _right: VBoxContainer var _source_menu: PanelContainer var _source_box: VBoxContainer var _popover: PanelContainer var _popover_box: VBoxContainer var _inspector_art: TextureRect +var _inspector_blank: Control +var _inspector_kind: PanelContainer var _inspector_text: RichTextLabel -var _tabs: TabContainer -var _log: RichTextLabel -var _combat: RichTextLabel +var _salvage_row: HBoxContainer +var _inspect_key := "" var _moves_box: VBoxContainer var _modal: Control var _modal_box: VBoxContainer @@ -57,12 +68,47 @@ var _log_count := -1 var _moves_version := -1 var _primary_move := {} var _art_cache := {} -var _settings := {"stops": "combat", "autoSkip": true, "checkInvariants": false, "botDelay": 0.45} +var _settings := GameSettings.DEFAULTS.duplicate() +var _ctx := {} + +# The terminal drawer. +var _drawer: Control +var _drawer_handle: Button +var _drawer_open := false +var _drawer_tween: Tween +var _log: RichTextLabel +var _prompt: Label +var _unread := 0 + +# The combat readout. +var _combat_panel: PanelContainer +var _combat: RichTextLabel +var _combat_id := -1 +## When the readout starts counting down to going away: the end of the show of the combat's end. +var _combat_done_at := -1.0 +## Whether the readout is up or on its way up (false: gone or fading out). +var _combat_shown := false +var _combat_tween: Tween + +# The turn banner. +var _banner: PanelContainer +var _banner_title: Label +var _banner_sub: Label +var _banner_tween: Tween + +# The hand-focus row. +var _focus: Control +var _focus_shade: TextureRect +var _focus_open := false +var _focus_by_edge := false +var _focus_cards: Array = [] +var _focus_hover := -1 +var _focus_sig := "" func _ready() -> void: layer = 1 - theme = _make_theme() + theme = Style.theme() _root = Control.new() _root.theme = theme _root.set_anchors_preset(Control.PRESET_FULL_RECT) @@ -71,204 +117,505 @@ func _ready() -> void: _build_top() _build_left() _build_right() + _build_combat() + _build_banner() + _build_focus() + _build_drawer() _build_center() _modal = Control.new() _modal.set_anchors_preset(Control.PRESET_FULL_RECT) _modal.visible = false _root.add_child(_modal) + get_viewport().size_changed.connect(_fit_layout) + _fit_layout() # --------------------------------------------------------------------------------------------- # Building -func _make_theme() -> Theme: - var t := Theme.new() - var font := SystemFont.new() - font.font_names = PackedStringArray(["DejaVu Sans Mono", "Adwaita Mono", "monospace"]) - t.default_font = font - t.default_font_size = 14 - t.set_color("font_color", "Label", COLORS.text) - t.set_color("default_color", "RichTextLabel", COLORS.text) - var panel := _box(COLORS.panel, COLORS.line) - t.set_stylebox("panel", "PanelContainer", panel) - t.set_stylebox("normal", "Button", _box(COLORS.panel2, COLORS.line)) - t.set_stylebox("hover", "Button", _box(Color("#16222c"), COLORS.accent)) - t.set_stylebox("pressed", "Button", _box(Color("#0f2a2a"), COLORS.accent)) - t.set_stylebox("disabled", "Button", _box(Color("#0a0f14"), Color("#141c24"))) - t.set_stylebox("focus", "Button", StyleBoxEmpty.new()) - t.set_color("font_color", "Button", COLORS.text) - t.set_color("font_hover_color", "Button", Color.WHITE) - t.set_color("font_disabled_color", "Button", Color("#3c4652")) - return t - - -static func _box(bg: Color, border: Color, radius := 5) -> StyleBoxFlat: - var b := StyleBoxFlat.new() - b.bg_color = bg - b.border_color = border - b.set_border_width_all(1) - b.set_corner_radius_all(radius) - b.content_margin_left = 9 - b.content_margin_right = 9 - b.content_margin_top = 6 - b.content_margin_bottom = 6 - return b - - func _build_top() -> void: var bar := PanelContainer.new() bar.set_anchors_preset(Control.PRESET_TOP_WIDE) - bar.add_theme_stylebox_override("panel", _box(COLORS.bg, COLORS.line, 0)) + bar.offset_left = Style.MARGIN + bar.offset_right = -Style.MARGIN + bar.offset_top = 4 + var box := Style.chamfer_box(Style.ACCENT_DK, Style.PANEL, 1.0, 0.0, 10.0) + box.content_margin_top = 4 + box.content_margin_bottom = 4 + box.corners = ChamferBox.BOTTOM_LEFT | ChamferBox.BOTTOM_RIGHT + bar.add_theme_stylebox_override("panel", box) _root.add_child(bar) var row := HBoxContainer.new() row.add_theme_constant_override("separation", 14) bar.add_child(row) - var brand := Label.new() - brand.text = "FILES TCG" - brand.add_theme_color_override("font_color", COLORS.accent) + var brand := RichTextLabel.new() + brand.bbcode_enabled = true + brand.fit_content = true + brand.autowrap_mode = TextServer.AUTOWRAP_OFF + brand.scroll_active = false + brand.mouse_filter = Control.MOUSE_FILTER_IGNORE + brand.add_theme_font_override("normal_font", Style.display_font(800)) + brand.add_theme_font_size_override("normal_font_size", 16) + brand.text = "[color=%s]FILES[/color][color=%s]//[/color][color=%s]TCG[/color]" % [ + Style.hex(Style.ACCENT), Style.hex(Style.ACCENT_DK), Style.hex(Style.SCREEN)] + brand.custom_minimum_size = Vector2(118, 0) + brand.size_flags_vertical = Control.SIZE_SHRINK_CENTER row.add_child(brand) _status = Label.new() + _status.add_theme_color_override("font_color", Style.SECONDARY) + _status.add_theme_font_size_override("font_size", 13) + _status.size_flags_vertical = Control.SIZE_SHRINK_CENTER row.add_child(_status) _stack = Label.new() - _stack.add_theme_color_override("font_color", COLORS.warn) + _stack.add_theme_color_override("font_color", Style.WARN) + _stack.add_theme_font_size_override("font_size", 13) _stack.size_flags_horizontal = Control.SIZE_EXPAND_FILL + _stack.size_flags_vertical = Control.SIZE_SHRINK_CENTER _stack.clip_text = true row.add_child(_stack) - row.add_child(_button("Top view T", func(): view_toggled.emit())) - row.add_child(_button("Settings", show_settings)) - row.add_child(_button("New game", func(): show_start({}))) + for spec in [["TOP VIEW T", func(): view_toggled.emit()], ["TERMINAL `", toggle_drawer], + ["SETTINGS", show_settings], ["MENU", _confirm_menu]]: + var b := Widgets.button(spec[0], spec[1]) + b.add_theme_font_size_override("font_size", 12) + row.add_child(b) func _build_left() -> void: var col := VBoxContainer.new() - col.position = Vector2(8, 44) - col.custom_minimum_size = Vector2(LEFT_W - 16, 0) + col.position = Vector2(Style.MARGIN, Style.PANEL_TOP + 6) + col.custom_minimum_size = Vector2(Style.PANEL_LEFT - 2 * Style.MARGIN, 0) col.add_theme_constant_override("separation", 8) _root.add_child(col) for i in 2: - var pc := PanelContainer.new() - var rt := _rich() - rt.custom_minimum_size = Vector2(LEFT_W - 34, 0) - pc.add_child(rt) - col.add_child(pc) - _panels.append(rt) + col.add_child(_make_strip()) var actions := PanelContainer.new() + var abox := Style.chamfer_box(Style.ACCENT, Style.PANEL, 1.5, 0.0, 10.0) + abox.ticks = true + abox.set_content_margin_all(10) + actions.add_theme_stylebox_override("panel", abox) var box := VBoxContainer.new() - box.add_theme_constant_override("separation", 6) + box.add_theme_constant_override("separation", 8) actions.add_child(box) - _banner_text = _rich() - _banner_text.custom_minimum_size = Vector2(LEFT_W - 34, 0) + _banner_text = Widgets.rich() + _banner_text.custom_minimum_size = Vector2(Style.PANEL_LEFT - 2 * Style.MARGIN - 22, 0) box.add_child(_banner_text) - _steps = Label.new() - _steps.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + _steps = Widgets.rich() + _steps.add_theme_font_size_override("normal_font_size", 11) + _steps.add_theme_font_size_override("bold_font_size", 11) box.add_child(_steps) - _primary = _button("", func(): if not _primary_move.is_empty(): move_chosen.emit(_primary_move)) - _primary.custom_minimum_size = Vector2(0, 38) - _primary.add_theme_color_override("font_color", COLORS.accent) + _primary = Widgets.button("", func(): if not _primary_move.is_empty(): move_chosen.emit(_primary_move), "PrimaryButton") + _primary.custom_minimum_size = Vector2(0, 40) box.add_child(_primary) - _end_command = _button("End command Enter", func(): end_command_pressed.emit()) + _end_command = Widgets.button("End command Enter", func(): end_command_pressed.emit()) box.add_child(_end_command) col.add_child(actions) +## A player's status strip: name, the Bandwidth bar, the location track, counts and Anomalies. +func _make_strip() -> PanelContainer: + var pc := PanelContainer.new() + var sb := Style.chamfer_box(Style.ACCENT_DK, Style.PANEL, 1.0, 0.0, 9.0) + sb.left_bar = 3.0 + sb.content_margin_left = 12 + pc.add_theme_stylebox_override("panel", sb) + var v := VBoxContainer.new() + v.add_theme_constant_override("separation", 3) + pc.add_child(v) + var head := HBoxContainer.new() + head.add_theme_constant_override("separation", 7) + v.add_child(head) + var badge_slot := CenterContainer.new() + head.add_child(badge_slot) + var title := Label.new() + title.add_theme_font_override("font", Style.display_font(700)) + title.add_theme_font_size_override("font_size", 13) + head.add_child(title) + var side := Label.new() + side.theme_type_variation = "Micro" + side.size_flags_horizontal = Control.SIZE_EXPAND_FILL + head.add_child(side) + var turn := Label.new() + turn.add_theme_font_override("font", Style.body_font(800)) + turn.add_theme_font_size_override("font_size", 11) + head.add_child(turn) + var gb_row := HBoxContainer.new() + gb_row.add_theme_constant_override("separation", 8) + v.add_child(gb_row) + var bar := BandwidthBar.new() + bar.size_flags_horizontal = Control.SIZE_EXPAND_FILL + bar.size_flags_vertical = Control.SIZE_SHRINK_CENTER + gb_row.add_child(bar) + var gb := RichTextLabel.new() + gb.bbcode_enabled = true + gb.fit_content = true + gb.scroll_active = false + gb.autowrap_mode = TextServer.AUTOWRAP_OFF + gb.custom_minimum_size = Vector2(78, 0) + gb.mouse_filter = Control.MOUSE_FILTER_IGNORE + gb_row.add_child(gb) + var body := Widgets.rich() + body.add_theme_font_size_override("normal_font_size", 12) + body.add_theme_font_size_override("bold_font_size", 12) + body.custom_minimum_size = Vector2(Style.PANEL_LEFT - 2 * Style.MARGIN - 26, 0) + v.add_child(body) + _strips.append({"panel": pc, "box": sb, "title": title, "side": side, "turn": turn, "bar": bar, "gb": gb, + "body": body, "badge_slot": badge_slot, "badge_for": -1}) + return pc + + func _build_right() -> void: - var col := VBoxContainer.new() - col.anchor_left = 1.0 - col.anchor_right = 1.0 - col.anchor_bottom = 1.0 - col.offset_left = -RIGHT_W + 8 - col.offset_right = -8 - col.offset_top = 44 - col.offset_bottom = -8 - col.add_theme_constant_override("separation", 8) - _root.add_child(col) + _right = VBoxContainer.new() + _right.anchor_left = 1.0 + _right.anchor_right = 1.0 + _right.anchor_bottom = 1.0 + _right.offset_left = -Style.PANEL_RIGHT + Style.MARGIN + _right.offset_right = -Style.MARGIN + _right.offset_top = Style.PANEL_TOP + 6 + _right.offset_bottom = -Style.MARGIN + _right.add_theme_constant_override("separation", 8) + _root.add_child(_right) + + # The inspector: the card large, then what it is and what it's doing. var insp := PanelContainer.new() - var ib := HBoxContainer.new() - ib.add_theme_constant_override("separation", 8) - insp.add_child(ib) + var ibox := Style.chamfer_box(Style.ACCENT_DK, Style.PANEL, 1.0, 0.0, 12.0) + ibox.ticks = true + ibox.set_content_margin_all(10) + insp.add_theme_stylebox_override("panel", ibox) + _right.add_child(insp) + var iv := VBoxContainer.new() + iv.add_theme_constant_override("separation", 6) + insp.add_child(iv) + var head := HBoxContainer.new() + iv.add_child(head) + var lbl := Widgets.label("// INSPECT", "Micro") + lbl.size_flags_horizontal = Control.SIZE_EXPAND_FILL + head.add_child(lbl) + _inspector_kind = Widgets.chip("") + _inspector_kind.visible = false + head.add_child(_inspector_kind) + var art_slot := Control.new() + art_slot.size_flags_horizontal = Control.SIZE_EXPAND_FILL + iv.add_child(art_slot) _inspector_art = TextureRect.new() - _inspector_art.custom_minimum_size = Vector2(150, 210) + _inspector_art.set_anchors_preset(Control.PRESET_FULL_RECT) _inspector_art.expand_mode = TextureRect.EXPAND_IGNORE_SIZE _inspector_art.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED _inspector_art.visible = false - ib.add_child(_inspector_art) - _inspector_text = _rich() - _inspector_text.size_flags_horizontal = Control.SIZE_EXPAND_FILL - _inspector_text.custom_minimum_size = Vector2(0, 210) + art_slot.add_child(_inspector_art) + _inspector_blank = Control.new() + _inspector_blank.set_anchors_preset(Control.PRESET_FULL_RECT) + _inspector_blank.draw.connect(_draw_blank_card) + art_slot.add_child(_inspector_blank) + _salvage_row = HBoxContainer.new() + _salvage_row.alignment = BoxContainer.ALIGNMENT_CENTER + _salvage_row.visible = false + iv.add_child(_salvage_row) + _inspector_text = Widgets.rich() _inspector_text.fit_content = false _inspector_text.scroll_active = true + _inspector_text.custom_minimum_size = Vector2(0, 118) _inspector_text.add_theme_font_size_override("normal_font_size", 12) _inspector_text.add_theme_font_size_override("bold_font_size", 13) - _inspector_text.text = "[color=#7d8a97]Point at a card, an Anomaly, a location or a gateway for its details.[/color]" - ib.add_child(_inspector_text) - col.add_child(insp) - # The picked source's moves, or your responses, between the inspector and the tabs. + _inspector_text.text = _muted_bb("Point at a card, an Anomaly, a location or a gateway for its details. Tab opens your hand.") + iv.add_child(_inspector_text) + + # The picked source's moves, or your responses, between the inspector and the move list. _source_menu = PanelContainer.new() _source_menu.visible = false - _source_menu.add_theme_stylebox_override("panel", _box(Color("#0d1a1c"), COLORS.accent)) - col.add_child(_source_menu) + var sbox := Style.chamfer_box(Style.ACCENT, Color("#04161af0"), 1.5, 8.0, 9.0) + sbox.set_content_margin_all(9) + _source_menu.add_theme_stylebox_override("panel", sbox) + _right.add_child(_source_menu) _source_box = VBoxContainer.new() + _source_box.add_theme_constant_override("separation", 5) _source_menu.add_child(_source_box) - _tabs = TabContainer.new() - _tabs.size_flags_vertical = Control.SIZE_EXPAND_FILL - col.add_child(_tabs) - _log = _rich() - _log.name = "Log" + + # Every move, grouped: you can click any from here. + var moves := PanelContainer.new() + moves.size_flags_vertical = Control.SIZE_EXPAND_FILL + var mbox := Style.chamfer_box(Style.ACCENT_DK, Style.PANEL, 1.0, 0.0, 10.0) + mbox.set_content_margin_all(9) + moves.add_theme_stylebox_override("panel", mbox) + _right.add_child(moves) + var mv := VBoxContainer.new() + mv.add_theme_constant_override("separation", 4) + moves.add_child(mv) + mv.add_child(Widgets.label("// MOVES", "Micro")) + var scroll := ScrollContainer.new() + scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL + scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED + mv.add_child(scroll) + _moves_box = VBoxContainer.new() + _moves_box.size_flags_horizontal = Control.SIZE_EXPAND_FILL + _moves_box.add_theme_constant_override("separation", 4) + scroll.add_child(_moves_box) + + +## An empty card outline where the art goes, for things that aren't cards. +func _draw_blank_card() -> void: + var c := _inspector_blank + var h := c.size.y + var w := minf(c.size.x, h * 750.0 / 1050.0) + var r := Rect2((c.size.x - w) / 2.0, 0, w, h) + var box := Style.chamfer_box(Color(Style.ACCENT_DK, 0.6), Color(Style.ACCENT, 0.03), 1.0, 0.0, w * Style.CHAMFER_RATIO) + box.draw(c.get_canvas_item(), r) + var f := Style.body_font() + var t := "// NO CARD" + var tw := f.get_string_size(t, HORIZONTAL_ALIGNMENT_LEFT, -1, 11).x + c.draw_string(f, r.get_center() + Vector2(-tw / 2.0, 4), t, HORIZONTAL_ALIGNMENT_LEFT, -1, 11, Color(Style.MUTED, 0.7)) + + +## The combat readout: a transient panel over the top of the table while a combat runs. +func _build_combat() -> void: + _combat_panel = PanelContainer.new() + _combat_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE + var box := Style.chamfer_box(Style.ATTACK, Color("#0a0306e8"), 1.5, 12.0, 12.0) + box.ticks = true + box.set_content_margin_all(11) + _combat_panel.add_theme_stylebox_override("panel", box) + _combat_panel.visible = false + _root.add_child(_combat_panel) + _combat = Widgets.rich() + _combat.mouse_filter = Control.MOUSE_FILTER_IGNORE + _combat.add_theme_font_size_override("normal_font_size", 12) + _combat.add_theme_font_size_override("bold_font_size", 13) + _combat_panel.add_child(_combat) + + +## The banner that sweeps across the table when a command starts. +func _build_banner() -> void: + _banner = PanelContainer.new() + _banner.mouse_filter = Control.MOUSE_FILTER_IGNORE + _banner.visible = false + var box := Style.chamfer_box(Style.ACCENT, Color(Style.BG, 0.86), 1.5, 14.0, 14.0) + box.ticks = true + box.content_margin_left = 36 + box.content_margin_right = 36 + box.content_margin_top = 10 + box.content_margin_bottom = 12 + _banner.add_theme_stylebox_override("panel", box) + _root.add_child(_banner) + var v := VBoxContainer.new() + v.alignment = BoxContainer.ALIGNMENT_CENTER + v.add_theme_constant_override("separation", 2) + _banner.add_child(v) + _banner_sub = Widgets.label("", "Micro") + _banner_sub.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + v.add_child(_banner_sub) + _banner_title = Widgets.heading("") + _banner_title.add_theme_font_size_override("font_size", 26) + _banner_title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + v.add_child(_banner_title) + + +## Sweeps `title` across the table on the motion curve: it rushes in, drifts while you read it, +## and rushes out. After `delay` seconds. +func banner(title: String, sub: String, color: Color, delay := 0.0) -> void: + if Motion.instant(): + return + if _banner_tween != null: + _banner_tween.kill() + _banner_title.text = title + _banner_sub.text = sub + _banner_title.add_theme_color_override("font_color", color) + var box: ChamferBox = _banner.get_theme_stylebox("panel") + box.border_color = color + _banner.reset_size() + var vp := _root.get_viewport_rect().size + var region := Style.table_region(vp) + var y := region.position.y + region.size.y * 0.36 - _banner.size.y / 2.0 + var mid := region.position.x + (region.size.x - _banner.size.x) / 2.0 + _banner.position = Vector2(mid - 260, y) + _banner.modulate.a = 0.0 + _banner_tween = create_tween() + if delay > 0.0: + _banner_tween.tween_interval(Motion.secs(delay)) + _banner_tween.tween_callback(func(): _banner.visible = true) + _banner_tween.set_parallel() + Motion.rush_in(_banner_tween, _banner, "position:x", mid - 12, 0.26) + Motion.rush_in(_banner_tween, _banner, "modulate:a", 1.0, 0.2) + _banner_tween.set_parallel(false) + Motion.drift(_banner_tween, _banner, "position:x", mid + 12, 0.55) + _banner_tween.set_parallel() + Motion.rush_out(_banner_tween, _banner, "position:x", mid + 340, 0.22) + Motion.rush_out(_banner_tween, _banner, "modulate:a", 0.0, 0.22) + _banner_tween.set_parallel(false) + _banner_tween.tween_callback(func(): _banner.visible = false) + + +func finish_banner() -> void: + if _banner_tween != null: + _banner_tween.kill() + _banner.visible = false + # A skipped show is over now, so a finished combat's readout counts down from here. + var now := Time.get_ticks_msec() / 1000.0 + if _combat_done_at > now: + _combat_done_at = now + + +## "+4 Gb" rising off player `p`'s Bandwidth readout, after `delay` seconds. +func pulse_bandwidth(p: int, delta: int, delay := 0.0) -> void: + if Motion.instant() or _ctx.is_empty(): + return + var st: Dictionary = _strips[1] if p == _ctx.match.human else _strips[0] + var gb: Control = st.gb + var l := Label.new() + l.text = "%+d Gb" % delta + l.mouse_filter = Control.MOUSE_FILTER_IGNORE + l.add_theme_font_override("font", Style.body_font(800)) + l.add_theme_font_size_override("font_size", 14) + l.add_theme_color_override("font_color", Style.OWNER[p].lightened(0.3) if delta > 0 else Style.BAD) + l.add_theme_color_override("font_outline_color", Style.BG) + l.add_theme_constant_override("outline_size", 5) + l.modulate.a = 0.0 + _root.add_child(l) + # Placed when it starts, over the readout, so the strip's layout is settled by then. + var y := [0.0] + var tw := l.create_tween() + if delay > 0.0: + tw.tween_interval(Motion.secs(delay)) + tw.tween_callback(func(): + l.reset_size() + var r := gb.get_global_rect() + l.position = Vector2(r.position.x + (r.size.x - l.size.x) / 2.0, r.position.y - 4) + y[0] = l.position.y) + tw.set_parallel() + Motion.rush_in(tw, l, "modulate:a", 1.0, 0.12) + tw.tween_method(func(k): l.position.y = y[0] - 14.0 * k, 0.0, 1.0, Motion.secs(0.25)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_OUT) + tw.set_parallel(false) + tw.tween_method(func(k): l.position.y = y[0] - 14.0 - 6.0 * k, 0.0, 1.0, Motion.secs(0.45)) + tw.set_parallel() + Motion.rush_out(tw, l, "modulate:a", 0.0, 0.2) + tw.tween_method(func(k): l.position.y = y[0] - 20.0 - 10.0 * k, 0.0, 1.0, Motion.secs(0.2)).set_trans(Tween.TRANS_EXPO).set_ease(Tween.EASE_IN) + tw.set_parallel(false) + tw.tween_callback(l.queue_free) + + +## The hand-focus row (gameplay-plan.md §B3): your hand as large 2D cards over the bottom of the +## table. Tab, or the mouse at the bottom edge, opens it. +func _build_focus() -> void: + _focus = Control.new() + _focus.set_anchors_preset(Control.PRESET_FULL_RECT) + _focus.mouse_filter = Control.MOUSE_FILTER_IGNORE + _focus.visible = false + _root.add_child(_focus) + _focus_shade = TextureRect.new() + _focus_shade.mouse_filter = Control.MOUSE_FILTER_IGNORE + var grad := Gradient.new() + grad.set_color(0, Color(Style.BG, 0.0)) + grad.set_color(1, Color(Style.BG, 0.92)) + grad.add_point(0.35, Color(Style.BG, 0.55)) + var gt := GradientTexture2D.new() + gt.gradient = grad + gt.fill_from = Vector2(0, 0) + gt.fill_to = Vector2(0, 1) + gt.width = 4 + gt.height = 128 + _focus_shade.texture = gt + _focus_shade.expand_mode = TextureRect.EXPAND_IGNORE_SIZE + _focus_shade.stretch_mode = TextureRect.STRETCH_SCALE + _focus.add_child(_focus_shade) + + +## The terminal: the log as a CRT console in a drawer at the bottom, hidden until ` or its handle. +func _build_drawer() -> void: + _drawer = Control.new() + _drawer.mouse_filter = Control.MOUSE_FILTER_IGNORE + _drawer.anchor_top = 1.0 + _drawer.anchor_bottom = 1.0 + _drawer.anchor_right = 1.0 + _root.add_child(_drawer) + _drawer_handle = Widgets.button("▴ // TERMINAL `", toggle_drawer) + _drawer_handle.add_theme_font_size_override("font_size", 11) + var hb := Style.chamfer_box(Style.ACCENT_DK, Style.PANEL, 1.0, 0.0, 7.0) + hb.corners = ChamferBox.TOP_LEFT | ChamferBox.TOP_RIGHT + hb.content_margin_left = 12 + hb.content_margin_right = 12 + hb.content_margin_top = 3 + hb.content_margin_bottom = 3 + _drawer_handle.add_theme_stylebox_override("normal", hb) + _drawer_handle.add_theme_stylebox_override("hover", hb.tinted(Color("#0c2730f0"), Style.ACCENT)) + _drawer_handle.add_theme_stylebox_override("pressed", hb.tinted(Color(Style.ACCENT, 0.3), Style.ACCENT)) + # The handle stays in the bottom-left corner, under the left column, open or shut. + _drawer_handle.anchor_top = 1.0 + _drawer_handle.anchor_bottom = 1.0 + _drawer_handle.offset_left = Style.MARGIN + _drawer_handle.offset_top = -26 + _root.add_child(_drawer_handle) + var panel := PanelContainer.new() + panel.name = "Screen" + var box := Style.chamfer_box(Style.ACCENT, Color("#020809f4"), 1.5, 10.0, 12.0) + box.corners = ChamferBox.TOP_LEFT | ChamferBox.TOP_RIGHT + box.ticks = true + box.set_content_margin_all(12) + panel.add_theme_stylebox_override("panel", box) + _drawer.add_child(panel) + var v := VBoxContainer.new() + v.add_theme_constant_override("separation", 4) + panel.add_child(v) + var head := RichTextLabel.new() + head.bbcode_enabled = true + head.fit_content = true + head.scroll_active = false + head.mouse_filter = Control.MOUSE_FILTER_IGNORE + head.add_theme_font_size_override("normal_font_size", 12) + head.text = "[color=%s]round@files:~$[/color] [color=%s]tail -f /var/log/match.log[/color]" % [Style.hex(Style.ACCENT), Style.hex(Style.SECONDARY)] + v.add_child(head) + _log = Widgets.rich() _log.fit_content = false _log.scroll_following = true _log.scroll_active = true - _tabs.add_child(_log) - _combat = _rich() - _combat.name = "Combat" - _combat.fit_content = false - _combat.scroll_active = true - _tabs.add_child(_combat) - var scroll := ScrollContainer.new() - scroll.name = "Moves" - scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED - _moves_box = VBoxContainer.new() - _moves_box.size_flags_horizontal = Control.SIZE_EXPAND_FILL - scroll.add_child(_moves_box) - _tabs.add_child(scroll) + _log.size_flags_vertical = Control.SIZE_EXPAND_FILL + _log.add_theme_font_size_override("normal_font_size", 12) + _log.add_theme_font_size_override("bold_font_size", 12) + v.add_child(_log) + _prompt = Label.new() + _prompt.add_theme_color_override("font_color", Style.ACCENT) + _prompt.add_theme_font_size_override("font_size", 12) + _prompt.text = "round@files:~$ ▌" + v.add_child(_prompt) + panel.add_child(Widgets.scanlines(0.18)) + var blink := create_tween().set_loops() + blink.tween_property(_prompt, "modulate:a", 0.35, 0.5) + blink.tween_property(_prompt, "modulate:a", 1.0, 0.5) func _build_center() -> void: _popover = PanelContainer.new() _popover.visible = false + var box := Style.chamfer_box(Style.ACCENT, Color("#05080af6"), 1.5, 10.0, 9.0) + box.set_content_margin_all(9) + _popover.add_theme_stylebox_override("panel", box) _root.add_child(_popover) _popover_box = VBoxContainer.new() + _popover_box.add_theme_constant_override("separation", 5) _popover.add_child(_popover_box) -func _rich() -> RichTextLabel: - var rt := RichTextLabel.new() - rt.bbcode_enabled = true - rt.fit_content = true - rt.scroll_active = false - rt.selection_enabled = false - return rt - - -func _button(text: String, fn: Callable) -> Button: - var b := Button.new() - b.text = text - b.pressed.connect(fn) - b.focus_mode = Control.FOCUS_NONE - return b - - -func _clear(box: Node) -> void: - for c in box.get_children(): - box.remove_child(c) - c.queue_free() +## Sizes what depends on the screen: the inspector's card, the drawer, the combat readout. +func _fit_layout() -> void: + var vp := _root.get_viewport_rect().size + var art_h := clampf(vp.y * 0.46, 220.0, 560.0) + art_h = minf(art_h, (Style.PANEL_RIGHT - 2 * Style.MARGIN - 20) * 1050.0 / 750.0) + _inspector_art.get_parent().custom_minimum_size = Vector2(0, art_h) + var region := Style.table_region(vp) + _drawer.offset_left = region.position.x + _drawer.offset_right = region.end.x - vp.x + var panel: Control = _drawer.get_node("Screen") + panel.size = Vector2(region.size.x, DRAWER_H) + panel.position = Vector2(0, 0) + _place_drawer(true) + _place_combat() + _layout_focus(true) # --------------------------------------------------------------------------------------------- # Drawing ## Redraws from the game's state. `ctx` holds: match, view, moves, selected, marks, thinking, paused, -## settings, me. +## preview. func refresh(ctx: Dictionary) -> void: + _ctx = ctx var m: LocalMatch = ctx.match var v: Dictionary = ctx.view var me: int = m.human @@ -280,20 +627,23 @@ func refresh(ctx: Dictionary) -> void: var items := [] for it in v.stack: items.append("%s (%s%s)" % [it.name.trim_prefix("Execute: "), State.player_name(it.player), " → %s" % it.target if it.target else ""]) - _stack.text = "Waiting: " + " ← ".join(items) if not items.is_empty() else "" + _stack.text = "WAITING: " + " ← ".join(items) if not items.is_empty() else "" - _panels[0].text = _player_panel(v, m.bot_side, me, not my_turn and not v.over) - _panels[1].text = _player_panel(v, me, me, my_turn) + _fill_strip(_strips[0], v, m.bot_side, me, v.active == m.bot_side and not v.over, not my_turn and not v.over) + _fill_strip(_strips[1], v, me, me, v.active == me and not v.over, my_turn and not v.over) - # The action bar. + # The action panel. if v.active == me: var parts := [] for st in STEPS: var on: bool = v.step == st[0] or (v.step == "resolve" and st[0] == "attack") - parts.append("[%s]" % st[1] if on else st[1]) - _steps.text = " ".join(parts) + if on: + parts.append("[bgcolor=%s][color=%s][b] %s [/b][/color][/bgcolor]" % [Style.hex(Style.ACCENT), Style.hex(Style.BG), st[1].to_upper()]) + else: + parts.append("[color=%s]%s[/color]" % [Style.hex(Style.MUTED), st[1].to_upper()]) + _steps.text = ("[color=%s] › [/color]" % Style.hex(Style.ACCENT_DK)).join(parts) else: - _steps.text = "%s's command" % State.player_name(m.bot_side) + _steps.text = "[color=%s]%s'S COMMAND[/color]" % [Style.hex(Style.OWNER[m.bot_side]), State.player_name(m.bot_side).to_upper()] _primary_move = {} for mv in ctx.moves: if mv.action.type == "pass": @@ -317,9 +667,12 @@ func refresh(ctx: Dictionary) -> void: _draw_source_menu(ctx, in_window, my_choice) _draw_log(m) _draw_combat(m, v, ctx) + _draw_salvage() if _moves_version != m.version: _moves_version = m.version _draw_moves(ctx.moves, v.over) + if _focus_open: + _sync_focus() if my_choice: _show_choice(v, ctx.moves) elif _modal.visible and _modal.get_meta("kind", "") == "choice": @@ -340,26 +693,53 @@ static func status_line(v: Dictionary, m: LocalMatch) -> String: return "%s · %s · %s step · %s" % [round, whose, Describe.STEP_NAMES[v.step], deciding] -func _player_panel(v: Dictionary, p: int, me: int, active: bool) -> String: +## One player's strip: `active` is whose command it is, `deciding` whose decision. +func _fill_strip(st: Dictionary, v: Dictionary, p: int, me: int, active: bool, deciding: bool) -> void: var pl: Dictionary = v.players[p] - var c: String = OWNER_HEX[p] + var col: Color = Style.OWNER[p] + var sb: ChamferBox = st.box + sb.border_color = Color(col, 0.85 if deciding else 0.4) + sb.glow = 7.0 if deciding else 0.0 + st.side.text = "YOU" if p == me else "BOT" + st.turn.text = "◀ COMMAND" if active else "" + if st.badge_for != p: + st.title.text = State.player_name(p).to_upper() + st.title.add_theme_color_override("font_color", col) + st.turn.add_theme_color_override("font_color", col) + for c in st.badge_slot.get_children(): + c.queue_free() + st.badge_slot.add_child(Widgets.owner_badge(p, 13)) + st.badge_for = p + var bar: BandwidthBar = st.bar + bar.color = col + bar.ticks = v.rules.firewallCost + var reach := Query.reachable_bandwidth(v, p) if p == me else int(pl.bandwidth) + bar.set_bandwidth(pl.bandwidth, reach) + var gb := "[b]%d[/b] [color=%s]Gb[/color]" % [pl.bandwidth, Style.hex(Style.MUTED)] + if reach > pl.bandwidth: + gb += " [color=%s]/%d[/color]" % [Style.hex(Color(col, 0.6)), reach] + st.gb.text = gb + var held := State.grid_count(v, p) var need: int = v.rules.winLocations - var bar := "■".repeat(held) + "□".repeat(maxi(0, need - held)) - var out := "[color=%s][b]%s[/b][/color] %s%s [b]%d Gb[/b]\n" % [c, State.player_name(p), "you" if p == me else "bot", " ◀" if active else "", pl.bandwidth] - out += "[color=%s]%s[/color] %d/%d locations\n" % [c, bar, held, need] - out += "[color=#7d8a97]hand[/color] %d [color=#7d8a97]deck[/color] %d [color=#7d8a97]discard[/color] %d [color=#7d8a97]Servers[/color] %d\n" % [pl.hand.size(), pl.deck.size(), pl.discard.size(), pl.serverPile.size()] + var c := Style.hex(col) + var mu := Style.hex(Style.MUTED) + var track := "■".repeat(held) + "[color=%s]%s[/color]" % [Style.hex(Color(col, 0.3)), "□".repeat(maxi(0, need - held))] + var out := "[color=%s]%s[/color] %d/%d [color=%s]LOC[/color]\n" % [c, track, held, need, mu] + out += "[color=%s]HAND[/color] %d [color=%s]DECK[/color] %d [color=%s]DISC[/color] %d [color=%s]SRV[/color] %d" % [ + mu, pl.hand.size(), mu, pl.deck.size(), mu, pl.discard.size(), mu, pl.serverPile.size()] for i in pl.anomalies.size(): var av: Dictionary = pl.anomalies[i] var r := State.ref(p, i + 1) if i >= 4 and av.at == null: continue var name := State.name_of(v, av.card) if av.card >= 0 and State.anomaly(v, State.original_of(r)).faceUp else "face down" - var where: String = av.at if av.at != null else ("in slot" if name != "face down" else "") + var where: String = av.at if av.at != null else ("slot" if name != "face down" else "") var n := "%d′" % (i - 3) if i >= 4 else str(i + 1) var stats := GameTable.badge_text(v, r) - out += "[color=#7d8a97]%s[/color] %s [color=#7d8a97]%s[/color] %s\n" % [n, name, where, stats] - return out.strip_edges() + var name_col := Style.hex(Style.SCREEN if name != "face down" else Style.MUTED) + out += "\n[color=%s]%s[/color] [color=%s]%s[/color] [color=%s]%s[/color] %s" % [c, n, name_col, _escape(name), mu, where, stats] + st.body.text = out func _banner_for(ctx: Dictionary, in_window: bool, my_turn: bool) -> String: @@ -382,7 +762,7 @@ func _banner_for(ctx: Dictionary, in_window: bool, my_turn: bool) -> String: what = _last_by(m, m.bot_side).trim_suffix(".") if what == "": what = "A response window is open" - return "[color=#ffb454][b]%s: respond?[/b][/color] Pick a glowing card or Ability, or Space to pass." % what + return "[color=%s][b]%s: respond?[/b][/color] Pick a glowing card or Ability, or Space to pass." % [Style.hex(Style.WARN), _escape(what)] if my_turn and v.choice == null: var hint: String = { "deploy": "Place, move or recall Anomalies, then advance one. A command is one advance or one attack.", @@ -390,10 +770,11 @@ func _banner_for(ctx: Dictionary, in_window: bool, my_turn: bool) -> String: "attack": "Attack from a location next to an enemy one.", "resolve": "", "playAgain": "Play more cards, then end your command.", }[v.step] - return "[color=#2de2c4][b]Your command.[/b][/color] %s" % hint + return "[color=%s][b]// YOUR COMMAND[/b][/color]\n%s" % [Style.hex(Style.ACCENT), hint] if not my_turn: var last := _last_by(m, m.bot_side) - return "%s %s [color=#7d8a97]%s[/color]" % [State.player_name(m.bot_side), "is paused." if ctx.paused else "is deciding…", last] + return "[color=%s][b]%s[/b][/color] %s\n[color=%s]%s[/color]" % [Style.hex(Style.OWNER[m.bot_side]), State.player_name(m.bot_side).to_upper(), + "is paused." if ctx.paused else "is deciding…", Style.hex(Style.MUTED), _escape(last)] return "" @@ -416,14 +797,14 @@ func _draw_source_menu(ctx: Dictionary, in_window: bool, my_choice: bool) -> voi var mine := (ctx.moves as Array).filter(func(mv): return mv.source == selected) var untargeted := mine.filter(func(mv): return mv.target == "none") var targeted := mine.filter(func(mv): return mv.target != "none") - _source_box.add_child(_title(source_title(v, selected, ctx.match.human))) + _source_box.add_child(Widgets.title(source_title(v, selected, ctx.match.human))) if not targeted.is_empty(): - _source_box.add_child(_muted("Click a highlighted %s." % _target_words(targeted))) + _source_box.add_child(Widgets.muted("Click a highlighted %s." % _target_words(targeted))) if ctx.get("preview", "") != "": - _source_box.add_child(_muted("Attack odds: %s" % ctx.preview)) + _source_box.add_child(Widgets.muted("Attack odds: %s" % ctx.preview)) for mv in untargeted: _source_box.add_child(_move_button(mv)) - _source_box.add_child(_button("Cancel Esc", func(): cancel_pressed.emit())) + _source_box.add_child(Widgets.button("Cancel Esc", func(): cancel_pressed.emit())) _source_menu.visible = true elif in_window: var by_source := {} @@ -433,38 +814,24 @@ func _draw_source_menu(ctx: Dictionary, in_window: bool, my_choice: bool) -> voi if not by_source.has(mv.source): by_source[mv.source] = [] by_source[mv.source].append(mv) - _source_box.add_child(_title("Your responses")) + _source_box.add_child(Widgets.title("// YOUR RESPONSES")) for src in by_source: var list: Array = by_source[src] if list.size() == 1: _source_box.add_child(_move_button(list[0])) else: var key: String = src - _source_box.add_child(_button("%s · %d ways" % [source_title(v, key, ctx.match.human), list.size()], func(): source_picked.emit(key))) + _source_box.add_child(Widgets.button("%s · %d ways" % [source_title(v, key, ctx.match.human), list.size()], func(): source_picked.emit(key))) if not _primary_move.is_empty(): _source_box.add_child(_move_button(_primary_move, "Pass Space")) _source_menu.visible = true -func _title(text: String) -> Label: - var l := Label.new() - l.text = text - l.add_theme_color_override("font_color", COLORS.accent) - return l - - -func _muted(text: String) -> Label: - var l := Label.new() - l.text = text - l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART - l.add_theme_color_override("font_color", COLORS.muted) - return l - - func _move_button(mv: Dictionary, text := "") -> Button: - var b := _button(text if text != "" else mv.label, func(): move_chosen.emit(mv)) + var b := Widgets.button(text if text != "" else mv.label, func(): move_chosen.emit(mv)) b.alignment = HORIZONTAL_ALIGNMENT_LEFT b.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + b.add_theme_font_size_override("font_size", 13) return b @@ -498,7 +865,7 @@ func show_popover(moves: Array, at: Vector2) -> void: _clear(_popover_box) for mv in moves: _popover_box.add_child(_move_button(mv)) - _popover_box.add_child(_button("Cancel", hide_popover)) + _popover_box.add_child(Widgets.button("Cancel", hide_popover)) _popover.visible = true _popover.reset_size() var vp := _root.get_viewport_rect().size @@ -520,30 +887,47 @@ func _draw_log(m: LocalMatch) -> void: if lines.size() < _log_count: _log.clear() _log_count = 0 + var added := 0 for i in range(maxi(0, _log_count), lines.size()): var l: Dictionary = lines[i] if l.text == "": continue - var color := "#7d8a97" + added += 1 + var text := _escape(l.text) if l.get("tag") == "turn": - color = "#d7dee6" + _log.append_text("\n[color=%s][b]// %s[/b][/color]\n" % [Style.hex(Style.ACCENT), text.strip_edges().trim_prefix("— ").trim_suffix(" —")]) elif l.get("player") != null: - color = OWNER_HEX[l.player] + _log.append_text("[color=%s]>[/color] [color=%s]%s[/color]\n" % [Style.hex(Style.ACCENT_DK), Style.hex(Style.OWNER[l.player]), text]) elif l.get("tag") == "combat": - color = "#ff8aa0" - _log.append_text("[color=%s]%s[/color]\n" % [color, _escape(l.text)]) + _log.append_text("[color=%s]![/color] [color=%s]%s[/color]\n" % [Style.hex(Style.ATTACK), Style.hex(Style.ATTACK.lightened(0.35)), text]) + else: + _log.append_text("[color=%s] %s[/color]\n" % [Style.hex(Style.MUTED), text]) + if _log_count >= 0 and not _drawer_open: + _unread += added _log_count = lines.size() + _prompt.text = "round %d@files:~$ ▌" % State.round_of(m.s, m.s.turn) if m.s.rules.commands.on else "turn %d@files:~$ ▌" % m.s.turn + _draw_handle() static func _escape(t: String) -> String: return t.replace("[", "[lb]") +static func _muted_bb(t: String) -> String: + return "[color=%s]%s[/color]" % [Style.hex(Style.MUTED), t] + + func _draw_combat(m: LocalMatch, v: Dictionary, ctx: Dictionary) -> void: var c = m.combat() if c == null: - _combat.text = "[color=#7d8a97]No combat yet. Combats show here with each side's Cores, dice and damage.[/color]" + _set_combat_visible(false) return + if c.id != _combat_id: + _combat_id = c.id + _combat_done_at = -1.0 + if c.done and _combat_done_at < 0: + # Counted from when the show of the result is over, so the readout outlasts the dice. + _combat_done_at = Time.get_ticks_msec() / 1000.0 + ctx.get("show_left", 0.0) # This combat's log lines: from its start up to the next combat. var own := m.log_lines().slice(c.logFrom) var mine := own @@ -551,16 +935,17 @@ func _draw_combat(m: LocalMatch, v: Dictionary, ctx: Dictionary) -> void: if own[i].get("tag") == "combat" and own[i].text.begins_with("Combat at"): mine = own.slice(0, i) break + var mu := Style.hex(Style.MUTED) var fighter := func(f: Dictionary, role: String) -> String: var name := Describe.ref_name(v, f.ref, m.human) var parts := [] for part in f.parts: parts.append("%+d %s" % [part.cores, part.source] if part.kind != "anomaly" else "%d %s" % [part.cores, part.source]) - var dice := ", ".join(f.dice.map(func(d): return str(d))) - var out := "[color=%s][b]%s[/b][/color] %s\n [b]%d Cores[/b] [color=#7d8a97]%s[/color]\n" % [ - OWNER_HEX[f.ref.player], role, name, f.cores, ", ".join(parts)] + var dice := " ".join(f.dice.map(func(d): return "[%d]" % d)) + var col := Style.hex(Style.OWNER[f.ref.player]) + var out := "[color=%s][b]%s[/b][/color] %s [b]%d CORES[/b]\n[color=%s] %s[/color]\n" % [col, role, _escape(name), f.cores, mu, _escape(", ".join(parts))] if dice != "": - out += " dice: %s = [b]%d[/b]\n" % [dice, Util.sum(f.dice)] + out += " [color=%s]dice[/color] %s = [b]%d[/b]\n" % [mu, _escape(dice), Util.sum(f.dice)] var took := 0 var dead := false for l in mine: @@ -569,25 +954,25 @@ func _draw_combat(m: LocalMatch, v: Dictionary, ctx: Dictionary) -> void: took += l.amount dead = dead or l.text.contains("destroyed") if v.rules.health.on and f.health > 0: - out += " %d/%d Health before the result" % [f.healthLeft, f.health] + out += " [color=%s]health[/color] %d/%d" % [mu, f.healthLeft, f.health] if took > 0: - out += " [color=#ff6b6b][b]took %d%s[/b][/color]" % [took, ", destroyed" if dead else ""] + out += " [color=%s][b]−%d%s[/b][/color]" % [Style.hex(Style.BAD), took, " DESTROYED" if dead else ""] out += "\n" return out var stage := "ended early" if c.done and c.ended else ("over" if c.done else ("after the roll" if c.rolled else "before the roll")) var kind: String = "Trace Route" if c.kind == "traceRoute" else c.kind - var out := "[b]Combat at %s[/b] [color=#7d8a97]%s · %s[/color]\n\n" % [c.loc, kind, stage] - out += fighter.call(c.attacker, "Attacker") + var out := "[color=%s][b]// COMBAT · %s[/b][/color] [color=%s]%s · %s[/color]\n" % [Style.hex(Style.ATTACK), c.loc, mu, kind, stage] + out += fighter.call(c.attacker, "ATK") for d in c.defenders: - out += "\n" + fighter.call(d, "Defender") + out += fighter.call(d, "DEF") if not c.rolled and not c.done and not ctx.thinking: var atk: int = c.attacker.cores var def := 0 for d in c.defenders: def += d.cores var o := Odds.roll_odds(atk, def) - out += "\n[color=#7d8a97]%d vs %d Cores: win %d%% · tie %d%% · lose %d%%\nAverage damage: %.1f to the defender, %.1f to the attacker[/color]\n" % [ - atk, def, roundi(o.win * 100), roundi(o.tie * 100), roundi(o.lose * 100), o.damageDealt, o.damageTaken] + out += "[color=%s]%d vs %d · win %d%% · tie %d%% · lose %d%% · avg dmg %.1f dealt, %.1f taken[/color]\n" % [ + Style.hex(Style.SECONDARY), atk, def, roundi(o.win * 100), roundi(o.tie * 100), roundi(o.lose * 100), o.damageDealt, o.damageTaken] # What happened: the result, damage, captures and cards played in it, after the opening line. var result := [] for i in range(1, mine.size()): @@ -595,30 +980,118 @@ func _draw_combat(m: LocalMatch, v: Dictionary, ctx: Dictionary) -> void: if l.text == "" or l.text.begins_with("Roll:"): continue if l.get("tag") == "combat" or l.get("tag") == "capture": - var color: String = OWNER_HEX[l.player] if l.get("player") != null else "#d7dee6" + var color: String = Style.hex(Style.OWNER[l.player]) if l.get("player") != null else Style.hex(Style.SCREEN) result.append("[color=%s]%s[/color]" % [color, _escape(l.text)]) if not result.is_empty(): - out += "\n" + "\n".join(result) - _combat.text = out + out += "\n".join(result.slice(maxi(0, result.size() - 4))) + _combat.text = out.strip_edges() + if _combat_panel.visible: + _place_combat() + _set_combat_visible(not c.done or Time.get_ticks_msec() / 1000.0 - _combat_done_at < COMBAT_LINGER) + + +func _set_combat_visible(on: bool) -> void: + # Each refresh asks again, so only a change starts a fade (restarting one every frame would + # hold it at its slow start forever). + if on == _combat_shown: + return + _combat_shown = on + if _combat_tween != null: + _combat_tween.kill() + if on: + _combat_panel.visible = true + _place_combat() + if Motion.instant(): + _combat_panel.modulate.a = 1.0 + return + _combat_panel.modulate.a = 0.0 + _combat_tween = create_tween() + Motion.rush_in(_combat_tween, _combat_panel, "modulate:a", 1.0, 0.25) + else: + if Motion.instant() or not _combat_panel.visible: + _combat_panel.visible = false + return + _combat_tween = create_tween() + Motion.rush_out(_combat_tween, _combat_panel, "modulate:a", 0.0, 0.3) + _combat_tween.tween_callback(func(): _combat_panel.visible = false) + + +func _place_combat() -> void: + var vp := _root.get_viewport_rect().size + var region := Style.table_region(vp) + var w := minf(560.0, region.size.x - 40) + # The text needs its width before it's measured, or it wraps at zero width and stands tall. + _combat.custom_minimum_size = Vector2(w - 22, 0) + _combat_panel.custom_minimum_size = Vector2(w, 0) + _combat_panel.size = Vector2(w, 0) + _combat_panel.reset_size() + _combat_panel.position = Vector2(region.position.x + (region.size.x - w) / 2.0, Style.PANEL_TOP + 8) + + +func _process(_delta: float) -> void: + if _combat_shown and _combat_done_at > 0 and Time.get_ticks_msec() / 1000.0 - _combat_done_at >= COMBAT_LINGER: + _set_combat_visible(false) + _watch_focus_edge() func _draw_moves(moves: Array, over: bool) -> void: _clear(_moves_box) if moves.is_empty(): - _moves_box.add_child(_muted("Game over." if over else "Nothing to do until the bot moves.")) + _moves_box.add_child(Widgets.muted("Game over." if over else "Nothing to do until the bot moves.")) return for g in Moves.group_moves(moves): - _moves_box.add_child(_title(g[0])) + var t := Widgets.label("// " + String(g[0]).to_upper(), "Micro") + t.add_theme_color_override("font_color", Style.ACCENT) + _moves_box.add_child(t) for mv in g[1]: _moves_box.add_child(_move_button(mv)) -## Shows a card or board object in the inspector: `info` is {art: card name or "", text: bbcode}. +## Shows a card or board object in the inspector: `info` is {art: card name or "", text: bbcode, +## key: what's inspected}. func inspect(info: Dictionary) -> void: var art: String = info.get("art", "") _inspector_art.texture = _art(art) if art != "" else null - _inspector_art.visible = art != "" + _inspector_art.visible = _inspector_art.texture != null + _inspector_blank.visible = not _inspector_art.visible _inspector_text.text = info.get("text", "") + _inspector_text.scroll_to_line(0) + _inspect_key = info.get("key", "") + var d: Dictionary = _ctx.view.defs.get(art, {}) if not _ctx.is_empty() and art != "" else {} + _inspector_kind.visible = not d.is_empty() + if not d.is_empty(): + var kind_name: String = Style.CLASS_NAMES.get(d.type, "Anomaly") if d.kind == "anomaly" else d.kind.capitalize() + _inspector_kind.get_child(0).text = kind_name.to_upper() + _inspector_kind.add_theme_stylebox_override("panel", Style.chip_box(Style.card_accent(d))) + _draw_salvage() + + +## The salvage chip under the inspected card (ui-plan.md §A6): only for a card in your hand you +## may salvage now, so it's found by pointing at a card without lighting up the whole hand. +func _draw_salvage() -> void: + _clear(_salvage_row) + var mv := _salvage_move(_inspect_key) + _salvage_row.visible = not mv.is_empty() + if not mv.is_empty(): + _salvage_row.add_child(_salvage_chip(mv)) + + +func _salvage_move(key: String) -> Dictionary: + if _ctx.is_empty() or not key.begins_with("hand:"): + return {} + for mv in _ctx.moves: + if mv.action.type == "salvage" and mv.source == key: + return mv + return {} + + +## "SALVAGE +7 Gb": a payment, not a discard, so it reads as Bandwidth gained. +func _salvage_chip(mv: Dictionary) -> Button: + var name: String = mv.source.substr(5) + var gb: int = _ctx.view.defs.get(name, {}).get("bandwidth", 0) + var b := Widgets.chip_button("SALVAGE +%d Gb" % gb, func(): move_chosen.emit(mv), Style.TYPE_ACCENT.server) + b.tooltip_text = "Discard %s for its printed %d Gb." % [name, gb] + return b func _art(card_name: String) -> Texture2D: @@ -628,12 +1101,238 @@ func _art(card_name: String) -> Texture2D: return _art_cache[card_name] -func show_log_tab() -> void: - _tabs.current_tab = 0 +# --------------------------------------------------------------------------------------------- +# The terminal drawer + +func toggle_drawer() -> void: + set_drawer(not _drawer_open) -func show_combat_tab() -> void: - _tabs.current_tab = 1 +func set_drawer(open: bool) -> void: + if open == _drawer_open: + return + _drawer_open = open + if open: + _unread = 0 + _draw_handle() + _place_drawer(false) + + +func drawer_open() -> bool: + return _drawer_open + + +func _draw_handle() -> void: + if _drawer_open: + _drawer_handle.text = "▾ // TERMINAL `" + elif _unread > 0: + _drawer_handle.text = "▴ // TERMINAL · %d new `" % _unread + else: + _drawer_handle.text = "▴ // TERMINAL `" + + +## Slides the drawer on the motion curve: it rushes up, and rushes back down. +func _place_drawer(instant: bool) -> void: + var to := -DRAWER_H if _drawer_open else 0.0 + if _drawer_tween != null: + _drawer_tween.kill() + if instant or Motion.instant(): + _drawer.offset_top = to + _drawer.offset_bottom = to + return + _drawer_tween = create_tween().set_parallel() + if _drawer_open: + Motion.rush_in(_drawer_tween, _drawer, "offset_top", to, 0.32) + Motion.rush_in(_drawer_tween, _drawer, "offset_bottom", to, 0.32) + else: + Motion.rush_out(_drawer_tween, _drawer, "offset_top", to, 0.24) + Motion.rush_out(_drawer_tween, _drawer, "offset_bottom", to, 0.24) + + +# --------------------------------------------------------------------------------------------- +# The hand-focus row + +func toggle_hand_focus() -> void: + set_hand_focus(not _focus_open) + + +func set_hand_focus(open: bool, by_edge := false) -> void: + if open == _focus_open: + return + _focus_open = open + _focus_by_edge = by_edge and open + _focus.visible = open + _focus_sig = "" + if open: + _sync_focus() + else: + _focus_hover = -1 + for c in _focus_cards: + c.node.queue_free() + _focus_cards = [] + hand_hovered.emit({}) + hand_focus_changed.emit(open) + + +func hand_focus_open() -> bool: + return _focus_open + + +## Opens the row when the mouse reaches the bottom edge over the table, and closes a row opened +## that way once the mouse leaves it. +func _watch_focus_edge() -> void: + if _ctx.is_empty() or _modal.visible or _drawer_open: + return + var vp := _root.get_viewport_rect().size + var mouse := _root.get_local_mouse_position() + var region := Style.table_region(vp) + var over_table := mouse.x > region.position.x and mouse.x < region.end.x + if not _focus_open: + if over_table and mouse.y >= vp.y - FOCUS_EDGE and mouse.y <= vp.y and DisplayServer.window_is_focused(): + set_hand_focus(true, true) + elif _focus_by_edge: + var card_h := FOCUS_CARD.y * Style.scale_of(vp).y + if mouse.y < vp.y - card_h * FOCUS_GROW - 50 or not over_table: + set_hand_focus(false) + + +## Rebuilds the row's cards when the hand changes, and restyles them for the marks. +func _sync_focus() -> void: + if _ctx.is_empty(): + return + var v: Dictionary = _ctx.view + var me: int = _ctx.match.human + var hand: Array = v.players[me].hand + var sig := ",".join(hand.map(func(id): return str(id))) + if sig != _focus_sig: + _focus_sig = sig + for c in _focus_cards: + c.node.queue_free() + _focus_cards = [] + _focus_hover = -1 + for i in hand.size(): + var name := State.name_of(v, hand[i]) + _focus_cards.append(_make_focus_card(i, name)) + for c in _focus_cards: + var mark = _ctx.marks.get(c.key) + var frame: ChamferBox = c.frame + if mark != null: + frame.border_color = Style.MARK[mark] + frame.glow = 14.0 + frame.border_width = 2.5 + else: + frame.border_color = Color(Style.ACCENT_DK, 0.0) + frame.glow = 0.0 + frame.border_width = 1.0 + c.node.queue_redraw() + c.frame_node.queue_redraw() + var mv := _salvage_move(c.key) + c.salvage.visible = not mv.is_empty() and c.index == _focus_hover + if not mv.is_empty(): + _clear(c.salvage) + c.salvage.add_child(_salvage_chip(mv)) + _layout_focus(true) + + +func _make_focus_card(i: int, card_name: String) -> Dictionary: + var node := Control.new() + node.mouse_filter = Control.MOUSE_FILTER_STOP + node.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND + _focus.add_child(node) + var frame := Style.chamfer_box(Color(0, 0, 0, 0), Color(0, 0, 0, 0), 1.0, 0.0, 8.0) + var frame_node := Panel.new() + frame_node.mouse_filter = Control.MOUSE_FILTER_IGNORE + frame_node.add_theme_stylebox_override("panel", frame) + frame_node.set_anchors_preset(Control.PRESET_FULL_RECT) + frame_node.offset_left = -3 + frame_node.offset_top = -3 + frame_node.offset_right = 3 + frame_node.offset_bottom = 3 + node.add_child(frame_node) + var art := TextureRect.new() + art.mouse_filter = Control.MOUSE_FILTER_IGNORE + art.set_anchors_preset(Control.PRESET_FULL_RECT) + art.expand_mode = TextureRect.EXPAND_IGNORE_SIZE + art.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED + art.texture = _art(card_name) + node.add_child(art) + var salvage := HBoxContainer.new() + salvage.alignment = BoxContainer.ALIGNMENT_CENTER + # Above the card, clear of its text: the card grows upward from its bottom edge. + salvage.anchor_left = 0.0 + salvage.anchor_right = 1.0 + salvage.offset_top = -30 + salvage.offset_bottom = -6 + salvage.visible = false + node.add_child(salvage) + var key := Moves.hand_key(card_name) + var entry := {"node": node, "frame": frame, "frame_node": frame_node, "key": key, "card": card_name, "index": i, "salvage": salvage, "tween": null} + node.mouse_entered.connect(func(): _hover_focus(i)) + node.mouse_exited.connect(func(): + if _focus_hover == i: + _hover_focus(-1)) + node.gui_input.connect(func(e: InputEvent): + if e is InputEventMouseButton and e.pressed: + if e.button_index == MOUSE_BUTTON_LEFT: + var at: Vector2 = node.get_global_rect().get_center() + set_hand_focus(false) + hand_picked.emit(key, at) + elif e.button_index == MOUSE_BUTTON_RIGHT: + set_hand_focus(false) + cancel_pressed.emit() + node.accept_event()) + return entry + + +func _hover_focus(i: int) -> void: + if i == _focus_hover: + return + _focus_hover = i + for c in _focus_cards: + c.salvage.visible = c.index == i and not _salvage_move(c.key).is_empty() + _layout_focus(false) + if i >= 0 and i < _focus_cards.size(): + hand_hovered.emit({"key": _focus_cards[i].key, "card": _focus_cards[i].card}) + else: + hand_hovered.emit({}) + + +## Lays out the row across the table's part of the screen; the hovered card grows and rises. +func _layout_focus(instant: bool) -> void: + if not _focus_open: + return + var vp := _root.get_viewport_rect().size + var sc := Style.scale_of(vp).y + var region := Style.table_region(vp) + var cw := FOCUS_CARD.x * sc + var ch := FOCUS_CARD.y * sc + var n := _focus_cards.size() + _focus_shade.position = Vector2(region.position.x - 20, vp.y - ch * FOCUS_GROW - 90) + _focus_shade.size = Vector2(region.size.x + 40, ch * FOCUS_GROW + 90) + if n == 0: + return + var room := region.size.x - 24 + var step := minf(cw + 12, (room - cw) / maxf(1, n - 1)) if n > 1 else 0.0 + var x0 := region.position.x + (region.size.x - (cw + step * (n - 1))) / 2.0 + var base_y := vp.y - ch - 14 * sc + for c in _focus_cards: + var node: Control = c.node + var hovered: bool = c.index == _focus_hover + node.size = Vector2(cw, ch) + node.pivot_offset = Vector2(cw / 2.0, ch) + node.z_index = 10 if hovered else c.index + var pos := Vector2(x0 + step * c.index, base_y - (24 * sc if hovered else 0.0)) + var grow := Vector2.ONE * (FOCUS_GROW if hovered else 1.0) + if c.tween != null: + c.tween.kill() + if instant or Motion.instant(): + node.position = pos + node.scale = grow + continue + var tw := create_tween().set_parallel() + Motion.rush_in(tw, node, "position", pos, 0.22) + Motion.rush_in(tw, node, "scale", grow, 0.22) + c.tween = tw # --------------------------------------------------------------------------------------------- @@ -643,17 +1342,23 @@ func _open_modal(kind: String, width := 520) -> VBoxContainer: _clear(_modal) _modal.set_meta("kind", kind) var dim := ColorRect.new() - dim.color = Color(0, 0, 0, 0.45 if kind != "choice" else 0.2) + dim.color = Color(Style.BG, 0.6 if kind != "choice" else 0.25) dim.set_anchors_preset(Control.PRESET_FULL_RECT) _modal.add_child(dim) + if kind != "choice": + _modal.add_child(Widgets.scanlines(0.1)) var center := CenterContainer.new() center.set_anchors_preset(Control.PRESET_FULL_RECT) _modal.add_child(center) var pc := PanelContainer.new() pc.custom_minimum_size = Vector2(width, 0) + var box := Style.chamfer_box(Style.ACCENT, Color(Style.BG, 0.93), 1.5, 16.0, 16.0) + box.ticks = true + box.set_content_margin_all(20) + pc.add_theme_stylebox_override("panel", box) center.add_child(pc) _modal_box = VBoxContainer.new() - _modal_box.add_theme_constant_override("separation", 8) + _modal_box.add_theme_constant_override("separation", 10) pc.add_child(_modal_box) _modal.visible = true return _modal_box @@ -675,10 +1380,9 @@ func _show_choice(v: Dictionary, moves: Array) -> void: return var box := _open_modal("choice", 560) _modal.set_meta("choice_key", key) - var prompt := Label.new() - prompt.text = v.choice.prompt + box.add_child(Widgets.label("// CHOOSE", "Micro")) + var prompt := Widgets.title(v.choice.prompt) prompt.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART - prompt.add_theme_color_override("font_color", COLORS.accent) box.add_child(prompt) var options := moves.filter(func(mv): return mv.action.type == "choose") for mv in options: @@ -689,129 +1393,79 @@ func _show_choice(v: Dictionary, moves: Array) -> void: var o: Dictionary = v.choice.options[i] blocked.append("%s (%d Gb)" % [o.label, o.get("cost", 0)]) if not blocked.is_empty(): - box.add_child(_muted("Not enough Gb for: %s. Salvage a card first." % ", ".join(blocked))) + box.add_child(Widgets.muted("Not enough Gb for: %s. Salvage a card first." % ", ".join(blocked))) + var row := HFlowContainer.new() + row.add_theme_constant_override("h_separation", 6) + row.add_theme_constant_override("v_separation", 6) + box.add_child(row) for mv in moves.filter(func(x): return x.action.type == "salvage"): - box.add_child(_move_button(mv)) + var name: String = mv.source.substr(5) + var gb: int = v.defs.get(name, {}).get("bandwidth", 0) + var mvv: Dictionary = mv + row.add_child(Widgets.chip_button("%s +%d Gb" % [name.to_upper(), gb], func(): move_chosen.emit(mvv), Style.TYPE_ACCENT.server)) func _show_game_over(m: LocalMatch) -> void: var s := m.s var me := m.human - var box := _open_modal("over", 560) - var title := "A draw" if s.winner == null else ("You win" if s.winner == me else "%s (the bot) wins" % State.player_name(s.winner)) - box.add_child(_title(title)) + var box := _open_modal("over", 580) + box.add_child(Widgets.label("// MATCH COMPLETE", "Micro")) + var title := "DRAW" if s.winner == null else ("VICTORY" if s.winner == me else "DEFEAT") + var h := Widgets.heading(title) + h.add_theme_font_size_override("font_size", 34) + if s.winner != null: + h.add_theme_color_override("font_color", Style.OWNER[s.winner]) + box.add_child(h) var reason := "%s holds %d locations." % [State.player_name(s.winner), s.rules.winLocations] if s.endReason == "win" else "The turn limit was reached." - box.add_child(_muted("%s Round %d, seed %d." % [reason, State.round_of(s, s.turn), m.setup.seed])) + box.add_child(Widgets.muted("%s Round %d, seed %d." % [reason, State.round_of(s, s.turn), m.setup.seed])) var grid := GridContainer.new() grid.columns = 3 grid.add_theme_constant_override("h_separation", 18) for t in ["", "%s (you)" % State.player_name(me), "%s (bot)" % State.player_name(m.bot_side)]: - grid.add_child(_title(t)) + grid.add_child(Widgets.title(t)) for k in Types.STAT_KEYS: if not STAT_LABELS.has(k) or (s.stats[k][0] == 0 and s.stats[k][1] == 0): continue for t in [STAT_LABELS[k], str(s.stats[k][me]), str(s.stats[k][m.bot_side])]: - var l := Label.new() - l.text = t - grid.add_child(l) + grid.add_child(Widgets.label(t)) box.add_child(grid) var row := HBoxContainer.new() - row.add_child(_button("New game", func(): show_start({}))) - row.add_child(_button("Rematch", func(): + row.add_theme_constant_override("separation", 10) + row.add_child(Widgets.button("Rematch", func(): close_modal() - new_game_requested.emit({"seed": m.setup.seed, "human": m.human, "style": m.setup.get("style", "greedy")}))) - row.add_child(_button("Look at the board", func(): + new_game_requested.emit({"seed": m.setup.seed, "human": m.human, "style": m.setup.get("style", "greedy")}), "PrimaryButton")) + row.add_child(Widgets.button("New game", func(): + close_modal() + menu_requested.emit("setup"))) + row.add_child(Widgets.button("Look at the board", func(): close_modal() _modal.set_meta("closed_over", true))) box.add_child(row) -## The new-game dialog. `defaults` may hold seed, human and style. -func show_start(defaults: Dictionary) -> void: - var box := _open_modal("start", 480) - box.add_child(_title("New game against the bot")) - box.add_child(_muted("Both decks are dealt at random from Set 1, from the seed.")) - var grid := GridContainer.new() - grid.columns = 2 - grid.add_theme_constant_override("h_separation", 12) - box.add_child(grid) - var seed_edit := LineEdit.new() - seed_edit.text = str(defaults.get("seed", randi_range(1, 999999))) - seed_edit.custom_minimum_size = Vector2(200, 0) - grid.add_child(_label("Seed")) - grid.add_child(seed_edit) - var side := OptionButton.new() - side.add_item("South (S1)") - side.add_item("North (S2)") - side.selected = defaults.get("human", 0) - grid.add_child(_label("You play")) - grid.add_child(side) - var style := OptionButton.new() - var styles: Dictionary = GreedyBot.STYLES - var keys := styles.keys() - for k in keys: - style.add_item(styles[k].label) - style.selected = maxi(0, keys.find(defaults.get("style", "greedy"))) - grid.add_child(_label("Bot")) - grid.add_child(style) - var about := _muted(styles[keys[style.selected]].about) - box.add_child(about) - style.item_selected.connect(func(i): about.text = styles[keys[i]].about) +func _confirm_menu() -> void: + var box := _open_modal("leave", 420) + box.add_child(Widgets.heading("LEAVE GAME?")) + box.add_child(Widgets.muted("This game ends and you go back to the menu.")) var row := HBoxContainer.new() - row.add_child(_button("Start", func(): - var opts := {"seed": int(seed_edit.text) if seed_edit.text.is_valid_int() else randi_range(1, 999999), - "human": side.selected, "style": keys[style.selected]} + row.add_theme_constant_override("separation", 10) + row.add_child(Widgets.button("Leave", func(): close_modal() - new_game_requested.emit(opts))) - if defaults.get("cancel", true): - row.add_child(_button("Cancel", close_modal)) + menu_requested.emit(""), "PrimaryButton")) + row.add_child(Widgets.button("Stay", close_modal)) box.add_child(row) -func _label(text: String) -> Label: - var l := Label.new() - l.text = text - return l - - -## Settings: when the game stops for you, skipping, bot speed, invariant checks. +## Settings: when the game stops for you, skipping, speeds, invariant checks. func show_settings(settings := {}) -> void: if settings.is_empty(): settings = _settings var box := _open_modal("settings", 520) - box.add_child(_title("Settings")) - box.add_child(_label("When the game stops for you to respond")) - var stops := OptionButton.new() - var stop_ids := ["combat", "all", "never"] - for label in ["In combat only", "Every opponent move", "Never"]: - stops.add_item(label) - stops.selected = maxi(0, stop_ids.find(settings.stops)) - box.add_child(stops) - box.add_child(_muted("Hold Shift to stop at the next window anyway.")) - var skip := CheckBox.new() - skip.text = "Skip steps where End and Salvage are the only moves" - skip.button_pressed = settings.autoSkip - box.add_child(skip) - var check := CheckBox.new() - check.text = "Check the rule invariants after every move" - check.button_pressed = settings.checkInvariants - box.add_child(check) - var speed_label := _label("") - box.add_child(speed_label) - var speed := HSlider.new() - speed.min_value = 0.0 - speed.max_value = 1.5 - speed.step = 0.05 - speed.value = settings.botDelay - var show_speed := func(x): speed_label.text = "Bot speed: %.2fs per move" % x - show_speed.call(speed.value) - speed.value_changed.connect(show_speed) - box.add_child(speed) - box.add_child(_button("Done", func(): - var out := {"stops": stop_ids[stops.selected], "autoSkip": skip.button_pressed, "checkInvariants": check.button_pressed, "botDelay": speed.value} + box.add_child(Widgets.heading("SETTINGS")) + Widgets.settings_form(box, settings, func(out): _settings = out close_modal() - settings_changed.emit(out))) + settings_changed.emit(out)) func set_settings(settings: Dictionary) -> void: @@ -821,6 +1475,18 @@ func set_settings(settings: Dictionary) -> void: func reset_for_new_game() -> void: _log.clear() _log_count = -1 + _unread = 0 + _draw_handle() _moves_version = -1 + _combat_id = -1 + _combat_done_at = -1.0 + _set_combat_visible(false) _modal.set_meta("closed_over", false) hide_popover() + set_hand_focus(false) + + +func _clear(box: Node) -> void: + for c in box.get_children(): + box.remove_child(c) + c.queue_free() diff --git a/ui/scanlines.gdshader b/ui/scanlines.gdshader new file mode 100644 index 0000000..07ef76f --- /dev/null +++ b/ui/scanlines.gdshader @@ -0,0 +1,16 @@ +shader_type canvas_item; + +// The CRT texture of the print templates' terminals (ui-plan.md §2): dark lines 2 px of every 4, +// laid over a ChamferBox panel. A StyleBox can't carry a shader, so this goes on a ColorRect on top. + +uniform float strength : hint_range(0.0, 1.0) = 0.16; +uniform float period = 4.0; +// A faint moving band, as on an old monitor; 0 turns it off. +uniform float roll = 0.04; + +void fragment() { + float line = step(mod(FRAGCOORD.y, period), period * 0.5); + float band = roll * smoothstep(0.0, 1.0, sin(FRAGCOORD.y * 0.012 - TIME * 1.7) * 0.5 + 0.5); + COLOR = vec4(0.0, 0.0, 0.0, strength * line - band * 0.5); + COLOR.a = max(COLOR.a, 0.0); +} diff --git a/ui/scanlines.gdshader.uid b/ui/scanlines.gdshader.uid new file mode 100644 index 0000000..e007f1e --- /dev/null +++ b/ui/scanlines.gdshader.uid @@ -0,0 +1 @@ +uid://tbf16hlo77r6 diff --git a/ui/style.gd b/ui/style.gd new file mode 100644 index 0000000..30597fd --- /dev/null +++ b/ui/style.gd @@ -0,0 +1,280 @@ +class_name Style +## The design system (ui-plan.md §2–3): the print templates' tokens, the two fonts, the chamfered +## boxes and the one Theme, plus the screen space the 2D panels take. The HUD, the table's own 2D +## readouts and the menu all read their colors and fonts from here, so nothing restyles by eye. + +# --------------------------------------------------------------------------------------------- +# Tokens, from decks/files-deck-1/*.css + +const BG := Color("#05080a") +## Primary, secondary and label text. +const SCREEN := Color("#e6fbff") +const SECONDARY := Color("#a9d9e0") +const MUTED := Color("#6f8a90") +## System chrome: frames, buttons, the grid, the terminal. +const ACCENT := Color("#22d3ee") +const ACCENT_DK := Color("#0e6b78") +## Panel fills: translucent black over the table, and a lifted shade for buttons. +const PANEL := Color("#05080ae6") +const PANEL_HI := Color("#0a1a20f0") +const DISABLED := Color("#33464b") +## Warnings, damage and attacks. +const WARN := Color("#ffb02e") +const BAD := Color("#ff5c5c") +const ATTACK := Color("#ff4f6d") + +## Okabe–Ito sky blue (South) and orange (North): they stay apart for color-blind players. A stripe +## (South) or dot (North) fill is the second cue, since chrome cyan sits beside South's blue. +const OWNER: Array[Color] = [Color("#56b4e9"), Color("#e69f00")] + +const TYPE_ACCENT := { + "server": Color("#39d353"), "hardware": Color("#ffd24a"), "execution": Color("#ffb02e"), + "program": Color("#8b949e"), "system": Color("#22d3ee"), +} +## Anomaly classes: Virus, Bug, Glitch, Patch. +const CLASS_ACCENT := {"V": Color("#3fb950"), "B": Color("#ff5c5c"), "G": Color("#d264ff"), "P": Color("#4aa3ff")} +const CLASS_NAMES := {"V": "Virus", "B": "Bug", "G": "Glitch", "P": "Patch"} + +## How table objects glow: legal sources, responses, the selection, targets, attacks, the combat. +const MARK := { + "source": ACCENT, "respond": WARN, "selected": Color.WHITE, + "target": ACCENT, "attack": ATTACK, "fight": ATTACK, +} +const MARK_STRENGTH := {"source": 1.0, "respond": 1.2, "selected": 2.0, "target": 1.5, "attack": 1.8, "fight": 1.2} + +# --------------------------------------------------------------------------------------------- +# Panel geometry (§0.4): the one source for what the HUD draws, where the camera fits the mat, +# where the hand lays out and which screen points the click test may use. Pixels at the +# 1600 × 900 base size; scale by the viewport. + +const BASE := Vector2(1600, 900) +const PANEL_LEFT := 300.0 +const PANEL_RIGHT := 360.0 +const PANEL_TOP := 44.0 +const PANEL_BOTTOM := 176.0 +## Gap between a panel and the screen edge. +const MARGIN := 8.0 + +## The chamfer, ~3 % of a card's shorter edge (22 px at 750 px). +const CHAMFER_RATIO := 22.0 / 750.0 + +# --------------------------------------------------------------------------------------------- +# Fonts + +const DISPLAY_PATH := "res://assets/fonts/Orbitron.ttf" +const BODY_PATH := "res://assets/fonts/JetBrainsMono.ttf" + +static var _fonts := {} +static var _theme: Theme + + +## Orbitron, for the logo, the menu and headings only: it is too wide for dense readouts. +static func display_font(weight := 700) -> Font: + return _font(DISPLAY_PATH, weight) + + +## JetBrains Mono, for every HUD string: the nearest shippable match to the cards' Consolas. +static func body_font(weight := 400) -> Font: + return _font(BODY_PATH, weight) + + +static func _font(path: String, weight: int) -> Font: + var key := "%s@%d" % [path, weight] + if not _fonts.has(key): + var base: FontFile = load(path) + var f := FontVariation.new() + f.base_font = base + f.variation_opentype = {"wght": weight} + _fonts[key] = f + return _fonts[key] + + +# --------------------------------------------------------------------------------------------- +# Boxes and the theme + +## A chamfered box: `accent` border, `fill` inside, `width` px border, `glow` px of outer glow. +static func chamfer_box(accent: Color, fill := PANEL, width := 1.5, glow := 0.0, cut := 8.0) -> ChamferBox: + var b := ChamferBox.new(fill, accent, width, cut) + b.glow = glow + return b + + +## An emphasis chip: filled accent, dark text (set the label's color to BG), a glow. +static func chip_box(accent: Color, cut := 5.0) -> ChamferBox: + var b := ChamferBox.new(accent, accent.lightened(0.25), 1.0, cut) + b.glow = 6.0 + b.glow_alpha = 0.3 + b.content_margin_left = 7 + b.content_margin_right = 7 + b.content_margin_top = 2 + b.content_margin_bottom = 2 + return b + + +static func type_accent(kind: String) -> Color: + return TYPE_ACCENT.get(kind, ACCENT) + + +## The V/B/G/P class color of an Anomaly type, or the accent. +static func class_accent(type: String) -> Color: + return CLASS_ACCENT.get(type, ACCENT) + + +## The accent for a card def: its class for Anomalies, its kind otherwise. +static func card_accent(d: Dictionary) -> Color: + if d.get("kind", "") == "anomaly": + return class_accent(d.get("type", "")) + return type_accent(d.get("kind", "")) + + +## A Firewall's color at `level` out of `levels` (the rules' firewallCost size): amber to red. +static func firewall_color(level: int, levels: int) -> Color: + var k := 0.0 if levels <= 1 else clampf(float(level - 1) / (levels - 1), 0.0, 1.0) + return WARN.lerp(BAD, k) + + +## "#22d3ee" for BBCode color tags, which ignore the theme. +static func hex(c: Color) -> String: + return "#" + c.to_html(c.a < 1.0) + + +## The one Theme for every 2D screen. +static func theme() -> Theme: + if _theme != null: + return _theme + var t := Theme.new() + t.default_font = body_font() + t.default_font_size = 14 + t.set_color("font_color", "Label", SCREEN) + t.set_color("default_color", "RichTextLabel", SCREEN) + t.set_font("normal_font", "RichTextLabel", body_font()) + t.set_font("bold_font", "RichTextLabel", body_font(700)) + t.set_font("mono_font", "RichTextLabel", body_font()) + t.set_font("italics_font", "RichTextLabel", body_font(300)) + t.set_stylebox("panel", "PanelContainer", chamfer_box(ACCENT_DK)) + t.set_stylebox("panel", "Panel", chamfer_box(ACCENT_DK)) + + # Buttons: dim frame at rest, the accent on hover, filled when pressed. + var normal := chamfer_box(ACCENT_DK, PANEL_HI, 1.0, 0.0, 6.0) + normal.content_margin_left = 10 + normal.content_margin_right = 10 + t.set_stylebox("normal", "Button", normal) + t.set_stylebox("hover", "Button", normal.tinted(Color("#0c2730f0"), ACCENT)) + t.set_stylebox("pressed", "Button", normal.tinted(Color(ACCENT, 0.35), ACCENT)) + t.set_stylebox("disabled", "Button", normal.tinted(Color("#05080ac0"), Color("#16262b"))) + t.set_stylebox("focus", "Button", StyleBoxEmpty.new()) + t.set_color("font_color", "Button", SCREEN) + t.set_color("font_hover_color", "Button", Color.WHITE) + t.set_color("font_pressed_color", "Button", Color.WHITE) + t.set_color("font_disabled_color", "Button", DISABLED) + # A filled accent button for the main action. + t.add_type("PrimaryButton") + t.set_type_variation("PrimaryButton", "Button") + var prim := chamfer_box(ACCENT, Color(ACCENT, 0.16), 1.5, 6.0, 8.0) + prim.ticks = true + t.set_stylebox("normal", "PrimaryButton", prim) + var prim_hover := prim.tinted(Color(ACCENT, 0.3), ACCENT.lightened(0.3)) + prim_hover.glow = 9.0 + t.set_stylebox("hover", "PrimaryButton", prim_hover) + t.set_stylebox("pressed", "PrimaryButton", prim.tinted(Color(ACCENT, 0.55), Color.WHITE)) + t.set_stylebox("disabled", "PrimaryButton", normal.tinted(Color("#05080ac0"), Color("#16262b"))) + t.set_color("font_color", "PrimaryButton", ACCENT.lightened(0.35)) + t.set_font("font", "PrimaryButton", body_font(700)) + # Big menu buttons in the display face (BigButton: MenuButton is a built-in class). + t.add_type("BigButton") + t.set_type_variation("BigButton", "Button") + var menu := chamfer_box(ACCENT_DK, Color("#05080ad0"), 1.5, 0.0, 12.0) + menu.content_margin_left = 24 + menu.content_margin_right = 24 + menu.content_margin_top = 12 + menu.content_margin_bottom = 12 + t.set_stylebox("normal", "BigButton", menu) + var menu_hover := menu.tinted(Color(ACCENT, 0.16), ACCENT) + menu_hover.glow = 12.0 + menu_hover.ticks = true + t.set_stylebox("hover", "BigButton", menu_hover) + t.set_stylebox("pressed", "BigButton", menu.tinted(Color(ACCENT, 0.4), Color.WHITE)) + t.set_stylebox("disabled", "BigButton", menu.tinted(Color("#05080a90"), Color("#132227"))) + t.set_font("font", "BigButton", display_font(600)) + t.set_font_size("font_size", "BigButton", 20) + + # Text styles. + t.add_type("Title") + t.set_type_variation("Title", "Label") + t.set_color("font_color", "Title", ACCENT) + t.set_font("font", "Title", body_font(700)) + t.add_type("Heading") + t.set_type_variation("Heading", "Label") + t.set_color("font_color", "Heading", ACCENT) + t.set_font("font", "Heading", display_font(700)) + t.set_font_size("font_size", "Heading", 18) + t.add_type("Muted") + t.set_type_variation("Muted", "Label") + t.set_color("font_color", "Muted", MUTED) + t.add_type("Micro") + t.set_type_variation("Micro", "Label") + t.set_color("font_color", "Micro", MUTED) + t.set_font_size("font_size", "Micro", 11) + + # Inputs. + var field := chamfer_box(ACCENT_DK, Color("#03090bf0"), 1.0, 0.0, 5.0) + t.set_stylebox("normal", "LineEdit", field) + t.set_stylebox("focus", "LineEdit", field.tinted(Color("#03090bf0"), ACCENT)) + t.set_color("font_color", "LineEdit", SCREEN) + t.set_color("caret_color", "LineEdit", ACCENT) + t.set_color("selection_color", "LineEdit", Color(ACCENT, 0.35)) + t.set_stylebox("normal", "OptionButton", normal) + t.set_stylebox("hover", "OptionButton", normal.tinted(Color("#0c2730f0"), ACCENT)) + t.set_stylebox("pressed", "OptionButton", normal.tinted(Color(ACCENT, 0.35), ACCENT)) + t.set_stylebox("focus", "OptionButton", StyleBoxEmpty.new()) + var popup := chamfer_box(ACCENT, Color("#05080af8"), 1.0, 0.0, 6.0) + t.set_stylebox("panel", "PopupMenu", popup) + t.set_stylebox("hover", "PopupMenu", chamfer_box(ACCENT, Color(ACCENT, 0.2), 0.0, 0.0, 4.0)) + t.set_color("font_color", "PopupMenu", SCREEN) + t.set_color("font_hover_color", "PopupMenu", Color.WHITE) + t.set_font("font", "PopupMenu", body_font()) + for state in ["normal", "hover", "pressed", "hover_pressed", "disabled"]: + t.set_stylebox(state, "CheckBox", StyleBoxEmpty.new()) + t.set_stylebox("focus", "CheckBox", StyleBoxEmpty.new()) + t.set_color("font_color", "CheckBox", SCREEN) + t.set_color("font_hover_color", "CheckBox", Color.WHITE) + t.set_color("font_pressed_color", "CheckBox", SCREEN) + t.set_color("font_hover_pressed_color", "CheckBox", Color.WHITE) + var track := chamfer_box(ACCENT_DK, Color("#03090b"), 1.0, 0.0, 3.0) + track.content_margin_top = 3 + track.content_margin_bottom = 3 + t.set_stylebox("slider", "HSlider", track) + var fill := chamfer_box(ACCENT, Color(ACCENT, 0.5), 0.0, 0.0, 3.0) + fill.content_margin_top = 3 + fill.content_margin_bottom = 3 + t.set_stylebox("grabber_area", "HSlider", fill) + t.set_stylebox("grabber_area_highlight", "HSlider", fill.tinted(Color(ACCENT, 0.75), ACCENT)) + # Thin scrollbars in the chrome color. + var grab := chamfer_box(ACCENT_DK, Color(ACCENT_DK, 0.8), 0.0, 0.0, 2.0) + grab.set_content_margin_all(3) + for bar in ["VScrollBar", "HScrollBar"]: + var empty := StyleBoxEmpty.new() + empty.set_content_margin_all(3) + t.set_stylebox("scroll", bar, empty) + t.set_stylebox("grabber", bar, grab) + t.set_stylebox("grabber_highlight", bar, grab.tinted(Color(ACCENT, 0.8), ACCENT)) + t.set_stylebox("grabber_pressed", bar, grab.tinted(ACCENT, ACCENT)) + var tip := chamfer_box(ACCENT, Color("#05080af8"), 1.0, 0.0, 5.0) + t.set_stylebox("panel", "TooltipPanel", tip) + t.set_color("font_color", "TooltipLabel", SCREEN) + _theme = t + return t + + +# --------------------------------------------------------------------------------------------- +# Screen geometry + +## The base-size scale for a viewport of size `vp`. +static func scale_of(vp: Vector2) -> Vector2: + return vp / BASE + + +## The screen rect the panels leave free for the table, in viewport pixels. +static func table_region(vp: Vector2, bottom := PANEL_BOTTOM) -> Rect2: + var s := scale_of(vp) + return Rect2(PANEL_LEFT * s.x, PANEL_TOP * s.y, vp.x - (PANEL_LEFT + PANEL_RIGHT) * s.x, vp.y - (PANEL_TOP + bottom) * s.y) diff --git a/ui/style.gd.uid b/ui/style.gd.uid new file mode 100644 index 0000000..b032acf --- /dev/null +++ b/ui/style.gd.uid @@ -0,0 +1 @@ +uid://drakm4raevia diff --git a/ui/widgets.gd b/ui/widgets.gd new file mode 100644 index 0000000..6a47e7f --- /dev/null +++ b/ui/widgets.gd @@ -0,0 +1,201 @@ +class_name Widgets +## Small builders shared by the HUD and the menu, so both make buttons, labels and forms the same +## way from Style's theme. + +const SCANLINES := preload("res://ui/scanlines.gdshader") + + +static func button(text: String, fn: Callable, variation := "") -> Button: + var b := Button.new() + b.text = text + b.pressed.connect(fn) + b.focus_mode = Control.FOCUS_NONE + if variation != "": + b.theme_type_variation = variation + return b + + +static func label(text: String, variation := "") -> Label: + var l := Label.new() + l.text = text + if variation != "": + l.theme_type_variation = variation + return l + + +static func title(text: String) -> Label: + return label(text, "Title") + + +static func heading(text: String) -> Label: + return label(text, "Heading") + + +static func muted(text: String) -> Label: + var l := label(text, "Muted") + l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART + return l + + +static func rich() -> RichTextLabel: + var rt := RichTextLabel.new() + rt.bbcode_enabled = true + rt.fit_content = true + rt.scroll_active = false + rt.selection_enabled = false + return rt + + +## A filled accent chip with dark text, e.g. "SALVAGE +4 Gb". +static func chip(text: String, accent := Style.ACCENT) -> PanelContainer: + var pc := PanelContainer.new() + pc.add_theme_stylebox_override("panel", Style.chip_box(accent)) + var l := Label.new() + l.text = text + l.add_theme_color_override("font_color", Style.BG) + l.add_theme_font_override("font", Style.body_font(800)) + l.add_theme_font_size_override("font_size", 12) + pc.add_child(l) + return pc + + +## A clickable chip: an accent-filled button. +static func chip_button(text: String, fn: Callable, accent := Style.ACCENT) -> Button: + var b := button(text, fn) + var box := Style.chip_box(accent) + b.add_theme_stylebox_override("normal", box) + var hover := box.tinted(accent.lightened(0.25), Color.WHITE) + hover.glow = 10.0 + b.add_theme_stylebox_override("hover", hover) + b.add_theme_stylebox_override("pressed", box.tinted(Color.WHITE, Color.WHITE)) + for c in ["font_color", "font_hover_color", "font_pressed_color"]: + b.add_theme_color_override(c, Style.BG) + b.add_theme_font_override("font", Style.body_font(800)) + b.add_theme_font_size_override("font_size", 12) + return b + + +## The CRT lines over a panel: add as the panel's last child. +static func scanlines(strength := 0.16) -> ColorRect: + var r := ColorRect.new() + r.mouse_filter = Control.MOUSE_FILTER_IGNORE + r.set_anchors_preset(Control.PRESET_FULL_RECT) + var m := ShaderMaterial.new() + m.shader = SCANLINES + m.set_shader_parameter("strength", strength) + r.material = m + return r + + +## A small swatch in player `p`'s color and pattern: stripes for South, dots for North (the second +## cue beside the color, as on the tiles). +static func owner_badge(p: int, size := 14.0) -> Control: + var c := Control.new() + c.custom_minimum_size = Vector2(size, size) + c.mouse_filter = Control.MOUSE_FILTER_IGNORE + c.draw.connect(func(): + var col: Color = Style.OWNER[p] + var r := Rect2(Vector2.ZERO, c.size) + c.draw_rect(r, Color(col, 0.18)) + if p == 0: + var n := 4 + for i in range(-n, n + 1): + var x := i * r.size.x / n * 0.75 + c.draw_line(Vector2(x, r.size.y), Vector2(x + r.size.y, 0), col, 1.5, true) + else: + for yy in 3: + for xx in 3: + c.draw_circle(Vector2((xx + 0.5) * r.size.x / 3, (yy + 0.5) * r.size.y / 3), r.size.x / 10, col) + c.draw_rect(r, col, false, 1.0)) + c.clip_contents = true + return c + + +# --------------------------------------------------------------------------------------------- +# Forms + +## The new-game form into `box`: seed, side and bot style. `on_start` gets {seed, human, style}. +## With `on_cancel`, there's a Cancel button too. +static func start_form(box: Container, defaults: Dictionary, on_start: Callable, on_cancel := Callable()) -> void: + var grid := GridContainer.new() + grid.columns = 2 + grid.add_theme_constant_override("h_separation", 14) + grid.add_theme_constant_override("v_separation", 8) + box.add_child(grid) + var seed_edit := LineEdit.new() + seed_edit.text = str(defaults.get("seed", randi_range(1, 999999))) + seed_edit.custom_minimum_size = Vector2(220, 0) + grid.add_child(label("SEED", "Muted")) + grid.add_child(seed_edit) + var side := OptionButton.new() + side.add_item("South (S1)") + side.add_item("North (S2)") + side.selected = defaults.get("human", 0) + side.focus_mode = Control.FOCUS_NONE + grid.add_child(label("YOU PLAY", "Muted")) + grid.add_child(side) + var style := OptionButton.new() + style.focus_mode = Control.FOCUS_NONE + var styles: Dictionary = GreedyBot.STYLES + var keys := styles.keys() + for k in keys: + style.add_item(styles[k].label) + style.selected = maxi(0, keys.find(defaults.get("style", "greedy"))) + grid.add_child(label("OPPONENT", "Muted")) + grid.add_child(style) + var about := muted(styles[keys[style.selected]].about) + box.add_child(about) + style.item_selected.connect(func(i): about.text = styles[keys[i]].about) + var row := HBoxContainer.new() + row.add_theme_constant_override("separation", 10) + row.add_child(button("DEAL ▸", func(): + on_start.call({"seed": int(seed_edit.text) if seed_edit.text.is_valid_int() else randi_range(1, 999999), + "human": side.selected, "style": keys[style.selected]}), "PrimaryButton")) + if on_cancel.is_valid(): + row.add_child(button("Cancel", on_cancel)) + box.add_child(row) + + +## The settings form into `box`. `on_done` gets the new settings. +static func settings_form(box: Container, settings: Dictionary, on_done: Callable) -> void: + box.add_child(label("WHEN THE GAME STOPS FOR YOU TO RESPOND", "Muted")) + var stops := OptionButton.new() + stops.focus_mode = Control.FOCUS_NONE + var stop_ids := ["combat", "all", "never"] + for text in ["In combat only", "Every opponent move", "Never"]: + stops.add_item(text) + stops.selected = maxi(0, stop_ids.find(settings.stops)) + box.add_child(stops) + box.add_child(muted("Hold Shift to stop at the next window anyway.")) + var skip := CheckBox.new() + skip.text = "Skip steps where End and Salvage are the only moves" + skip.button_pressed = settings.autoSkip + skip.focus_mode = Control.FOCUS_NONE + box.add_child(skip) + var check := CheckBox.new() + check.text = "Check the rule invariants after every move" + check.button_pressed = settings.checkInvariants + check.focus_mode = Control.FOCUS_NONE + box.add_child(check) + box.add_child(label("ANIMATION", "Muted")) + var anim := OptionButton.new() + anim.focus_mode = Control.FOCUS_NONE + var anim_ids: Array = GameSettings.ANIM_SPEEDS.keys() + for k in anim_ids: + anim.add_item(GameSettings.ANIM_SPEEDS[k].label) + anim.selected = maxi(0, anim_ids.find(settings.get("anim", "normal"))) + box.add_child(anim) + var speed_label := label("") + box.add_child(speed_label) + var speed := HSlider.new() + speed.min_value = 0.0 + speed.max_value = 1.5 + speed.step = 0.05 + speed.value = settings.botDelay + var show_speed := func(x): speed_label.text = "Bot pause between moves: %.2fs" % x + show_speed.call(speed.value) + speed.value_changed.connect(show_speed) + box.add_child(speed) + box.add_child(button("Done", func(): + on_done.call({"stops": stop_ids[stops.selected], "autoSkip": skip.button_pressed, + "checkInvariants": check.button_pressed, "botDelay": speed.value, "anim": anim_ids[anim.selected]}), "PrimaryButton")) diff --git a/ui/widgets.gd.uid b/ui/widgets.gd.uid new file mode 100644 index 0000000..199ec48 --- /dev/null +++ b/ui/widgets.gd.uid @@ -0,0 +1 @@ +uid://ctlo6e1kgdksi