cuju-render 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cuju/render/__init__.py +759 -0
- cuju/render/__main__.py +1065 -0
- cuju/render/_export/__init__.py +3 -0
- cuju/render/_export/feed.py +542 -0
- cuju/render/_export/sizes.py +157 -0
- cuju/render/_export/video.py +1618 -0
- cuju/render/_export/video_jobs.py +408 -0
- cuju/render/_format/__init__.py +3 -0
- cuju/render/_format/annotations.py +235 -0
- cuju/render/_format/codec.py +307 -0
- cuju/render/_format/keep.py +121 -0
- cuju/render/_format/recording.py +860 -0
- cuju/render/_format/writer.py +54 -0
- cuju/render/_guide/__init__.py +3 -0
- cuju/render/_guide/doctor.py +523 -0
- cuju/render/_guide/help.py +62 -0
- cuju/render/_guide/tutorial.py +254 -0
- cuju/render/_http/__init__.py +3 -0
- cuju/render/_http/commands.py +57 -0
- cuju/render/_http/headers.py +103 -0
- cuju/render/_http/launch.py +500 -0
- cuju/render/_http/launchers.py +408 -0
- cuju/render/_http/pwa.py +128 -0
- cuju/render/_http/server.py +2105 -0
- cuju/render/_http/window.py +360 -0
- cuju/render/_moments/__init__.py +3 -0
- cuju/render/_moments/captions.py +284 -0
- cuju/render/_moments/events.py +1123 -0
- cuju/render/_moments/search.py +694 -0
- cuju/render/_packages/__init__.py +3 -0
- cuju/render/_packages/glsl.py +746 -0
- cuju/render/_packages/loudness.py +334 -0
- cuju/render/_packages/pack.py +1959 -0
- cuju/render/_packages/presentation.py +1376 -0
- cuju/render/_packages/vocabulary.py +609 -0
- cuju/render/_playing/__init__.py +3 -0
- cuju/render/_playing/achievements.py +463 -0
- cuju/render/_playing/bench.py +609 -0
- cuju/render/_playing/challenges.py +1813 -0
- cuju/render/_playing/demo.py +323 -0
- cuju/render/_playing/draw.py +211 -0
- cuju/render/_playing/errors.py +20 -0
- cuju/render/_playing/game.py +645 -0
- cuju/render/_playing/limits.py +339 -0
- cuju/render/_playing/play.py +926 -0
- cuju/render/_playing/policy_worker.py +250 -0
- cuju/render/_playing/strict.py +810 -0
- cuju/render/_registry/__init__.py +3 -0
- cuju/render/_registry/clips.py +394 -0
- cuju/render/_registry/joints.py +108 -0
- cuju/render/_registry/teams.py +2058 -0
- cuju/render/_store/__init__.py +3 -0
- cuju/render/_store/home.py +70 -0
- cuju/render/_store/library.py +604 -0
- cuju/render/_store/samples.py +163 -0
- cuju/render/_text/__init__.py +3 -0
- cuju/render/_text/languages.py +637 -0
- cuju/render/_text/messages.py +1396 -0
- cuju/render/_tournaments/__init__.py +3 -0
- cuju/render/_tournaments/results.py +547 -0
- cuju/render/_tournaments/tournament.py +2742 -0
- cuju/render/_tournaments/tournament_cli.py +587 -0
- cuju/render/_tournaments/tournament_runner.py +1975 -0
- cuju/render/_version.py +6 -0
- cuju/render/_watch/__init__.py +3 -0
- cuju/render/_watch/grid.py +265 -0
- cuju/render/_watch/live.py +664 -0
- cuju/render/_watch/notebook.py +79 -0
- cuju/render/_watch/show.py +171 -0
- cuju/render/samples/sample-11v11.cjr +0 -0
- cuju/render/samples/sample-5v5.cjr +0 -0
- cuju/render/samples/teams/starter/main.py +33 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_easy.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_hard.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_medium.py +46 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_easy.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_hard.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_medium.py +34 -0
- cuju/render/web/assets/adboard_polygon.webp +0 -0
- cuju/render/web/assets/adboard_your_ad_here.webp +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-combatmelee.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-general.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementadvanced.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementbasic.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-simulation.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-special.glb +0 -0
- cuju/render/web/assets/ball.glb +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/corner.mp4 +0 -0
- cuju/render/web/assets/challenges/corner.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.webp +0 -0
- cuju/render/web/assets/challenges/manifest.json +375 -0
- cuju/render/web/assets/challenges/one_on_one.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one.webp +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.webp +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.mp4 +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.webp +0 -0
- cuju/render/web/assets/crowd.webp +0 -0
- cuju/render/web/assets/crowd_normal.webp +0 -0
- cuju/render/web/assets/cuju-logo-384.png +0 -0
- cuju/render/web/assets/cuju-logo.png +0 -0
- cuju/render/web/assets/cuju-logo.svg +46 -0
- cuju/render/web/assets/cuju-mark-light.svg +33 -0
- cuju/render/web/assets/cuju-mark.svg +33 -0
- cuju/render/web/assets/goal.glb +0 -0
- cuju/render/web/assets/grass.webp +0 -0
- cuju/render/web/assets/hair_black.png +0 -0
- cuju/render/web/assets/hair_blonde.png +0 -0
- cuju/render/web/assets/hair_brown.png +0 -0
- cuju/render/web/assets/hair_darkblonde.png +0 -0
- cuju/render/web/assets/hair_long01.glb +0 -0
- cuju/render/web/assets/hair_long02.glb +0 -0
- cuju/render/web/assets/hair_medium01.glb +0 -0
- cuju/render/web/assets/hair_red.png +0 -0
- cuju/render/web/assets/hair_short01.glb +0 -0
- cuju/render/web/assets/hair_short02.glb +0 -0
- cuju/render/web/assets/icons/cuju-192.png +0 -0
- cuju/render/web/assets/icons/cuju-512.png +0 -0
- cuju/render/web/assets/icons/cuju-maskable-512.png +0 -0
- cuju/render/web/assets/kit_goalkeeper.webp +0 -0
- cuju/render/web/assets/kit_mask.png +0 -0
- cuju/render/web/assets/kit_normal.webp +0 -0
- cuju/render/web/assets/manifest.json +601 -0
- cuju/render/web/assets/models/kaykit-barbarian.glb +0 -0
- cuju/render/web/assets/models/kaykit-barbarian.json +23 -0
- cuju/render/web/assets/models/kaykit-knight.glb +0 -0
- cuju/render/web/assets/models/kaykit-knight.json +23 -0
- cuju/render/web/assets/models/kaykit-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.glb +0 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.json +23 -0
- cuju/render/web/assets/models/kaykit-ranger.glb +0 -0
- cuju/render/web/assets/models/kaykit-ranger.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.json +23 -0
- cuju/render/web/assets/pitch.webp +0 -0
- cuju/render/web/assets/pitch_normal.webp +0 -0
- cuju/render/web/assets/player.glb +0 -0
- cuju/render/web/assets/shoe.webp +0 -0
- cuju/render/web/assets/shoe_sole.png +0 -0
- cuju/render/web/assets/skin_01.png +0 -0
- cuju/render/web/assets/skin_02.png +0 -0
- cuju/render/web/assets/skin_03.png +0 -0
- cuju/render/web/assets/skin_04.png +0 -0
- cuju/render/web/assets/sounds/applause.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-1.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-2.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-3.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-4.ogg +0 -0
- cuju/render/web/assets/sounds/city-horn.ogg +0 -0
- cuju/render/web/assets/sounds/city-loop.ogg +0 -0
- cuju/render/web/assets/sounds/city-siren.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-cheer.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-loop.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-ooh.ogg +0 -0
- cuju/render/web/assets/sounds/gulls.ogg +0 -0
- cuju/render/web/assets/sounds/neon-sting.ogg +0 -0
- cuju/render/web/assets/sounds/rain-loop.ogg +0 -0
- cuju/render/web/assets/sounds/sounds.json +46 -0
- cuju/render/web/assets/sounds/space-beep.ogg +0 -0
- cuju/render/web/assets/sounds/space-hum.ogg +0 -0
- cuju/render/web/assets/sounds/space-radio.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-long.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-short.ogg +0 -0
- cuju/render/web/assets/sounds/wind-loop.ogg +0 -0
- cuju/render/web/easy.css +357 -0
- cuju/render/web/export.html +23 -0
- cuju/render/web/feed.css +262 -0
- cuju/render/web/feed.html +28 -0
- cuju/render/web/flat.css +120 -0
- cuju/render/web/home.css +837 -0
- cuju/render/web/index.html +373 -0
- cuju/render/web/js/boot.js +50 -0
- cuju/render/web/js/broadcast/audio.js +2141 -0
- cuju/render/web/js/broadcast/celebrate.js +1238 -0
- cuju/render/web/js/broadcast/decisions.js +609 -0
- cuju/render/web/js/broadcast/hud.js +352 -0
- cuju/render/web/js/broadcast/show.js +3614 -0
- cuju/render/web/js/broadcast/transition.js +2231 -0
- cuju/render/web/js/broadcast/voices.js +153 -0
- cuju/render/web/js/capture.js +101 -0
- cuju/render/web/js/core/accessibility.js +90 -0
- cuju/render/web/js/core/api.js +429 -0
- cuju/render/web/js/core/comfort.js +135 -0
- cuju/render/web/js/core/i18n.js +705 -0
- cuju/render/web/js/core/icons.js +167 -0
- cuju/render/web/js/core/input-settings.js +156 -0
- cuju/render/web/js/core/keys.js +277 -0
- cuju/render/web/js/core/language-ui.js +125 -0
- cuju/render/web/js/core/menu.js +853 -0
- cuju/render/web/js/core/names.js +113 -0
- cuju/render/web/js/core/page-structure.js +110 -0
- cuju/render/web/js/core/scenarios.js +109 -0
- cuju/render/web/js/core/spoilers.js +236 -0
- cuju/render/web/js/core/typeahead.js +38 -0
- cuju/render/web/js/export/dom-picture.js +330 -0
- cuju/render/web/js/export/export-host.js +97 -0
- cuju/render/web/js/export/feed-dialog.js +191 -0
- cuju/render/web/js/export/feed-params.js +266 -0
- cuju/render/web/js/export/feed.js +363 -0
- cuju/render/web/js/export/mp4-mux.js +295 -0
- cuju/render/web/js/export/photo-core.js +313 -0
- cuju/render/web/js/export/photo.js +1314 -0
- cuju/render/web/js/export/safe-frame.js +59 -0
- cuju/render/web/js/export/size-fields.js +103 -0
- cuju/render/web/js/export/sizes.js +178 -0
- cuju/render/web/js/export/video-boot.js +55 -0
- cuju/render/web/js/export/video-browser.js +325 -0
- cuju/render/web/js/export/video-export.js +417 -0
- cuju/render/web/js/export/video-plan.js +207 -0
- cuju/render/web/js/export/video-range.js +185 -0
- cuju/render/web/js/export/webm-mux.js +198 -0
- cuju/render/web/js/feed-boot.js +151 -0
- cuju/render/web/js/feed-frame.js +101 -0
- cuju/render/web/js/help/doctor.js +488 -0
- cuju/render/web/js/help/firstrun.js +379 -0
- cuju/render/web/js/help/help-center.js +438 -0
- cuju/render/web/js/help/install-offer.js +164 -0
- cuju/render/web/js/help/install-state.js +104 -0
- cuju/render/web/js/help/lessons-core.js +207 -0
- cuju/render/web/js/help/lessons.js +463 -0
- cuju/render/web/js/help/palette.js +584 -0
- cuju/render/web/js/help/pwa.js +257 -0
- cuju/render/web/js/help/tour-core.js +241 -0
- cuju/render/web/js/help/tour.js +461 -0
- cuju/render/web/js/main.js +2513 -0
- cuju/render/web/js/pages/draw.js +188 -0
- cuju/render/web/js/pages/fieldpage.js +530 -0
- cuju/render/web/js/pages/home.js +521 -0
- cuju/render/web/js/pages/matches.js +779 -0
- cuju/render/web/js/pages/moments-ui.js +359 -0
- cuju/render/web/js/pages/queue-filters.js +63 -0
- cuju/render/web/js/pages/recording-groups.js +80 -0
- cuju/render/web/js/pages/recordings.js +1069 -0
- cuju/render/web/js/play/bench.js +347 -0
- cuju/render/web/js/play/challenges.js +1302 -0
- cuju/render/web/js/play/medals.js +127 -0
- cuju/render/web/js/play/play.js +1953 -0
- cuju/render/web/js/play/teasers.js +196 -0
- cuju/render/web/js/play/touch.js +350 -0
- cuju/render/web/js/play/tournament-layout.js +487 -0
- cuju/render/web/js/play/tournament-results.js +441 -0
- cuju/render/web/js/play/tournament-strict.js +560 -0
- cuju/render/web/js/play/tournament.js +2585 -0
- cuju/render/web/js/players/animate.js +972 -0
- cuju/render/web/js/players/clips.js +224 -0
- cuju/render/web/js/players/kaykit.js +162 -0
- cuju/render/web/js/players/kits.js +676 -0
- cuju/render/web/js/players/number-patch.js +82 -0
- cuju/render/web/js/players/players.js +2694 -0
- cuju/render/web/js/players/recolor.js +893 -0
- cuju/render/web/js/players/retarget.js +325 -0
- cuju/render/web/js/players/rig-numbers.js +174 -0
- cuju/render/web/js/presentation/animator.js +231 -0
- cuju/render/web/js/presentation/assign.js +85 -0
- cuju/render/web/js/presentation/behaviors.js +440 -0
- cuju/render/web/js/presentation/budget.js +209 -0
- cuju/render/web/js/presentation/catalog.js +1674 -0
- cuju/render/web/js/presentation/clocks.js +72 -0
- cuju/render/web/js/presentation/commands.js +301 -0
- cuju/render/web/js/presentation/contract.js +240 -0
- cuju/render/web/js/presentation/effects.js +904 -0
- cuju/render/web/js/presentation/flash.js +605 -0
- cuju/render/web/js/presentation/freeze-worklet.js +22 -0
- cuju/render/web/js/presentation/glsl.js +464 -0
- cuju/render/web/js/presentation/host.js +323 -0
- cuju/render/web/js/presentation/index.js +2066 -0
- cuju/render/web/js/presentation/loudness-worklet.js +235 -0
- cuju/render/web/js/presentation/loudness.js +740 -0
- cuju/render/web/js/presentation/moments.js +536 -0
- cuju/render/web/js/presentation/post.js +327 -0
- cuju/render/web/js/presentation/preview.js +180 -0
- cuju/render/web/js/presentation/protocol.js +174 -0
- cuju/render/web/js/presentation/reach.js +158 -0
- cuju/render/web/js/presentation/rigging.js +130 -0
- cuju/render/web/js/presentation/sandbox.js +157 -0
- cuju/render/web/js/presentation/shaders.js +235 -0
- cuju/render/web/js/presentation/stage.js +402 -0
- cuju/render/web/js/presentation/teamaudio.js +722 -0
- cuju/render/web/js/presentation/tracks.js +197 -0
- cuju/render/web/js/presentation/values.js +81 -0
- cuju/render/web/js/recording/annotation-data.js +203 -0
- cuju/render/web/js/recording/captions.js +491 -0
- cuju/render/web/js/recording/codec.js +185 -0
- cuju/render/web/js/recording/decode-worker.js +70 -0
- cuju/render/web/js/recording/decode.js +94 -0
- cuju/render/web/js/recording/episodes.js +46 -0
- cuju/render/web/js/recording/format.js +461 -0
- cuju/render/web/js/recording/live.js +348 -0
- cuju/render/web/js/recording/moments-query.js +59 -0
- cuju/render/web/js/recording/moments.js +149 -0
- cuju/render/web/js/recording/pose.js +86 -0
- cuju/render/web/js/recording/timeline.js +275 -0
- cuju/render/web/js/teams/art.js +50 -0
- cuju/render/web/js/teams/clip-editor.js +293 -0
- cuju/render/web/js/teams/editor.js +1979 -0
- cuju/render/web/js/teams/library.js +344 -0
- cuju/render/web/js/teams/painter.js +633 -0
- cuju/render/web/js/teams/surprise-ui.js +195 -0
- cuju/render/web/js/teams/surprise.js +497 -0
- cuju/render/web/js/teams/team-check.js +127 -0
- cuju/render/web/js/watch/annotations.js +270 -0
- cuju/render/web/js/watch/flat.js +366 -0
- cuju/render/web/js/watch/grid.js +436 -0
- cuju/render/web/js/watch/pitch2d.js +289 -0
- cuju/render/web/js/watch/player-tools.js +192 -0
- cuju/render/web/js/watch/presets.js +201 -0
- cuju/render/web/js/world/arenas.js +997 -0
- cuju/render/web/js/world/ball.js +204 -0
- cuju/render/web/js/world/cameras.js +982 -0
- cuju/render/web/js/world/crowd.js +376 -0
- cuju/render/web/js/world/field.js +227 -0
- cuju/render/web/js/world/framing.js +145 -0
- cuju/render/web/js/world/occlusion.js +48 -0
- cuju/render/web/js/world/pitch.js +703 -0
- cuju/render/web/js/world/scene.js +395 -0
- cuju/render/web/js/world/sky.js +325 -0
- cuju/render/web/js/world/stadium.js +1262 -0
- cuju/render/web/js/world/vendor-sky.js +367 -0
- cuju/render/web/js/world/weather.js +264 -0
- cuju/render/web/languages/en.json +4750 -0
- cuju/render/web/lessons.json +137 -0
- cuju/render/web/manifest.webmanifest +23 -0
- cuju/render/web/style.css +8399 -0
- cuju/render/web/sw.js +235 -0
- cuju/render/web/vendor/fabric/LICENSE +16 -0
- cuju/render/web/vendor/fabric/fabric.min.mjs +1 -0
- cuju/render/web/vendor/lucide/LICENSE +43 -0
- cuju/render/web/vendor/lucide/icons.js +141 -0
- cuju/render/web/vendor/three/LICENSE +21 -0
- cuju/render/web/vendor/three/build/three.core.js +60586 -0
- cuju/render/web/vendor/three/build/three.module.js +19719 -0
- cuju/render/web/vendor/three/examples/jsm/loaders/GLTFLoader.js +4925 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/EffectComposer.js +365 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/OutputPass.js +148 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/RenderPass.js +193 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/UnrealBloomPass.js +541 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- cuju/render/web/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1501 -0
- cuju/render/web/vendor/three/examples/jsm/utils/SkeletonUtils.js +496 -0
- cuju_render-0.1.0.dist-info/METADATA +116 -0
- cuju_render-0.1.0.dist-info/RECORD +382 -0
- cuju_render-0.1.0.dist-info/WHEEL +4 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSE +202 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC-BY-4.0.txt +396 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC0-1.0.txt +127 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/ISC.txt +16 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/MIT.txt +24 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/Unlicense.txt +13 -0
- cuju_render-0.1.0.dist-info/licenses/NOTICE +35 -0
|
@@ -0,0 +1,1959 @@
|
|
|
1
|
+
# Copyright 2026 The cuju Authors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""The author tools of team presentation packages, `cuju render pack check` and `pack new`.
|
|
5
|
+
|
|
6
|
+
`check` reads a package the way the server and the page read it and reports what each of them
|
|
7
|
+
would make of it, before the author imports the team. It takes a team's submission folder with
|
|
8
|
+
`cuju-team` inside, a `cuju-team` folder, a `presentation` folder or a `.zip` export of a team,
|
|
9
|
+
which it reads in memory. It runs every check of an import and of serving, the paths, kinds and
|
|
10
|
+
sizes of the files, the limits of a package and the manifest's own check, and adds the checks
|
|
11
|
+
the page makes as it draws, the static rules of the shaders, the static cost of every model and
|
|
12
|
+
attachment against the budgets of each quality, the names that the rig, behaviours and clips give
|
|
13
|
+
to nodes and animations of the models, the contact markers of action clips and the loudness and
|
|
14
|
+
true peak of every WAV sample.
|
|
15
|
+
|
|
16
|
+
Errors are what makes the server leave a part out or refuse the package, or what the page can never
|
|
17
|
+
run, a required feature it lacks, a team model that import sets aside or a module that does not
|
|
18
|
+
parse. Warnings are what the page holds back or degrades as it draws, and information is everything
|
|
19
|
+
else worth knowing.
|
|
20
|
+
|
|
21
|
+
The check compiles no shader and runs no JavaScript. It reads each shader by the static rules of
|
|
22
|
+
`_glsl`, which also catch an operator with nothing after it, and parses the worker and the worklet
|
|
23
|
+
with Node.js when Node.js is installed. The page compiles every shader before it draws and names
|
|
24
|
+
in a notice a shader that does not compile or a worker that does not load.
|
|
25
|
+
|
|
26
|
+
`new` writes a small working package for an author to start from, a team submission folder with
|
|
27
|
+
an agent, a team file and a package that uses most levels of contract 1.1.
|
|
28
|
+
|
|
29
|
+
Loudness follows ITU-R BS.1770 with its K weighting, the momentary loudness of 400 ms, the
|
|
30
|
+
short-term loudness of 3 s, the gated integrated loudness and the true peak of four times
|
|
31
|
+
oversampling, as `web/js/presentation/loudness.js` measures on the page. It uses numpy when it
|
|
32
|
+
imports and pure Python otherwise, and reads at most the first 60 seconds of each sample.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
from __future__ import annotations
|
|
36
|
+
|
|
37
|
+
import base64
|
|
38
|
+
import difflib
|
|
39
|
+
import io
|
|
40
|
+
import json
|
|
41
|
+
import math
|
|
42
|
+
import os
|
|
43
|
+
import re
|
|
44
|
+
import struct
|
|
45
|
+
import zipfile
|
|
46
|
+
import zlib
|
|
47
|
+
from pathlib import Path, PurePosixPath
|
|
48
|
+
from typing import Any
|
|
49
|
+
|
|
50
|
+
from cuju.errors import ArgumentError
|
|
51
|
+
|
|
52
|
+
from .._registry import joints as _joints
|
|
53
|
+
from .._registry import teams as _teams
|
|
54
|
+
from . import glsl as _glsl
|
|
55
|
+
from . import presentation as _presentation
|
|
56
|
+
from . import vocabulary as _vocabulary
|
|
57
|
+
from .loudness import MAXIMUM_SECONDS as MAXIMUM_SECONDS
|
|
58
|
+
from .loudness import MOMENTARY_CEILING as MOMENTARY_CEILING
|
|
59
|
+
from .loudness import SHORT_TERM_CEILING as SHORT_TERM_CEILING
|
|
60
|
+
from .loudness import TARGET_LUFS as TARGET_LUFS
|
|
61
|
+
from .loudness import TRUE_PEAK_CEILING as TRUE_PEAK_CEILING
|
|
62
|
+
from .loudness import _wav as _wav
|
|
63
|
+
from .loudness import loudness as loudness
|
|
64
|
+
|
|
65
|
+
FOLDER = _presentation.FOLDER
|
|
66
|
+
MANIFEST = _presentation.MANIFEST
|
|
67
|
+
QUALITIES = ('high', 'medium', 'low')
|
|
68
|
+
_MB = 1024 * 1024
|
|
69
|
+
# The budgets of a team that a package's static counts meet, after docs/presentation.md and the
|
|
70
|
+
# table of web/js/presentation/budget.js.
|
|
71
|
+
BUDGETS = {
|
|
72
|
+
'high': {
|
|
73
|
+
'drawCalls': 150,
|
|
74
|
+
'triangles': 400_000,
|
|
75
|
+
'textureBytes': 128 * _MB,
|
|
76
|
+
'particles': 20_000,
|
|
77
|
+
'lights': 4,
|
|
78
|
+
'localLights': 16,
|
|
79
|
+
'shaders': _glsl.BUDGET['high'],
|
|
80
|
+
'worklets': 4,
|
|
81
|
+
'audioBytes': 64 * _MB,
|
|
82
|
+
'fullscreen': 1,
|
|
83
|
+
},
|
|
84
|
+
'medium': {
|
|
85
|
+
'drawCalls': 100,
|
|
86
|
+
'triangles': 200_000,
|
|
87
|
+
'textureBytes': 64 * _MB,
|
|
88
|
+
'particles': 8_000,
|
|
89
|
+
'lights': 2,
|
|
90
|
+
'localLights': 16,
|
|
91
|
+
'shaders': _glsl.BUDGET['medium'],
|
|
92
|
+
'worklets': 4,
|
|
93
|
+
'audioBytes': 64 * _MB,
|
|
94
|
+
'fullscreen': 0,
|
|
95
|
+
},
|
|
96
|
+
'low': {
|
|
97
|
+
'drawCalls': 60,
|
|
98
|
+
'triangles': 80_000,
|
|
99
|
+
'textureBytes': 32 * _MB,
|
|
100
|
+
'particles': 2_000,
|
|
101
|
+
'lights': 1,
|
|
102
|
+
'localLights': 16,
|
|
103
|
+
'shaders': _glsl.BUDGET['low'],
|
|
104
|
+
'worklets': 2,
|
|
105
|
+
'audioBytes': 32 * _MB,
|
|
106
|
+
'fullscreen': 0,
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
_BUDGET_NAMES = {
|
|
110
|
+
'drawCalls': 'draw calls',
|
|
111
|
+
'triangles': 'triangles',
|
|
112
|
+
'textureBytes': 'bytes of texture memory',
|
|
113
|
+
'particles': 'particles',
|
|
114
|
+
'lights': 'pool lights',
|
|
115
|
+
'localLights': 'local lights',
|
|
116
|
+
'shaders': 'shader programs',
|
|
117
|
+
'worklets': 'worklet nodes',
|
|
118
|
+
'audioBytes': 'bytes of decoded audio',
|
|
119
|
+
'fullscreen': 'full screen passes',
|
|
120
|
+
}
|
|
121
|
+
# The sample rate at which the page decodes sound, for the estimate of decoded audio.
|
|
122
|
+
_DECODE_RATE = 48000
|
|
123
|
+
# Features that only a worker uses, whose lack drops the worker and keeps the manifest.
|
|
124
|
+
WORKER_FEATURES = ('drivers.worker', 'geometry.worker', 'overlay.offscreen')
|
|
125
|
+
# The roles of clips that meet the ball, whose clips may carry a contact marker.
|
|
126
|
+
ACTION_ROLES = (
|
|
127
|
+
'kick',
|
|
128
|
+
'pass.short',
|
|
129
|
+
'pass.long',
|
|
130
|
+
'pass.high',
|
|
131
|
+
'shot',
|
|
132
|
+
'header',
|
|
133
|
+
'volley',
|
|
134
|
+
'slide',
|
|
135
|
+
'trip',
|
|
136
|
+
'catch',
|
|
137
|
+
'parry',
|
|
138
|
+
'dive.left',
|
|
139
|
+
'dive.right',
|
|
140
|
+
'throwIn',
|
|
141
|
+
'trap',
|
|
142
|
+
'deflect',
|
|
143
|
+
'restart.kickoff',
|
|
144
|
+
'restart.goal_kick',
|
|
145
|
+
'restart.free_kick',
|
|
146
|
+
'restart.corner',
|
|
147
|
+
'restart.throw_in',
|
|
148
|
+
'restart.penalty',
|
|
149
|
+
)
|
|
150
|
+
_KINDS = {
|
|
151
|
+
'.glb': 'model',
|
|
152
|
+
'.png': 'texture',
|
|
153
|
+
'.jpg': 'texture',
|
|
154
|
+
'.webp': 'texture',
|
|
155
|
+
'.ktx2': 'texture',
|
|
156
|
+
'.ogg': 'sound',
|
|
157
|
+
'.mp3': 'sound',
|
|
158
|
+
'.wav': 'sound',
|
|
159
|
+
'.js': 'module',
|
|
160
|
+
'.json': 'data',
|
|
161
|
+
'.glsl': 'shader',
|
|
162
|
+
'.wasm': 'webassembly',
|
|
163
|
+
}
|
|
164
|
+
_TEXTURES = ('.png', '.jpg', '.webp', '.ktx2')
|
|
165
|
+
_SOUNDS = ('.ogg', '.mp3', '.wav')
|
|
166
|
+
_MAXIMUM_TEAM_FILE = 1024 * 1024
|
|
167
|
+
_MAXIMUM_MODEL = 30 * _MB
|
|
168
|
+
# The bytes an archive may unpack to before the rest is counted by size alone.
|
|
169
|
+
_MAXIMUM_READ = 200 * _MB
|
|
170
|
+
_JSON_CHUNK = 0x4E4F534A
|
|
171
|
+
_BIN_CHUNK = 0x004E4942
|
|
172
|
+
# What reading a damaged file may raise.
|
|
173
|
+
_UNREADABLE = (ArgumentError, OSError, ValueError, KeyError, TypeError, IndexError, struct.error)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _sanitized(name: str) -> str:
|
|
177
|
+
"""Returns a node name as three.js keeps it, with spaces as underscores and no `[].:/`."""
|
|
178
|
+
return re.sub(r'[\[\].:/]', '', re.sub(r'\s', '_', name))
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
# Reading a package.
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class _Source:
|
|
185
|
+
"""The files of a package as read from a folder or an archive, and what lies around them."""
|
|
186
|
+
|
|
187
|
+
def __init__(self, label: str) -> None:
|
|
188
|
+
self.label = label
|
|
189
|
+
# The files of the presentation folder by their paths inside it, each with its size.
|
|
190
|
+
self.sizes: dict[str, int] = {}
|
|
191
|
+
self.data: dict[str, bytes] = {}
|
|
192
|
+
self.paths: dict[str, Path] = {}
|
|
193
|
+
self.errors: list[str] = []
|
|
194
|
+
self.info: list[str] = []
|
|
195
|
+
self.team: Any = None
|
|
196
|
+
self.model: bytes | None = None
|
|
197
|
+
|
|
198
|
+
def read(self, name: str) -> bytes:
|
|
199
|
+
if name in self.data:
|
|
200
|
+
return self.data[name]
|
|
201
|
+
if name in self.paths:
|
|
202
|
+
return self.paths[name].read_bytes()
|
|
203
|
+
raise ArgumentError(f'expected {name} to be read, an archive member past what is read')
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def _team_files(source: _Source, team: bytes | None, model: bytes | None) -> None:
|
|
207
|
+
"""Keeps the team file and model of the team around a package."""
|
|
208
|
+
if team is not None:
|
|
209
|
+
try:
|
|
210
|
+
source.team = json.loads(team)
|
|
211
|
+
except (ValueError, UnicodeDecodeError):
|
|
212
|
+
source.errors.append('team.json holds no JSON, so import keeps the defaults of a team')
|
|
213
|
+
source.model = model
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _folder(path: Path) -> _Source:
|
|
217
|
+
"""Reads a team's submission folder, its `cuju-team` folder or a `presentation` folder."""
|
|
218
|
+
if (path / _teams.TEAM_FOLDER).is_dir():
|
|
219
|
+
root, team = path, path / _teams.TEAM_FOLDER
|
|
220
|
+
package = team / FOLDER
|
|
221
|
+
elif (path / FOLDER).is_dir():
|
|
222
|
+
root, team, package = None, path, path / FOLDER
|
|
223
|
+
elif (path / MANIFEST).is_file():
|
|
224
|
+
root, team, package = None, path.parent, path
|
|
225
|
+
else:
|
|
226
|
+
raise ArgumentError(
|
|
227
|
+
f'expected a team submission folder, a cuju-team folder or a presentation folder, '
|
|
228
|
+
f'found {str(path)!r}'
|
|
229
|
+
)
|
|
230
|
+
source = _Source(str(path))
|
|
231
|
+
if root is not None and not (root / 'main.py').is_file():
|
|
232
|
+
source.errors.append('the submission holds no main.py, which import needs')
|
|
233
|
+
if (team / 'team.json').is_file() or team.name == _teams.TEAM_FOLDER:
|
|
234
|
+
team_json = team / 'team.json'
|
|
235
|
+
model = team / 'model.glb'
|
|
236
|
+
_team_files(
|
|
237
|
+
source,
|
|
238
|
+
team_json.read_bytes()
|
|
239
|
+
if team_json.is_file() and team_json.stat().st_size <= _MAXIMUM_TEAM_FILE
|
|
240
|
+
else None,
|
|
241
|
+
model.read_bytes()
|
|
242
|
+
if model.is_file() and model.stat().st_size <= _MAXIMUM_MODEL
|
|
243
|
+
else None,
|
|
244
|
+
)
|
|
245
|
+
if not package.is_dir():
|
|
246
|
+
return source
|
|
247
|
+
for directory, folders, files in os.walk(package, followlinks=False):
|
|
248
|
+
here = Path(directory)
|
|
249
|
+
for name in sorted(folders):
|
|
250
|
+
if (here / name).is_symlink():
|
|
251
|
+
relative = (here / name).relative_to(package).as_posix()
|
|
252
|
+
source.errors.append(f'{relative} is a link, which import deletes')
|
|
253
|
+
for name in files:
|
|
254
|
+
item = here / name
|
|
255
|
+
relative = item.relative_to(package).as_posix()
|
|
256
|
+
if item.is_symlink():
|
|
257
|
+
source.errors.append(f'{relative} is a link, which import deletes')
|
|
258
|
+
continue
|
|
259
|
+
source.sizes[relative] = item.stat().st_size
|
|
260
|
+
source.paths[relative] = item
|
|
261
|
+
return source
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def _archive(path: Path) -> _Source:
|
|
265
|
+
"""Reads the package of a team's `.zip` export in memory, without unpacking it."""
|
|
266
|
+
try:
|
|
267
|
+
archive = zipfile.ZipFile(path)
|
|
268
|
+
except (zipfile.BadZipFile, OSError) as error:
|
|
269
|
+
raise ArgumentError(f'expected a readable .zip archive, found {error}') from error
|
|
270
|
+
source = _Source(str(path))
|
|
271
|
+
with archive:
|
|
272
|
+
members = [item for item in archive.infolist() if not item.is_dir()]
|
|
273
|
+
names = {item.filename: item for item in members}
|
|
274
|
+
wanted = f'{_teams.TEAM_FOLDER}/{FOLDER}/{MANIFEST}'
|
|
275
|
+
found = sorted(
|
|
276
|
+
(name for name in names if name == MANIFEST or name.endswith(f'{FOLDER}/{MANIFEST}')),
|
|
277
|
+
key=len,
|
|
278
|
+
)
|
|
279
|
+
if wanted in names:
|
|
280
|
+
prefix = f'{_teams.TEAM_FOLDER}/{FOLDER}/'
|
|
281
|
+
elif found:
|
|
282
|
+
prefix = found[0][: -len(MANIFEST)]
|
|
283
|
+
else:
|
|
284
|
+
raise ArgumentError(f'expected an archive of a team that holds {wanted}')
|
|
285
|
+
if prefix == f'{_teams.TEAM_FOLDER}/{FOLDER}/':
|
|
286
|
+
if 'main.py' not in names:
|
|
287
|
+
source.errors.append('the archive holds no main.py at its top, which import needs')
|
|
288
|
+
elif prefix.endswith(f'{_teams.TEAM_FOLDER}/{FOLDER}/'):
|
|
289
|
+
source.errors.append(
|
|
290
|
+
f'the archive holds its team under {prefix[: -len(FOLDER) - 1]}, and import reads '
|
|
291
|
+
f'{_teams.TEAM_FOLDER} at the top of the archive'
|
|
292
|
+
)
|
|
293
|
+
else:
|
|
294
|
+
source.errors.append(
|
|
295
|
+
f'the archive holds its package as {prefix}{MANIFEST}, and import reads a team '
|
|
296
|
+
f'with main.py and {_teams.TEAM_FOLDER} at the top of the archive'
|
|
297
|
+
)
|
|
298
|
+
try:
|
|
299
|
+
_teams._check_unpacked(len(members), sum(item.file_size for item in members))
|
|
300
|
+
for item in members:
|
|
301
|
+
_teams._check_member(item.filename)
|
|
302
|
+
except ArgumentError as error:
|
|
303
|
+
source.errors.append(f'import refuses the archive, {error}')
|
|
304
|
+
team = prefix[: -len(FOLDER) - 1] if prefix.endswith(f'{FOLDER}/') else None
|
|
305
|
+
read = 0
|
|
306
|
+
|
|
307
|
+
def member(name: str, limit: int) -> bytes | None:
|
|
308
|
+
nonlocal read
|
|
309
|
+
item = names.get(name)
|
|
310
|
+
if item is None or item.file_size > limit or read + item.file_size > _MAXIMUM_READ:
|
|
311
|
+
return None
|
|
312
|
+
read += item.file_size
|
|
313
|
+
try:
|
|
314
|
+
return archive.read(item)
|
|
315
|
+
except (zipfile.BadZipFile, OSError, ValueError, RuntimeError, EOFError, zlib.error):
|
|
316
|
+
source.errors.append(f'{name} cannot be read from the archive')
|
|
317
|
+
return None
|
|
318
|
+
|
|
319
|
+
if team is not None:
|
|
320
|
+
_team_files(
|
|
321
|
+
source,
|
|
322
|
+
member(f'{team}team.json', _MAXIMUM_TEAM_FILE),
|
|
323
|
+
member(f'{team}model.glb', _MAXIMUM_MODEL),
|
|
324
|
+
)
|
|
325
|
+
for name, item in sorted(names.items()):
|
|
326
|
+
if not name.startswith(prefix) or name == prefix:
|
|
327
|
+
continue
|
|
328
|
+
relative = name[len(prefix) :]
|
|
329
|
+
source.sizes[relative] = item.file_size
|
|
330
|
+
suffix = PurePosixPath(relative).suffix
|
|
331
|
+
data = member(name, _presentation.MAXIMUM_BYTES.get(suffix, 0))
|
|
332
|
+
if data is not None:
|
|
333
|
+
source.data[relative] = data
|
|
334
|
+
return source
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
# Binary glTF and images.
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def _gltf(data: bytes) -> tuple[dict[str, Any], bytes]:
|
|
341
|
+
"""Returns the JSON document and the binary chunk of a binary glTF file."""
|
|
342
|
+
size, _ = struct.unpack_from('<II', data, 12)
|
|
343
|
+
document = json.loads(data[20 : 20 + size])
|
|
344
|
+
offset = 20 + size + (-size % 4)
|
|
345
|
+
binary = b''
|
|
346
|
+
if offset + 8 <= len(data):
|
|
347
|
+
length, kind = struct.unpack_from('<II', data, offset)
|
|
348
|
+
if kind == _BIN_CHUNK:
|
|
349
|
+
binary = data[offset + 8 : offset + 8 + length]
|
|
350
|
+
return document, binary
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def image_size(data: bytes) -> tuple[int, int] | None:
|
|
354
|
+
"""Returns the width and height of a PNG, JPEG, WebP or KTX2 image from its header."""
|
|
355
|
+
if data.startswith(b'\x89PNG\r\n\x1a\n') and len(data) >= 24 and data[12:16] == b'IHDR':
|
|
356
|
+
return struct.unpack_from('>II', data, 16)
|
|
357
|
+
if data.startswith(b'\xab\x4b\x54\x58\x20\x32\x30\xbb\r\n\x1a\n') and len(data) >= 28:
|
|
358
|
+
return struct.unpack_from('<II', data, 20)
|
|
359
|
+
if data[:4] == b'RIFF' and data[8:12] == b'WEBP' and len(data) >= 30:
|
|
360
|
+
chunk = data[12:16]
|
|
361
|
+
if chunk == b'VP8 ':
|
|
362
|
+
width, height = struct.unpack_from('<HH', data, 26)
|
|
363
|
+
return width & 0x3FFF, height & 0x3FFF
|
|
364
|
+
if chunk == b'VP8L':
|
|
365
|
+
(bits,) = struct.unpack_from('<I', data, 21)
|
|
366
|
+
return (bits & 0x3FFF) + 1, ((bits >> 14) & 0x3FFF) + 1
|
|
367
|
+
if chunk == b'VP8X':
|
|
368
|
+
width = int.from_bytes(data[24:27], 'little') + 1
|
|
369
|
+
height = int.from_bytes(data[27:30], 'little') + 1
|
|
370
|
+
return width, height
|
|
371
|
+
return None
|
|
372
|
+
if data.startswith(b'\xff\xd8'):
|
|
373
|
+
offset = 2
|
|
374
|
+
while offset + 9 <= len(data):
|
|
375
|
+
if data[offset] != 0xFF:
|
|
376
|
+
offset += 1
|
|
377
|
+
continue
|
|
378
|
+
marker = data[offset + 1]
|
|
379
|
+
if marker in (0xD8, 0x01) or 0xD0 <= marker <= 0xD7 or marker == 0xFF:
|
|
380
|
+
offset += 1 if marker == 0xFF else 2
|
|
381
|
+
continue
|
|
382
|
+
(length,) = struct.unpack_from('>H', data, offset + 2)
|
|
383
|
+
if 0xC0 <= marker <= 0xCF and marker not in (0xC4, 0xC8, 0xCC):
|
|
384
|
+
height, width = struct.unpack_from('>HH', data, offset + 5)
|
|
385
|
+
return width, height
|
|
386
|
+
offset += 2 + length
|
|
387
|
+
return None
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def _texture_names(value: Any, out: set[int]) -> None:
|
|
391
|
+
"""Collects the texture indices that a material, its extensions included, names."""
|
|
392
|
+
if isinstance(value, dict):
|
|
393
|
+
for key, item in value.items():
|
|
394
|
+
if (
|
|
395
|
+
key.endswith('Texture')
|
|
396
|
+
and isinstance(item, dict)
|
|
397
|
+
and isinstance(item.get('index'), int)
|
|
398
|
+
):
|
|
399
|
+
out.add(item['index'])
|
|
400
|
+
else:
|
|
401
|
+
_texture_names(item, out)
|
|
402
|
+
elif isinstance(value, list):
|
|
403
|
+
for item in value:
|
|
404
|
+
_texture_names(item, out)
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def model_stats(data: bytes) -> dict[str, Any]:
|
|
408
|
+
"""Returns the static cost and the names of a binary glTF file as the page loads it.
|
|
409
|
+
|
|
410
|
+
Returns:
|
|
411
|
+
A dictionary with `drawCalls`, a draw for each primitive of each mesh node of the scene,
|
|
412
|
+
`triangles`, a third of each primitive's indices or positions, `textureBytes`, four bytes
|
|
413
|
+
for each pixel of each texture its drawn materials name, `nodes`, the names of its nodes,
|
|
414
|
+
and `animations`, each animation's name with its `duration` in seconds and its `contact`
|
|
415
|
+
marker or `None`.
|
|
416
|
+
"""
|
|
417
|
+
document, binary = _gltf(data)
|
|
418
|
+
nodes = document.get('nodes') or []
|
|
419
|
+
meshes = document.get('meshes') or []
|
|
420
|
+
accessors = document.get('accessors') or []
|
|
421
|
+
scenes = document.get('scenes') or []
|
|
422
|
+
scene = document.get('scene', 0)
|
|
423
|
+
if isinstance(scene, int) and 0 <= scene < len(scenes) and isinstance(scenes[scene], dict):
|
|
424
|
+
roots = scenes[scene].get('nodes') or []
|
|
425
|
+
else:
|
|
426
|
+
children = {c for n in nodes if isinstance(n, dict) for c in n.get('children') or []}
|
|
427
|
+
roots = [i for i in range(len(nodes)) if i not in children]
|
|
428
|
+
seen: set[int] = set()
|
|
429
|
+
stack = [r for r in roots if isinstance(r, int)]
|
|
430
|
+
draws = triangles = 0
|
|
431
|
+
materials: set[int] = set()
|
|
432
|
+
while stack:
|
|
433
|
+
index = stack.pop()
|
|
434
|
+
if index in seen or not 0 <= index < len(nodes) or not isinstance(nodes[index], dict):
|
|
435
|
+
continue
|
|
436
|
+
seen.add(index)
|
|
437
|
+
node = nodes[index]
|
|
438
|
+
stack.extend(c for c in node.get('children') or [] if isinstance(c, int))
|
|
439
|
+
mesh = node.get('mesh')
|
|
440
|
+
if not isinstance(mesh, int) or not 0 <= mesh < len(meshes):
|
|
441
|
+
continue
|
|
442
|
+
for primitive in meshes[mesh].get('primitives') or []:
|
|
443
|
+
draws += 1
|
|
444
|
+
accessor = primitive.get('indices')
|
|
445
|
+
if not isinstance(accessor, int):
|
|
446
|
+
accessor = (primitive.get('attributes') or {}).get('POSITION')
|
|
447
|
+
if isinstance(accessor, int) and 0 <= accessor < len(accessors):
|
|
448
|
+
triangles += int(accessors[accessor].get('count', 0)) // 3
|
|
449
|
+
if isinstance(primitive.get('material'), int):
|
|
450
|
+
materials.add(primitive['material'])
|
|
451
|
+
textures: set[int] = set()
|
|
452
|
+
for index in materials:
|
|
453
|
+
if 0 <= index < len(document.get('materials') or []):
|
|
454
|
+
_texture_names(document['materials'][index], textures)
|
|
455
|
+
texture_bytes = 0
|
|
456
|
+
images = document.get('images') or []
|
|
457
|
+
views = document.get('bufferViews') or []
|
|
458
|
+
for index in textures:
|
|
459
|
+
texture = (document.get('textures') or [{}] * (index + 1))[index]
|
|
460
|
+
source = texture.get('source') if isinstance(texture, dict) else None
|
|
461
|
+
for extension in (texture.get('extensions') or {}).values() if texture else []:
|
|
462
|
+
if isinstance(extension, dict) and isinstance(extension.get('source'), int):
|
|
463
|
+
source = extension['source']
|
|
464
|
+
if not isinstance(source, int) or not 0 <= source < len(images):
|
|
465
|
+
continue
|
|
466
|
+
image = images[source]
|
|
467
|
+
content = b''
|
|
468
|
+
if isinstance(image.get('bufferView'), int) and image['bufferView'] < len(views):
|
|
469
|
+
view = views[image['bufferView']]
|
|
470
|
+
start = int(view.get('byteOffset', 0))
|
|
471
|
+
content = binary[start : start + int(view.get('byteLength', 0))]
|
|
472
|
+
elif isinstance(image.get('uri'), str) and image['uri'].startswith('data:'):
|
|
473
|
+
content = base64.b64decode(image['uri'].split(',', 1)[-1] + '==')
|
|
474
|
+
size = image_size(content)
|
|
475
|
+
if size:
|
|
476
|
+
texture_bytes += size[0] * size[1] * 4
|
|
477
|
+
animations = {}
|
|
478
|
+
for index, animation in enumerate(document.get('animations') or []):
|
|
479
|
+
if not isinstance(animation, dict):
|
|
480
|
+
continue
|
|
481
|
+
duration = 0.0
|
|
482
|
+
for sampler in animation.get('samplers') or []:
|
|
483
|
+
accessor = sampler.get('input') if isinstance(sampler, dict) else None
|
|
484
|
+
if isinstance(accessor, int) and 0 <= accessor < len(accessors):
|
|
485
|
+
top = accessors[accessor].get('max') or [0]
|
|
486
|
+
if top and isinstance(top[0], (int, float)):
|
|
487
|
+
duration = max(duration, float(top[0]))
|
|
488
|
+
extras = animation.get('extras')
|
|
489
|
+
markers = _dict(_dict(_dict(extras).get('cuju')).get('markers'))
|
|
490
|
+
contact = markers.get('contact')
|
|
491
|
+
name = animation.get('name') if isinstance(animation.get('name'), str) else ''
|
|
492
|
+
entry = {'duration': duration, 'contact': contact}
|
|
493
|
+
animations[name or f'animation_{index}'] = entry
|
|
494
|
+
# The team editor names an unnamed animation by its place, from one.
|
|
495
|
+
animations.setdefault(f'Animation {index + 1}', entry)
|
|
496
|
+
names = {n['name'] for n in nodes if isinstance(n, dict) and isinstance(n.get('name'), str)}
|
|
497
|
+
return {
|
|
498
|
+
'drawCalls': draws,
|
|
499
|
+
'triangles': triangles,
|
|
500
|
+
'textureBytes': texture_bytes,
|
|
501
|
+
'nodes': names | {_sanitized(name) for name in names},
|
|
502
|
+
'animations': animations,
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
# The check of a package.
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def _wearers(when: Any, size: int) -> int:
|
|
510
|
+
"""Returns how many players of a team of `size` a selector picks."""
|
|
511
|
+
if not isinstance(when, dict):
|
|
512
|
+
return size
|
|
513
|
+
counts = [size]
|
|
514
|
+
if when.get('role') == 'goalkeeper':
|
|
515
|
+
counts.append(1)
|
|
516
|
+
elif when.get('role') == 'outfield':
|
|
517
|
+
counts.append(size - 1)
|
|
518
|
+
for key in ('number', 'index'):
|
|
519
|
+
if key in when:
|
|
520
|
+
items = when[key] if isinstance(when[key], list) else [when[key]]
|
|
521
|
+
picked = {i for i in items if isinstance(i, int)}
|
|
522
|
+
if key == 'index':
|
|
523
|
+
picked = {i for i in picked if 0 <= i < size}
|
|
524
|
+
counts.append(len(picked))
|
|
525
|
+
return max(0, min(counts))
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def _dict(value: Any) -> dict[str, Any]:
|
|
529
|
+
return value if isinstance(value, dict) else {}
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
def _list(value: Any) -> list[Any]:
|
|
533
|
+
return value if isinstance(value, list) else []
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
class _Report:
|
|
537
|
+
"""Collects the findings of a check, each said once."""
|
|
538
|
+
|
|
539
|
+
def __init__(self) -> None:
|
|
540
|
+
self.errors: list[str] = []
|
|
541
|
+
self.warnings: list[str] = []
|
|
542
|
+
self.info: list[str] = []
|
|
543
|
+
|
|
544
|
+
def add(self, kind: str, message: str) -> None:
|
|
545
|
+
items = getattr(self, kind)
|
|
546
|
+
if message not in items:
|
|
547
|
+
items.append(message)
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
def _clip_names(clips: Any) -> list[tuple[str, str]]:
|
|
551
|
+
"""Returns each clip name of a manifest's clips with the role that names it."""
|
|
552
|
+
out = []
|
|
553
|
+
for role, entry in _dict(clips).items():
|
|
554
|
+
if isinstance(entry, dict) and entry.get('space') == 'speed':
|
|
555
|
+
entries = _list(entry.get('clips'))
|
|
556
|
+
else:
|
|
557
|
+
entries = entry if isinstance(entry, list) else [entry]
|
|
558
|
+
for item in entries:
|
|
559
|
+
if isinstance(item, list) and item:
|
|
560
|
+
item = item[0]
|
|
561
|
+
if isinstance(item, dict):
|
|
562
|
+
item = item.get('clip')
|
|
563
|
+
if isinstance(item, str):
|
|
564
|
+
out.append((role, item))
|
|
565
|
+
return out
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
# GRF's own figure, which the team draws unless a model of the package, the team's own model or
|
|
569
|
+
# a shipped character takes its place.
|
|
570
|
+
GRF_FIGURE = 'grf'
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def _figures(document: dict[str, Any], source: _Source, assets: dict[str, str]) -> dict[str, int]:
|
|
574
|
+
"""Returns how many players of the team draw each figure, as the page picks it.
|
|
575
|
+
|
|
576
|
+
A figure is a model file of the package, `model.glb` for the team's own model, `grf` for
|
|
577
|
+
GRF's own figure or the name of a shipped character. The goalkeeper is the first player of
|
|
578
|
+
the roster, as in every shipped scenario.
|
|
579
|
+
"""
|
|
580
|
+
team = _dict(source.team)
|
|
581
|
+
style = _dict(team.get('style'))
|
|
582
|
+
size = _teams.FORMATS.get(team.get('format'), _teams.FORMATS['11v11'])
|
|
583
|
+
roster = _list(style.get('players'))
|
|
584
|
+
section = _dict(document.get('models'))
|
|
585
|
+
numbers = _dict(section.get('byNumber'))
|
|
586
|
+
out: dict[str, int] = {}
|
|
587
|
+
for index in range(size):
|
|
588
|
+
player = _dict(roster[index]) if index < len(roster) else {}
|
|
589
|
+
number = player.get('number', index + 1)
|
|
590
|
+
wanted = numbers.get(str(number))
|
|
591
|
+
if not isinstance(wanted, str):
|
|
592
|
+
wanted = section.get('goalkeeper') if index == 0 else None
|
|
593
|
+
if not isinstance(wanted, str):
|
|
594
|
+
wanted = section.get('outfield')
|
|
595
|
+
if isinstance(wanted, str) and wanted in assets and wanted.endswith('.glb'):
|
|
596
|
+
figure = wanted
|
|
597
|
+
else:
|
|
598
|
+
model = player.get('model')
|
|
599
|
+
figure = model if isinstance(model, str) and model != 'team' else style.get('model')
|
|
600
|
+
figure = figure if isinstance(figure, str) and figure else GRF_FIGURE
|
|
601
|
+
if figure == 'custom':
|
|
602
|
+
figure = 'model.glb' if source.model is not None else GRF_FIGURE
|
|
603
|
+
out[figure] = out.get(figure, 0) + 1
|
|
604
|
+
return out
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
def _references(
|
|
608
|
+
document: dict[str, Any],
|
|
609
|
+
assets: dict[str, str],
|
|
610
|
+
models: dict[str, dict[str, Any]],
|
|
611
|
+
report: _Report,
|
|
612
|
+
figures: dict[str, int] | None = None,
|
|
613
|
+
) -> set[str]:
|
|
614
|
+
"""Checks that every name of the manifest names a file, node, clip or part of the package.
|
|
615
|
+
|
|
616
|
+
The names of nodes are checked against the models the team draws, GRF's figure among them,
|
|
617
|
+
and the names of clips against the models of the package and the team's own model, since
|
|
618
|
+
GRF's figure plays no clip of a package.
|
|
619
|
+
|
|
620
|
+
Returns:
|
|
621
|
+
The paths of the files that the manifest names.
|
|
622
|
+
"""
|
|
623
|
+
named: set[str] = set()
|
|
624
|
+
figures = figures or {}
|
|
625
|
+
grf = GRF_FIGURE in figures
|
|
626
|
+
# A shipped character has bones of its own that the check does not read.
|
|
627
|
+
shipped = any(f not in (GRF_FIGURE, 'model.glb') and f not in assets for f in figures)
|
|
628
|
+
|
|
629
|
+
def file(value: Any, what: str, suffixes: tuple[str, ...] | None = None) -> None:
|
|
630
|
+
if not isinstance(value, str):
|
|
631
|
+
report.add('errors', f'{what} names no file, found {value!r}')
|
|
632
|
+
return
|
|
633
|
+
named.add(value)
|
|
634
|
+
if value not in assets:
|
|
635
|
+
if not any(value in error for error in report.errors):
|
|
636
|
+
report.add('errors', f'{what} names {value}, which is no file of the package')
|
|
637
|
+
elif suffixes and PurePosixPath(value).suffix not in suffixes:
|
|
638
|
+
report.add('errors', f'{what} names {value}, expected a {"/".join(suffixes)} file')
|
|
639
|
+
|
|
640
|
+
def lacks(what: str, kind: str, value: Any, owner: str) -> None:
|
|
641
|
+
report.add('errors', f'{what} names the {kind} {value}, which {owner} lacks')
|
|
642
|
+
|
|
643
|
+
rig = _dict(document.get('rig'))
|
|
644
|
+
sockets = set(_dict(rig.get('sockets'))) | {'root'}
|
|
645
|
+
attachments = _dict(rig.get('attachments'))
|
|
646
|
+
lights = _dict(document.get('lights'))
|
|
647
|
+
audio = _dict(document.get('audio'))
|
|
648
|
+
processors = audio.get('processors')
|
|
649
|
+
music = _dict(audio.get('music'))
|
|
650
|
+
nodes = set().union(*(m['nodes'] for m in models.values())) if models else set()
|
|
651
|
+
animations = {n for m in models.values() for n in m['animations']}
|
|
652
|
+
unchecked: list[str] = []
|
|
653
|
+
no_clips: list[str] = []
|
|
654
|
+
|
|
655
|
+
def node(value: Any, what: str) -> None:
|
|
656
|
+
if not isinstance(value, str):
|
|
657
|
+
report.add('errors', f'{what} names no node, found {value!r}')
|
|
658
|
+
elif value in nodes or (grf and value in _joints.NODES):
|
|
659
|
+
return
|
|
660
|
+
elif models:
|
|
661
|
+
report.add('errors', f'{what} names the node {value}, which no model of the team has')
|
|
662
|
+
elif grf and not shipped:
|
|
663
|
+
report.add(
|
|
664
|
+
'warnings',
|
|
665
|
+
f"{what} names the node {value}, which GRF's figure lacks, so the page uses the "
|
|
666
|
+
f"root of the figure there, and GRF's figure has the nodes "
|
|
667
|
+
f'{_presentation.words(_joints.NODES, "and")}',
|
|
668
|
+
)
|
|
669
|
+
else:
|
|
670
|
+
unchecked.append(what)
|
|
671
|
+
|
|
672
|
+
def clip(value: Any, what: str) -> None:
|
|
673
|
+
if not isinstance(value, str):
|
|
674
|
+
report.add('errors', f'{what} names no clip, found {value!r}')
|
|
675
|
+
elif models and value not in animations:
|
|
676
|
+
report.add('errors', f'{what} names the clip {value}, which no model of the team holds')
|
|
677
|
+
elif not models and grf and not shipped:
|
|
678
|
+
no_clips.append(what)
|
|
679
|
+
elif not models:
|
|
680
|
+
unchecked.append(what)
|
|
681
|
+
|
|
682
|
+
models_section = _dict(document.get('models'))
|
|
683
|
+
for role in ('outfield', 'goalkeeper'):
|
|
684
|
+
if role in models_section:
|
|
685
|
+
file(models_section[role], f'the {role} model', ('.glb',))
|
|
686
|
+
for number, value in _dict(models_section.get('byNumber')).items():
|
|
687
|
+
file(value, f'the model of number {number}', ('.glb',))
|
|
688
|
+
for name, socket in _dict(rig.get('sockets')).items():
|
|
689
|
+
if isinstance(socket, dict) and socket.get('node'):
|
|
690
|
+
node(socket['node'], f'socket {name}')
|
|
691
|
+
for joint, bone in _dict(rig.get('joints')).items():
|
|
692
|
+
node(bone, f'the joint {joint}')
|
|
693
|
+
for name, item in attachments.items():
|
|
694
|
+
item = _dict(item)
|
|
695
|
+
file(item.get('file'), f'attachment {name}', ('.glb',))
|
|
696
|
+
if item.get('socket', 'root') not in sockets:
|
|
697
|
+
lacks(f'attachment {name}', 'socket', item.get('socket'), 'the rig')
|
|
698
|
+
for name, chain in _dict(rig.get('ik')).items():
|
|
699
|
+
chain = _dict(chain)
|
|
700
|
+
for bone in _list(chain.get('chain')):
|
|
701
|
+
node(bone, f'the chain of ik {name}')
|
|
702
|
+
if 'socket' in chain and chain['socket'] not in sockets:
|
|
703
|
+
lacks(f'ik {name}', 'socket', chain['socket'], 'the rig')
|
|
704
|
+
for index, layer in enumerate(_list(rig.get('layers')), 1):
|
|
705
|
+
layer = _dict(layer)
|
|
706
|
+
for bone in _list(layer.get('mask')):
|
|
707
|
+
node(bone, f'the mask of layer {index}')
|
|
708
|
+
if 'clip' in layer:
|
|
709
|
+
clip(layer['clip'], f'layer {index}')
|
|
710
|
+
if 'role' in layer and layer['role'] not in _presentation.ROLES:
|
|
711
|
+
lacks(f'layer {index}', 'role', layer['role'], 'the contract')
|
|
712
|
+
for role, name in _clip_names(document.get('clips')):
|
|
713
|
+
clip(name, f'the role {role}')
|
|
714
|
+
for index, spec in enumerate(_list(document.get('behaviours'))):
|
|
715
|
+
spec = _dict(spec)
|
|
716
|
+
what = _presentation._behaviour_name(spec, index)
|
|
717
|
+
if 'node' in spec:
|
|
718
|
+
node(spec['node'], what)
|
|
719
|
+
if spec.get('type') == 'spin' and 'clip' in spec:
|
|
720
|
+
clip(spec['clip'], what)
|
|
721
|
+
if 'attachment' in spec and spec['attachment'] not in attachments:
|
|
722
|
+
lacks(what, 'attachment', spec['attachment'], 'the rig')
|
|
723
|
+
if 'light' in spec and spec['light'] not in lights:
|
|
724
|
+
lacks(what, 'light', spec['light'], 'the section lights')
|
|
725
|
+
if (
|
|
726
|
+
isinstance(processors, dict)
|
|
727
|
+
and 'processor' in spec
|
|
728
|
+
and spec['processor'] not in processors
|
|
729
|
+
):
|
|
730
|
+
lacks(what, 'processor', spec['processor'], 'audio')
|
|
731
|
+
for name, light in lights.items():
|
|
732
|
+
light = _dict(light)
|
|
733
|
+
if light.get('socket', 'root') not in sockets:
|
|
734
|
+
lacks(f'light {name}', 'socket', light.get('socket'), 'the rig')
|
|
735
|
+
if 'worker' in document:
|
|
736
|
+
file(document['worker'], 'the worker', ('.js',))
|
|
737
|
+
for name, files in _dict(audio.get('cues')).items():
|
|
738
|
+
for item in files if isinstance(files, list) else [files]:
|
|
739
|
+
file(item, f'cue {name}', _SOUNDS)
|
|
740
|
+
for name, spec in music.items():
|
|
741
|
+
for item in _list(_dict(spec).get('stems')):
|
|
742
|
+
file(item, f'music {name}', _SOUNDS)
|
|
743
|
+
if 'worklet' in audio:
|
|
744
|
+
file(audio['worklet'], 'the worklet', ('.js',))
|
|
745
|
+
for name, effect in _dict(document.get('effects')).items():
|
|
746
|
+
effect = _dict(effect)
|
|
747
|
+
if 'file' in effect:
|
|
748
|
+
kinds = ('.glb',) if effect.get('type') == 'mesh' else None
|
|
749
|
+
file(effect['file'], f'effect {name}', kinds)
|
|
750
|
+
if 'texture' in effect:
|
|
751
|
+
file(effect['texture'], f'the texture of effect {name}', _TEXTURES)
|
|
752
|
+
if 'shader' in effect:
|
|
753
|
+
file(effect['shader'], f'the shader of effect {name}', ('.glsl',))
|
|
754
|
+
materials = document.get('materials')
|
|
755
|
+
entries = list(materials.items()) if isinstance(materials, dict) else []
|
|
756
|
+
for name, look in entries:
|
|
757
|
+
for rule in [_dict(look), *map(_dict, _list(_dict(look).get('rules')))]:
|
|
758
|
+
if 'shader' in rule:
|
|
759
|
+
file(rule['shader'], f'the shader of material {name}', ('.glsl',))
|
|
760
|
+
for key, texture in _dict(rule.get('textures')).items():
|
|
761
|
+
file(texture, f'the texture {key} of material {name}', _TEXTURES)
|
|
762
|
+
for name, layer in _dict(document.get('post')).items():
|
|
763
|
+
if 'shader' in _dict(layer):
|
|
764
|
+
file(layer['shader'], f'the shader of post {name}', ('.glsl',))
|
|
765
|
+
for index, reflex in enumerate(_list(document.get('reflexes')), 1):
|
|
766
|
+
for action in _list(_dict(reflex).get('do')):
|
|
767
|
+
action = _dict(action)
|
|
768
|
+
if 'music' in action and action['music'] not in music:
|
|
769
|
+
lacks(f'reflex {index}', 'music', action['music'], 'audio')
|
|
770
|
+
attach = action.get('attach')
|
|
771
|
+
socket = _dict(attach).get('socket') if isinstance(attach, dict) else None
|
|
772
|
+
if isinstance(attach, str) and attach.startswith('socket:'):
|
|
773
|
+
socket = attach[len('socket:') :]
|
|
774
|
+
if socket is not None and socket not in sockets:
|
|
775
|
+
lacks(f'reflex {index}', 'socket', socket, 'the rig')
|
|
776
|
+
environment = _dict(action.get('environment'))
|
|
777
|
+
if 'tifo' in environment:
|
|
778
|
+
file(environment['tifo'], f'the tifo of reflex {index}', _TEXTURES)
|
|
779
|
+
if unchecked:
|
|
780
|
+
report.add(
|
|
781
|
+
'info',
|
|
782
|
+
f'the team draws a shipped character, so the names of nodes and clips of '
|
|
783
|
+
f'{unchecked[0]} and {len(unchecked) - 1} more stay unchecked'
|
|
784
|
+
if len(unchecked) > 1
|
|
785
|
+
else f'the team draws a shipped character, so the names of {unchecked[0]} stay '
|
|
786
|
+
f'unchecked',
|
|
787
|
+
)
|
|
788
|
+
if no_clips:
|
|
789
|
+
more = f' and {len(no_clips) - 1} more' if len(no_clips) > 1 else ''
|
|
790
|
+
report.add(
|
|
791
|
+
'warnings',
|
|
792
|
+
f"the team draws GRF's figure, which plays no clip of a package, so {no_clips[0]}"
|
|
793
|
+
f"{more} shows only on a model of the package or the team's own model",
|
|
794
|
+
)
|
|
795
|
+
if grf:
|
|
796
|
+
drivers = rig.get('driver', 'grf')
|
|
797
|
+
if isinstance(drivers, str):
|
|
798
|
+
drivers = {'outfield': drivers, 'goalkeeper': drivers}
|
|
799
|
+
others = sorted({d for d in _dict(drivers).values() if isinstance(d, str) and d != 'grf'})
|
|
800
|
+
if others:
|
|
801
|
+
report.add(
|
|
802
|
+
'warnings',
|
|
803
|
+
f"GRF's figure keeps the grf driver, so the {_presentation.words(others, 'and')} "
|
|
804
|
+
f"driver of the rig applies only to a model of the package or the team's own model",
|
|
805
|
+
)
|
|
806
|
+
count = figures[GRF_FIGURE]
|
|
807
|
+
report.add(
|
|
808
|
+
'info',
|
|
809
|
+
f"{count} player{'s draw' if count != 1 else ' draws'} GRF's figure, which "
|
|
810
|
+
f'carries the sockets, attachments, behaviours, materials, shaders and lights of the '
|
|
811
|
+
f'package on its own nodes and plays no clip of the package',
|
|
812
|
+
)
|
|
813
|
+
return named
|
|
814
|
+
|
|
815
|
+
|
|
816
|
+
def _models(
|
|
817
|
+
document: dict[str, Any], source: _Source, assets: dict[str, str], report: _Report
|
|
818
|
+
) -> tuple[dict[str, dict[str, Any]], dict[str, int]]:
|
|
819
|
+
"""Returns the statistics of the models the team draws and how many players draw each."""
|
|
820
|
+
size = _teams.FORMATS.get(_dict(source.team).get('format'), _teams.FORMATS['11v11'])
|
|
821
|
+
section = _dict(document.get('models'))
|
|
822
|
+
numbers = _dict(section.get('byNumber'))
|
|
823
|
+
counts: dict[str, int] = {}
|
|
824
|
+
for value in numbers.values():
|
|
825
|
+
if isinstance(value, str):
|
|
826
|
+
counts[value] = counts.get(value, 0) + 1
|
|
827
|
+
if isinstance(section.get('goalkeeper'), str):
|
|
828
|
+
counts[section['goalkeeper']] = counts.get(section['goalkeeper'], 0) + 1
|
|
829
|
+
if isinstance(section.get('outfield'), str):
|
|
830
|
+
rest = max(0, size - 1 - len(numbers))
|
|
831
|
+
counts[section['outfield']] = counts.get(section['outfield'], 0) + rest
|
|
832
|
+
stats: dict[str, dict[str, Any]] = {}
|
|
833
|
+
for name in counts:
|
|
834
|
+
if name in assets and name.endswith('.glb'):
|
|
835
|
+
try:
|
|
836
|
+
stats[name] = model_stats(source.read(name))
|
|
837
|
+
except _UNREADABLE as error:
|
|
838
|
+
report.add('warnings', f'{name} could not be read for its cost, {error}')
|
|
839
|
+
# A player whom no model of the package picks draws the team's own model.
|
|
840
|
+
if source.model is not None and not (
|
|
841
|
+
isinstance(section.get('outfield'), str) and isinstance(section.get('goalkeeper'), str)
|
|
842
|
+
):
|
|
843
|
+
try:
|
|
844
|
+
stats['model.glb'] = model_stats(source.model)
|
|
845
|
+
except _UNREADABLE:
|
|
846
|
+
report.add('warnings', 'the team model.glb could not be read for its names')
|
|
847
|
+
return stats, counts
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
def _budgets(
|
|
851
|
+
document: dict[str, Any],
|
|
852
|
+
kept: dict[str, Any],
|
|
853
|
+
source: _Source,
|
|
854
|
+
assets: dict[str, str],
|
|
855
|
+
stats: dict[str, dict[str, Any]],
|
|
856
|
+
counts: dict[str, int],
|
|
857
|
+
named: set[str],
|
|
858
|
+
report: _Report,
|
|
859
|
+
) -> dict[str, dict[str, list[int]]]:
|
|
860
|
+
"""Returns the static use of each budget at each quality and reports what passes a budget.
|
|
861
|
+
|
|
862
|
+
Only the parts that the server keeps count, `kept` being the checked manifest, so a value the
|
|
863
|
+
check refuses, such as a count of particles past its range, adds no warning of its own.
|
|
864
|
+
"""
|
|
865
|
+
size = _teams.FORMATS.get(_dict(source.team).get('format'), _teams.FORMATS['11v11'])
|
|
866
|
+
used = dict.fromkeys(BUDGETS['high'], 0)
|
|
867
|
+
|
|
868
|
+
def add_model(cost: dict[str, Any], times: int) -> None:
|
|
869
|
+
for key in ('drawCalls', 'triangles', 'textureBytes'):
|
|
870
|
+
used[key] += cost[key] * times
|
|
871
|
+
|
|
872
|
+
for name, times in counts.items():
|
|
873
|
+
if name in stats:
|
|
874
|
+
add_model(stats[name], times)
|
|
875
|
+
rig = _dict(document.get('rig'))
|
|
876
|
+
attachments = _dict(_dict(kept.get('rig')).get('attachments'))
|
|
877
|
+
for name, item in _dict(rig.get('attachments')).items():
|
|
878
|
+
if name not in attachments:
|
|
879
|
+
continue
|
|
880
|
+
item = _dict(item)
|
|
881
|
+
path = item.get('file')
|
|
882
|
+
if path in assets and str(path).endswith('.glb'):
|
|
883
|
+
try:
|
|
884
|
+
add_model(model_stats(source.read(path)), _wearers(item.get('when'), size))
|
|
885
|
+
except _UNREADABLE as error:
|
|
886
|
+
report.add('warnings', f'attachment {name} could not be read for its cost, {error}')
|
|
887
|
+
for name, effect in _dict(document.get('effects')).items():
|
|
888
|
+
if name not in _dict(kept.get('effects')):
|
|
889
|
+
continue
|
|
890
|
+
effect = _dict(effect)
|
|
891
|
+
kind = effect.get('type')
|
|
892
|
+
if kind == 'mesh' and effect.get('file') in assets:
|
|
893
|
+
try:
|
|
894
|
+
add_model(model_stats(source.read(effect['file'])), 1)
|
|
895
|
+
except _UNREADABLE:
|
|
896
|
+
report.add('warnings', f'effect {name} could not be read for its cost')
|
|
897
|
+
elif kind == 'particles':
|
|
898
|
+
life = [v for v in _list(effect.get('life')) if isinstance(v, (int, float))]
|
|
899
|
+
count, rate = effect.get('count', 0), effect.get('rate', 0)
|
|
900
|
+
count = count if isinstance(count, (int, float)) else 0
|
|
901
|
+
rate = rate if isinstance(rate, (int, float)) else 0
|
|
902
|
+
used['particles'] += int(max(count, rate * max(life, default=1.0)))
|
|
903
|
+
elif kind == 'post' and effect.get('scope') == 'fullscreen':
|
|
904
|
+
used['fullscreen'] += 1
|
|
905
|
+
for name in sorted(named):
|
|
906
|
+
if name in assets and PurePosixPath(name).suffix in _TEXTURES:
|
|
907
|
+
dimensions = image_size(source.read(name))
|
|
908
|
+
if dimensions:
|
|
909
|
+
used['textureBytes'] += dimensions[0] * dimensions[1] * 4
|
|
910
|
+
used['shaders'] = _glsl.programs(kept)
|
|
911
|
+
for name, light in _dict(document.get('lights')).items():
|
|
912
|
+
if name not in _dict(kept.get('lights')):
|
|
913
|
+
continue
|
|
914
|
+
key = 'lights' if _dict(light).get('kind') == 'pool' else 'localLights'
|
|
915
|
+
used[key] += _wearers(_dict(light).get('when'), size)
|
|
916
|
+
used['worklets'] = len(_dict(_dict(document.get('audio')).get('processors')))
|
|
917
|
+
for name in sorted(named):
|
|
918
|
+
if name in assets and name.endswith('.wav'):
|
|
919
|
+
try:
|
|
920
|
+
_, rate, channels, _, frames, _ = _wav(source.read(name))
|
|
921
|
+
used['audioBytes'] += int(frames / rate * _DECODE_RATE) * channels * 4
|
|
922
|
+
except _UNREADABLE:
|
|
923
|
+
pass
|
|
924
|
+
out: dict[str, dict[str, list[int]]] = {}
|
|
925
|
+
for quality in QUALITIES:
|
|
926
|
+
out[quality] = {}
|
|
927
|
+
for key, limit in BUDGETS[quality].items():
|
|
928
|
+
out[quality][key] = [used[key], limit]
|
|
929
|
+
if used[key] <= limit:
|
|
930
|
+
continue
|
|
931
|
+
if key == 'fullscreen':
|
|
932
|
+
report.add(
|
|
933
|
+
'info',
|
|
934
|
+
f'at {quality} quality the page draws no full screen pass, so the '
|
|
935
|
+
f'{used[key]} of the package stay off there',
|
|
936
|
+
)
|
|
937
|
+
else:
|
|
938
|
+
report.add(
|
|
939
|
+
'warnings',
|
|
940
|
+
f'at {quality} quality the package uses {used[key]} of {limit} '
|
|
941
|
+
f'{_BUDGET_NAMES[key]}, and the page holds back what passes the budget',
|
|
942
|
+
)
|
|
943
|
+
return out
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
def _markers(document: dict[str, Any], stats: dict[str, dict[str, Any]], report: _Report) -> None:
|
|
947
|
+
"""Reports the contact markers of the clips of the roles that meet the ball."""
|
|
948
|
+
animations: dict[str, dict[str, Any]] = {}
|
|
949
|
+
for model in stats.values():
|
|
950
|
+
for name, entry in model['animations'].items():
|
|
951
|
+
animations.setdefault(name, entry)
|
|
952
|
+
for role, name in _clip_names(document.get('clips')):
|
|
953
|
+
if role not in ACTION_ROLES or name not in animations:
|
|
954
|
+
continue
|
|
955
|
+
contact, duration = animations[name]['contact'], animations[name]['duration']
|
|
956
|
+
if contact is None:
|
|
957
|
+
report.add(
|
|
958
|
+
'info',
|
|
959
|
+
f'clip {name} of {role} has no contact marker, so its contact falls at 40 '
|
|
960
|
+
'percent of its length',
|
|
961
|
+
)
|
|
962
|
+
elif (
|
|
963
|
+
isinstance(contact, bool)
|
|
964
|
+
or not isinstance(contact, (int, float))
|
|
965
|
+
or not 0 <= contact <= duration
|
|
966
|
+
):
|
|
967
|
+
report.add(
|
|
968
|
+
'warnings',
|
|
969
|
+
f'clip {name} of {role} marks its contact at {contact!r}, outside its '
|
|
970
|
+
f'{duration:g} seconds, so the page takes 40 percent of its length',
|
|
971
|
+
)
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
_FRAME = re.compile(
|
|
975
|
+
r'\bexport\s+(?:async\s+)?function\s*\*?\s*frame\b'
|
|
976
|
+
r'|\bexport\s+(?:const|let|var)\s+frame\b|\bexport\s*\{[^}]*\bframe\b'
|
|
977
|
+
)
|
|
978
|
+
_REGISTER = re.compile(r'registerProcessor\s*\(\s*[\'"]([^\'"]+)[\'"]')
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
def _modules(
|
|
982
|
+
document: dict[str, Any], source: _Source, assets: dict[str, str], report: _Report
|
|
983
|
+
) -> None:
|
|
984
|
+
"""Checks that the worker exports its frame and the worklet registers its processors."""
|
|
985
|
+
worker = document.get('worker')
|
|
986
|
+
if isinstance(worker, str) and worker in assets:
|
|
987
|
+
if not _FRAME.search(source.read(worker).decode('utf-8', 'replace')):
|
|
988
|
+
report.add('warnings', f'the worker {worker} exports no frame, so the page ends it')
|
|
989
|
+
audio = _dict(document.get('audio'))
|
|
990
|
+
worklet = audio.get('worklet')
|
|
991
|
+
if isinstance(worklet, str) and worklet in assets:
|
|
992
|
+
registered = set(_REGISTER.findall(source.read(worklet).decode('utf-8', 'replace')))
|
|
993
|
+
for name, spec in _dict(audio.get('processors')).items():
|
|
994
|
+
processor = _dict(spec).get('processor')
|
|
995
|
+
if isinstance(processor, str) and processor not in registered:
|
|
996
|
+
report.add(
|
|
997
|
+
'warnings',
|
|
998
|
+
f'processor {name} names {processor}, which the worklet {worklet} never '
|
|
999
|
+
'registers',
|
|
1000
|
+
)
|
|
1001
|
+
|
|
1002
|
+
|
|
1003
|
+
def _team_model(source: _Source, report: _Report) -> None:
|
|
1004
|
+
"""Checks the team's own `model.glb` by the rule of an import, which keeps or sets it aside."""
|
|
1005
|
+
if source.model is None:
|
|
1006
|
+
return
|
|
1007
|
+
saved = _dict(source.team)
|
|
1008
|
+
joints = (
|
|
1009
|
+
_dict(saved.get('model')).get('joints') if isinstance(saved.get('model'), dict) else None
|
|
1010
|
+
)
|
|
1011
|
+
try:
|
|
1012
|
+
joints, guessed = _joints.resolve(joints, _teams._skin_joints(source.model))
|
|
1013
|
+
except _UNREADABLE as error:
|
|
1014
|
+
report.add(
|
|
1015
|
+
'errors',
|
|
1016
|
+
f'the team model.glb fails the checks of an uploaded model, so import sets it aside, '
|
|
1017
|
+
f'{error}',
|
|
1018
|
+
)
|
|
1019
|
+
return
|
|
1020
|
+
if guessed:
|
|
1021
|
+
report.add(
|
|
1022
|
+
'info',
|
|
1023
|
+
f'team.json gives no model.joints, so import maps model.glb by its bone names, body '
|
|
1024
|
+
f'to {joints["body"]} and {len(joints) - 1} more joints',
|
|
1025
|
+
)
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
# The longest a parse of one module by Node.js may take, in seconds.
|
|
1029
|
+
_NODE_SECONDS = 20
|
|
1030
|
+
_NODE_LINE = re.compile(r'^\[stdin\]:(\d+)', re.M)
|
|
1031
|
+
_NODE_ERROR = re.compile(r'^(\w*Error): (.*)$', re.M)
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
def _parse_module(text: str, node: str) -> str | None:
|
|
1035
|
+
"""Returns the syntax error of an ES module as Node.js reads it, or `None` when it parses.
|
|
1036
|
+
|
|
1037
|
+
Node.js only parses the module, `--check`, and runs none of it.
|
|
1038
|
+
"""
|
|
1039
|
+
import subprocess
|
|
1040
|
+
|
|
1041
|
+
try:
|
|
1042
|
+
done = subprocess.run(
|
|
1043
|
+
[node, '--input-type=module', '--check'],
|
|
1044
|
+
input=text.encode('utf-8'),
|
|
1045
|
+
capture_output=True,
|
|
1046
|
+
timeout=_NODE_SECONDS,
|
|
1047
|
+
check=False,
|
|
1048
|
+
)
|
|
1049
|
+
except (OSError, subprocess.SubprocessError):
|
|
1050
|
+
return None
|
|
1051
|
+
if done.returncode == 0:
|
|
1052
|
+
return None
|
|
1053
|
+
message = done.stderr.decode('utf-8', 'replace')
|
|
1054
|
+
line = _NODE_LINE.search(message)
|
|
1055
|
+
error = _NODE_ERROR.search(message)
|
|
1056
|
+
what = f'{error.group(1)}, {error.group(2).strip()}' if error else 'a syntax error'
|
|
1057
|
+
return f'{what}, at line {line.group(1)}' if line else what
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
def _syntax(
|
|
1061
|
+
document: dict[str, Any], source: _Source, assets: dict[str, str], report: _Report
|
|
1062
|
+
) -> None:
|
|
1063
|
+
"""Parses the worker and the worklet with Node.js when it is installed.
|
|
1064
|
+
|
|
1065
|
+
Python reads no JavaScript, so without Node.js the check leaves their syntax to the page,
|
|
1066
|
+
which names a module that does not load in a notice.
|
|
1067
|
+
"""
|
|
1068
|
+
import shutil
|
|
1069
|
+
|
|
1070
|
+
modules = [('the worker', document.get('worker'))]
|
|
1071
|
+
modules.append(('the worklet', _dict(document.get('audio')).get('worklet')))
|
|
1072
|
+
modules = [(what, name) for what, name in modules if isinstance(name, str) and name in assets]
|
|
1073
|
+
if not modules:
|
|
1074
|
+
return
|
|
1075
|
+
node = shutil.which('node')
|
|
1076
|
+
if node is None:
|
|
1077
|
+
report.add(
|
|
1078
|
+
'info',
|
|
1079
|
+
'Node.js is not installed, so the check leaves the syntax of the JavaScript modules '
|
|
1080
|
+
'to the page',
|
|
1081
|
+
)
|
|
1082
|
+
return
|
|
1083
|
+
for what, name in modules:
|
|
1084
|
+
problem = _parse_module(source.read(name).decode('utf-8', 'replace'), node)
|
|
1085
|
+
if problem is not None:
|
|
1086
|
+
report.add(
|
|
1087
|
+
'errors', f'{what} {name} does not parse, {problem}, so the page cannot load it'
|
|
1088
|
+
)
|
|
1089
|
+
|
|
1090
|
+
|
|
1091
|
+
def _sounds(assets: dict[str, str], source: _Source, report: _Report) -> list[dict[str, Any]]:
|
|
1092
|
+
"""Measures every WAV sample of the package against the team's ceilings."""
|
|
1093
|
+
out = []
|
|
1094
|
+
for name in sorted(assets):
|
|
1095
|
+
suffix = PurePosixPath(name).suffix
|
|
1096
|
+
if suffix in ('.ogg', '.mp3'):
|
|
1097
|
+
report.add('info', f'{name} is measured on the page when it loads')
|
|
1098
|
+
if suffix != '.wav':
|
|
1099
|
+
continue
|
|
1100
|
+
try:
|
|
1101
|
+
measured = loudness(source.read(name))
|
|
1102
|
+
except _UNREADABLE as error:
|
|
1103
|
+
report.add('warnings', f'{name} could not be measured, {error}')
|
|
1104
|
+
continue
|
|
1105
|
+
keys = ('integrated', 'maxMomentary', 'maxShortTerm', 'truePeak')
|
|
1106
|
+
out.append({'file': name, **{key: measured[key] for key in keys}})
|
|
1107
|
+
if measured['maxMomentary'] is None:
|
|
1108
|
+
report.add('info', f'{name} is silent')
|
|
1109
|
+
continue
|
|
1110
|
+
if measured['seconds'] < 0.4:
|
|
1111
|
+
report.add(
|
|
1112
|
+
'info',
|
|
1113
|
+
f'{name} lasts {measured["seconds"]:g} seconds, less than one block of 400 ms, so '
|
|
1114
|
+
'its integrated loudness is its mean over its own length and reads above its '
|
|
1115
|
+
'momentary loudness, which spreads it over 400 ms',
|
|
1116
|
+
)
|
|
1117
|
+
if measured['measured'] < measured['seconds']:
|
|
1118
|
+
report.add('info', f'{name} is measured over its first {MAXIMUM_SECONDS} seconds')
|
|
1119
|
+
short = measured['maxShortTerm'] if measured['maxShortTerm'] is not None else -math.inf
|
|
1120
|
+
lowering = max(
|
|
1121
|
+
0.0, short - SHORT_TERM_CEILING, measured['maxMomentary'] - MOMENTARY_CEILING
|
|
1122
|
+
)
|
|
1123
|
+
if lowering > 0:
|
|
1124
|
+
report.add(
|
|
1125
|
+
'info',
|
|
1126
|
+
f'{name} reaches {short:.1f} LUFS short-term and {measured["maxMomentary"]:.1f} '
|
|
1127
|
+
f'LUFS momentary, so the page lowers it {lowering:.1f} dB to the team ceilings '
|
|
1128
|
+
f'of {SHORT_TERM_CEILING:g} and {MOMENTARY_CEILING:g} LUFS',
|
|
1129
|
+
)
|
|
1130
|
+
else:
|
|
1131
|
+
report.add(
|
|
1132
|
+
'info',
|
|
1133
|
+
f'{name} reaches {short:.1f} LUFS short-term, within the team ceiling of '
|
|
1134
|
+
f'{SHORT_TERM_CEILING:g} LUFS',
|
|
1135
|
+
)
|
|
1136
|
+
if measured['truePeak'] is not None and measured['truePeak'] > TRUE_PEAK_CEILING:
|
|
1137
|
+
report.add(
|
|
1138
|
+
'warnings',
|
|
1139
|
+
f'{name} peaks at {measured["truePeak"]:+.1f} dBTP, over {TRUE_PEAK_CEILING:g} '
|
|
1140
|
+
'dBTP, so leave it headroom before the page scales and limits it',
|
|
1141
|
+
)
|
|
1142
|
+
return out
|
|
1143
|
+
|
|
1144
|
+
|
|
1145
|
+
def _features(document: dict[str, Any], report: _Report, newer: bool) -> dict[str, list[str]]:
|
|
1146
|
+
"""Returns the features a manifest requires and prefers and those this renderer lacks.
|
|
1147
|
+
|
|
1148
|
+
A required feature that this renderer lacks, other than one a worker alone uses, loses the
|
|
1149
|
+
whole package, so it is an error, unless the manifest is of a newer contract, which a newer
|
|
1150
|
+
renderer reads in full.
|
|
1151
|
+
"""
|
|
1152
|
+
required = [f for f in _list(document.get('requires')) if isinstance(f, str)]
|
|
1153
|
+
preferred = [f for f in _list(document.get('prefers')) if isinstance(f, str)]
|
|
1154
|
+
missing = [f for f in required if f not in _vocabulary.FEATURES]
|
|
1155
|
+
lacking = [f for f in preferred if f not in _vocabulary.FEATURES]
|
|
1156
|
+
known = (*_vocabulary.FEATURES, *getattr(_vocabulary, 'PLANNED', ()))
|
|
1157
|
+
for feature in missing:
|
|
1158
|
+
if feature in WORKER_FEATURES:
|
|
1159
|
+
report.add(
|
|
1160
|
+
'warnings',
|
|
1161
|
+
f'this renderer lacks {feature}, which only a worker uses, so the page drops the '
|
|
1162
|
+
'worker and keeps the manifest',
|
|
1163
|
+
)
|
|
1164
|
+
continue
|
|
1165
|
+
if feature in known:
|
|
1166
|
+
message = f'this renderer lacks the required feature {feature}'
|
|
1167
|
+
else:
|
|
1168
|
+
near = difflib.get_close_matches(feature, _vocabulary.FEATURES, 1, 0.6)
|
|
1169
|
+
hint = f', the nearest is {near[0]}' if near else ''
|
|
1170
|
+
message = f'the package requires {feature}, a feature no renderer names{hint}'
|
|
1171
|
+
report.add(
|
|
1172
|
+
'warnings' if newer else 'errors',
|
|
1173
|
+
f'{message}, so the page draws the team in its stock look, and prefers takes a '
|
|
1174
|
+
'feature the team can do without',
|
|
1175
|
+
)
|
|
1176
|
+
for feature in lacking:
|
|
1177
|
+
report.add(
|
|
1178
|
+
'info',
|
|
1179
|
+
f'this renderer lacks the preferred feature {feature}, which the worker learns from '
|
|
1180
|
+
'its Hello',
|
|
1181
|
+
)
|
|
1182
|
+
return {'required': required, 'preferred': preferred, 'missing': missing, 'lacking': lacking}
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
def check(path: str | Path) -> dict[str, Any]:
|
|
1186
|
+
"""Checks a team's presentation package as the server and the page read it.
|
|
1187
|
+
|
|
1188
|
+
Args:
|
|
1189
|
+
path: A team's submission folder with `cuju-team` inside, a `cuju-team` folder, a
|
|
1190
|
+
`presentation` folder or a `.zip` export of a team.
|
|
1191
|
+
|
|
1192
|
+
Returns:
|
|
1193
|
+
A dictionary with `ok`, whether nothing is an error, `errors`, what makes the server
|
|
1194
|
+
leave a part out or refuse the package, `warnings`, what the page holds back or degrades,
|
|
1195
|
+
`info`, `manifest`, the manifest as the server checks it or `None`, `features`, with the
|
|
1196
|
+
`required` and `preferred` features and those this renderer lacks, `missing` and
|
|
1197
|
+
`lacking`, `budgets`, each quality's budgets as the static use and the limit, `files`,
|
|
1198
|
+
each file's `path`, `bytes` and `kind`, and `loudness`, the levels of each WAV sample.
|
|
1199
|
+
|
|
1200
|
+
Raises:
|
|
1201
|
+
ArgumentError: If the path is no folder or archive of a team or a package.
|
|
1202
|
+
"""
|
|
1203
|
+
path = Path(path)
|
|
1204
|
+
if path.is_file() and path.name == MANIFEST:
|
|
1205
|
+
source = _folder(path.parent)
|
|
1206
|
+
elif path.is_file():
|
|
1207
|
+
if not zipfile.is_zipfile(path):
|
|
1208
|
+
raise ArgumentError(
|
|
1209
|
+
f'expected a team folder, its cuju-team or presentation folder, its {MANIFEST} or '
|
|
1210
|
+
f'a .zip export of a team, found the file {str(path)!r}'
|
|
1211
|
+
)
|
|
1212
|
+
source = _archive(path)
|
|
1213
|
+
elif path.is_dir():
|
|
1214
|
+
source = _folder(path)
|
|
1215
|
+
else:
|
|
1216
|
+
raise ArgumentError(f'expected a folder or a .zip archive of a team, found {str(path)!r}')
|
|
1217
|
+
report = _Report()
|
|
1218
|
+
for message in source.errors:
|
|
1219
|
+
report.add('errors', message)
|
|
1220
|
+
for message in source.info:
|
|
1221
|
+
report.add('info', message)
|
|
1222
|
+
result: dict[str, Any] = {
|
|
1223
|
+
'ok': False,
|
|
1224
|
+
'errors': report.errors,
|
|
1225
|
+
'warnings': report.warnings,
|
|
1226
|
+
'info': report.info,
|
|
1227
|
+
'manifest': None,
|
|
1228
|
+
'features': {'required': [], 'preferred': [], 'missing': [], 'lacking': []},
|
|
1229
|
+
'budgets': {},
|
|
1230
|
+
'files': [],
|
|
1231
|
+
'loudness': [],
|
|
1232
|
+
}
|
|
1233
|
+
assets = _files(source, result, report)
|
|
1234
|
+
_team_model(source, report)
|
|
1235
|
+
if MANIFEST not in source.sizes:
|
|
1236
|
+
report.add('errors', f'the package holds no {MANIFEST}, so the team draws its stock look')
|
|
1237
|
+
return _finish(result, report)
|
|
1238
|
+
if MANIFEST not in assets:
|
|
1239
|
+
return _finish(result, report)
|
|
1240
|
+
data = source.read(MANIFEST)
|
|
1241
|
+
if len(data) > _presentation.MAXIMUM_MANIFEST_BYTES:
|
|
1242
|
+
report.add('errors', 'the manifest holds more than 256 KB, so the page draws without it')
|
|
1243
|
+
return _finish(result, report)
|
|
1244
|
+
document = json.loads(data.decode('utf-8'))
|
|
1245
|
+
result['manifest'] = _manifest(document, assets, report)
|
|
1246
|
+
if not isinstance(document, dict):
|
|
1247
|
+
return _finish(result, report)
|
|
1248
|
+
kept = result['manifest'] or {}
|
|
1249
|
+
newer = bool(kept) and not _presentation.supported(kept.get('contract'))
|
|
1250
|
+
result['features'] = _features(document, report, newer)
|
|
1251
|
+
shaders = [(shader, mode) for shader, mode in _glsl.shaders(document) if shader in assets]
|
|
1252
|
+
for shader, mode in shaders:
|
|
1253
|
+
text = source.read(shader).decode('utf-8', 'replace')
|
|
1254
|
+
for problem in _glsl.check(text, mode):
|
|
1255
|
+
report.add('errors', f'{shader} of mode {mode} {problem}')
|
|
1256
|
+
if shaders:
|
|
1257
|
+
report.add(
|
|
1258
|
+
'info',
|
|
1259
|
+
f'the check read {len(shaders)} shader{"s" if len(shaders) != 1 else ""} by the '
|
|
1260
|
+
f'static rules of the section Shaders and compiled none, and the page compiles each '
|
|
1261
|
+
f'before it draws and names one that fails in a notice',
|
|
1262
|
+
)
|
|
1263
|
+
stats, counts = _models(document, source, assets, report)
|
|
1264
|
+
named = _references(document, assets, stats, report, _figures(document, source, assets))
|
|
1265
|
+
result['budgets'] = _budgets(document, kept, source, assets, stats, counts, named, report)
|
|
1266
|
+
_markers(document, stats, report)
|
|
1267
|
+
_modules(document, source, assets, report)
|
|
1268
|
+
_syntax(document, source, assets, report)
|
|
1269
|
+
result['loudness'] = _sounds(assets, source, report)
|
|
1270
|
+
for name in sorted(set(assets) - named - {MANIFEST}):
|
|
1271
|
+
report.add('info', f'{name} is named by no part of the manifest')
|
|
1272
|
+
return _finish(result, report)
|
|
1273
|
+
|
|
1274
|
+
|
|
1275
|
+
def _files(source: _Source, result: dict[str, Any], report: _Report) -> dict[str, str]:
|
|
1276
|
+
"""Checks every file of the package as an import does and returns those that stay."""
|
|
1277
|
+
assets: dict[str, str] = {}
|
|
1278
|
+
total = 0
|
|
1279
|
+
for name in sorted(source.sizes):
|
|
1280
|
+
size = source.sizes[name]
|
|
1281
|
+
suffix = PurePosixPath(name).suffix
|
|
1282
|
+
kind = 'manifest' if name == MANIFEST else _KINDS.get(suffix, 'other')
|
|
1283
|
+
result['files'].append({'path': name, 'bytes': size, 'kind': kind})
|
|
1284
|
+
try:
|
|
1285
|
+
_presentation.check_path(name)
|
|
1286
|
+
limit = _presentation.MAXIMUM_BYTES[suffix]
|
|
1287
|
+
if size > limit:
|
|
1288
|
+
raise ArgumentError(f'expected {name} of at most {limit} bytes, found {size}')
|
|
1289
|
+
_presentation.check_file(name, source.read(name))
|
|
1290
|
+
except (ArgumentError, OSError) as error:
|
|
1291
|
+
report.add('errors', f'{name} fails its check, so import deletes it, {error}')
|
|
1292
|
+
continue
|
|
1293
|
+
if len(assets) >= _presentation.MAXIMUM_FILES or (
|
|
1294
|
+
total + size > _presentation.MAXIMUM_TOTAL_BYTES
|
|
1295
|
+
):
|
|
1296
|
+
report.add(
|
|
1297
|
+
'errors',
|
|
1298
|
+
f'{name} lies past the limits of a package, {_presentation.MAXIMUM_FILES} files '
|
|
1299
|
+
f'and {_presentation.MAXIMUM_TOTAL_BYTES // _MB} MB, so import deletes it',
|
|
1300
|
+
)
|
|
1301
|
+
continue
|
|
1302
|
+
total += size
|
|
1303
|
+
assets[name] = name
|
|
1304
|
+
return assets
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
def _manifest(document: Any, assets: dict[str, str], report: _Report) -> dict[str, Any] | None:
|
|
1308
|
+
"""Runs the server's check of the manifest and sorts what it leaves out into the report.
|
|
1309
|
+
|
|
1310
|
+
A manifest of a newer minor contract than this renderer's is read as this renderer's own,
|
|
1311
|
+
so its older sections are still checked, and what the check leaves out are warnings, since a
|
|
1312
|
+
newer renderer reads more of it.
|
|
1313
|
+
"""
|
|
1314
|
+
version = document.get('contract') if isinstance(document, dict) else None
|
|
1315
|
+
match = re.fullmatch(r'(\d+)\.(\d+)', version) if isinstance(version, str) else None
|
|
1316
|
+
newer = (
|
|
1317
|
+
match is not None
|
|
1318
|
+
and int(match.group(1)) == _presentation.MAJOR
|
|
1319
|
+
and not _presentation.supported(version)
|
|
1320
|
+
)
|
|
1321
|
+
found: list[str] = []
|
|
1322
|
+
try:
|
|
1323
|
+
if newer:
|
|
1324
|
+
report.add(
|
|
1325
|
+
'warnings',
|
|
1326
|
+
f'the manifest is of contract {version}, newer than the contract '
|
|
1327
|
+
f'{_presentation.CONTRACT} of this renderer, which draws the team in its stock '
|
|
1328
|
+
f'look, so the checks read it as {_presentation.CONTRACT}',
|
|
1329
|
+
)
|
|
1330
|
+
manifest = _presentation.check(
|
|
1331
|
+
{**document, 'contract': _presentation.CONTRACT}, assets, found
|
|
1332
|
+
)
|
|
1333
|
+
manifest['contract'] = version
|
|
1334
|
+
else:
|
|
1335
|
+
manifest = _presentation.check(document, assets, found)
|
|
1336
|
+
except ArgumentError as error:
|
|
1337
|
+
report.add('errors', f'the page draws the team without its manifest, {error}')
|
|
1338
|
+
return None
|
|
1339
|
+
for message in found:
|
|
1340
|
+
report.add('errors' if ' left out' in message and not newer else 'warnings', message)
|
|
1341
|
+
return manifest
|
|
1342
|
+
|
|
1343
|
+
|
|
1344
|
+
def _finish(result: dict[str, Any], report: _Report) -> dict[str, Any]:
|
|
1345
|
+
result['ok'] = not report.errors
|
|
1346
|
+
return result
|
|
1347
|
+
|
|
1348
|
+
|
|
1349
|
+
def text_report(result: dict[str, Any], path: str | Path) -> str:
|
|
1350
|
+
"""Returns the result of `check` as a readable report."""
|
|
1351
|
+
lines = [f'cuju render pack check {path}']
|
|
1352
|
+
manifest = result.get('manifest') or {}
|
|
1353
|
+
files = result.get('files', [])
|
|
1354
|
+
size = sum(item['bytes'] for item in files)
|
|
1355
|
+
lines.append(
|
|
1356
|
+
f'contract {manifest.get("contract", "unknown")}, {manifest.get("name", "no name")}, '
|
|
1357
|
+
f'{len(files)} files, {size / 1024:.1f} KB'
|
|
1358
|
+
)
|
|
1359
|
+
for title, key in (('errors', 'errors'), ('warnings', 'warnings'), ('information', 'info')):
|
|
1360
|
+
if result.get(key):
|
|
1361
|
+
lines.append(title)
|
|
1362
|
+
lines.extend(f' {message}' for message in result[key])
|
|
1363
|
+
if result.get('budgets'):
|
|
1364
|
+
lines.append('budgets')
|
|
1365
|
+
for quality, budgets in result['budgets'].items():
|
|
1366
|
+
parts = [
|
|
1367
|
+
f'{_BUDGET_NAMES[key]} {used:,} of {limit:,}'
|
|
1368
|
+
for key, (used, limit) in budgets.items()
|
|
1369
|
+
if used or key in ('drawCalls', 'triangles', 'shaders')
|
|
1370
|
+
]
|
|
1371
|
+
lines.append(f' {quality}, ' + ', '.join(parts))
|
|
1372
|
+
if result.get('loudness'):
|
|
1373
|
+
lines.append('loudness')
|
|
1374
|
+
|
|
1375
|
+
def level(value: float | None, unit: str) -> str:
|
|
1376
|
+
return f'{value:.1f} {unit}' if value is not None else 'silence'
|
|
1377
|
+
|
|
1378
|
+
for item in result['loudness']:
|
|
1379
|
+
lines.append(
|
|
1380
|
+
f' {item["file"]}, integrated {level(item["integrated"], "LUFS")}, momentary '
|
|
1381
|
+
f'{level(item["maxMomentary"], "LUFS")}, short-term '
|
|
1382
|
+
f'{level(item["maxShortTerm"], "LUFS")}, true peak '
|
|
1383
|
+
f'{level(item["truePeak"], "dBTP")}'
|
|
1384
|
+
)
|
|
1385
|
+
count = len(result.get('errors', []))
|
|
1386
|
+
lines.append('ok' if result.get('ok') else f'{count} error{"s" if count != 1 else ""}')
|
|
1387
|
+
return '\n'.join(lines)
|
|
1388
|
+
|
|
1389
|
+
|
|
1390
|
+
# The template of a new package.
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
def _pad(data: bytes, fill: bytes = b'\0') -> bytes:
|
|
1394
|
+
return data + fill * (-len(data) % 4)
|
|
1395
|
+
|
|
1396
|
+
|
|
1397
|
+
class _Writer:
|
|
1398
|
+
"""Collects the binary buffer, views and accessors of one glTF file."""
|
|
1399
|
+
|
|
1400
|
+
def __init__(self) -> None:
|
|
1401
|
+
self.binary = bytearray()
|
|
1402
|
+
self.views: list[dict[str, Any]] = []
|
|
1403
|
+
self.accessors: list[dict[str, Any]] = []
|
|
1404
|
+
|
|
1405
|
+
def add(self, data: bytes, count: int, kind: str, component: int = 5126, **options: Any) -> int:
|
|
1406
|
+
offset = len(self.binary)
|
|
1407
|
+
self.binary.extend(_pad(data))
|
|
1408
|
+
view = {'buffer': 0, 'byteOffset': offset, 'byteLength': len(data)}
|
|
1409
|
+
if options.get('target'):
|
|
1410
|
+
view['target'] = options['target']
|
|
1411
|
+
self.views.append(view)
|
|
1412
|
+
accessor = {
|
|
1413
|
+
'bufferView': len(self.views) - 1,
|
|
1414
|
+
'componentType': component,
|
|
1415
|
+
'count': count,
|
|
1416
|
+
'type': kind,
|
|
1417
|
+
}
|
|
1418
|
+
if options.get('minimum') is not None:
|
|
1419
|
+
accessor['min'], accessor['max'] = options['minimum'], options['maximum']
|
|
1420
|
+
self.accessors.append(accessor)
|
|
1421
|
+
return len(self.accessors) - 1
|
|
1422
|
+
|
|
1423
|
+
def glb(self, document: dict[str, Any]) -> bytes:
|
|
1424
|
+
document['buffers'] = [{'byteLength': len(self.binary)}]
|
|
1425
|
+
document['bufferViews'] = self.views
|
|
1426
|
+
document['accessors'] = self.accessors
|
|
1427
|
+
text = _pad(json.dumps(document).encode(), b' ')
|
|
1428
|
+
chunks = struct.pack('<II', len(text), _JSON_CHUNK) + text
|
|
1429
|
+
chunks += struct.pack('<II', len(self.binary), _BIN_CHUNK) + bytes(self.binary)
|
|
1430
|
+
return b'glTF' + struct.pack('<II', 2, 12 + len(chunks)) + chunks
|
|
1431
|
+
|
|
1432
|
+
|
|
1433
|
+
def ring_bytes(segments: int = 24) -> bytes:
|
|
1434
|
+
"""Returns a flat glowing ring of quads, 0.48 meters across, without a skin, to attach."""
|
|
1435
|
+
w = _Writer()
|
|
1436
|
+
points: list[float] = []
|
|
1437
|
+
for i in range(segments):
|
|
1438
|
+
angle = 2 * math.pi * i / segments
|
|
1439
|
+
for radius in (0.18, 0.24):
|
|
1440
|
+
points += [radius * math.cos(angle), 0.0, radius * math.sin(angle)]
|
|
1441
|
+
indices: list[int] = []
|
|
1442
|
+
for i in range(segments):
|
|
1443
|
+
a, b = 2 * i, 2 * ((i + 1) % segments)
|
|
1444
|
+
indices += [a, b, a + 1, b, b + 1, a + 1]
|
|
1445
|
+
position = w.add(
|
|
1446
|
+
struct.pack(f'<{len(points)}f', *points),
|
|
1447
|
+
len(points) // 3,
|
|
1448
|
+
'VEC3',
|
|
1449
|
+
target=34962,
|
|
1450
|
+
minimum=[-0.24, 0, -0.24],
|
|
1451
|
+
maximum=[0.24, 0, 0.24],
|
|
1452
|
+
)
|
|
1453
|
+
index = w.add(
|
|
1454
|
+
struct.pack(f'<{len(indices)}H', *indices),
|
|
1455
|
+
len(indices),
|
|
1456
|
+
'SCALAR',
|
|
1457
|
+
component=5123,
|
|
1458
|
+
target=34963,
|
|
1459
|
+
)
|
|
1460
|
+
material = {
|
|
1461
|
+
'name': 'Ring',
|
|
1462
|
+
'doubleSided': True,
|
|
1463
|
+
'emissiveFactor': [1.0, 0.75, 0.3],
|
|
1464
|
+
'pbrMetallicRoughness': {'baseColorFactor': [1.0, 0.85, 0.5, 1], 'metallicFactor': 0},
|
|
1465
|
+
}
|
|
1466
|
+
primitive = {'attributes': {'POSITION': position}, 'indices': index, 'material': 0}
|
|
1467
|
+
document = {
|
|
1468
|
+
'asset': {'version': '2.0', 'generator': 'cuju render pack new'},
|
|
1469
|
+
'scene': 0,
|
|
1470
|
+
'scenes': [{'nodes': [0]}],
|
|
1471
|
+
'nodes': [{'name': 'Ring', 'mesh': 0}],
|
|
1472
|
+
'materials': [material],
|
|
1473
|
+
'meshes': [{'primitives': [primitive]}],
|
|
1474
|
+
}
|
|
1475
|
+
return w.glb(document)
|
|
1476
|
+
|
|
1477
|
+
|
|
1478
|
+
def tone_bytes(seconds: float = 0.15, frequency: float = 880.0, level: float = -12.0) -> bytes:
|
|
1479
|
+
"""Returns a short sine tone with soft ends as a 16 bit mono WAV file at 48 kHz.
|
|
1480
|
+
|
|
1481
|
+
Args:
|
|
1482
|
+
seconds: The length of the tone.
|
|
1483
|
+
frequency: Its pitch in hertz.
|
|
1484
|
+
level: Its peak in dB below full scale.
|
|
1485
|
+
"""
|
|
1486
|
+
rate = 48000
|
|
1487
|
+
count = int(seconds * rate)
|
|
1488
|
+
ramp = int(0.005 * rate)
|
|
1489
|
+
amplitude = 10 ** (level / 20) * 32767
|
|
1490
|
+
values = []
|
|
1491
|
+
for i in range(count):
|
|
1492
|
+
edge = min(1.0, i / ramp, (count - 1 - i) / ramp)
|
|
1493
|
+
envelope = 0.5 - 0.5 * math.cos(math.pi * edge)
|
|
1494
|
+
values.append(round(amplitude * envelope * math.sin(2 * math.pi * frequency * i / rate)))
|
|
1495
|
+
samples = struct.pack(f'<{count}h', *values)
|
|
1496
|
+
header = struct.pack(
|
|
1497
|
+
'<4sI4s4sIHHIIHH4sI',
|
|
1498
|
+
b'RIFF',
|
|
1499
|
+
36 + len(samples),
|
|
1500
|
+
b'WAVE',
|
|
1501
|
+
b'fmt ',
|
|
1502
|
+
16,
|
|
1503
|
+
1,
|
|
1504
|
+
1,
|
|
1505
|
+
rate,
|
|
1506
|
+
rate * 2,
|
|
1507
|
+
2,
|
|
1508
|
+
16,
|
|
1509
|
+
b'data',
|
|
1510
|
+
len(samples),
|
|
1511
|
+
)
|
|
1512
|
+
return header + samples
|
|
1513
|
+
|
|
1514
|
+
|
|
1515
|
+
_MAIN = '''"""The agent of the team, which Kaggle calls with each observation."""
|
|
1516
|
+
|
|
1517
|
+
|
|
1518
|
+
def agent(obs):
|
|
1519
|
+
"""Answers every player the team controls with the action 0, which keeps him idle."""
|
|
1520
|
+
return [0] * max(1, len(obs.get('players_raw') or []))
|
|
1521
|
+
'''
|
|
1522
|
+
|
|
1523
|
+
_WORKER = """\
|
|
1524
|
+
// The worker of the package, one module of its own without imports. The renderer runs it in a
|
|
1525
|
+
// sandbox with no network, no files and no page, hands it the Hello once and then one Frame at a
|
|
1526
|
+
// time, and draws the commands of each answer. docs/presentation.md describes every field.
|
|
1527
|
+
|
|
1528
|
+
let hello = null;
|
|
1529
|
+
let frames = 0;
|
|
1530
|
+
|
|
1531
|
+
// Keeps the Hello, which names the team, its roster, the quality and the features at hand.
|
|
1532
|
+
export function init(h) {
|
|
1533
|
+
hello = h;
|
|
1534
|
+
frames = 0;
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
// Answers each Frame. A reset starts a new epoch, after a seek, a cut or a restart of the worker,
|
|
1538
|
+
// so the worker sets its behaviours again then, here a slow bob of every player of the team.
|
|
1539
|
+
export function frame(f) {
|
|
1540
|
+
frames += 1;
|
|
1541
|
+
const out = { behaviours: [], log: [] };
|
|
1542
|
+
if (frames === 1 || f.reset) {
|
|
1543
|
+
out.behaviours.push({
|
|
1544
|
+
op: 'set',
|
|
1545
|
+
id: 'bob',
|
|
1546
|
+
behaviour: { type: 'oscillate', channel: 'y', amp: 0.02, freq: 0.6 },
|
|
1547
|
+
});
|
|
1548
|
+
out.log.push(`epoch ${f.epoch}, ${f.reset ? f.reset.reason : 'start'}, team ${hello.team}`);
|
|
1549
|
+
}
|
|
1550
|
+
// The log shows in the browser console, here each goal of the team.
|
|
1551
|
+
for (const e of f.events) {
|
|
1552
|
+
if (e.kind === 'goal' && e.phase === 'occur' && e.team === hello.team) {
|
|
1553
|
+
out.log.push(`goal at ${e.t.toFixed(1)} seconds`);
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
return out;
|
|
1557
|
+
}
|
|
1558
|
+
"""
|
|
1559
|
+
|
|
1560
|
+
_GLOW = """\
|
|
1561
|
+
// The glow of the team, a shader of mode chunks. The renderer declares every uniform, uPulse,
|
|
1562
|
+
// which rises with each event of the team and decays, uTeamColor, the team's color, and uGlow,
|
|
1563
|
+
// the uniform that the manifest gives this material.
|
|
1564
|
+
|
|
1565
|
+
vec3 cujuEmissive(vec3 emissive, vec2 uv) {
|
|
1566
|
+
return emissive + uTeamColor * (uPulse * uGlow);
|
|
1567
|
+
}
|
|
1568
|
+
"""
|
|
1569
|
+
|
|
1570
|
+
|
|
1571
|
+
def template_manifest(name: str = 'My team') -> dict[str, Any]:
|
|
1572
|
+
"""Returns the manifest of the template package, of contract 1.1."""
|
|
1573
|
+
return {
|
|
1574
|
+
'contract': '1.1',
|
|
1575
|
+
'name': name,
|
|
1576
|
+
'requires': ['drivers.grf'],
|
|
1577
|
+
'prefers': ['shader.custom'],
|
|
1578
|
+
'rig': {
|
|
1579
|
+
'driver': 'grf',
|
|
1580
|
+
'sockets': {'crown': {'offset': [0, 2.05, 0]}},
|
|
1581
|
+
'attachments': {
|
|
1582
|
+
'ring': {'file': 'models/ring.glb', 'socket': 'crown', 'shadows': False}
|
|
1583
|
+
},
|
|
1584
|
+
},
|
|
1585
|
+
'behaviours': [
|
|
1586
|
+
{
|
|
1587
|
+
'id': 'ringSpin',
|
|
1588
|
+
'type': 'spin',
|
|
1589
|
+
'attachment': 'ring',
|
|
1590
|
+
'axis': [0, 1, 0],
|
|
1591
|
+
'rate': {'input': 'speed', 'keys': [[0, 1], [7, 4]]},
|
|
1592
|
+
}
|
|
1593
|
+
],
|
|
1594
|
+
'materials': {
|
|
1595
|
+
'glow': {
|
|
1596
|
+
'match': '*',
|
|
1597
|
+
'shader': 'shaders/glow.glsl',
|
|
1598
|
+
'mode': 'chunks',
|
|
1599
|
+
'uniforms': {'uGlow': 0.6},
|
|
1600
|
+
}
|
|
1601
|
+
},
|
|
1602
|
+
'effects': {
|
|
1603
|
+
'spark': {
|
|
1604
|
+
'type': 'particles',
|
|
1605
|
+
'count': 40,
|
|
1606
|
+
'duration': 0,
|
|
1607
|
+
'life': [0.2, 0.5],
|
|
1608
|
+
'speed': [1, 4],
|
|
1609
|
+
'spread': 0.8,
|
|
1610
|
+
'gravity': -9.8,
|
|
1611
|
+
'size': [0.06, 0],
|
|
1612
|
+
'color': [[255, 230, 160], [255, 120, 40]],
|
|
1613
|
+
'opacity': [1, 0],
|
|
1614
|
+
'blend': 'additive',
|
|
1615
|
+
},
|
|
1616
|
+
'streak': {
|
|
1617
|
+
'type': 'trail',
|
|
1618
|
+
'length': 0.4,
|
|
1619
|
+
'width': [0.12, 0],
|
|
1620
|
+
'color': [[255, 255, 255], [255, 200, 120]],
|
|
1621
|
+
'opacity': [0.8, 0],
|
|
1622
|
+
'blend': 'additive',
|
|
1623
|
+
'duration': 1.2,
|
|
1624
|
+
},
|
|
1625
|
+
'flare': {
|
|
1626
|
+
'type': 'light',
|
|
1627
|
+
'color': [255, 220, 150],
|
|
1628
|
+
'intensity': 8,
|
|
1629
|
+
'distance': 12,
|
|
1630
|
+
'decay': 2,
|
|
1631
|
+
'duration': 1.5,
|
|
1632
|
+
'attack': 0.1,
|
|
1633
|
+
'release': 1,
|
|
1634
|
+
},
|
|
1635
|
+
},
|
|
1636
|
+
'audio': {'cues': {'tick': ['audio/tick.wav']}},
|
|
1637
|
+
'reflexes': [
|
|
1638
|
+
{
|
|
1639
|
+
'on': 'touch',
|
|
1640
|
+
'where': {'team': 'self'},
|
|
1641
|
+
'do': [
|
|
1642
|
+
{'audio': 'tick', 'at': 'contact', 'replay': 'quiet'},
|
|
1643
|
+
{'effect': 'spark', 'attach': 'ball', 'claim': 'ball'},
|
|
1644
|
+
],
|
|
1645
|
+
},
|
|
1646
|
+
{
|
|
1647
|
+
'on': 'shot',
|
|
1648
|
+
'where': {'team': 'self'},
|
|
1649
|
+
'do': [{'effect': 'streak', 'attach': 'ball', 'claim': 'ball'}],
|
|
1650
|
+
},
|
|
1651
|
+
{
|
|
1652
|
+
'on': 'goal',
|
|
1653
|
+
'where': {'team': 'self'},
|
|
1654
|
+
'do': [{'effect': 'flare', 'attach': 'self'}],
|
|
1655
|
+
},
|
|
1656
|
+
],
|
|
1657
|
+
'worker': 'worker.js',
|
|
1658
|
+
'reducedMotion': {'amplitude': 0.3},
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
|
|
1662
|
+
def template_files(name: str = 'My team') -> dict[str, bytes]:
|
|
1663
|
+
"""Returns every file of the template by its path in a team's submission folder."""
|
|
1664
|
+
# The team draws GRF's figure, or a model.glb put beside team.json, whose joints import guesses.
|
|
1665
|
+
team = {'name': name, 'format': '11v11'}
|
|
1666
|
+
folder = f'{_teams.TEAM_FOLDER}/{FOLDER}'
|
|
1667
|
+
return {
|
|
1668
|
+
'main.py': _MAIN.encode(),
|
|
1669
|
+
f'{_teams.TEAM_FOLDER}/team.json': (json_text(team) + '\n').encode(),
|
|
1670
|
+
f'{folder}/{MANIFEST}': (json_text(template_manifest(name)) + '\n').encode(),
|
|
1671
|
+
f'{folder}/worker.js': _WORKER.encode(),
|
|
1672
|
+
f'{folder}/shaders/glow.glsl': _GLOW.encode(),
|
|
1673
|
+
f'{folder}/models/ring.glb': ring_bytes(),
|
|
1674
|
+
f'{folder}/audio/tick.wav': tone_bytes(),
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
def json_text(value: Any, indent: int = 0, width: int = 96) -> str:
|
|
1679
|
+
"""Returns JSON indented by four spaces, with each short list or object on one line.
|
|
1680
|
+
|
|
1681
|
+
A list of numbers, such as a vector or the keys of a curve, stays on one line when it fits in
|
|
1682
|
+
`width` characters, so a manifest reads as an author writes it.
|
|
1683
|
+
"""
|
|
1684
|
+
flat = json.dumps(value)
|
|
1685
|
+
if not isinstance(value, (list, dict)) or not value:
|
|
1686
|
+
return flat
|
|
1687
|
+
items = value.values() if isinstance(value, dict) else value
|
|
1688
|
+
# A value of scalars and lists of scalars stays on one line when it fits, the top level apart.
|
|
1689
|
+
simple = all(
|
|
1690
|
+
not isinstance(item, (list, dict))
|
|
1691
|
+
or (isinstance(item, list) and not any(isinstance(x, (list, dict)) for x in item))
|
|
1692
|
+
for item in items
|
|
1693
|
+
)
|
|
1694
|
+
if simple and indent > 0 and 4 * indent + len(flat) + 24 <= width:
|
|
1695
|
+
return flat
|
|
1696
|
+
pad = ' ' * (4 * (indent + 1))
|
|
1697
|
+
if isinstance(value, list):
|
|
1698
|
+
items = [pad + json_text(item, indent + 1, width) for item in value]
|
|
1699
|
+
return '[\n' + ',\n'.join(items) + '\n' + ' ' * (4 * indent) + ']'
|
|
1700
|
+
items = [
|
|
1701
|
+
f'{pad}{json.dumps(key)}: {json_text(item, indent + 1, width)}'
|
|
1702
|
+
for key, item in value.items()
|
|
1703
|
+
]
|
|
1704
|
+
return '{\n' + ',\n'.join(items) + '\n' + ' ' * (4 * indent) + '}'
|
|
1705
|
+
|
|
1706
|
+
|
|
1707
|
+
def next_steps(folder: str | Path) -> list[str]:
|
|
1708
|
+
"""Returns the commands that follow `pack new`, to check, preview and register the team."""
|
|
1709
|
+
where = str(folder)
|
|
1710
|
+
quoted = f'"{where}"' if ' ' in where else where
|
|
1711
|
+
return [
|
|
1712
|
+
'next steps',
|
|
1713
|
+
f' cuju render pack check {quoted} checks it as the server and the page read it',
|
|
1714
|
+
f' cuju render pack preview {quoted} plays it on a sample match with the preview panel',
|
|
1715
|
+
f' cuju render team add {quoted} registers the team',
|
|
1716
|
+
'docs/presentation.md describes every part of a package',
|
|
1717
|
+
]
|
|
1718
|
+
|
|
1719
|
+
|
|
1720
|
+
# The preview teams of `pack preview` by the folder or archive they came from, in the home.
|
|
1721
|
+
PREVIEWS_FILE = 'presentation-previews.json'
|
|
1722
|
+
|
|
1723
|
+
|
|
1724
|
+
def _preview_source(path: str | Path) -> tuple[bytes, Path]:
|
|
1725
|
+
"""Returns the zip a preview registers and the folder or archive it came from."""
|
|
1726
|
+
source = Path(path).expanduser()
|
|
1727
|
+
if source.is_file() and source.suffix == '.zip':
|
|
1728
|
+
return source.read_bytes(), source.resolve()
|
|
1729
|
+
if source.is_file() and source.name == MANIFEST:
|
|
1730
|
+
source = source.parent
|
|
1731
|
+
if not source.is_dir():
|
|
1732
|
+
raise ArgumentError(f'expected a team folder or a zip to preview, found {path}')
|
|
1733
|
+
root = source
|
|
1734
|
+
if (root / MANIFEST).is_file():
|
|
1735
|
+
root = root.parent.parent
|
|
1736
|
+
elif root.name == _teams.TEAM_FOLDER:
|
|
1737
|
+
root = root.parent
|
|
1738
|
+
buffer = io.BytesIO()
|
|
1739
|
+
with zipfile.ZipFile(buffer, 'w') as archive:
|
|
1740
|
+
for item in sorted(root.rglob('*')):
|
|
1741
|
+
if item.is_file() and not item.is_symlink() and '__pycache__' not in item.parts:
|
|
1742
|
+
archive.write(item, item.relative_to(root).as_posix())
|
|
1743
|
+
return buffer.getvalue(), root.resolve()
|
|
1744
|
+
|
|
1745
|
+
|
|
1746
|
+
def _preview_name(data: bytes, origin: Path) -> str:
|
|
1747
|
+
"""Returns the name a preview team takes, the manifest's, the team's or the folder's own."""
|
|
1748
|
+
wanted = f'{_teams.TEAM_FOLDER}/{FOLDER}/{MANIFEST}'
|
|
1749
|
+
for member, key in ((wanted, 'name'), (f'{_teams.TEAM_FOLDER}/team.json', 'name')):
|
|
1750
|
+
try:
|
|
1751
|
+
with zipfile.ZipFile(io.BytesIO(data)) as archive:
|
|
1752
|
+
document = json.loads(archive.read(member))
|
|
1753
|
+
except (KeyError, ValueError, zipfile.BadZipFile, OSError, UnicodeDecodeError):
|
|
1754
|
+
continue
|
|
1755
|
+
value = document.get(key) if isinstance(document, dict) else None
|
|
1756
|
+
if isinstance(value, str) and _teams._printable(value).strip():
|
|
1757
|
+
return _teams._printable(value).strip()[:80]
|
|
1758
|
+
return (origin.stem if origin.suffix == '.zip' else origin.name)[:80] or 'Preview'
|
|
1759
|
+
|
|
1760
|
+
|
|
1761
|
+
def _previews() -> dict[str, str]:
|
|
1762
|
+
from .._store import home as _home
|
|
1763
|
+
|
|
1764
|
+
try:
|
|
1765
|
+
document = json.loads((_home.home() / PREVIEWS_FILE).read_text(encoding='utf-8'))
|
|
1766
|
+
except (OSError, ValueError, UnicodeDecodeError):
|
|
1767
|
+
return {}
|
|
1768
|
+
return (
|
|
1769
|
+
{k: v for k, v in document.items() if isinstance(v, str)}
|
|
1770
|
+
if isinstance(document, dict)
|
|
1771
|
+
else {}
|
|
1772
|
+
)
|
|
1773
|
+
|
|
1774
|
+
|
|
1775
|
+
def _names_kit(data: bytes) -> bool:
|
|
1776
|
+
"""Returns whether the team file of a preview's zip names a kit of its own."""
|
|
1777
|
+
try:
|
|
1778
|
+
with zipfile.ZipFile(io.BytesIO(data)) as archive:
|
|
1779
|
+
document = json.loads(archive.read(f'{_teams.TEAM_FOLDER}/team.json'))
|
|
1780
|
+
except (KeyError, ValueError, zipfile.BadZipFile, OSError, UnicodeDecodeError):
|
|
1781
|
+
return False
|
|
1782
|
+
style = document.get('style') if isinstance(document, dict) else None
|
|
1783
|
+
return isinstance(style, dict) and isinstance(style.get('kit'), dict)
|
|
1784
|
+
|
|
1785
|
+
|
|
1786
|
+
def _take_place(old: str, new: dict[str, Any], keep_kit: bool = False) -> dict[str, Any] | None:
|
|
1787
|
+
"""Moves a freshly registered team into the folder of an older one, keeping the older id.
|
|
1788
|
+
|
|
1789
|
+
With `keep_kit` the team keeps the kit and the fans' colors of the older one, so a team
|
|
1790
|
+
whose file names no kit wears the same kit at every preview.
|
|
1791
|
+
|
|
1792
|
+
Returns:
|
|
1793
|
+
The entry of the team under the older id, or `None` when the older folder cannot go.
|
|
1794
|
+
"""
|
|
1795
|
+
import shutil
|
|
1796
|
+
|
|
1797
|
+
from .._store import home as _home
|
|
1798
|
+
|
|
1799
|
+
teams = _home.folder('teams')
|
|
1800
|
+
if not _home.valid_identifier(old) or not (teams / old / _teams.TEAM_FOLDER).is_dir():
|
|
1801
|
+
return None
|
|
1802
|
+
if keep_kit:
|
|
1803
|
+
try:
|
|
1804
|
+
before = _teams.entry(old)['style']
|
|
1805
|
+
new = {**new, 'style': {**new['style'], 'kit': before['kit'], 'crowd': before['crowd']}}
|
|
1806
|
+
except (ArgumentError, KeyError, TypeError):
|
|
1807
|
+
pass
|
|
1808
|
+
parked = teams / f'{old}.old'
|
|
1809
|
+
try:
|
|
1810
|
+
os.replace(teams / old, parked)
|
|
1811
|
+
except OSError:
|
|
1812
|
+
return None
|
|
1813
|
+
try:
|
|
1814
|
+
os.replace(teams / new['id'], teams / old)
|
|
1815
|
+
except OSError:
|
|
1816
|
+
os.replace(parked, teams / old)
|
|
1817
|
+
return None
|
|
1818
|
+
shutil.rmtree(parked, ignore_errors=True)
|
|
1819
|
+
_teams._write(old, {**new, 'id': old})
|
|
1820
|
+
return _teams.entry(old)
|
|
1821
|
+
|
|
1822
|
+
|
|
1823
|
+
def register_preview(path: str | Path, side: str = 'left') -> dict[str, Any]:
|
|
1824
|
+
"""Registers a package as a team, sets the side that draws it and returns what to open.
|
|
1825
|
+
|
|
1826
|
+
A zip registers as it is, a folder as the zip an export of it would make, under the name of
|
|
1827
|
+
its manifest. A second preview of the same folder or zip updates the team of the first in
|
|
1828
|
+
place, so its identifier, and a `developer.json` that names it, stay.
|
|
1829
|
+
|
|
1830
|
+
Returns:
|
|
1831
|
+
A dictionary with `team`, the identifier, `name`, `side` and `place`, the end of the
|
|
1832
|
+
address of the page from `#` on, the shipped five a side sample with the preview panel
|
|
1833
|
+
open on `side`.
|
|
1834
|
+
|
|
1835
|
+
Raises:
|
|
1836
|
+
ArgumentError: If the path is neither a team folder nor a zip, or import refuses it.
|
|
1837
|
+
"""
|
|
1838
|
+
from .._http import launch as _launch
|
|
1839
|
+
from .._store import home as _home
|
|
1840
|
+
from .._store import library as _library
|
|
1841
|
+
|
|
1842
|
+
if side not in _presentation.SIDES:
|
|
1843
|
+
raise ArgumentError(f'expected the side left or right, found {side!r}')
|
|
1844
|
+
data, origin = _preview_source(path)
|
|
1845
|
+
name = _preview_name(data, origin)
|
|
1846
|
+
team = _teams.add(name, 'team.zip', data)
|
|
1847
|
+
previews = _previews()
|
|
1848
|
+
earlier = previews.get(str(origin))
|
|
1849
|
+
if earlier and earlier != team['id']:
|
|
1850
|
+
team = _take_place(earlier, team, not _names_kit(data)) or team
|
|
1851
|
+
previews[str(origin)] = team['id']
|
|
1852
|
+
(_home.home() / PREVIEWS_FILE).write_text(json.dumps(previews, indent=1), encoding='utf-8')
|
|
1853
|
+
# The package draws on the side asked for alone, so a preview on the right after one on the
|
|
1854
|
+
# left moves it there.
|
|
1855
|
+
changes: dict[str, str | None] = {side: team['id']}
|
|
1856
|
+
for other, chosen in _presentation.sides().items():
|
|
1857
|
+
if other != side and chosen == team['id']:
|
|
1858
|
+
changes[other] = None
|
|
1859
|
+
_presentation.assign(changes)
|
|
1860
|
+
place = _launch.resolve(str(_library._SAMPLES / 'sample-5v5.cjr'))
|
|
1861
|
+
return {
|
|
1862
|
+
'team': team['id'],
|
|
1863
|
+
'name': team['name'],
|
|
1864
|
+
'side': side,
|
|
1865
|
+
'place': f'{place}&preview={side}',
|
|
1866
|
+
}
|
|
1867
|
+
|
|
1868
|
+
|
|
1869
|
+
def sides_lines(sides: dict[str, str | None]) -> list[str]:
|
|
1870
|
+
"""Returns the presentation of each side as lines to read, for `cuju render pack sides`."""
|
|
1871
|
+
lines = []
|
|
1872
|
+
for side in _presentation.SIDES:
|
|
1873
|
+
identifier = sides.get(side)
|
|
1874
|
+
if identifier is None:
|
|
1875
|
+
lines.append(f'{side} draws the package of the team that plays it')
|
|
1876
|
+
continue
|
|
1877
|
+
try:
|
|
1878
|
+
name = _teams.entry(identifier).get('name') or identifier
|
|
1879
|
+
except (ArgumentError, OSError, ValueError, KeyError):
|
|
1880
|
+
name = identifier
|
|
1881
|
+
lines.append(f'{side} draws the package of {name}, team {identifier}')
|
|
1882
|
+
return lines
|
|
1883
|
+
|
|
1884
|
+
|
|
1885
|
+
def preview(path: str | Path, side: str = 'left') -> str:
|
|
1886
|
+
"""Registers a package as a team for a preview and returns the end of the page's address.
|
|
1887
|
+
|
|
1888
|
+
`register_preview` describes the registration.
|
|
1889
|
+
"""
|
|
1890
|
+
return register_preview(path, side)['place']
|
|
1891
|
+
|
|
1892
|
+
|
|
1893
|
+
def run_preview(
|
|
1894
|
+
path: str | Path, side: str, port: int, open_page: bool = True, as_json: bool = False
|
|
1895
|
+
) -> int:
|
|
1896
|
+
"""Runs `cuju render pack preview`, which registers a package and opens it on the sample.
|
|
1897
|
+
|
|
1898
|
+
A server of the home that runs already serves the page, and otherwise this one serves it in
|
|
1899
|
+
the foreground until interrupted. The browser opens through the renderer's guarded opening,
|
|
1900
|
+
which opens none on a machine without a display, and stays shut with `open_page` false.
|
|
1901
|
+
|
|
1902
|
+
Args:
|
|
1903
|
+
path: The team folder, `cuju-team` folder, `presentation` folder or zip.
|
|
1904
|
+
side: The side that draws the package, left or right.
|
|
1905
|
+
port: The port of a server that this call starts.
|
|
1906
|
+
open_page: Whether to open the page in a browser.
|
|
1907
|
+
as_json: Whether to print the address, the team and the side as one line of JSON.
|
|
1908
|
+
|
|
1909
|
+
Returns:
|
|
1910
|
+
The exit status.
|
|
1911
|
+
"""
|
|
1912
|
+
from .._http import launch as _launch
|
|
1913
|
+
from .._http import server as _server
|
|
1914
|
+
|
|
1915
|
+
shown = register_preview(path, side)
|
|
1916
|
+
server = _launch.running()
|
|
1917
|
+
base = server.url if server is not None else f'http://127.0.0.1:{port}/'
|
|
1918
|
+
url = base + shown['place']
|
|
1919
|
+
if as_json:
|
|
1920
|
+
print(json.dumps({**shown, 'url': url, 'running': server is not None}), flush=True)
|
|
1921
|
+
else:
|
|
1922
|
+
print(f'previewing {shown["name"]}, team {shown["team"]}, on the {side} side', flush=True)
|
|
1923
|
+
if server is None:
|
|
1924
|
+
_server.serve(port, open_page, page=shown['place'])
|
|
1925
|
+
return 0
|
|
1926
|
+
if open_page and _launch.open_browser(url):
|
|
1927
|
+
if not as_json:
|
|
1928
|
+
print(f'opened {url}', flush=True)
|
|
1929
|
+
elif not as_json:
|
|
1930
|
+
print(f'open it in a browser at {url}', flush=True)
|
|
1931
|
+
return 0
|
|
1932
|
+
|
|
1933
|
+
|
|
1934
|
+
def new(folder: str | Path, name: str = 'My team') -> list[Path]:
|
|
1935
|
+
"""Writes a small working team with a presentation package into a new folder.
|
|
1936
|
+
|
|
1937
|
+
Args:
|
|
1938
|
+
folder: The folder to write, absent or empty.
|
|
1939
|
+
name: The name of the team and of its package.
|
|
1940
|
+
|
|
1941
|
+
Returns:
|
|
1942
|
+
The paths of the files written.
|
|
1943
|
+
|
|
1944
|
+
Raises:
|
|
1945
|
+
ArgumentError: If the folder holds anything already, or the name is empty.
|
|
1946
|
+
"""
|
|
1947
|
+
folder = Path(folder)
|
|
1948
|
+
if folder.exists() and (not folder.is_dir() or any(folder.iterdir())):
|
|
1949
|
+
raise ArgumentError(f'expected an empty folder for the new team, found {str(folder)!r}')
|
|
1950
|
+
name = _teams._printable(str(name)).strip()[:80]
|
|
1951
|
+
if not name:
|
|
1952
|
+
raise ArgumentError('expected a name of the team')
|
|
1953
|
+
written = []
|
|
1954
|
+
for relative, data in template_files(name).items():
|
|
1955
|
+
target = folder.joinpath(*relative.split('/'))
|
|
1956
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
1957
|
+
target.write_bytes(data)
|
|
1958
|
+
written.append(target)
|
|
1959
|
+
return written
|