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,3614 @@
|
|
|
1
|
+
// Copyright 2026 The cuju Authors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// The broadcast, match statistics and the MVP, lineups before kick-off, the celebration camera
|
|
5
|
+
// and a chosen replay after goals, and the show with the podium at full time.
|
|
6
|
+
|
|
7
|
+
import * as THREE from 'three';
|
|
8
|
+
import * as cameraModule from '../world/cameras.js';
|
|
9
|
+
import * as transitionModule from './transition.js';
|
|
10
|
+
import {
|
|
11
|
+
Celebration, Reactions, ballIntoNet, choseCelebration, danceNames, figureSize, kaykitCelebration, posePlayer, roleName,
|
|
12
|
+
seeded, showDance,
|
|
13
|
+
} from './celebrate.js';
|
|
14
|
+
import { ACTION, NODES_FLOAT, PLAYER_FLOATS, TOUCH, isCut } from '../recording/format.js';
|
|
15
|
+
import { fullMatch, summaryRange } from '../recording/episodes.js';
|
|
16
|
+
import { aspectFov, narrowShare, turnBetween } from '../world/framing.js';
|
|
17
|
+
import { bareTeamName, kitSwatch, teamNames } from './hud.js';
|
|
18
|
+
import { HALF_H, HALF_W } from '../world/pitch.js';
|
|
19
|
+
import { Players } from '../players/players.js';
|
|
20
|
+
import { icon, symbolOnly } from '../core/icons.js';
|
|
21
|
+
import { h } from '../teams/library.js';
|
|
22
|
+
import { css } from '../players/kits.js';
|
|
23
|
+
import { formatNumber, t, tn } from '../core/i18n.js';
|
|
24
|
+
|
|
25
|
+
// GRF's goal, the posts at 3.66 meters either side of the center of the goal line and the bar at
|
|
26
|
+
// 2.44 meters.
|
|
27
|
+
const POST_Y = 3.66;
|
|
28
|
+
const BAR_Z = 2.44;
|
|
29
|
+
const PASSES = new Set([ACTION.shortPass, ACTION.longPass, ACTION.highPass]);
|
|
30
|
+
const SAVES = new Set([ACTION.catch, ACTION.deflect, ACTION.interfere, ACTION.ballControl, ACTION.trap]);
|
|
31
|
+
const CATCHES = new Set([ACTION.catch, ACTION.ballControl, ACTION.trap]);
|
|
32
|
+
const TACKLES = new Set([ACTION.sliding, ACTION.interfere]);
|
|
33
|
+
|
|
34
|
+
const ballX = (f) => f.data[8];
|
|
35
|
+
const ballY = (f) => f.data[9];
|
|
36
|
+
const ballZ = (f) => f.data[10];
|
|
37
|
+
|
|
38
|
+
// The goal line a team attacks, the left team defends negative x.
|
|
39
|
+
const attackX = (team) => (team === 0 ? HALF_W : -HALF_W);
|
|
40
|
+
const scoreOf = (f, team) => (team === 0 ? f.scoreLeft : f.scoreRight);
|
|
41
|
+
// A number as toFixed writes it, with the decimal separator of the language.
|
|
42
|
+
const DECIMAL = formatNumber(0.5).charAt(1);
|
|
43
|
+
const fixed = (value, digits) => value.toFixed(digits).replace('.', DECIMAL);
|
|
44
|
+
|
|
45
|
+
// Whether the ball, flying from a to b over one step, would cross the goal line at goalX between
|
|
46
|
+
// the posts and under the bar. It flies straight with gravity and no drag, close enough over the
|
|
47
|
+
// two seconds that a save allows.
|
|
48
|
+
function headsInGoal(a, b, goalX, sps, margin) {
|
|
49
|
+
const vx = (ballX(b) - ballX(a)) * sps;
|
|
50
|
+
if (Math.sign(vx) !== Math.sign(goalX) || Math.abs(vx) < 1) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const t = (goalX - ballX(b)) / vx;
|
|
54
|
+
if (t < 0 || t > 2) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const y = ballY(b) + (ballY(b) - ballY(a)) * sps * t;
|
|
58
|
+
const z = ballZ(b) + (ballZ(b) - ballZ(a)) * sps * t - 4.9 * t * t;
|
|
59
|
+
return Math.abs(y) < POST_Y + margin && z < BAR_Z + margin;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Follows the ball after a shot until it crosses the goal line, a player touches it, play stops
|
|
63
|
+
// or four seconds pass. A shot is on target when the ball crosses between the posts and under the
|
|
64
|
+
// bar, when it goes in, or when the keeper touches a ball that was heading in. Another player's
|
|
65
|
+
// touch blocks it.
|
|
66
|
+
function followShot(store, shot, sps, n, header) {
|
|
67
|
+
const goalX = attackX(shot.team);
|
|
68
|
+
const end = Math.min(store.last, shot.i + 4 * sps);
|
|
69
|
+
const out = { onTarget: false, goal: false, keeper: null, end };
|
|
70
|
+
let prev = store.get(shot.i);
|
|
71
|
+
for (let j = shot.i + 1; j <= end; j++) {
|
|
72
|
+
const f = store.get(j);
|
|
73
|
+
if (!prev || !f || isCut(prev, f)) {
|
|
74
|
+
out.end = j;
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
if (scoreOf(f, shot.team) > scoreOf(prev, shot.team)) {
|
|
78
|
+
Object.assign(out, { onTarget: true, goal: true, goalIndex: j, end: j });
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
const x0 = ballX(prev);
|
|
82
|
+
const x1 = ballX(f);
|
|
83
|
+
if (Math.abs(x1) >= HALF_W && Math.sign(x1) === Math.sign(goalX) && Math.abs(x0) < HALF_W) {
|
|
84
|
+
const w = (Math.abs(goalX) - Math.abs(x0)) / Math.max(1e-6, Math.abs(x1 - x0));
|
|
85
|
+
const y = ballY(prev) + (ballY(f) - ballY(prev)) * w;
|
|
86
|
+
const z = ballZ(prev) + (ballZ(f) - ballZ(prev)) * w;
|
|
87
|
+
out.onTarget = Math.abs(y) < POST_Y && z < BAR_Z;
|
|
88
|
+
out.end = j;
|
|
89
|
+
// A ball over the line between the posts goes in a step or two later.
|
|
90
|
+
for (let g = j; g <= Math.min(store.last, j + 3); g++) {
|
|
91
|
+
if (store.get(g) && scoreOf(store.get(g), shot.team) > scoreOf(prev, shot.team)) {
|
|
92
|
+
Object.assign(out, { onTarget: true, goal: true, goalIndex: g });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
for (let k = 0; k < n; k++) {
|
|
98
|
+
if (!f.touches[k] || (k === shot.k && prev.touches[k] && prev.actions[k] === f.actions[k])) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const p = header.players[k];
|
|
102
|
+
out.end = j;
|
|
103
|
+
if (p.goalkeeper && p.team !== shot.team) {
|
|
104
|
+
const a = store.get(Math.max(shot.i, j - 2));
|
|
105
|
+
const b = j - 1 > shot.i ? prev : f;
|
|
106
|
+
out.onTarget = headsInGoal(a, b, goalX, sps, 0.5);
|
|
107
|
+
out.keeper = { i: j, k, action: f.actions[k] };
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
if (f.gameMode !== 0 && prev.gameMode === 0) {
|
|
112
|
+
out.end = j;
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
prev = f;
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Whether the shooting team scores after the keeper's touch before anyone else touches the ball.
|
|
121
|
+
function goalAfterKeeper(store, shot, keeper, sps, n) {
|
|
122
|
+
const before = scoreOf(store.get(keeper.i - 1), shot.team);
|
|
123
|
+
let prev = store.get(keeper.i);
|
|
124
|
+
for (let j = keeper.i + 1; j <= Math.min(store.last, keeper.i + 3 * sps); j++) {
|
|
125
|
+
const f = store.get(j);
|
|
126
|
+
if (!prev || !f || isCut(prev, f)) {
|
|
127
|
+
return -1;
|
|
128
|
+
}
|
|
129
|
+
if (scoreOf(f, shot.team) > before) {
|
|
130
|
+
return j;
|
|
131
|
+
}
|
|
132
|
+
for (let k = 0; k < n; k++) {
|
|
133
|
+
if (f.touches[k] && k !== keeper.k) {
|
|
134
|
+
return -1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
prev = f;
|
|
138
|
+
}
|
|
139
|
+
return -1;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Whether a tackle at frame i won the ball, the next owner or the next player to touch it within
|
|
143
|
+
// three seconds plays for the tackler's team.
|
|
144
|
+
function wonBall(store, i, k, team, sps, n, header) {
|
|
145
|
+
let prev = store.get(i);
|
|
146
|
+
for (let j = i; j <= Math.min(store.last, i + 3 * sps); j++) {
|
|
147
|
+
const f = store.get(j);
|
|
148
|
+
if (j > i && isCut(prev, f)) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (f.ownedTeam >= 0) {
|
|
152
|
+
return f.ownedTeam === team;
|
|
153
|
+
}
|
|
154
|
+
if (j > i) {
|
|
155
|
+
for (let m = 0; m < n; m++) {
|
|
156
|
+
if (f.touches[m] && m !== k) {
|
|
157
|
+
return header.players[m].team === team;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
prev = f;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Whether play runs on between frames from and to, no restart, cut or goal in between.
|
|
167
|
+
function openPlay(store, from, to) {
|
|
168
|
+
let prev = store.get(from);
|
|
169
|
+
if (!prev || prev.gameMode !== 0) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
for (let j = from + 1; j <= to; j++) {
|
|
173
|
+
const f = store.get(j);
|
|
174
|
+
if (!f || f.foul.type > 0 || f.gameMode !== 0 || isCut(prev, f) || f.scoreLeft !== prev.scoreLeft || f.scoreRight !== prev.scoreRight) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
prev = f;
|
|
178
|
+
}
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Touch events from the touch bytes of frames from to to. A touch that lasts several steps with
|
|
183
|
+
// the same action is one event, at its first step.
|
|
184
|
+
function touchEvents(store, header, from, to) {
|
|
185
|
+
const n = header.players.length;
|
|
186
|
+
const events = [];
|
|
187
|
+
let prev = null;
|
|
188
|
+
for (let i = from; i <= to; i++) {
|
|
189
|
+
const f = store.get(i);
|
|
190
|
+
if (!f) {
|
|
191
|
+
prev = null;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
const joined = prev && !isCut(prev, f);
|
|
195
|
+
for (let k = 0; k < n; k++) {
|
|
196
|
+
const touch = f.touches[k];
|
|
197
|
+
if (!touch || (joined && prev.touches[k] && prev.actions[k] === f.actions[k])) {
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
events.push({ i, k, team: header.players[k].team, action: f.actions[k], touch });
|
|
201
|
+
}
|
|
202
|
+
prev = f;
|
|
203
|
+
}
|
|
204
|
+
return events;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// The scorer and assist of the goal that shows at frame i. The scorer is the shooter of a shot
|
|
208
|
+
// that went in, else the last player to touch the ball before the goal, else its last owner, and
|
|
209
|
+
// a goal by a player of the conceding team is his own goal. The assist is the previous touch by
|
|
210
|
+
// a teammate of the scorer within ten seconds, an opponent's intentional touch in between
|
|
211
|
+
// cancels it.
|
|
212
|
+
function attribute(store, header, events, shots, i, team) {
|
|
213
|
+
const n = header.players.length;
|
|
214
|
+
const sps = header.steps_per_second || 10;
|
|
215
|
+
let scorer = -1;
|
|
216
|
+
let from = -1;
|
|
217
|
+
const shot = shots.find((s) => s.goal && s.goalIndex === i);
|
|
218
|
+
if (shot) {
|
|
219
|
+
scorer = shot.k;
|
|
220
|
+
from = events.indexOf(shot.event);
|
|
221
|
+
} else {
|
|
222
|
+
let last = events.length - 1;
|
|
223
|
+
while (last >= 0 && events[last].i > i) {
|
|
224
|
+
last--;
|
|
225
|
+
}
|
|
226
|
+
while (last >= 0 && events[last].touch === TOUCH.accidental) {
|
|
227
|
+
last--;
|
|
228
|
+
}
|
|
229
|
+
if (last >= 0 && events[last].i >= i - 15 * sps) {
|
|
230
|
+
// Of several touches in the same step, the scoring team's counts.
|
|
231
|
+
from = last;
|
|
232
|
+
for (let e = last; e >= 0 && events[e].i === events[last].i; e--) {
|
|
233
|
+
if (events[e].team === team && events[e].touch !== TOUCH.accidental) {
|
|
234
|
+
from = e;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
scorer = events[from].k;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (scorer < 0) {
|
|
242
|
+
for (let j = i - 1; j >= Math.max(store.first, i - 30 * sps); j--) {
|
|
243
|
+
const f = store.get(j);
|
|
244
|
+
if (f.ownedPlayer >= 0 && f.ownedPlayer < n) {
|
|
245
|
+
scorer = f.ownedPlayer;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// The engine's scorer counts only when it names a player of the header.
|
|
251
|
+
const engine = header.engine_scorer ? ((store.get(i).flags >>> 8) & 31) - 1 : -1;
|
|
252
|
+
if (engine >= 0 && engine < n) {
|
|
253
|
+
scorer = engine;
|
|
254
|
+
from = events.findLastIndex((e) => e.k === scorer && e.i <= i);
|
|
255
|
+
}
|
|
256
|
+
const own = scorer >= 0 && header.players[scorer].team !== team;
|
|
257
|
+
let assist = -1;
|
|
258
|
+
if (scorer >= 0 && !own && from >= 0) {
|
|
259
|
+
const at = events[from].i;
|
|
260
|
+
for (let e = from - 1; e >= 0 && events[e].i >= at - 10 * sps; e--) {
|
|
261
|
+
const ev = events[e];
|
|
262
|
+
if (ev.k === scorer) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (ev.team !== team) {
|
|
266
|
+
if (ev.touch === TOUCH.accidental) {
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
break;
|
|
270
|
+
}
|
|
271
|
+
assist = ev.k;
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return { scorer, assist, ownGoal: own };
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Shots, saves, passes and tackles of frames from to to, from the actions and touches.
|
|
279
|
+
// A shot is an intentional touch with the Shot action, or with the Header action when the ball
|
|
280
|
+
// then flies towards the opponent goal from within 30 meters of it. A save is the defending
|
|
281
|
+
// keeper touching a shot on target within two seconds with the Catch, Deflect, Interfere,
|
|
282
|
+
// BallControl or Trap action, when no goal follows before someone else touches the ball. A pass
|
|
283
|
+
// is an intentional touch with a pass action, completed when the next player to touch the ball
|
|
284
|
+
// is a teammate. A tackle is a Sliding or Interfere touch after an opponent's touch that wins the
|
|
285
|
+
// ball for the tackler's team, or a steal, an outfield player's intentional touch in open play
|
|
286
|
+
// right after an opponent's intentional one that wins the ball the same way.
|
|
287
|
+
function analyse(store, header, from = store.first, to = store.last) {
|
|
288
|
+
const n = header.players.length;
|
|
289
|
+
const sps = header.steps_per_second || 10;
|
|
290
|
+
const events = touchEvents(store, header, from, to);
|
|
291
|
+
const shots = [];
|
|
292
|
+
const saveTouches = new Set();
|
|
293
|
+
for (let e = 0; e < events.length; e++) {
|
|
294
|
+
const ev = events[e];
|
|
295
|
+
if (ev.touch !== TOUCH.kicked && ev.touch !== TOUCH.nonKicked) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
let shoots = ev.action === ACTION.shot;
|
|
299
|
+
if (ev.action === ACTION.header && ev.i + 2 <= to) {
|
|
300
|
+
const a = store.get(ev.i);
|
|
301
|
+
const b = store.get(ev.i + 2);
|
|
302
|
+
const goalX = attackX(ev.team);
|
|
303
|
+
const vx = (ballX(b) - ballX(a)) * sps / 2;
|
|
304
|
+
shoots = !isCut(a, store.get(ev.i + 1)) && !isCut(store.get(ev.i + 1), b)
|
|
305
|
+
&& Math.sign(vx) === Math.sign(goalX) && Math.abs(vx) > 3
|
|
306
|
+
&& Math.abs(goalX - ballX(a)) < 30;
|
|
307
|
+
}
|
|
308
|
+
if (!shoots) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const shot = { i: ev.i, k: ev.k, team: ev.team, event: ev, ...followShot(store, ev, sps, n, header) };
|
|
312
|
+
if (shot.keeper) {
|
|
313
|
+
const scored = goalAfterKeeper(store, shot, shot.keeper, sps, n);
|
|
314
|
+
if (scored >= 0) {
|
|
315
|
+
Object.assign(shot, { onTarget: true, goal: true, goalIndex: scored });
|
|
316
|
+
} else if (shot.onTarget && shot.keeper.i - shot.i <= 2 * sps && SAVES.has(shot.keeper.action)) {
|
|
317
|
+
shot.saved = true;
|
|
318
|
+
saveTouches.add(`${shot.keeper.i}:${shot.keeper.k}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
shots.push(shot);
|
|
322
|
+
}
|
|
323
|
+
const passes = [];
|
|
324
|
+
const tackles = [];
|
|
325
|
+
for (let e = 0; e < events.length; e++) {
|
|
326
|
+
const ev = events[e];
|
|
327
|
+
const intentional = ev.touch === TOUCH.kicked || ev.touch === TOUCH.nonKicked;
|
|
328
|
+
if (intentional && PASSES.has(ev.action)) {
|
|
329
|
+
let next = null;
|
|
330
|
+
for (let m = e + 1; m < events.length && events[m].i <= ev.i + 10 * sps; m++) {
|
|
331
|
+
if (!openPlay(store, ev.i, events[m].i)) {
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
if (events[m].k !== ev.k) {
|
|
335
|
+
next = events[m];
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
passes.push({ i: ev.i, k: ev.k, team: ev.team, receiver: next ? next.k : -1, completed: !!next && next.team === ev.team });
|
|
340
|
+
}
|
|
341
|
+
if (TACKLES.has(ev.action) && !saveTouches.has(`${ev.i}:${ev.k}`)) {
|
|
342
|
+
let before = null;
|
|
343
|
+
for (let m = e - 1; m >= 0 && events[m].i >= ev.i - 5 * sps; m--) {
|
|
344
|
+
if (events[m].k !== ev.k) {
|
|
345
|
+
before = events[m];
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (before && before.team !== ev.team && wonBall(store, ev.i, ev.k, ev.team, sps, n, header)) {
|
|
350
|
+
tackles.push({ i: ev.i, k: ev.k, team: ev.team });
|
|
351
|
+
}
|
|
352
|
+
} else if (intentional && !header.players[ev.k].goalkeeper && !saveTouches.has(`${ev.i}:${ev.k}`)) {
|
|
353
|
+
// A steal, an outfield player's intentional touch that takes the ball from an
|
|
354
|
+
// opponent who played it on purpose in open play, and keeps it for his team.
|
|
355
|
+
let before = null;
|
|
356
|
+
for (let m = e - 1; m >= 0 && events[m].i >= ev.i - 3 * sps; m--) {
|
|
357
|
+
if (events[m].k !== ev.k) {
|
|
358
|
+
before = events[m];
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const opponent = before && before.team !== ev.team
|
|
363
|
+
&& (before.touch === TOUCH.kicked || before.touch === TOUCH.nonKicked);
|
|
364
|
+
if (opponent && openPlay(store, before.i, ev.i) && wonBall(store, ev.i, ev.k, ev.team, sps, n, header)) {
|
|
365
|
+
tackles.push({ i: ev.i, k: ev.k, team: ev.team, steal: true });
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const goals = [];
|
|
370
|
+
let prev = null;
|
|
371
|
+
for (let i = Math.max(from, store.first + 1); i <= to; i++) {
|
|
372
|
+
const f = store.get(i);
|
|
373
|
+
const p = prev || store.get(i - 1);
|
|
374
|
+
prev = f;
|
|
375
|
+
if (isCut(p, f) || !(f.scoreLeft > p.scoreLeft || f.scoreRight > p.scoreRight)) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
const team = f.scoreLeft > p.scoreLeft ? 0 : 1;
|
|
379
|
+
goals.push({ index: i, team, ...attribute(store, header, events, shots, i, team) });
|
|
380
|
+
}
|
|
381
|
+
return { events, shots, passes, tackles, goals };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// Statistics from the frames alone, see analyse for the events and attribute for the goals.
|
|
385
|
+
// The MVP score adds 5 per goal, 3 per assist, 2 per save, 1 per tackle, 0.1 per completed pass
|
|
386
|
+
// and 0.05 per touch, and takes 5 per own goal.
|
|
387
|
+
const statsCache = new WeakMap();
|
|
388
|
+
|
|
389
|
+
export function matchStats(store, header) {
|
|
390
|
+
const cached = statsCache.get(store);
|
|
391
|
+
if (cached && cached.first === store.first && cached.last === store.last) {
|
|
392
|
+
return cached.result;
|
|
393
|
+
}
|
|
394
|
+
const n = header.players.length;
|
|
395
|
+
const stats = header.players.map((p, k) => ({
|
|
396
|
+
k, team: p.team, index: p.index, goalkeeper: p.goalkeeper,
|
|
397
|
+
goals: 0, assists: 0, touches: 0, passes: 0, passesCompleted: 0, tackles: 0, shots: 0,
|
|
398
|
+
shotsOnTarget: 0, saves: 0, catches: 0, parries: 0, ownGoals: 0, score: 0,
|
|
399
|
+
goalFrames: [], assistFrames: [], saveFrames: [], tackleFrames: [], run: null,
|
|
400
|
+
}));
|
|
401
|
+
const a = analyse(store, header);
|
|
402
|
+
for (const ev of a.events) {
|
|
403
|
+
stats[ev.k].touches++;
|
|
404
|
+
}
|
|
405
|
+
for (const s of a.shots) {
|
|
406
|
+
stats[s.k].shots++;
|
|
407
|
+
stats[s.k].shotsOnTarget += s.onTarget ? 1 : 0;
|
|
408
|
+
if (s.saved) {
|
|
409
|
+
const keeper = stats[s.keeper.k];
|
|
410
|
+
keeper.saves++;
|
|
411
|
+
keeper.saveFrames.push(s.keeper.i);
|
|
412
|
+
if (CATCHES.has(s.keeper.action)) {
|
|
413
|
+
keeper.catches++;
|
|
414
|
+
} else {
|
|
415
|
+
keeper.parries++;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
for (const p of a.passes) {
|
|
420
|
+
stats[p.k].passes++;
|
|
421
|
+
stats[p.k].passesCompleted += p.completed ? 1 : 0;
|
|
422
|
+
}
|
|
423
|
+
for (const t of a.tackles) {
|
|
424
|
+
stats[t.k].tackles++;
|
|
425
|
+
stats[t.k].tackleFrames.push(t.i);
|
|
426
|
+
}
|
|
427
|
+
for (const g of a.goals) {
|
|
428
|
+
if (g.scorer >= 0) {
|
|
429
|
+
if (g.ownGoal) {
|
|
430
|
+
stats[g.scorer].ownGoals++;
|
|
431
|
+
} else {
|
|
432
|
+
stats[g.scorer].goals++;
|
|
433
|
+
stats[g.scorer].goalFrames.push(g.index);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
if (g.assist >= 0) {
|
|
437
|
+
stats[g.assist].assists++;
|
|
438
|
+
stats[g.assist].assistFrames.push(g.index);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
// The longest spell on the ball, for players with nothing better to show. A spell ends when
|
|
442
|
+
// another player takes the ball, at a cut, or with the last frame.
|
|
443
|
+
let owner = -1;
|
|
444
|
+
let runStart = -1;
|
|
445
|
+
const closeRun = (end) => {
|
|
446
|
+
if (owner >= 0 && runStart >= 0) {
|
|
447
|
+
const r = stats[owner].run;
|
|
448
|
+
if (!r || end - runStart > r.end - r.start) {
|
|
449
|
+
stats[owner].run = { start: runStart, end };
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
owner = -1;
|
|
453
|
+
};
|
|
454
|
+
for (let i = store.first; i <= store.last; i++) {
|
|
455
|
+
const f = store.get(i);
|
|
456
|
+
if (i > store.first && isCut(store.get(i - 1), f)) {
|
|
457
|
+
closeRun(i - 1);
|
|
458
|
+
}
|
|
459
|
+
if (f.ownedPlayer >= 0 && f.ownedPlayer < n && f.ownedPlayer !== owner) {
|
|
460
|
+
closeRun(i);
|
|
461
|
+
runStart = i;
|
|
462
|
+
owner = f.ownedPlayer;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
closeRun(store.last);
|
|
466
|
+
for (const s of stats) {
|
|
467
|
+
s.score = 5 * s.goals + 3 * s.assists + 2 * s.saves + s.tackles + 0.1 * s.passesCompleted
|
|
468
|
+
+ 0.05 * s.touches - 5 * s.ownGoals;
|
|
469
|
+
}
|
|
470
|
+
const result = { stats, goals: a.goals, shots: a.shots, passes: a.passes, tackles: a.tackles };
|
|
471
|
+
statsCache.set(store, { first: store.first, last: store.last, result });
|
|
472
|
+
return result;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// The scorer and assist of the goal that shows at frame i, from the twenty seconds before it.
|
|
476
|
+
export function scorerAt(store, i, team, header) {
|
|
477
|
+
const sps = header.steps_per_second || 10;
|
|
478
|
+
const a = analyse(store, header, Math.max(store.first, i - 20 * sps), Math.min(store.last, i));
|
|
479
|
+
const g = a.goals.find((goal) => goal.index === i);
|
|
480
|
+
return g ? { scorer: g.scorer, assist: g.assist, ownGoal: g.ownGoal } : { scorer: -1, assist: -1, ownGoal: false };
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// Whether player k of these figures plays a clip, a test that is false for figures without clips.
|
|
484
|
+
function clipTest(players) {
|
|
485
|
+
return (k, name) => {
|
|
486
|
+
if (!players || !name) {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
if (typeof players.hasClip === 'function') {
|
|
490
|
+
return players.hasClip(k, name);
|
|
491
|
+
}
|
|
492
|
+
return typeof players.clipNames === 'function' && players.clipNames(k).includes(name);
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function threeColorOf(c) {
|
|
497
|
+
return new THREE.Color().setRGB(c[0] / 255, c[1] / 255, c[2] / 255, THREE.SRGBColorSpace);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// The few rules the show's panels need beyond the page's own sheet, two compact cards stacked in
|
|
501
|
+
// the panel after a draw.
|
|
502
|
+
function injectShowStyle() {
|
|
503
|
+
if (document.getElementById('cuju-show-style')) {
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const style = document.createElement('style');
|
|
507
|
+
style.id = 'cuju-show-style';
|
|
508
|
+
style.textContent = `
|
|
509
|
+
#victory.draw .victory-cards { flex-direction: column; gap: 8px; }
|
|
510
|
+
#victory.draw .mvp-card { min-width: 0; padding: 8px 12px; }
|
|
511
|
+
#victory { max-height: calc(100% - 32px); overflow-y: auto; }
|
|
512
|
+
`;
|
|
513
|
+
document.head.appendChild(style);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Gives figures drawn apart from the match, on the podium or the stage, the colors that the
|
|
517
|
+
// match's figures show, the away colors of a clash among them.
|
|
518
|
+
function shareColors(target, source) {
|
|
519
|
+
if (!target || !source || typeof source.colorsOf !== 'function' || typeof target.setColors !== 'function' || !target.used) {
|
|
520
|
+
return;
|
|
521
|
+
}
|
|
522
|
+
try {
|
|
523
|
+
[0, 1].forEach((team) => {
|
|
524
|
+
const used = target.used[team];
|
|
525
|
+
if (used) {
|
|
526
|
+
for (const model of used.keys()) {
|
|
527
|
+
target.setColors(team, model, source.colorsOf(team, model));
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
} catch (err) {
|
|
532
|
+
console.warn('show colors not shared', err);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// A beam of light, brightest where the surface faces the eye and near the lamp, so a cone of it
|
|
537
|
+
// reads as light in the air rather than as a tinted shell.
|
|
538
|
+
function beamMaterial(color, opacity) {
|
|
539
|
+
return new THREE.ShaderMaterial({
|
|
540
|
+
uniforms: { color: { value: new THREE.Color(color) }, opacity: { value: opacity } },
|
|
541
|
+
vertexShader: `
|
|
542
|
+
varying vec3 vNormal;
|
|
543
|
+
varying vec3 vView;
|
|
544
|
+
varying float vHeight;
|
|
545
|
+
void main() {
|
|
546
|
+
vec4 mv = modelViewMatrix * vec4(position, 1.0);
|
|
547
|
+
vView = -mv.xyz;
|
|
548
|
+
vNormal = normalMatrix * normal;
|
|
549
|
+
vHeight = uv.y;
|
|
550
|
+
gl_Position = projectionMatrix * mv;
|
|
551
|
+
}`,
|
|
552
|
+
fragmentShader: `
|
|
553
|
+
uniform vec3 color;
|
|
554
|
+
uniform float opacity;
|
|
555
|
+
varying vec3 vNormal;
|
|
556
|
+
varying vec3 vView;
|
|
557
|
+
varying float vHeight;
|
|
558
|
+
void main() {
|
|
559
|
+
float facing = abs(dot(normalize(vNormal), normalize(vView)));
|
|
560
|
+
float a = opacity * pow(facing, 2.5) * mix(0.2, 1.0, vHeight);
|
|
561
|
+
gl_FragColor = vec4(color * a, a);
|
|
562
|
+
}`,
|
|
563
|
+
transparent: true,
|
|
564
|
+
depthWrite: false,
|
|
565
|
+
side: THREE.DoubleSide,
|
|
566
|
+
blending: THREE.AdditiveBlending,
|
|
567
|
+
});
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// A dance player k of these figures can perform, a clip only where his model carries it.
|
|
571
|
+
function usableDance(players, k, name, random = Math.random) {
|
|
572
|
+
if (!name || !name.startsWith('clip:')) {
|
|
573
|
+
return name;
|
|
574
|
+
}
|
|
575
|
+
if (clipTest(players)(k, name)) {
|
|
576
|
+
return name;
|
|
577
|
+
}
|
|
578
|
+
const list = danceNames();
|
|
579
|
+
return list.length ? list[Math.floor(random() * list.length)] : 'dance';
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// What the page shows of a player, his number, name, team and colors.
|
|
583
|
+
export function playerInfo(app, k) {
|
|
584
|
+
const header = app.source.header;
|
|
585
|
+
const p = header.players[k];
|
|
586
|
+
const style = app.styles ? app.styles[p.team] : null;
|
|
587
|
+
const roster = style && style.players ? style.players[p.index] : null;
|
|
588
|
+
const number = roster ? roster.number : (p.goalkeeper ? 1 : p.index + 1);
|
|
589
|
+
const name = roster && roster.name ? roster.name : (p.goalkeeper ? t('show.player.goalkeeper') : t('show.player.unnamed', { number }));
|
|
590
|
+
const kit = style ? (p.goalkeeper && style.goalkeeper ? style.goalkeeper : style.kit) : null;
|
|
591
|
+
const rgb = kit ? kit.primary : [255, 111, 0];
|
|
592
|
+
const light = 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2] > 150;
|
|
593
|
+
return {
|
|
594
|
+
k, team: p.team, index: p.index, goalkeeper: p.goalkeeper, number, name, named: !!(roster && roster.name),
|
|
595
|
+
teamName: teamNames(header)[p.team], color: css(rgb), ink: light ? '#202124' : '#ffffff',
|
|
596
|
+
badge: style && style.badge ? style.badge : '',
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// The goal graphic's lines for the goal at frame index.
|
|
601
|
+
function goalInfo(app, index, team, who) {
|
|
602
|
+
const store = app.timeline.store;
|
|
603
|
+
const f = store.get(index);
|
|
604
|
+
const info = {
|
|
605
|
+
score: `${f.scoreLeft} – ${f.scoreRight}`,
|
|
606
|
+
minute: Math.max(1, Math.ceil(f.timeMs / 60000)),
|
|
607
|
+
name: '', number: null, assist: '', color: null,
|
|
608
|
+
};
|
|
609
|
+
if (who.scorer >= 0) {
|
|
610
|
+
const s = playerInfo(app, who.scorer);
|
|
611
|
+
info.name = s.name;
|
|
612
|
+
info.number = s.number;
|
|
613
|
+
info.color = s.color;
|
|
614
|
+
if (who.ownGoal) {
|
|
615
|
+
info.assist = t('show.goal.own', { team: s.teamName });
|
|
616
|
+
} else if (who.assist >= 0) {
|
|
617
|
+
const a = playerInfo(app, who.assist);
|
|
618
|
+
info.assist = a.named ? t('show.goal.assist.numbered', { number: a.number, name: a.name }) : t('show.goal.assist', { name: a.name });
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
return info;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// The engine position of the ball at timeline position t, between frames.
|
|
625
|
+
function ballAt(store, t, out) {
|
|
626
|
+
const i = Math.floor(t);
|
|
627
|
+
const a = store.get(Math.max(store.first, Math.min(store.last, i)));
|
|
628
|
+
const b = store.get(Math.max(store.first, Math.min(store.last, i + 1))) || a;
|
|
629
|
+
const w = isCut(a, b) ? 0 : t - i;
|
|
630
|
+
for (let c = 0; c < 3; c++) {
|
|
631
|
+
out[c] = a.data[8 + c] + (b.data[8 + c] - a.data[8 + c]) * w;
|
|
632
|
+
}
|
|
633
|
+
return out;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function playerAt(store, k, t, out) {
|
|
637
|
+
const i = Math.floor(t);
|
|
638
|
+
const a = store.get(Math.max(store.first, Math.min(store.last, i)));
|
|
639
|
+
const b = store.get(Math.max(store.first, Math.min(store.last, i + 1))) || a;
|
|
640
|
+
const w = isCut(a, b) ? 0 : t - i;
|
|
641
|
+
const o = NODES_FLOAT + k * PLAYER_FLOATS;
|
|
642
|
+
out[0] = a.data[o] + (b.data[o] - a.data[o]) * w;
|
|
643
|
+
out[1] = a.data[o + 1] + (b.data[o + 1] - a.data[o + 1]) * w;
|
|
644
|
+
return out;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// Replay angles. high rides above and behind a team move, reverse stands behind the scorer and
|
|
648
|
+
// watches the ball fly, netcam looks out from inside the goal at a close finish, the rest are
|
|
649
|
+
// the camera rig's own modes.
|
|
650
|
+
export const REPLAY_ANGLES = ['broadcast', 'reverse', 'netcam', 'high'];
|
|
651
|
+
const ANGLE_NAMES = {
|
|
652
|
+
broadcast: t('show.angle.broadcast'), reverse: t('show.angle.reverse'), netcam: t('show.angle.netcam'),
|
|
653
|
+
high: t('show.angle.high'), lowside: t('show.angle.lowside'),
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
// How a goal's replay plays, the angle that suits it best unless one is asked for, where the
|
|
657
|
+
// clip starts, the shot to slow down at and the frame before the goal where it ends.
|
|
658
|
+
export function replayPlan(store, header, goal, angle = 'auto') {
|
|
659
|
+
const sps = header.steps_per_second || 10;
|
|
660
|
+
const g = goal.index;
|
|
661
|
+
const from = Math.max(store.first, g - 25 * sps);
|
|
662
|
+
const a = analyse(store, header, from, g);
|
|
663
|
+
const scored = a.goals.find((x) => x.index === g) || { scorer: -1, assist: -1, ownGoal: false };
|
|
664
|
+
const shot = a.shots.find((s) => s.goal && s.goalIndex === g);
|
|
665
|
+
let shotIndex = shot ? shot.i : -1;
|
|
666
|
+
if (shotIndex < 0) {
|
|
667
|
+
for (let e = a.events.length - 1; e >= 0; e--) {
|
|
668
|
+
if (a.events[e].i < g && (scored.scorer < 0 || a.events[e].k === scored.scorer)) {
|
|
669
|
+
shotIndex = a.events[e].i;
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
if (shotIndex < 0) {
|
|
675
|
+
shotIndex = Math.max(store.first, g - 8);
|
|
676
|
+
}
|
|
677
|
+
const sf = store.get(shotIndex);
|
|
678
|
+
const distance = sf ? Math.hypot(ballX(sf) - attackX(goal.team), ballY(sf)) : 0;
|
|
679
|
+
// The move, the team's completed passes since the other team last played the ball.
|
|
680
|
+
let lastLoss = from;
|
|
681
|
+
for (const ev of a.events) {
|
|
682
|
+
const intentional = ev.touch === TOUCH.kicked || ev.touch === TOUCH.nonKicked;
|
|
683
|
+
if (ev.i < shotIndex && ev.team !== goal.team && intentional) {
|
|
684
|
+
lastLoss = ev.i;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
const passes = a.passes.filter((p) => p.team === goal.team && p.completed && p.i > lastLoss && p.i < shotIndex
|
|
688
|
+
&& p.i >= shotIndex - 12 * sps);
|
|
689
|
+
let chosen = angle;
|
|
690
|
+
if (chosen === 'auto') {
|
|
691
|
+
if (scored.ownGoal || passes.length >= 3) {
|
|
692
|
+
chosen = 'high';
|
|
693
|
+
} else if (distance >= 18) {
|
|
694
|
+
chosen = 'reverse';
|
|
695
|
+
} else {
|
|
696
|
+
chosen = 'netcam';
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
let begin = passes.length >= 2 ? passes[0].i - 12 : shotIndex - 45;
|
|
700
|
+
begin = Math.max(store.first, g - 130, Math.min(begin, g - 35));
|
|
701
|
+
// Never across a cut, the replay starts after the last one.
|
|
702
|
+
for (let i = g - 1; i > begin; i--) {
|
|
703
|
+
if (isCut(store.get(i - 1), store.get(i))) {
|
|
704
|
+
begin = i;
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
const keeper = header.players.findIndex((p) => p.goalkeeper && p.team !== goal.team);
|
|
709
|
+
return {
|
|
710
|
+
goal, angle: chosen, begin, end: g - 1, shotIndex, slowFrom: shotIndex - 4, scorer: scored.scorer,
|
|
711
|
+
keeper, distance, passes: passes.length,
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// The stages of the celebration camera in seconds, the live shot while the ball hits the net,
|
|
716
|
+
// a close tracking shot of the scorer, a slow orbit of the group and a low hero angle.
|
|
717
|
+
const CELEBRATION_SHOTS = [
|
|
718
|
+
{ at: 0, kind: 'live' },
|
|
719
|
+
{ at: 1.3, kind: 'close', snap: true },
|
|
720
|
+
{ at: 3.9, kind: 'orbit' },
|
|
721
|
+
{ at: 6.8, kind: 'hero' },
|
|
722
|
+
];
|
|
723
|
+
const CELEBRATION_LENGTH = 9.4;
|
|
724
|
+
// Seconds the end of a replay holds on the goal while the ball settles in the net.
|
|
725
|
+
const REPLAY_HOLD = 0.75;
|
|
726
|
+
const LINEUP_LENGTH = 9;
|
|
727
|
+
|
|
728
|
+
const tmpBall = new Float32Array(3);
|
|
729
|
+
const tmpA = new Float32Array(3);
|
|
730
|
+
const tmpB = new Float32Array(3);
|
|
731
|
+
|
|
732
|
+
// Gives the mouse back for a part that asks for a click or a key.
|
|
733
|
+
function release(app) {
|
|
734
|
+
if (typeof app.releasePointer === 'function') {
|
|
735
|
+
app.releasePointer();
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function confineShot(v) {
|
|
740
|
+
if (typeof cameraModule.confine === 'function') {
|
|
741
|
+
cameraModule.confine(v);
|
|
742
|
+
}
|
|
743
|
+
return v;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// The director of the broadcast. Lineups before kick-off, the celebration camera and one chosen
|
|
747
|
+
// replay after each goal, more angles on request, and the reel of goals after the match. Every
|
|
748
|
+
// part ends with Enter, Escape or a click, and the cuts between parts hide behind a stinger.
|
|
749
|
+
export class Director {
|
|
750
|
+
constructor(app) {
|
|
751
|
+
this.app = app;
|
|
752
|
+
this.active = null;
|
|
753
|
+
this.cel = null;
|
|
754
|
+
this.lineup = null;
|
|
755
|
+
this.hold = null;
|
|
756
|
+
this.wiping = false;
|
|
757
|
+
this.handled = null;
|
|
758
|
+
this.recent = null;
|
|
759
|
+
this.lastT = null;
|
|
760
|
+
this.lastNow = performance.now();
|
|
761
|
+
this.pending = null;
|
|
762
|
+
this.shot = { pos: new THREE.Vector3(), target: new THREE.Vector3(), fov: 40, rate: 3, snap: false };
|
|
763
|
+
this.hook = (pose, sample) => this.dress(pose, sample);
|
|
764
|
+
this.bindSettings();
|
|
765
|
+
const stage = document.getElementById('stage');
|
|
766
|
+
if (stage) {
|
|
767
|
+
// A click skips, a drag that turns a camera does not.
|
|
768
|
+
let down = null;
|
|
769
|
+
stage.addEventListener('pointerdown', (e) => {
|
|
770
|
+
down = { x: e.clientX, y: e.clientY };
|
|
771
|
+
});
|
|
772
|
+
stage.addEventListener('click', (e) => {
|
|
773
|
+
const still = down && Math.hypot(e.clientX - down.x, e.clientY - down.y) < 6;
|
|
774
|
+
if (still && this.running && !this.app.postMatch.running) {
|
|
775
|
+
this.skip();
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// The settings this director adds, kept like the page's own.
|
|
782
|
+
bindSettings() {
|
|
783
|
+
const app = this.app;
|
|
784
|
+
const load = (key, fallback) => {
|
|
785
|
+
try {
|
|
786
|
+
const v = localStorage.getItem(`cuju.${key}`);
|
|
787
|
+
return v === null ? fallback : JSON.parse(v);
|
|
788
|
+
} catch {
|
|
789
|
+
return fallback;
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
for (const [id, key] of [['lineups-on', 'lineups'], ['celebrations-on', 'celebrations']]) {
|
|
793
|
+
if (app.settings[key] === undefined) {
|
|
794
|
+
app.settings[key] = load(key, true);
|
|
795
|
+
}
|
|
796
|
+
const box = document.getElementById(id);
|
|
797
|
+
if (!box) {
|
|
798
|
+
continue;
|
|
799
|
+
}
|
|
800
|
+
box.checked = !!app.settings[key];
|
|
801
|
+
box.addEventListener('change', () => {
|
|
802
|
+
app.settings[key] = box.checked;
|
|
803
|
+
try {
|
|
804
|
+
localStorage.setItem(`cuju.${key}`, JSON.stringify(box.checked));
|
|
805
|
+
} catch {
|
|
806
|
+
// Storage can be unavailable, the setting then lasts for this visit only.
|
|
807
|
+
}
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
get running() {
|
|
813
|
+
return !!this.active || !!this.cel || !!this.lineup || this.wiping;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
get celebrating() {
|
|
817
|
+
return this.cel;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
savedState() {
|
|
821
|
+
const app = this.app;
|
|
822
|
+
const tl = app.timeline;
|
|
823
|
+
const cams = app.cameras;
|
|
824
|
+
let camera = cams.mode;
|
|
825
|
+
if (camera === 'scripted' || camera === 'podium') {
|
|
826
|
+
camera = app.settings.camera || 'broadcast';
|
|
827
|
+
}
|
|
828
|
+
return {
|
|
829
|
+
t: tl.t, playing: tl.playing, following: tl.following, speed: tl.speed || 1, direction: tl.direction,
|
|
830
|
+
camera, focus: cams.focusIndex, view: cams.playerView,
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
useScripted() {
|
|
835
|
+
const cams = this.app.cameras;
|
|
836
|
+
cams.scripted = this.shot;
|
|
837
|
+
if (cams.mode !== 'scripted') {
|
|
838
|
+
cams.setMode('scripted');
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// The wipe that hides a cut, the restarts' own logo wipe when the page has it, so every
|
|
843
|
+
// transition of the broadcast looks alike, else the stinger of the HUD. onCovered runs while
|
|
844
|
+
// the view is hidden. The wipe runs on the frame clock, see update.
|
|
845
|
+
sting(label, onCovered) {
|
|
846
|
+
const app = this.app;
|
|
847
|
+
const wipe = app.transition && app.transition.wipe;
|
|
848
|
+
if (!wipe || typeof wipe.show !== 'function') {
|
|
849
|
+
app.hud.stinger(onCovered);
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
if (typeof wipe.setTeams === 'function') {
|
|
853
|
+
wipe.setTeams(app.styles);
|
|
854
|
+
}
|
|
855
|
+
const seconds = typeof transitionModule.WIPE === 'number' ? transitionModule.WIPE : 0.72;
|
|
856
|
+
this.stingState = { clock: 0, seconds, onCovered, label, covered: false };
|
|
857
|
+
wipe.show(0.01, label);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
stepSting(dt) {
|
|
861
|
+
const st = this.stingState;
|
|
862
|
+
if (!st) {
|
|
863
|
+
return;
|
|
864
|
+
}
|
|
865
|
+
const wipe = this.app.transition.wipe;
|
|
866
|
+
st.clock += dt;
|
|
867
|
+
const p = st.clock / st.seconds;
|
|
868
|
+
if (!st.covered && p >= 0.5) {
|
|
869
|
+
st.covered = true;
|
|
870
|
+
if (st.onCovered) {
|
|
871
|
+
st.onCovered();
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
if (this.stingState !== st) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
if (p >= 1) {
|
|
878
|
+
this.stingState = null;
|
|
879
|
+
wipe.show(null);
|
|
880
|
+
} else {
|
|
881
|
+
wipe.show(p, st.label);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
cancelSting() {
|
|
886
|
+
const app = this.app;
|
|
887
|
+
app.hud.cancelStinger();
|
|
888
|
+
if (this.stingState) {
|
|
889
|
+
this.stingState = null;
|
|
890
|
+
if (app.transition && app.transition.wipe) {
|
|
891
|
+
app.transition.wipe.show(null);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
restoreCamera(s) {
|
|
897
|
+
const cams = this.app.cameras;
|
|
898
|
+
cams.focusIndex = s.focus;
|
|
899
|
+
cams.playerView = s.view;
|
|
900
|
+
cams.setMode(s.camera);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// Back to play at frame t with the state saved before a sequence, under a cut.
|
|
904
|
+
resume(s, t) {
|
|
905
|
+
const app = this.app;
|
|
906
|
+
const tl = app.timeline;
|
|
907
|
+
if (!tl) {
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
tl.speed = s.speed;
|
|
911
|
+
tl.direction = s.direction;
|
|
912
|
+
this.restoreCamera(s);
|
|
913
|
+
if (s.following && tl.live) {
|
|
914
|
+
tl.goLive();
|
|
915
|
+
} else {
|
|
916
|
+
tl.seek(t);
|
|
917
|
+
tl.playing = s.playing;
|
|
918
|
+
}
|
|
919
|
+
app.lastIndex = tl.index;
|
|
920
|
+
this.lastT = tl.t;
|
|
921
|
+
// The restarts and the ball take this as a seek, so the goal is not played again.
|
|
922
|
+
app.afterSeek();
|
|
923
|
+
app.updatePlayUi();
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
// Called by the page when play crosses a goal, and by update a moment before, so the frame
|
|
927
|
+
// before the goal can hold while the scorer celebrates.
|
|
928
|
+
goalScored(index, team, early = false) {
|
|
929
|
+
const app = this.app;
|
|
930
|
+
const tl = app.timeline;
|
|
931
|
+
if (!tl || this.running || this.handled === index || app.postMatch.running) {
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
this.handled = index;
|
|
935
|
+
const who = scorerAt(tl.store, index, team, app.source.header);
|
|
936
|
+
const info = goalInfo(app, index, team, who);
|
|
937
|
+
if (early) {
|
|
938
|
+
app.sound.goal(team);
|
|
939
|
+
app.goalBoost = 1;
|
|
940
|
+
}
|
|
941
|
+
app.lastGoal = { index, team };
|
|
942
|
+
app.hud.showGoal(team, true, info, 8000);
|
|
943
|
+
release(app);
|
|
944
|
+
this.recent = null;
|
|
945
|
+
clearTimeout(this.pending);
|
|
946
|
+
if (app.settings.celebrations && index - 1 >= tl.first && tl.direction > 0) {
|
|
947
|
+
this.startCelebration(index, team, who);
|
|
948
|
+
} else if (app.settings.replays) {
|
|
949
|
+
this.pending = setTimeout(() => {
|
|
950
|
+
// Only while play is still just after the goal, a seek away cancels it.
|
|
951
|
+
const near = tl.t >= index - 1 && tl.t < index + 8 * tl.sps;
|
|
952
|
+
if (!this.running && app.timeline === tl && tl.playing && near && !app.postMatch.running) {
|
|
953
|
+
this.play([{ goal: { index, team }, shot: 'auto' }]);
|
|
954
|
+
}
|
|
955
|
+
}, 2500);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
startCelebration(index, team, who) {
|
|
960
|
+
const app = this.app;
|
|
961
|
+
// The team's own celebration sound follows the roar, once the scorer is off running.
|
|
962
|
+
setTimeout(() => {
|
|
963
|
+
if (this.running && typeof app.sound.teamSound === 'function') {
|
|
964
|
+
app.sound.teamSound(team, 'celebration');
|
|
965
|
+
}
|
|
966
|
+
}, 1400);
|
|
967
|
+
const tl = app.timeline;
|
|
968
|
+
const store = tl.store;
|
|
969
|
+
const header = app.source.header;
|
|
970
|
+
const saved = { ...this.savedState(), t: index };
|
|
971
|
+
tl.following = false;
|
|
972
|
+
tl.seek(index - 1);
|
|
973
|
+
tl.t = index - 1;
|
|
974
|
+
tl.playing = true;
|
|
975
|
+
tl.direction = 1;
|
|
976
|
+
tl.speed = 0;
|
|
977
|
+
app.lastIndex = index - 1;
|
|
978
|
+
const frame = store.get(index - 1);
|
|
979
|
+
const before = store.get(index - 2) || frame;
|
|
980
|
+
// An own goal is celebrated by the scoring team's player nearest the ball.
|
|
981
|
+
let celebrant = who.scorer;
|
|
982
|
+
if (celebrant < 0 || who.ownGoal) {
|
|
983
|
+
let best = Infinity;
|
|
984
|
+
celebrant = -1;
|
|
985
|
+
header.players.forEach((p, k) => {
|
|
986
|
+
if (p.team !== team || p.goalkeeper || !(frame.playerFlags[k] & 1)) {
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
const o = NODES_FLOAT + k * PLAYER_FLOATS;
|
|
990
|
+
const d = Math.hypot(frame.data[o] - ballX(frame), frame.data[o + 1] - ballY(frame));
|
|
991
|
+
if (d < best) {
|
|
992
|
+
best = d;
|
|
993
|
+
celebrant = k;
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
const players = app.players;
|
|
998
|
+
const hasClip = clipTest(players);
|
|
999
|
+
const choreo = new Celebration({
|
|
1000
|
+
frame, before, header, styles: app.styles, team, scorer: celebrant, sps: tl.sps, seed: index * 31 + team, hasClip,
|
|
1001
|
+
radius: (k) => figureSize(players, k).radius,
|
|
1002
|
+
});
|
|
1003
|
+
this.cel = { goal: { index, team }, who, celebrant, clock: 0, choreo, saved, stage: -1, orbit: 0 };
|
|
1004
|
+
app.hud.scoreOf(store.get(index));
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
// Each frame, the parts that run, or a look for a goal just ahead.
|
|
1008
|
+
update() {
|
|
1009
|
+
const app = this.app;
|
|
1010
|
+
const now = performance.now();
|
|
1011
|
+
const dt = Math.min(0.1, Math.max(0, (now - this.lastNow) / 1000));
|
|
1012
|
+
this.lastNow = now;
|
|
1013
|
+
if (app.poseHooks && !app.poseHooks.includes(this.hook)) {
|
|
1014
|
+
app.poseHooks.push(this.hook);
|
|
1015
|
+
}
|
|
1016
|
+
this.stepSting(dt);
|
|
1017
|
+
if (app.postMatch && typeof app.postMatch.update === 'function') {
|
|
1018
|
+
app.postMatch.update(dt);
|
|
1019
|
+
}
|
|
1020
|
+
const tl = app.timeline;
|
|
1021
|
+
if (!tl) {
|
|
1022
|
+
return;
|
|
1023
|
+
}
|
|
1024
|
+
if (this.handled != null && (tl.t < this.handled - 2 || tl.t > this.handled + 40)) {
|
|
1025
|
+
this.handled = null;
|
|
1026
|
+
}
|
|
1027
|
+
if (this.lineup) {
|
|
1028
|
+
this.updateLineup(dt);
|
|
1029
|
+
} else if (this.cel) {
|
|
1030
|
+
this.updateCelebration(dt);
|
|
1031
|
+
} else if (this.active) {
|
|
1032
|
+
this.updateReplay(dt);
|
|
1033
|
+
} else if (!this.wiping) {
|
|
1034
|
+
this.lookAhead();
|
|
1035
|
+
}
|
|
1036
|
+
this.lastT = tl.t;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// Stops play on the frame before a goal that normal play is about to cross, so the frames of
|
|
1040
|
+
// the kick-off after it stay unseen until the celebration and replay are over.
|
|
1041
|
+
lookAhead() {
|
|
1042
|
+
const app = this.app;
|
|
1043
|
+
const tl = app.timeline;
|
|
1044
|
+
if (!app.settings.celebrations || !tl.playing || tl.direction <= 0 || tl.speed > 2.5 || tl.speed <= 0
|
|
1045
|
+
|| this.lastT == null || app.postMatch.running) {
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
const from = this.lastT;
|
|
1049
|
+
if (tl.t - from > 1.5 || tl.t <= from) {
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
for (const g of tl.store.goals) {
|
|
1053
|
+
if (from <= g.index - 1 && tl.t > g.index - 1 && g.index - 1 >= tl.first && this.handled !== g.index) {
|
|
1054
|
+
const a = tl.store.get(g.index - 1);
|
|
1055
|
+
const b = tl.store.get(g.index);
|
|
1056
|
+
if (!a || !b || isCut(a, b)) {
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
this.goalScored(g.index, g.team, true);
|
|
1060
|
+
return;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
updateCelebration(dt) {
|
|
1066
|
+
const app = this.app;
|
|
1067
|
+
const tl = app.timeline;
|
|
1068
|
+
const c = this.cel;
|
|
1069
|
+
if (!this.wiping && (tl.index !== c.goal.index - 1 || !tl.playing || tl.speed !== 0)) {
|
|
1070
|
+
// Someone moved the timeline, the celebration gives way at once.
|
|
1071
|
+
this.endCelebration();
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
c.clock += dt;
|
|
1075
|
+
let stage = 0;
|
|
1076
|
+
for (let i = 0; i < CELEBRATION_SHOTS.length; i++) {
|
|
1077
|
+
if (c.clock >= CELEBRATION_SHOTS[i].at) {
|
|
1078
|
+
stage = i;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
const shot = CELEBRATION_SHOTS[stage];
|
|
1082
|
+
if (shot.kind !== 'live') {
|
|
1083
|
+
const s = c.choreo.focus(c.clock);
|
|
1084
|
+
const p = new THREE.Vector3(s.x, 0, -s.y);
|
|
1085
|
+
// The scorer's neck as drawn, so slides and moves on the ground stay in the frame.
|
|
1086
|
+
let head = 1.5;
|
|
1087
|
+
const pose = app.pose;
|
|
1088
|
+
if (pose && c.celebrant >= 0 && c.celebrant < pose.players) {
|
|
1089
|
+
const o = c.celebrant * PLAYER_FLOATS + 3 * 7;
|
|
1090
|
+
p.set(pose.nodes[o], 0, -pose.nodes[o + 1]);
|
|
1091
|
+
head = Math.max(0.35, Math.min(1.6, pose.nodes[o + 2]));
|
|
1092
|
+
}
|
|
1093
|
+
const face = new THREE.Vector3(Math.sin(s.heading), 0, Math.cos(s.heading));
|
|
1094
|
+
const right = new THREE.Vector3(-face.z, 0, face.x);
|
|
1095
|
+
const sh = this.shot;
|
|
1096
|
+
if (stage !== c.stage) {
|
|
1097
|
+
// Reduced motion cuts to each shot.
|
|
1098
|
+
sh.snap = !!shot.snap || app.reducedMotion;
|
|
1099
|
+
if (shot.kind === 'orbit') {
|
|
1100
|
+
const from = app.cameras.camera ? app.cameras.camera.position : p;
|
|
1101
|
+
c.orbit = Math.atan2(from.z - p.z, from.x - p.x);
|
|
1102
|
+
}
|
|
1103
|
+
this.useScripted();
|
|
1104
|
+
}
|
|
1105
|
+
if (shot.kind === 'close') {
|
|
1106
|
+
sh.pos.copy(p).addScaledVector(face, 5.2).addScaledVector(right, 1.6);
|
|
1107
|
+
sh.pos.y = 1.55;
|
|
1108
|
+
sh.target.copy(p).setY(Math.min(1.15, head * 0.8));
|
|
1109
|
+
sh.fov = 32;
|
|
1110
|
+
sh.rate = 5;
|
|
1111
|
+
} else if (shot.kind === 'orbit') {
|
|
1112
|
+
// Around the scorer and the teammates close to him.
|
|
1113
|
+
const center = p.clone();
|
|
1114
|
+
let n = 1;
|
|
1115
|
+
const header = app.source.header;
|
|
1116
|
+
for (let k = 0; k < header.players.length; k++) {
|
|
1117
|
+
if (k === c.celebrant || header.players[k].team !== c.goal.team) {
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
const m = c.choreo.state(k, c.clock);
|
|
1121
|
+
if (m && Math.hypot(m.x - s.x, m.y - s.y) < 3) {
|
|
1122
|
+
center.x += m.x;
|
|
1123
|
+
center.z -= m.y;
|
|
1124
|
+
n++;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
// The scorer stays near the middle of the frame, the group around him.
|
|
1128
|
+
center.multiplyScalar(1 / n).lerp(p, 0.5);
|
|
1129
|
+
const a = c.orbit + 0.26 * (c.clock - shot.at);
|
|
1130
|
+
sh.pos.set(center.x + Math.cos(a) * 9.5, 3.9, center.z + Math.sin(a) * 9.5);
|
|
1131
|
+
sh.target.copy(center).setY(1.0);
|
|
1132
|
+
sh.fov = 36;
|
|
1133
|
+
sh.rate = 1.8;
|
|
1134
|
+
} else {
|
|
1135
|
+
sh.pos.copy(p).addScaledVector(face, 4.0).addScaledVector(right, 0.8);
|
|
1136
|
+
sh.pos.y = 0.45;
|
|
1137
|
+
sh.target.copy(p).setY(head);
|
|
1138
|
+
sh.fov = 46;
|
|
1139
|
+
sh.rate = 2.2;
|
|
1140
|
+
}
|
|
1141
|
+
sh.pos.y += this.clearance(c, sh.pos, sh.target);
|
|
1142
|
+
confineShot(sh.pos);
|
|
1143
|
+
}
|
|
1144
|
+
c.stage = stage;
|
|
1145
|
+
if (c.clock >= CELEBRATION_LENGTH && !this.wiping) {
|
|
1146
|
+
this.afterCelebration();
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// How far to raise a celebration shot so nobody stands between the camera and the scorer,
|
|
1151
|
+
// from the players near the line of sight on the ground.
|
|
1152
|
+
clearance(c, pos, target) {
|
|
1153
|
+
const header = this.app.source.header;
|
|
1154
|
+
const dx = target.x - pos.x;
|
|
1155
|
+
const dz = target.z - pos.z;
|
|
1156
|
+
const len2 = dx * dx + dz * dz || 1;
|
|
1157
|
+
let lift = 0;
|
|
1158
|
+
for (let k = 0; k < header.players.length; k++) {
|
|
1159
|
+
if (k === c.celebrant) {
|
|
1160
|
+
continue;
|
|
1161
|
+
}
|
|
1162
|
+
const m = c.choreo.state(k, c.clock);
|
|
1163
|
+
if (!m) {
|
|
1164
|
+
continue;
|
|
1165
|
+
}
|
|
1166
|
+
const px = m.x - pos.x;
|
|
1167
|
+
const pz = -m.y - pos.z;
|
|
1168
|
+
const u = (px * dx + pz * dz) / len2;
|
|
1169
|
+
if (u <= 0 || u >= 0.85) {
|
|
1170
|
+
continue;
|
|
1171
|
+
}
|
|
1172
|
+
const d = Math.hypot(px - dx * u, pz - dz * u);
|
|
1173
|
+
if (d < 1.1) {
|
|
1174
|
+
lift = Math.max(lift, ((1.1 - d) / 1.1) * 3 * (1 - u));
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
return lift;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// The stinger, and behind it the chosen replay, or play again.
|
|
1181
|
+
afterCelebration() {
|
|
1182
|
+
const app = this.app;
|
|
1183
|
+
const c = this.cel;
|
|
1184
|
+
if (!c || this.wiping) {
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
this.wiping = true;
|
|
1188
|
+
this.sting(app.settings.replays ? t('show.sting.replay') : '', () => {
|
|
1189
|
+
this.wiping = false;
|
|
1190
|
+
this.cel = null;
|
|
1191
|
+
this.releaseClips(c);
|
|
1192
|
+
app.hud.scoreOf(null);
|
|
1193
|
+
app.hud.hideGoal();
|
|
1194
|
+
if (app.settings.replays) {
|
|
1195
|
+
this.play([{ goal: c.goal, shot: 'auto' }], { saved: c.saved, returnT: c.goal.index, wipe: false });
|
|
1196
|
+
} else {
|
|
1197
|
+
this.resume(c.saved, c.goal.index);
|
|
1198
|
+
}
|
|
1199
|
+
});
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
releaseClips(c) {
|
|
1203
|
+
const players = this.app.players;
|
|
1204
|
+
if (players && typeof players.stopClip === 'function') {
|
|
1205
|
+
c.choreo.release((k) => players.stopClip(k));
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
// Ends a celebration that something else interrupted, without a stinger.
|
|
1210
|
+
endCelebration() {
|
|
1211
|
+
const app = this.app;
|
|
1212
|
+
const c = this.cel;
|
|
1213
|
+
this.cel = null;
|
|
1214
|
+
if (!c) {
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
this.releaseClips(c);
|
|
1218
|
+
app.hud.scoreOf(null);
|
|
1219
|
+
const tl = app.timeline;
|
|
1220
|
+
this.restoreCamera(c.saved);
|
|
1221
|
+
if (tl) {
|
|
1222
|
+
if (tl.speed === 0) {
|
|
1223
|
+
tl.speed = c.saved.speed;
|
|
1224
|
+
}
|
|
1225
|
+
// Still on the frame before the goal, play moves on to the kick-off after it.
|
|
1226
|
+
if (tl.index === c.goal.index - 1 && Math.abs(tl.t - (c.goal.index - 1)) < 1e-6) {
|
|
1227
|
+
tl.seek(c.goal.index);
|
|
1228
|
+
app.lastIndex = tl.index;
|
|
1229
|
+
this.lastT = tl.t;
|
|
1230
|
+
app.afterSeek();
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1233
|
+
app.ball.reset();
|
|
1234
|
+
app.cameras.jump();
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
// Dresses the frame on screen, the celebration on the frame before the goal, the ball
|
|
1238
|
+
// settling in the net at the end of a replay.
|
|
1239
|
+
dress(pose, sample) {
|
|
1240
|
+
const c = this.cel;
|
|
1241
|
+
if (c && sample.index === c.goal.index - 1) {
|
|
1242
|
+
const players = this.app.players;
|
|
1243
|
+
const clip = players && typeof players.playClip === 'function' ? (k, name, t, w) => players.playClip(k, name, t, w) : null;
|
|
1244
|
+
c.choreo.apply(pose, c.clock, 1, clip);
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1247
|
+
const h = this.hold;
|
|
1248
|
+
if (h && sample.index === h.index && pose.ball) {
|
|
1249
|
+
ballIntoNet(h.a, h.b, h.team, h.sps, h.clock, tmpBall);
|
|
1250
|
+
pose.ball[0] = tmpBall[0];
|
|
1251
|
+
pose.ball[1] = tmpBall[1];
|
|
1252
|
+
pose.ball[2] = tmpBall[2];
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
// A single replay on request, the chosen angle.
|
|
1257
|
+
start(goal) {
|
|
1258
|
+
this.recent = null;
|
|
1259
|
+
// The replay plays, so a pause of the viewer before it ends here.
|
|
1260
|
+
this.app.userPaused = false;
|
|
1261
|
+
this.play([{ goal, shot: 'auto' }]);
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// The angles not shown yet of the last replayed goal, or of the last goal.
|
|
1265
|
+
moreAngles() {
|
|
1266
|
+
const app = this.app;
|
|
1267
|
+
const tl = app.timeline;
|
|
1268
|
+
if (!tl) {
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
const goal = (this.active && this.active.plan && this.active.plan.goal) || (this.recent && this.recent.goal)
|
|
1272
|
+
|| app.lastGoal || tl.goalNear(-1);
|
|
1273
|
+
if (!goal) {
|
|
1274
|
+
app.hud.toast(t('show.replay.none'));
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
const shown = new Set(this.recent && this.recent.goal.index === goal.index ? this.recent.angles : []);
|
|
1278
|
+
if (this.active && this.active.plan) {
|
|
1279
|
+
shown.add(this.active.plan.angle);
|
|
1280
|
+
}
|
|
1281
|
+
if (!shown.size) {
|
|
1282
|
+
shown.add(replayPlan(tl.store, app.source.header, goal).angle);
|
|
1283
|
+
}
|
|
1284
|
+
let left = REPLAY_ANGLES.filter((a) => !shown.has(a));
|
|
1285
|
+
if (!left.length) {
|
|
1286
|
+
left = REPLAY_ANGLES.slice();
|
|
1287
|
+
shown.clear();
|
|
1288
|
+
}
|
|
1289
|
+
const queue = left.slice(0, 2).map((shot) => ({ goal, shot }));
|
|
1290
|
+
if (this.active) {
|
|
1291
|
+
// A replay in progress plays the new angles next, keeping where it returns to.
|
|
1292
|
+
this.active.queue = this.active.queue.slice(0, this.active.item + 1).concat(queue);
|
|
1293
|
+
const angles = queue.map((q) => ANGLE_NAMES[q.shot].toLowerCase());
|
|
1294
|
+
const named = angles.reduce((first, second) => t('show.replay.and', { first, second }));
|
|
1295
|
+
app.hud.toast(t('show.replay.more.one', { count: angles.length, angle: named }), 'info', 2200);
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
this.recent = { goal, angles: [...shown] };
|
|
1299
|
+
this.play(queue);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// Plays a queue of goals and angles. The options are saved and returnT for where play goes
|
|
1303
|
+
// back to, onDone called at the end, restore false to stay where the queue ended, slow false
|
|
1304
|
+
// for no slow motion, wipe false when a stinger already covers the start.
|
|
1305
|
+
play(queue, options = {}) {
|
|
1306
|
+
const app = this.app;
|
|
1307
|
+
const tl = app.timeline;
|
|
1308
|
+
// The 2D view skips replays, which need the 3D view.
|
|
1309
|
+
if (tl && queue.length && app.flat && app.flat.blocks('replay')) {
|
|
1310
|
+
if (options.onDone) {
|
|
1311
|
+
options.onDone();
|
|
1312
|
+
}
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
if (!tl || !queue.length) {
|
|
1316
|
+
if (options.onDone) {
|
|
1317
|
+
options.onDone();
|
|
1318
|
+
}
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
clearTimeout(this.pending);
|
|
1322
|
+
// A replay asked for during a celebration returns to the kick-off after the goal.
|
|
1323
|
+
const cel = this.cel;
|
|
1324
|
+
if (!this.active) {
|
|
1325
|
+
const saved = options.saved || (cel ? cel.saved : this.savedState());
|
|
1326
|
+
const back = options.returnT != null ? options.returnT : (cel ? cel.goal.index : saved.t);
|
|
1327
|
+
this.active = { saved, returnT: back };
|
|
1328
|
+
// The bug holds the live score and clock while a replay shows earlier frames.
|
|
1329
|
+
if (!app.postMatch.running) {
|
|
1330
|
+
const store = tl.store;
|
|
1331
|
+
app.hud.freeze(store.get(Math.max(store.first, Math.min(store.last, Math.floor(back)))));
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
Object.assign(this.active, { queue, item: -1, options, plan: null, phase: 'wait' });
|
|
1335
|
+
app.hud.hideGoal();
|
|
1336
|
+
release(app);
|
|
1337
|
+
const begin = () => {
|
|
1338
|
+
if (this.cel) {
|
|
1339
|
+
const c = this.cel;
|
|
1340
|
+
this.cel = null;
|
|
1341
|
+
this.releaseClips(c);
|
|
1342
|
+
app.hud.scoreOf(null);
|
|
1343
|
+
}
|
|
1344
|
+
this.nextShot();
|
|
1345
|
+
};
|
|
1346
|
+
if (options.wipe === false) {
|
|
1347
|
+
begin();
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
this.wiping = true;
|
|
1351
|
+
this.sting(t('show.sting.replay'), () => {
|
|
1352
|
+
this.wiping = false;
|
|
1353
|
+
if (this.active) {
|
|
1354
|
+
begin();
|
|
1355
|
+
}
|
|
1356
|
+
});
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
nextShot() {
|
|
1360
|
+
const a = this.active;
|
|
1361
|
+
const app = this.app;
|
|
1362
|
+
const tl = app.timeline;
|
|
1363
|
+
a.item++;
|
|
1364
|
+
this.hold = null;
|
|
1365
|
+
if (a.item >= a.queue.length) {
|
|
1366
|
+
const done = a.options.onDone;
|
|
1367
|
+
this.stop(a.options.restore !== false, true);
|
|
1368
|
+
if (done) {
|
|
1369
|
+
done();
|
|
1370
|
+
}
|
|
1371
|
+
return;
|
|
1372
|
+
}
|
|
1373
|
+
const { goal, shot } = a.queue[a.item];
|
|
1374
|
+
const plan = replayPlan(tl.store, app.source.header, goal, shot || 'auto');
|
|
1375
|
+
a.plan = plan;
|
|
1376
|
+
a.phase = 'play';
|
|
1377
|
+
a.holdClock = 0;
|
|
1378
|
+
a.slow = a.options.slow !== false;
|
|
1379
|
+
const shownBefore = this.recent && this.recent.goal.index === goal.index ? this.recent.angles : [];
|
|
1380
|
+
this.recent = { goal, angles: [...new Set([...shownBefore, plan.angle])] };
|
|
1381
|
+
tl.following = false;
|
|
1382
|
+
tl.seek(plan.begin);
|
|
1383
|
+
tl.direction = 1;
|
|
1384
|
+
tl.playing = true;
|
|
1385
|
+
tl.speed = 1;
|
|
1386
|
+
app.lastIndex = tl.index;
|
|
1387
|
+
const cams = app.cameras;
|
|
1388
|
+
if (plan.angle === 'broadcast' || plan.angle === 'lowside' || plan.angle === 'goal') {
|
|
1389
|
+
cams.focusIndex = plan.scorer;
|
|
1390
|
+
cams.setMode(plan.angle);
|
|
1391
|
+
} else {
|
|
1392
|
+
this.replayShot(plan, tl.t);
|
|
1393
|
+
this.shot.snap = true;
|
|
1394
|
+
this.useScripted();
|
|
1395
|
+
}
|
|
1396
|
+
app.afterSeek();
|
|
1397
|
+
const angle = ANGLE_NAMES[plan.angle] || t('show.sting.replay');
|
|
1398
|
+
app.hud.setReplay(true, a.item < a.queue.length - 1 ? tn('show.replay.bar.next', { angle }) : tn('show.replay.bar.skip', { angle }));
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
// The scripted replay angles, from the ball and the scorer at timeline position t.
|
|
1402
|
+
replayShot(plan, t) {
|
|
1403
|
+
const app = this.app;
|
|
1404
|
+
const store = app.timeline.store;
|
|
1405
|
+
const sh = this.shot;
|
|
1406
|
+
const b = ballAt(store, t, tmpBall);
|
|
1407
|
+
const ball = new THREE.Vector3(b[0], Math.max(0.2, b[2]), -b[1]);
|
|
1408
|
+
const dir = plan.goal.team === 0 ? 1 : -1;
|
|
1409
|
+
const goal = new THREE.Vector3(attackX(plan.goal.team), 1, 0);
|
|
1410
|
+
if (plan.angle === 'high') {
|
|
1411
|
+
sh.pos.set(b[0] - dir * 24, 24, -b[1] * 0.55 + 14);
|
|
1412
|
+
sh.target.set(b[0] + dir * 8, 0, -b[1] * 0.85);
|
|
1413
|
+
// A narrow picture turns the camera towards the goal as the ball nears it, so the ball
|
|
1414
|
+
// and the goal both stay in it.
|
|
1415
|
+
const near = THREE.MathUtils.clamp((60 - Math.hypot(goal.x - ball.x, goal.z - ball.z)) / 40, 0, 1);
|
|
1416
|
+
turnBetween(sh.pos, sh.target, ball, goal, narrowShare(app.view.aspect) * near);
|
|
1417
|
+
sh.fov = 44;
|
|
1418
|
+
sh.rate = 2.2;
|
|
1419
|
+
} else if (plan.angle === 'reverse') {
|
|
1420
|
+
const k = plan.scorer;
|
|
1421
|
+
const at = Math.min(t, plan.shotIndex);
|
|
1422
|
+
const s = k >= 0 ? playerAt(store, k, at, tmpA) : ballAt(store, at, tmpA);
|
|
1423
|
+
const anchor = new THREE.Vector3(s[0], 0, -s[1]);
|
|
1424
|
+
const d = new THREE.Vector3().subVectors(goal, anchor).setY(0);
|
|
1425
|
+
if (d.lengthSq() < 1) {
|
|
1426
|
+
d.set(dir, 0, 0);
|
|
1427
|
+
}
|
|
1428
|
+
d.normalize();
|
|
1429
|
+
const side = new THREE.Vector3(-d.z, 0, d.x);
|
|
1430
|
+
// High enough to see over the shooter, the goal mouth always in the frame.
|
|
1431
|
+
sh.pos.copy(anchor).addScaledVector(d, -10).addScaledVector(side, 1.4);
|
|
1432
|
+
sh.pos.y = 4.2;
|
|
1433
|
+
sh.target.copy(ball).lerp(goal, t >= plan.shotIndex ? 0.6 : 0.45);
|
|
1434
|
+
sh.target.y = Math.min(1.4, sh.target.y);
|
|
1435
|
+
sh.fov = 34;
|
|
1436
|
+
sh.rate = 3;
|
|
1437
|
+
} else {
|
|
1438
|
+
// From behind the net, a little off center, looking out at the ball.
|
|
1439
|
+
const z = Math.max(-1.2, Math.min(1.2, -b[1] * 0.15));
|
|
1440
|
+
sh.pos.set(dir * (HALF_W + 3.6), 1.35, z);
|
|
1441
|
+
sh.target.copy(ball);
|
|
1442
|
+
sh.target.y = Math.min(ball.y, 1.6);
|
|
1443
|
+
sh.fov = 42;
|
|
1444
|
+
sh.rate = 4;
|
|
1445
|
+
}
|
|
1446
|
+
confineShot(sh.pos);
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
// Each frame of a replay, slow motion from the shot on, the hold on the goal, the next angle.
|
|
1450
|
+
updateReplay(dt) {
|
|
1451
|
+
const a = this.active;
|
|
1452
|
+
const app = this.app;
|
|
1453
|
+
const tl = app.timeline;
|
|
1454
|
+
const p = a.plan;
|
|
1455
|
+
if (!p || this.wiping) {
|
|
1456
|
+
return;
|
|
1457
|
+
}
|
|
1458
|
+
const slowmo = Number(app.settings.slowmo) || 1;
|
|
1459
|
+
if (a.phase === 'play') {
|
|
1460
|
+
if (!tl.playing || tl.direction < 0) {
|
|
1461
|
+
this.stop(false);
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
tl.speed = a.slow && tl.t >= p.slowFrom ? slowmo : 1;
|
|
1465
|
+
if (tl.t >= p.end) {
|
|
1466
|
+
tl.t = p.end;
|
|
1467
|
+
tl.speed = 0;
|
|
1468
|
+
a.phase = 'hold';
|
|
1469
|
+
const fa = tl.store.get(p.end - 1) || tl.store.get(p.end);
|
|
1470
|
+
const fb = tl.store.get(p.end);
|
|
1471
|
+
this.hold = {
|
|
1472
|
+
index: p.end, clock: 0, team: p.goal.team, sps: tl.sps,
|
|
1473
|
+
a: fa.data.slice(8, 11), b: fb.data.slice(8, 11),
|
|
1474
|
+
};
|
|
1475
|
+
}
|
|
1476
|
+
} else if (a.phase === 'hold') {
|
|
1477
|
+
a.holdClock += dt * (a.slow ? slowmo : 1);
|
|
1478
|
+
this.hold.clock = a.holdClock;
|
|
1479
|
+
if (a.holdClock >= REPLAY_HOLD) {
|
|
1480
|
+
a.phase = 'wait';
|
|
1481
|
+
this.wiping = true;
|
|
1482
|
+
this.sting(a.item < a.queue.length - 1 ? t('show.sting.replay') : '', () => {
|
|
1483
|
+
this.wiping = false;
|
|
1484
|
+
if (this.active === a) {
|
|
1485
|
+
this.nextShot();
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
if (app.cameras.mode === 'scripted') {
|
|
1491
|
+
const t = a.phase === 'hold' ? p.end + Math.min(1, a.holdClock * 1.5) * 0.9 : tl.t;
|
|
1492
|
+
if (a.phase === 'hold') {
|
|
1493
|
+
// The camera follows the ball on into the net.
|
|
1494
|
+
const bx = tmpB;
|
|
1495
|
+
ballIntoNet(this.hold.a, this.hold.b, p.goal.team, tl.sps, a.holdClock, bx);
|
|
1496
|
+
this.replayShot(p, p.end);
|
|
1497
|
+
this.shot.target.set(bx[0], Math.min(1.6, Math.max(0.2, bx[2])), -bx[1]);
|
|
1498
|
+
} else {
|
|
1499
|
+
this.replayShot(p, t);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
// The orbit shot circles the player in focus.
|
|
1505
|
+
focusPoint(pose) {
|
|
1506
|
+
const k = this.app.cameras.focusIndex;
|
|
1507
|
+
if (k == null || k < 0 || k >= pose.players) {
|
|
1508
|
+
return null;
|
|
1509
|
+
}
|
|
1510
|
+
const o = k * PLAYER_FLOATS;
|
|
1511
|
+
return new THREE.Vector3(pose.nodes[o], 0, -pose.nodes[o + 1]);
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
// Enter or a click moves on, the lineups to kick-off, a celebration to its replay, a replay
|
|
1515
|
+
// to its next angle or back to play.
|
|
1516
|
+
skip() {
|
|
1517
|
+
if (this.wiping) {
|
|
1518
|
+
return;
|
|
1519
|
+
}
|
|
1520
|
+
if (this.lineup) {
|
|
1521
|
+
this.endLineups(true);
|
|
1522
|
+
} else if (this.cel) {
|
|
1523
|
+
this.afterCelebration();
|
|
1524
|
+
} else if (this.active && this.active.plan) {
|
|
1525
|
+
const a = this.active;
|
|
1526
|
+
a.phase = 'wait';
|
|
1527
|
+
this.wiping = true;
|
|
1528
|
+
this.sting(a.item < a.queue.length - 1 ? t('show.sting.replay') : '', () => {
|
|
1529
|
+
this.wiping = false;
|
|
1530
|
+
if (this.active === a) {
|
|
1531
|
+
this.nextShot();
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
// Ends whatever runs. restore puts play back where it was, else play stays where it is,
|
|
1538
|
+
// as when the user seeks or pauses. covered says a stinger already hides the cut.
|
|
1539
|
+
stop(restore, covered = false) {
|
|
1540
|
+
const app = this.app;
|
|
1541
|
+
clearTimeout(this.pending);
|
|
1542
|
+
if (this.wiping) {
|
|
1543
|
+
this.cancelSting();
|
|
1544
|
+
this.wiping = false;
|
|
1545
|
+
}
|
|
1546
|
+
this.hold = null;
|
|
1547
|
+
if (this.lineup) {
|
|
1548
|
+
this.closeLineups(restore);
|
|
1549
|
+
}
|
|
1550
|
+
if (this.cel) {
|
|
1551
|
+
const c = this.cel;
|
|
1552
|
+
if (restore) {
|
|
1553
|
+
this.cel = null;
|
|
1554
|
+
this.releaseClips(c);
|
|
1555
|
+
app.hud.scoreOf(null);
|
|
1556
|
+
this.resume(c.saved, c.goal.index);
|
|
1557
|
+
} else {
|
|
1558
|
+
this.endCelebration();
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
const a = this.active;
|
|
1562
|
+
if (!a) {
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
this.active = null;
|
|
1566
|
+
app.hud.setReplay(false);
|
|
1567
|
+
if (!app.postMatch.running) {
|
|
1568
|
+
app.hud.unfreeze();
|
|
1569
|
+
}
|
|
1570
|
+
if (!app.timeline) {
|
|
1571
|
+
return;
|
|
1572
|
+
}
|
|
1573
|
+
const tl = app.timeline;
|
|
1574
|
+
tl.speed = a.saved.speed;
|
|
1575
|
+
if (!restore) {
|
|
1576
|
+
if (!covered) {
|
|
1577
|
+
this.restoreCamera(a.saved);
|
|
1578
|
+
}
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1581
|
+
this.resume(a.saved, a.returnT);
|
|
1582
|
+
app.afterSeek();
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
// Team sheets before kick-off over a slow pan of the ground, while play waits.
|
|
1586
|
+
showLineups() {
|
|
1587
|
+
const app = this.app;
|
|
1588
|
+
const tl = app.timeline;
|
|
1589
|
+
if (!tl || !app.source || app.source.kind === 'live' || !app.settings.lineups || this.running
|
|
1590
|
+
|| tl.t > tl.first + 1 || app.postMatch.running) {
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
const saved = this.savedState();
|
|
1594
|
+
tl.pause();
|
|
1595
|
+
const overlay = this.lineupCard();
|
|
1596
|
+
document.getElementById('watch').appendChild(overlay);
|
|
1597
|
+
release(app);
|
|
1598
|
+
this.lineup = { clock: 0, overlay, saved };
|
|
1599
|
+
this.shot.snap = true;
|
|
1600
|
+
this.lineupShot(0);
|
|
1601
|
+
this.useScripted();
|
|
1602
|
+
app.updatePlayUi();
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
lineupShot(clock) {
|
|
1606
|
+
// Reduced motion holds the middle of the pan.
|
|
1607
|
+
const u = this.app.reducedMotion ? 0.5 : clock / LINEUP_LENGTH;
|
|
1608
|
+
const sh = this.shot;
|
|
1609
|
+
sh.pos.set(-38 + 76 * u, 26 - 6 * u, 58);
|
|
1610
|
+
sh.target.set(-14 + 28 * u, 0, 0);
|
|
1611
|
+
sh.fov = 40;
|
|
1612
|
+
sh.rate = 2;
|
|
1613
|
+
confineShot(sh.pos);
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1616
|
+
updateLineup(dt) {
|
|
1617
|
+
const l = this.lineup;
|
|
1618
|
+
l.clock += dt;
|
|
1619
|
+
this.lineupShot(l.clock);
|
|
1620
|
+
if (l.clock >= LINEUP_LENGTH && !this.wiping) {
|
|
1621
|
+
this.endLineups(true);
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
endLineups(playAfter) {
|
|
1626
|
+
if (this.wiping || !this.lineup) {
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
this.wiping = true;
|
|
1630
|
+
this.lineup.overlay.classList.add('leaving');
|
|
1631
|
+
this.sting('', () => {
|
|
1632
|
+
this.wiping = false;
|
|
1633
|
+
this.closeLineups(playAfter);
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
|
|
1637
|
+
closeLineups(playAfter) {
|
|
1638
|
+
const app = this.app;
|
|
1639
|
+
const l = this.lineup;
|
|
1640
|
+
this.lineup = null;
|
|
1641
|
+
if (!l) {
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
l.overlay.remove();
|
|
1645
|
+
this.restoreCamera(l.saved);
|
|
1646
|
+
app.cameras.jump();
|
|
1647
|
+
if (playAfter && app.timeline) {
|
|
1648
|
+
app.timeline.play(1);
|
|
1649
|
+
}
|
|
1650
|
+
app.updatePlayUi();
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
// The formation of a team sheet, such as 2-2, which names itself as the formation at kick-off.
|
|
1654
|
+
formationTag(lines) {
|
|
1655
|
+
const shape = lines.map((l) => l.length).join('-');
|
|
1656
|
+
const text = t('show.lineups.formation', { shape });
|
|
1657
|
+
return h('span', { class: 'ls-formation', title: text }, h('span', { 'aria-hidden': 'true' }, shape), h('span', { class: 'sr-only' }, text));
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
// The team sheets, keeper first, then the lines from the back, each from the team's left to
|
|
1661
|
+
// its right, with the formation read from the first frame.
|
|
1662
|
+
lineupCard() {
|
|
1663
|
+
const app = this.app;
|
|
1664
|
+
const header = app.source.header;
|
|
1665
|
+
const store = app.timeline.store;
|
|
1666
|
+
const names = teamNames(header);
|
|
1667
|
+
const sheets = [0, 1].map((team) => {
|
|
1668
|
+
const style = app.styles ? app.styles[team] : null;
|
|
1669
|
+
const { keeper, lines } = formation(store, header, team);
|
|
1670
|
+
const rows = [];
|
|
1671
|
+
const row = (k, role) => {
|
|
1672
|
+
const info = playerInfo(app, k);
|
|
1673
|
+
const num = h('span', { class: 'ls-num' }, String(info.number));
|
|
1674
|
+
num.style.background = info.color;
|
|
1675
|
+
num.style.color = info.ink;
|
|
1676
|
+
return h('li', { style: `--i:${rows.length}` }, num, h('span', { class: 'ls-name' }, info.name), h('span', { class: 'ls-role' }, ROLE_SHORT[role]));
|
|
1677
|
+
};
|
|
1678
|
+
if (keeper >= 0) {
|
|
1679
|
+
rows.push(row(keeper, 'GK'));
|
|
1680
|
+
}
|
|
1681
|
+
lines.forEach((line, i) => {
|
|
1682
|
+
const role = i === 0 && lines.length > 1 ? 'DF' : (i === lines.length - 1 && lines.length > 1 ? 'FW' : 'MF');
|
|
1683
|
+
for (const k of line) {
|
|
1684
|
+
rows.push(row(k, role));
|
|
1685
|
+
}
|
|
1686
|
+
});
|
|
1687
|
+
const chip = h('i', { class: 'ls-chip' });
|
|
1688
|
+
chip.style.background = kitSwatch(style);
|
|
1689
|
+
return h('section', { class: `ls-sheet side-${team}` },
|
|
1690
|
+
h('header', {}, chip, style && style.badge ? h('b', { class: 'ls-badge' }, style.badge) : null,
|
|
1691
|
+
h('span', { class: 'ls-team' }, names[team]),
|
|
1692
|
+
lines.length > 1 ? this.formationTag(lines) : null),
|
|
1693
|
+
h('ol', { class: 'ls-list' }, rows));
|
|
1694
|
+
});
|
|
1695
|
+
const card = h('div', { id: 'lineups', class: 'lineups' },
|
|
1696
|
+
h('div', { class: 'post-kicker' }, t('show.lineups.title')),
|
|
1697
|
+
h('div', { class: 'ls-sheets' }, sheets),
|
|
1698
|
+
h('div', { class: 'post-hint muted small' }, tn('show.lineups.hint')));
|
|
1699
|
+
card.addEventListener('click', () => this.skip());
|
|
1700
|
+
return card;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
// A team's keeper and its outfield lines from the back, read from the first frame. A player
|
|
1705
|
+
// shares the line of the one before within a gap of depth of 5 meters, or of two fifths of the
|
|
1706
|
+
// depth the team spans when that is less, and at least a meter, so the close lines of five a side,
|
|
1707
|
+
// a few meters apart at kick-off, part as those of eleven a side do. Each line runs from the
|
|
1708
|
+
// team's left.
|
|
1709
|
+
export function formation(store, header, team) {
|
|
1710
|
+
const f = store.get(store.first);
|
|
1711
|
+
const attack = team === 0 ? 1 : -1;
|
|
1712
|
+
let keeper = -1;
|
|
1713
|
+
const list = [];
|
|
1714
|
+
header.players.forEach((p, k) => {
|
|
1715
|
+
if (p.team !== team) {
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
if (p.goalkeeper) {
|
|
1719
|
+
keeper = k;
|
|
1720
|
+
return;
|
|
1721
|
+
}
|
|
1722
|
+
const o = NODES_FLOAT + k * PLAYER_FLOATS;
|
|
1723
|
+
list.push({ k, depth: f ? f.data[o] * attack : p.index, side: f ? f.data[o + 1] * attack : 0 });
|
|
1724
|
+
});
|
|
1725
|
+
list.sort((a, b) => a.depth - b.depth);
|
|
1726
|
+
const span = list.length ? list[list.length - 1].depth - list[0].depth : 0;
|
|
1727
|
+
const gap = Math.max(1, Math.min(5, span * 0.4));
|
|
1728
|
+
const lines = [];
|
|
1729
|
+
for (const x of list) {
|
|
1730
|
+
const line = lines[lines.length - 1];
|
|
1731
|
+
if (line && x.depth - line[line.length - 1].depth < gap) {
|
|
1732
|
+
line.push(x);
|
|
1733
|
+
} else {
|
|
1734
|
+
lines.push([x]);
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
return { keeper, lines: lines.map((line) => line.sort((a, b) => b.side - a.side).map((x) => x.k)) };
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// Match facts, scorers with minutes, possession, shots, passes, tackles, saves and cards, all
|
|
1741
|
+
// from the frames. Possession counts the steps each team owns the ball.
|
|
1742
|
+
export function matchFacts(store, header) {
|
|
1743
|
+
const { stats, goals, shots, passes, tackles } = matchStats(store, header);
|
|
1744
|
+
const owned = [0, 0];
|
|
1745
|
+
for (let i = store.first; i <= store.last; i++) {
|
|
1746
|
+
const f = store.get(i);
|
|
1747
|
+
if (f.ownedTeam === 0 || f.ownedTeam === 1) {
|
|
1748
|
+
owned[f.ownedTeam]++;
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
const perTeam = (list, keep = () => true) => [0, 1].map((team) => list.filter((x) => x.team === team && keep(x)).length);
|
|
1752
|
+
const saves = [0, 1].map((team) => stats.filter((s) => s.team === team).reduce((sum, s) => sum + s.saves, 0));
|
|
1753
|
+
const final = store.get(store.last);
|
|
1754
|
+
const cards = header.players.map((p, k) => ({ k, p, flags: final.playerFlags[k] }))
|
|
1755
|
+
.filter((c) => c.flags & 6)
|
|
1756
|
+
.map((c) => ({ k: c.k, team: c.p.team, red: !!(c.flags & 4) }));
|
|
1757
|
+
const total = owned[0] + owned[1] || 1;
|
|
1758
|
+
return {
|
|
1759
|
+
stats,
|
|
1760
|
+
shotEvents: shots,
|
|
1761
|
+
passEvents: passes,
|
|
1762
|
+
score: [final.scoreLeft, final.scoreRight],
|
|
1763
|
+
scorers: goals.map((g) => ({ ...g, minute: Math.max(1, Math.ceil(store.get(g.index).timeMs / 60000)) })),
|
|
1764
|
+
possession: [Math.round((owned[0] / total) * 100), Math.round((owned[1] / total) * 100)],
|
|
1765
|
+
shots: perTeam(shots),
|
|
1766
|
+
onTarget: perTeam(shots, (s) => s.onTarget),
|
|
1767
|
+
passes: perTeam(passes),
|
|
1768
|
+
passesCompleted: perTeam(passes, (p) => p.completed),
|
|
1769
|
+
tackles: perTeam(tackles),
|
|
1770
|
+
saves,
|
|
1771
|
+
cards,
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
// Player contribution grades, achievements and the statistics screen.
|
|
1776
|
+
export const GRADES =
|
|
1777
|
+
[ 'F', 'D-', 'D', 'D+', 'C-', 'C', 'C+', 'B-', 'B', 'B+', 'A-', 'A', 'A+', 'S' ];
|
|
1778
|
+
export const CUTOFFS = [ 0, 2, 3, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9.5 ];
|
|
1779
|
+
const clamp = (x, lo, hi) => Math.max(lo, Math.min(hi, x));
|
|
1780
|
+
const pos = (f, k) => f.data[NODES_FLOAT + k * PLAYER_FLOATS];
|
|
1781
|
+
const medal = (s) => h('span', {
|
|
1782
|
+
class: `grade-medal tier-${s.tier}`,
|
|
1783
|
+
title: s.grade ? t('show.medal.rating', { rating: fixed(s.rating, 2) }) : t('show.medal.ungraded')
|
|
1784
|
+
},
|
|
1785
|
+
s.grade || '—');
|
|
1786
|
+
|
|
1787
|
+
// The frames that the statistics describe, all of a recording, or for a live source the latest
|
|
1788
|
+
// completed episode, and the current one until an episode completes.
|
|
1789
|
+
export function summaryStore(store, live) {
|
|
1790
|
+
const { first, last } = live ? summaryRange(store) : { first: store.first, last: store.last };
|
|
1791
|
+
const frames = [];
|
|
1792
|
+
for (let i = first; i <= last; i++) frames.push(store.get(i));
|
|
1793
|
+
return {first, last, get: (i) => frames[i - first]};
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
export function contribution(store, header, facts) {
|
|
1797
|
+
const first = store.get(store.first);
|
|
1798
|
+
const last = store.get(store.last);
|
|
1799
|
+
const duration = Math.max(0, (last.timeMs - first.timeMs) / 60000);
|
|
1800
|
+
const players = facts.stats.map((s) => {
|
|
1801
|
+
const x = pos(first, s.k) * (s.team === 0 ? 1 : -1);
|
|
1802
|
+
const role = s.goalkeeper ? 'GK' : x < -15 ? 'DF' : x > 10 ? 'FW' : 'MF';
|
|
1803
|
+
return {
|
|
1804
|
+
...s,
|
|
1805
|
+
role,
|
|
1806
|
+
minutes: 0,
|
|
1807
|
+
elapsedMs: 0,
|
|
1808
|
+
keyPasses: 0,
|
|
1809
|
+
yellow: 0,
|
|
1810
|
+
red: 0,
|
|
1811
|
+
clean: 0,
|
|
1812
|
+
achievements: []
|
|
1813
|
+
};
|
|
1814
|
+
});
|
|
1815
|
+
const bins = Array.from({length: 12},
|
|
1816
|
+
() => ({owned: [ 0, 0 ], pressure: 0, count: 0, shots: [ 0, 0 ], goals: [ 0, 0 ]}));
|
|
1817
|
+
const marks = [];
|
|
1818
|
+
const binOf = (i) =>
|
|
1819
|
+
clamp(Math.floor((i - store.first) / Math.max(1, store.last - store.first) * 12), 0, 11);
|
|
1820
|
+
for (let i = store.first + 1; i <= store.last; i++) {
|
|
1821
|
+
const a = store.get(i - 1);
|
|
1822
|
+
const b = store.get(i);
|
|
1823
|
+
if (!a || !b || isCut(a, b)) continue;
|
|
1824
|
+
const dt = clamp(b.timeMs - a.timeMs, 0, 60000);
|
|
1825
|
+
const bin = bins[binOf(i)];
|
|
1826
|
+
if (b.ownedTeam >= 0 && b.ownedTeam <= 1) {
|
|
1827
|
+
bin.owned[b.ownedTeam]++;
|
|
1828
|
+
bin.pressure += 0.5 * clamp(b.data[8] / 52.5, -1, 1) + (b.ownedTeam === 0 ? 0.5 : -0.5);
|
|
1829
|
+
bin.count++;
|
|
1830
|
+
}
|
|
1831
|
+
for (const s of players) {
|
|
1832
|
+
if (a.playerFlags[s.k] & 1) s.elapsedMs += dt;
|
|
1833
|
+
const added = b.playerFlags[s.k] & ~a.playerFlags[s.k];
|
|
1834
|
+
if (added & 2) s.yellow++;
|
|
1835
|
+
if (added & 4) s.red++;
|
|
1836
|
+
if (added & 6)
|
|
1837
|
+
marks.push({
|
|
1838
|
+
i,
|
|
1839
|
+
team: s.team,
|
|
1840
|
+
label: added & 4 ? 'Red card' : 'Yellow card',
|
|
1841
|
+
icon: added & 4 ? '🟥' : '🟨'
|
|
1842
|
+
});
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
for (const shot of facts.shotEvents) {
|
|
1846
|
+
bins[binOf(shot.i)].shots[shot.team]++;
|
|
1847
|
+
const pass = facts.passEvents.findLast((p) => p.completed && p.team === shot.team &&
|
|
1848
|
+
p.receiver === shot.k && p.i < shot.i &&
|
|
1849
|
+
shot.i - p.i <= 10 * (header.steps_per_second || 10));
|
|
1850
|
+
if (pass) {
|
|
1851
|
+
let clear = true;
|
|
1852
|
+
for (let i = pass.i + 1; i <= shot.i; i++) {
|
|
1853
|
+
const f = store.get(i);
|
|
1854
|
+
if (!f || isCut(store.get(i - 1), f) || f.gameMode !== 0 ||
|
|
1855
|
+
(f.ownedTeam >= 0 && f.ownedTeam !== shot.team) ||
|
|
1856
|
+
f.touches.some((touch, k) => (touch === 1 || touch === 2) &&
|
|
1857
|
+
header.players[k].team !== shot.team)) {
|
|
1858
|
+
clear = false;
|
|
1859
|
+
break;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
if (clear) players[pass.k].keyPasses++;
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
for (const g of facts.scorers) {
|
|
1866
|
+
bins[binOf(g.index)].goals[g.team]++;
|
|
1867
|
+
marks.push({i: g.index, team: g.team, label: 'Goal', icon: '●'});
|
|
1868
|
+
}
|
|
1869
|
+
// The name stays the English key that orders the headline, the label is what people read,
|
|
1870
|
+
// and brief is the reason the headline shows.
|
|
1871
|
+
const award = (s, name, icon, reason, brief = reason) =>
|
|
1872
|
+
s.achievements.push({name, label: AWARD_LABELS[name], icon, reason, brief});
|
|
1873
|
+
const max = (key) => Math.max(0, ...players.map((s) => s[key]));
|
|
1874
|
+
for (const s of players) {
|
|
1875
|
+
s.minutes = s.elapsedMs / 60000;
|
|
1876
|
+
const conceded =
|
|
1877
|
+
facts.scorers
|
|
1878
|
+
.filter((g) => g.team !== s.team && (store.get(g.index).playerFlags[s.k] & 1))
|
|
1879
|
+
.length;
|
|
1880
|
+
s.clean = duration >= 1 && s.minutes >= duration * 0.8 && conceded === 0 ? 1 : 0;
|
|
1881
|
+
const defense = s.role === 'GK' || s.role === 'DF';
|
|
1882
|
+
const scale = Math.min(3, 30 / Math.max(10, s.minutes));
|
|
1883
|
+
const accuracy = s.passes ? s.passesCompleted / s.passes : 0;
|
|
1884
|
+
s.accuracy = s.passes ? Math.round(100 * accuracy) : null;
|
|
1885
|
+
s.shotAccuracy = s.shots ? Math.round(100 * s.shotsOnTarget / s.shots) : null;
|
|
1886
|
+
s.positive = scale *
|
|
1887
|
+
(1.4 * s.goals + s.assists + 0.25 * s.shotsOnTarget + 0.35 * s.keyPasses +
|
|
1888
|
+
(defense ? 0.6 : 0.35) * s.tackles + (s.goalkeeper ? 0.65 : 0) * s.saves);
|
|
1889
|
+
s.passing = s.passes >= 3 ? (accuracy - 0.65) * 1.5 : 0;
|
|
1890
|
+
s.sheet = s.clean ? (defense ? 1 : 0.3) : 0;
|
|
1891
|
+
s.penalty = 2 * s.ownGoals + 0.4 * s.yellow + 1.5 * s.red;
|
|
1892
|
+
s.rating = clamp(5 + s.positive + s.passing + s.sheet - s.penalty, 0, 10);
|
|
1893
|
+
const eligible = s.minutes >= Math.max(0.5, Math.min(10, duration * 0.2));
|
|
1894
|
+
let gradeIndex = CUTOFFS.findLastIndex((v) => s.rating >= v);
|
|
1895
|
+
if (gradeIndex === 13 &&
|
|
1896
|
+
(s.minutes < Math.max(1, duration * 0.6) || s.positive < 4.5 || s.penalty > 0))
|
|
1897
|
+
gradeIndex = 12;
|
|
1898
|
+
s.gradeRank = eligible ? gradeIndex : -1;
|
|
1899
|
+
s.grade = eligible ? GRADES[gradeIndex] : null;
|
|
1900
|
+
const tiers = ['plain', 'plain', 'plain', 'plain', 'bronze', 'bronze', 'bronze',
|
|
1901
|
+
'silver', 'silver', 'silver', 'gold', 'gold', 'gold', 's'];
|
|
1902
|
+
s.tier = eligible ? tiers[gradeIndex] : 'plain';
|
|
1903
|
+
if (s.goals >= 3)
|
|
1904
|
+
award(s, 'Hat trick', '⚽', t('show.award.hattrick.reason', { count: s.goals }));
|
|
1905
|
+
else if (s.goals === 2)
|
|
1906
|
+
award(s, 'Brace', '⚽', t('show.award.brace.reason'));
|
|
1907
|
+
if (s.assists > 0 && s.assists === max('assists'))
|
|
1908
|
+
award(s, 'Playmaker', '✦', t('show.award.playmaker.reason', { count: s.assists }),
|
|
1909
|
+
t('show.award.playmaker.brief', { count: s.assists }));
|
|
1910
|
+
else if (s.keyPasses >= 2 && s.keyPasses === max('keyPasses'))
|
|
1911
|
+
award(s, 'Creator', '✦', t('show.award.creator.reason', { count: s.keyPasses }),
|
|
1912
|
+
t('show.award.creator.brief', { count: s.keyPasses }));
|
|
1913
|
+
if (s.saves > 0 && s.saves === max('saves'))
|
|
1914
|
+
award(s, 'Wall', '▣', t('show.award.wall.reason', { count: s.saves }),
|
|
1915
|
+
t('show.award.wall.brief', { count: s.saves }));
|
|
1916
|
+
if (s.clean)
|
|
1917
|
+
award(s, 'Clean sheet', '◇', t('show.award.cleansheet.reason', { count: fixed(s.minutes, 1) }));
|
|
1918
|
+
if (s.touches >= 5 && s.touches === max('touches'))
|
|
1919
|
+
award(s, 'Engine', '↯', t('show.award.engine.reason', { count: s.touches }),
|
|
1920
|
+
t('show.award.engine.brief', { count: s.touches }));
|
|
1921
|
+
if (s.tackles >= 2 && s.tackles === max('tackles'))
|
|
1922
|
+
award(s, 'Ball winner', '◆', t('show.award.ballwinner.reason', { count: s.tackles }),
|
|
1923
|
+
t('show.award.ballwinner.brief', { count: s.tackles }));
|
|
1924
|
+
if (s.shots >= 3 && s.shotsOnTarget / s.shots >= 0.75)
|
|
1925
|
+
award(s, 'Sharpshooter', '◎', t('show.award.sharpshooter.reason', { onTarget: s.shotsOnTarget, count: s.shots }));
|
|
1926
|
+
if (s.ownGoals) award(s, 'Own goal', '↶', t('show.award.owngoal.reason', { count: s.ownGoals }));
|
|
1927
|
+
if (s.red) award(s, 'Sent off', '▮', t('show.award.sentoff.reason', { count: s.red }));
|
|
1928
|
+
}
|
|
1929
|
+
const teams = [ [], [] ];
|
|
1930
|
+
for (const team of [0, 1]) {
|
|
1931
|
+
const opponent = 1 - team;
|
|
1932
|
+
if (duration >= 1 && facts.score[opponent] === 0 &&
|
|
1933
|
+
(team === 0 ? first.scoreRight : first.scoreLeft) === 0)
|
|
1934
|
+
teams[team].push({
|
|
1935
|
+
name: 'Clean sheet',
|
|
1936
|
+
label: AWARD_LABELS['Clean sheet'],
|
|
1937
|
+
icon: '◇',
|
|
1938
|
+
reason: t('show.award.team.cleansheet.reason')
|
|
1939
|
+
});
|
|
1940
|
+
if (facts.score[team] > facts.score[opponent]) {
|
|
1941
|
+
const trailed = facts.scorers.some((g) => {
|
|
1942
|
+
const f = store.get(g.index);
|
|
1943
|
+
return (team === 0 ? f.scoreLeft - f.scoreRight : f.scoreRight - f.scoreLeft) < 0;
|
|
1944
|
+
});
|
|
1945
|
+
if (trailed)
|
|
1946
|
+
teams[team].push({
|
|
1947
|
+
name: 'Comeback',
|
|
1948
|
+
label: AWARD_LABELS.Comeback,
|
|
1949
|
+
icon: '↗',
|
|
1950
|
+
reason: t('show.award.comeback.reason', { scored: facts.score[team], conceded: facts.score[opponent] })
|
|
1951
|
+
});
|
|
1952
|
+
const winner = facts.scorers.find((g) => g.team === team &&
|
|
1953
|
+
(team === 0 ? store.get(g.index).scoreLeft : store.get(g.index).scoreRight) ===
|
|
1954
|
+
facts.score[opponent] + 1);
|
|
1955
|
+
if (winner && duration >= 1 &&
|
|
1956
|
+
store.get(winner.index).timeMs >= first.timeMs + duration * 60000 * 0.9)
|
|
1957
|
+
teams[team].push({
|
|
1958
|
+
name: 'Late winner',
|
|
1959
|
+
label: AWARD_LABELS['Late winner'],
|
|
1960
|
+
icon: '◷',
|
|
1961
|
+
reason: t('show.award.latewinner.reason', { minute: winner.minute })
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
return {players, bins, marks, teams, duration};
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
// The comparison of the two teams, a row per fact with both values and a bar of their shares.
|
|
1969
|
+
export function comparisonTable(f, styles = [null, null]) {
|
|
1970
|
+
const row = (label, a, b, va = Number(a), vb = Number(b)) => {
|
|
1971
|
+
const sum = (va || 0) + (vb || 0);
|
|
1972
|
+
const share = sum > 0 ? (va / sum) * 100 : 50;
|
|
1973
|
+
const bar = h('div', { class: 'post-bar', 'aria-hidden': 'true' }, h('i', { style: `width:${share}%` }));
|
|
1974
|
+
return h('tr', {}, h('td', { class: 'num' }, String(a)),
|
|
1975
|
+
h('th', { scope: 'row' }, label, sum > 0 ? bar : null), h('td', { class: 'num' }, String(b)));
|
|
1976
|
+
};
|
|
1977
|
+
const cards = (team, red) => f.cards.filter((c) => c.team === team && c.red === red).length;
|
|
1978
|
+
const accuracy = (team) => (f.passes[team] ? Math.round((100 * f.passesCompleted[team]) / f.passes[team]) : null);
|
|
1979
|
+
const pct = (v) => (v == null ? '–' : `${v}%`);
|
|
1980
|
+
const table = h('table', { class: 'post-table' }, h('tbody', {},
|
|
1981
|
+
row(t('show.compare.possession'), `${f.possession[0]}%`, `${f.possession[1]}%`, f.possession[0], f.possession[1]),
|
|
1982
|
+
row(t('show.compare.shots'), f.shots[0], f.shots[1]),
|
|
1983
|
+
row(t('show.compare.ontarget'), f.onTarget[0], f.onTarget[1]),
|
|
1984
|
+
row(t('show.compare.passes'), f.passes[0], f.passes[1]),
|
|
1985
|
+
row(t('show.compare.accuracy'), pct(accuracy(0)), pct(accuracy(1)), accuracy(0) || 0, accuracy(1) || 0),
|
|
1986
|
+
row(t('show.compare.tackles'), f.tackles[0], f.tackles[1]),
|
|
1987
|
+
row(t('show.compare.saves'), f.saves[0], f.saves[1]),
|
|
1988
|
+
row(t('show.compare.yellow'), cards(0, false), cards(1, false)),
|
|
1989
|
+
row(t('show.compare.red'), cards(0, true), cards(1, true))));
|
|
1990
|
+
table.style.setProperty('--left', styles && styles[0] ? css(styles[0].kit.primary) : 'var(--accent)');
|
|
1991
|
+
table.style.setProperty('--right', styles && styles[1] ? css(styles[1].kit.primary) : 'var(--muted)');
|
|
1992
|
+
return table;
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
// The player of the match, the winners' best by score, or the best of both teams after a draw.
|
|
1996
|
+
export function playerOfMatch(stats, score) {
|
|
1997
|
+
const winner = score[0] === score[1] ? -1 : score[0] > score[1] ? 0 : 1;
|
|
1998
|
+
const best = stats.slice().sort((a, b) => b.score - a.score);
|
|
1999
|
+
return winner >= 0 ? best.find((s) => s.team === winner) : best[0];
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
// The comparison of the statistics screen draws its bars in the colors of the charts.
|
|
2003
|
+
function chartColors(table) {
|
|
2004
|
+
table.style.setProperty('--left', 'var(--chart-0)');
|
|
2005
|
+
table.style.setProperty('--right', 'var(--chart-1)');
|
|
2006
|
+
return table;
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
let medalCount = 0;
|
|
2010
|
+
|
|
2011
|
+
// The MVP medal, a gold disc with an embossed rim, a laurel, a star and MVP lettering, hung from a
|
|
2012
|
+
// ribbon in the two colors of the player's team. It is inline SVG, crisp at any size, and a band of
|
|
2013
|
+
// light sweeps across the gold now and then. Each color comes as its red, green and blue channels,
|
|
2014
|
+
// and the SVG takes them as numbers from 0 to 255 alone.
|
|
2015
|
+
export function mvpMedal(channels) {
|
|
2016
|
+
const id = `mvp-medal-${++medalCount}`;
|
|
2017
|
+
const colors = channels.map((c) => `rgb(${[0, 1, 2].map((i) =>
|
|
2018
|
+
Math.round(Math.min(255, Math.max(0, Number(c[i]) || 0)))).join(', ')})`);
|
|
2019
|
+
const f = (v) => v.toFixed(2);
|
|
2020
|
+
const leaves = [];
|
|
2021
|
+
for (const side of [-1, 1]) {
|
|
2022
|
+
for (let i = 0; i < 7; i++) {
|
|
2023
|
+
const phi = 26 + i * 17;
|
|
2024
|
+
const r = (phi * Math.PI) / 180;
|
|
2025
|
+
const x = 60 + side * 29 * Math.sin(r);
|
|
2026
|
+
const y = 112 + 29 * Math.cos(r);
|
|
2027
|
+
const angle = side * (90 - phi) + side * (i % 2 ? -28 : 28);
|
|
2028
|
+
leaves.push(`<ellipse cx="${f(x)}" cy="${f(y)}" rx="2.4" ry="5.6" transform="rotate(${f(angle)} ${f(x)} ${f(y)})"/>`);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
const star = Array.from({ length: 10 }, (_, i) => {
|
|
2032
|
+
const r = i % 2 ? 4.6 : 11;
|
|
2033
|
+
const a = (Math.PI / 5) * i - Math.PI / 2;
|
|
2034
|
+
return `${f(60 + r * Math.cos(a))},${f(98 + r * Math.sin(a))}`;
|
|
2035
|
+
}).join(' ');
|
|
2036
|
+
const node = h('div', { class: 'mvp-medal', role: 'img', 'aria-label': t('show.mvp.medal') });
|
|
2037
|
+
node.innerHTML = `<svg viewBox="0 0 120 170" aria-hidden="true" focusable="false">
|
|
2038
|
+
<defs>
|
|
2039
|
+
<linearGradient id="${id}-rim" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#fff4c2"/><stop offset="0.35" stop-color="#e7b94c"/><stop offset="0.7" stop-color="#a8701a"/><stop offset="1" stop-color="#6e4608"/></linearGradient>
|
|
2040
|
+
<linearGradient id="${id}-bevel" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#8a5a10"/><stop offset="0.5" stop-color="#c8922e"/><stop offset="1" stop-color="#fff0b0"/></linearGradient>
|
|
2041
|
+
<radialGradient id="${id}-face" cx="0.38" cy="0.32" r="0.75"><stop offset="0" stop-color="#fff6cf"/><stop offset="0.45" stop-color="#f0c75a"/><stop offset="1" stop-color="#b8801f"/></radialGradient>
|
|
2042
|
+
<linearGradient id="${id}-shade" x1="0" y1="0" x2="1" y2="0"><stop offset="0" stop-color="#000" stop-opacity="0.35"/><stop offset="0.5" stop-color="#000" stop-opacity="0"/><stop offset="1" stop-color="#000" stop-opacity="0.35"/></linearGradient>
|
|
2043
|
+
<linearGradient id="${id}-shine" x1="0" y1="0" x2="1" y2="0"><stop offset="0" stop-color="#fff" stop-opacity="0"/><stop offset="0.5" stop-color="#fff" stop-opacity="0.75"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></linearGradient>
|
|
2044
|
+
<clipPath id="${id}-clip"><circle cx="60" cy="112" r="46"/></clipPath>
|
|
2045
|
+
</defs>
|
|
2046
|
+
<path d="M36 0H60V64L48 74L36 64Z" fill="${colors[0]}"/>
|
|
2047
|
+
<path d="M60 0H84V64L72 74L60 64Z" fill="${colors[1]}"/>
|
|
2048
|
+
<path d="M36 0H84V64L72 74L60 64L48 74L36 64Z" fill="url(#${id}-shade)" stroke="#00000066" stroke-width="1"/>
|
|
2049
|
+
<rect x="49" y="57" width="22" height="10" rx="2" fill="url(#${id}-rim)" stroke="#6e4608" stroke-width="0.8"/>
|
|
2050
|
+
<circle cx="60" cy="112" r="46" fill="url(#${id}-rim)"/>
|
|
2051
|
+
<circle cx="60" cy="112" r="40.5" fill="url(#${id}-bevel)"/>
|
|
2052
|
+
<circle cx="60" cy="112" r="37.5" fill="url(#${id}-face)"/>
|
|
2053
|
+
<circle cx="60" cy="112" r="43.2" fill="none" stroke="#fff4c8" stroke-opacity="0.75" stroke-width="1.5" stroke-dasharray="0.1 3.4" stroke-linecap="round"/>
|
|
2054
|
+
<g fill="#9a6a14" stroke="#fff0b8" stroke-opacity="0.55" stroke-width="0.5">${leaves.join('')}</g>
|
|
2055
|
+
<polygon points="${star}" fill="#fff1b8" stroke="#8a5a10" stroke-width="1.2" stroke-linejoin="round"/>
|
|
2056
|
+
<text x="60" y="131" text-anchor="middle" font-family="Georgia, 'Times New Roman', serif" font-size="17" font-weight="700" letter-spacing="1.5" fill="#fff4cc" opacity="0.8">MVP</text>
|
|
2057
|
+
<text x="60" y="130" text-anchor="middle" font-family="Georgia, 'Times New Roman', serif" font-size="17" font-weight="700" letter-spacing="1.5" fill="#6b440a">MVP</text>
|
|
2058
|
+
<g clip-path="url(#${id}-clip)"><g transform="rotate(24 60 112)"><rect class="medal-shine" x="-10" y="40" width="22" height="150" fill="url(#${id}-shine)"/></g></g>
|
|
2059
|
+
</svg>`;
|
|
2060
|
+
return node;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
// The kit colors of the two teams for the charts, or null without kits. A second team whose shirt
|
|
2064
|
+
// is close to the first team's takes its trim color, so the two sides stay apart.
|
|
2065
|
+
export function teamChartColors(styles) {
|
|
2066
|
+
if (!styles || !styles[0] || !styles[1] || !styles[0].kit || !styles[1].kit) {
|
|
2067
|
+
return null;
|
|
2068
|
+
}
|
|
2069
|
+
const a = styles[0].kit.primary;
|
|
2070
|
+
let b = styles[1].kit.primary;
|
|
2071
|
+
const gap = (x, y) => Math.hypot(x[0] - y[0], x[1] - y[1], x[2] - y[2]);
|
|
2072
|
+
if (gap(a, b) < 90 && styles[1].kit.secondary && gap(a, styles[1].kit.secondary) > gap(a, b)) {
|
|
2073
|
+
b = styles[1].kit.secondary;
|
|
2074
|
+
}
|
|
2075
|
+
return [css(a), css(b)];
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
// Numbers the clip paths of the possession charts, so each chart on the page has its own.
|
|
2079
|
+
let chartCount = 0;
|
|
2080
|
+
|
|
2081
|
+
// One chart over the periods of the match, drawn in the colors of the two sides.
|
|
2082
|
+
function chart(report, kind, names, store) {
|
|
2083
|
+
const ns = 'http://www.w3.org/2000/svg';
|
|
2084
|
+
const svg = document.createElementNS(ns, 'svg');
|
|
2085
|
+
svg.setAttribute('viewBox', '0 0 320 106');
|
|
2086
|
+
svg.setAttribute('role', 'img');
|
|
2087
|
+
const draw = (tag, attrs, text) => {
|
|
2088
|
+
const node = document.createElementNS(ns, tag);
|
|
2089
|
+
for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v);
|
|
2090
|
+
if (text != null) node.textContent = text;
|
|
2091
|
+
svg.append(node);
|
|
2092
|
+
return node;
|
|
2093
|
+
};
|
|
2094
|
+
const tip = (node, text) => {
|
|
2095
|
+
const title = document.createElementNS(ns, 'title');
|
|
2096
|
+
title.textContent = text;
|
|
2097
|
+
node.append(title);
|
|
2098
|
+
};
|
|
2099
|
+
const left = 6;
|
|
2100
|
+
const width = 308;
|
|
2101
|
+
const top = 6;
|
|
2102
|
+
const bottom = 86;
|
|
2103
|
+
const step = width / 12;
|
|
2104
|
+
const bins = report.bins;
|
|
2105
|
+
const legend = [];
|
|
2106
|
+
if (kind === 'possession') {
|
|
2107
|
+
// The share of the first team in each period around an even split. The line and the
|
|
2108
|
+
// area under it take the first team's color above the middle and the second's below,
|
|
2109
|
+
// so the color changes where the line crosses the middle.
|
|
2110
|
+
const mid = (top + bottom) / 2;
|
|
2111
|
+
const id = `possession-${++chartCount}`;
|
|
2112
|
+
const defs = draw('defs', {});
|
|
2113
|
+
for (const [side, y, height] of [[0, top - 4, mid - top + 4], [1, mid, bottom - mid + 4]]) {
|
|
2114
|
+
const clip = document.createElementNS(ns, 'clipPath');
|
|
2115
|
+
clip.setAttribute('id', `${id}-${side}`);
|
|
2116
|
+
const rect = document.createElementNS(ns, 'rect');
|
|
2117
|
+
for (const [k, v] of Object.entries({ x: 0, y, width: 320, height })) rect.setAttribute(k, v);
|
|
2118
|
+
clip.append(rect);
|
|
2119
|
+
defs.append(clip);
|
|
2120
|
+
}
|
|
2121
|
+
let last = 0.5;
|
|
2122
|
+
const points = bins.map((b, i) => {
|
|
2123
|
+
const total = b.owned[0] + b.owned[1];
|
|
2124
|
+
const share = total ? b.owned[0] / total : last;
|
|
2125
|
+
last = share;
|
|
2126
|
+
return { x: left + (i + 0.5) * step, y: mid - (share - 0.5) * 2 * (mid - top), share, total };
|
|
2127
|
+
});
|
|
2128
|
+
const line = points.map((p) => `${p.x},${p.y}`);
|
|
2129
|
+
const first = points[0] || { y: mid };
|
|
2130
|
+
const end = points[points.length - 1] || first;
|
|
2131
|
+
const edge = [`${left},${first.y}`, ...line, `${left + width},${end.y}`];
|
|
2132
|
+
const area = `M${left} ${mid}L${edge.join('L')}L${left + width} ${mid}Z`;
|
|
2133
|
+
for (const side of [0, 1]) {
|
|
2134
|
+
draw('path', { d: area, class: `chart-side-${side} chart-area`, 'clip-path': `url(#${id}-${side})` });
|
|
2135
|
+
draw('polyline', { points: edge.join(' '), class: `chart-line side-${side}`, 'clip-path': `url(#${id}-${side})` });
|
|
2136
|
+
}
|
|
2137
|
+
for (const p of points) {
|
|
2138
|
+
if (!p.total) continue;
|
|
2139
|
+
const text = t('show.chart.possession.tip', { left: names[0], leftShare: Math.round(100 * p.share), right: names[1], rightShare: Math.round(100 * (1 - p.share)) });
|
|
2140
|
+
tip(draw('circle', { cx: p.x, cy: p.y, r: 2.5, class: `chart-side-${p.share >= 0.5 ? 0 : 1}` }), text);
|
|
2141
|
+
}
|
|
2142
|
+
draw('path', { d: `M${left} ${mid}H${left + width}`, class: 'chart-rule half' });
|
|
2143
|
+
draw('text', { x: left + width - 3, y: mid - 3, class: 'chart-note end' }, '50%');
|
|
2144
|
+
draw('text', { x: left + 3, y: top + 11, class: 'chart-note' }, t('show.chart.possession.more', { team: names[0] }));
|
|
2145
|
+
draw('text', { x: left + 3, y: bottom - 5, class: 'chart-note' }, t('show.chart.possession.more', { team: names[1] }));
|
|
2146
|
+
legend.push(['side-0', t('show.chart.possession.above', { team: names[0] })], ['side-1', t('show.chart.possession.below', { team: names[1] })]);
|
|
2147
|
+
} else if (kind === 'shots') {
|
|
2148
|
+
const sums = (team, key) => bins.reduce((v, b) => v + b[key][team], 0);
|
|
2149
|
+
const ceiling = Math.max(1, sums(0, 'shots'), sums(1, 'shots'), sums(0, 'goals'), sums(1, 'goals'));
|
|
2150
|
+
draw('path', { d: `M${left} ${top}H${left + width}`, class: 'chart-rule faint' });
|
|
2151
|
+
for (const team of [0, 1]) {
|
|
2152
|
+
for (const key of ['shots', 'goals']) {
|
|
2153
|
+
let sum = 0;
|
|
2154
|
+
const points = [`${left},${bottom}`];
|
|
2155
|
+
bins.forEach((b, i) => {
|
|
2156
|
+
sum += b[key][team];
|
|
2157
|
+
points.push(`${left + (i + 1) * step},${bottom - (sum / ceiling) * (bottom - top)}`);
|
|
2158
|
+
});
|
|
2159
|
+
draw('polyline', { points: points.join(' '), class: `chart-line side-${team} ${key}` });
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
draw('text', { x: left + 3, y: top + 11, class: 'chart-note' }, t('show.chart.shots.top', { count: ceiling }));
|
|
2163
|
+
legend.push(['side-0', names[0]], ['side-1', names[1]], ['solid', t('show.chart.legend.goals')], ['dashed', t('show.chart.legend.shots')]);
|
|
2164
|
+
} else {
|
|
2165
|
+
const mid = (top + bottom) / 2;
|
|
2166
|
+
draw('path', { d: `M${left} ${mid}H${left + width}`, class: 'chart-rule half' });
|
|
2167
|
+
const points = bins.map((b, i) => {
|
|
2168
|
+
const pressure = b.count ? b.pressure / b.count : 0;
|
|
2169
|
+
return `${left + (i + 0.5) * step},${mid - pressure * (mid - top)}`;
|
|
2170
|
+
});
|
|
2171
|
+
draw('polyline', { points: points.join(' '), class: 'chart-line neutral' });
|
|
2172
|
+
draw('text', { x: left + 3, y: top + 11, class: 'chart-note' }, t('show.chart.pressure.top', { team: names[0] }));
|
|
2173
|
+
draw('text', { x: left + 3, y: bottom - 5, class: 'chart-note' }, t('show.chart.pressure.top', { team: names[1] }));
|
|
2174
|
+
}
|
|
2175
|
+
draw('path', { d: `M${left} ${bottom}H${left + width}`, class: 'chart-rule' });
|
|
2176
|
+
// Goals and cards on a strip under the chart, at their moment.
|
|
2177
|
+
let cards = false;
|
|
2178
|
+
for (const m of report.marks) {
|
|
2179
|
+
const x = left + ((m.i - store.first) / Math.max(1, store.last - store.first)) * width;
|
|
2180
|
+
const y = 97;
|
|
2181
|
+
const node = m.label === 'Goal'
|
|
2182
|
+
? draw('circle', { cx: x, cy: y, r: 3.5, class: `chart-side-${m.team}` })
|
|
2183
|
+
: draw('rect', { x: x - 2.5, y: y - 4.5, width: 5, height: 9, class: m.label === 'Red card' ? 'chart-red' : 'chart-yellow' });
|
|
2184
|
+
cards ||= m.label !== 'Goal';
|
|
2185
|
+
tip(node, t('show.chart.mark', { mark: MARK_LABELS[m.label] || m.label, team: names[m.team], count: fixed(store.get(m.i).timeMs / 60000, 1) }));
|
|
2186
|
+
}
|
|
2187
|
+
if (report.marks.some((m) => m.label === 'Goal')) legend.push(['dot', t('show.chart.legend.goal')]);
|
|
2188
|
+
if (cards) legend.push(['card', t('show.chart.legend.card')]);
|
|
2189
|
+
const values = bins.map((b, i) => {
|
|
2190
|
+
const total = b.owned[0] + b.owned[1];
|
|
2191
|
+
const value = kind === 'possession'
|
|
2192
|
+
? total ? t('show.chart.period.possession', { percent: Math.round((100 * b.owned[0]) / total), team: names[0] }) : t('show.chart.period.none')
|
|
2193
|
+
: kind === 'pressure'
|
|
2194
|
+
? fixed(b.count ? b.pressure / b.count : 0, 2)
|
|
2195
|
+
: t('show.chart.period.shots', { shotsLeft: b.shots[0], shotsRight: b.shots[1], goalsLeft: b.goals[0], goalsRight: b.goals[1] });
|
|
2196
|
+
return t('show.chart.period', { number: i + 1, value });
|
|
2197
|
+
});
|
|
2198
|
+
const title = {
|
|
2199
|
+
possession: t('show.chart.title.possession'),
|
|
2200
|
+
shots: t('show.chart.title.shots'),
|
|
2201
|
+
pressure: t('show.chart.title.pressure'),
|
|
2202
|
+
}[kind];
|
|
2203
|
+
svg.setAttribute('aria-label', t('show.chart.label', { title, team: names[0], values: values.join('. ') }));
|
|
2204
|
+
const minute = (i) => t('show.chart.minute', { minutes: Math.round(store.get(i).timeMs / 60000) });
|
|
2205
|
+
return h('figure', { class: 'stats-chart' },
|
|
2206
|
+
h('figcaption', {}, title),
|
|
2207
|
+
svg,
|
|
2208
|
+
h('div', { class: 'chart-axis', 'aria-hidden': 'true' }, h('span', {}, minute(store.first)), h('span', {}, minute(store.last))),
|
|
2209
|
+
h('div', { class: 'chart-legend', 'aria-hidden': 'true' },
|
|
2210
|
+
legend.map(([key, text]) => h('span', { class: `chart-key ${key}` }, text))));
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
// Awards, in the order the headline shows them, the rarest first.
|
|
2214
|
+
const AWARD_ORDER = ['Hat trick', 'Brace', 'Playmaker', 'Wall', 'Sharpshooter', 'Creator', 'Ball winner', 'Clean sheet', 'Engine'];
|
|
2215
|
+
// What people read of each award, by its English name.
|
|
2216
|
+
const AWARD_LABELS = {
|
|
2217
|
+
'Hat trick': t('show.award.hattrick'), Brace: t('show.award.brace'), Playmaker: t('show.award.playmaker'),
|
|
2218
|
+
Creator: t('show.award.creator'), Wall: t('show.award.wall'), 'Clean sheet': t('show.award.cleansheet'),
|
|
2219
|
+
Engine: t('show.award.engine'), 'Ball winner': t('show.award.ballwinner'), Sharpshooter: t('show.award.sharpshooter'),
|
|
2220
|
+
'Own goal': t('show.award.owngoal'), 'Sent off': t('show.award.sentoff'), Comeback: t('show.award.comeback'),
|
|
2221
|
+
'Late winner': t('show.award.latewinner'),
|
|
2222
|
+
};
|
|
2223
|
+
// What people read of the marks under the charts, by their English label.
|
|
2224
|
+
const MARK_LABELS = {
|
|
2225
|
+
Goal: t('show.chart.mark.goal'), 'Yellow card': t('show.chart.mark.yellow'), 'Red card': t('show.chart.mark.red'),
|
|
2226
|
+
};
|
|
2227
|
+
|
|
2228
|
+
// The columns of the player table, the first set always shown and the rest on demand.
|
|
2229
|
+
const COLUMNS = [
|
|
2230
|
+
['gradeRank', t('show.column.grade')], ['minutes', t('show.column.minutes')], ['goals', t('show.column.goals')],
|
|
2231
|
+
['assists', t('show.column.assists')], ['shots', t('show.column.shots')], ['passesCompleted', t('show.column.passes')],
|
|
2232
|
+
['tackles', t('show.column.tackles')], ['saves', t('show.column.saves')],
|
|
2233
|
+
];
|
|
2234
|
+
const MORE_COLUMNS = [
|
|
2235
|
+
['shotsOnTarget', t('show.column.ontarget')], ['keyPasses', t('show.column.keypasses')],
|
|
2236
|
+
['accuracy', t('show.column.accuracy')], ['shotAccuracy', t('show.column.shotaccuracy')],
|
|
2237
|
+
['touches', t('show.column.touches')], ['clean', t('show.column.clean')], ['ownGoals', t('show.column.owngoals')],
|
|
2238
|
+
['yellow', t('show.column.yellow')], ['red', t('show.column.red')],
|
|
2239
|
+
];
|
|
2240
|
+
const ROLE_NAMES = { GK: t('show.role.gk'), DF: t('show.role.df'), MF: t('show.role.mf'), FW: t('show.role.fw') };
|
|
2241
|
+
// The short roles of the team sheets.
|
|
2242
|
+
const ROLE_SHORT = { GK: t('show.role.short.gk'), DF: t('show.role.short.df'), MF: t('show.role.short.mf'), FW: t('show.role.short.fw') };
|
|
2243
|
+
|
|
2244
|
+
// The statistics screen of the show after the match. It opens on the result and the headline
|
|
2245
|
+
// awards, then compares the teams, lists every player of each team with a grade medal, and ends
|
|
2246
|
+
// with charts over the match. Extra columns, the rating inputs of a player and the grade guide
|
|
2247
|
+
// open on demand.
|
|
2248
|
+
export function statsScreen(report, names, info, store, advance, extra = {}) {
|
|
2249
|
+
const facts = extra.facts;
|
|
2250
|
+
let team = 0;
|
|
2251
|
+
let sort = 'gradeRank';
|
|
2252
|
+
let descending = true;
|
|
2253
|
+
let more = false;
|
|
2254
|
+
const head = h('thead', {});
|
|
2255
|
+
const body = h('tbody', {});
|
|
2256
|
+
const cell = (s, key) => {
|
|
2257
|
+
if (key === 'gradeRank') return medal(s);
|
|
2258
|
+
if (key === 'minutes') return fixed(s.minutes, 1);
|
|
2259
|
+
if (key === 'passesCompleted') return s.passes ? t('show.stats.of', { done: s.passesCompleted, total: s.passes }) : '0';
|
|
2260
|
+
if (key === 'accuracy' || key === 'shotAccuracy') return s[key] == null ? '–' : `${s[key]}%`;
|
|
2261
|
+
if (key === 'clean') return s.clean ? t('show.stats.yes') : '–';
|
|
2262
|
+
return String(s[key] ?? '–');
|
|
2263
|
+
};
|
|
2264
|
+
const columns = () => (more ? [...COLUMNS, ...MORE_COLUMNS] : COLUMNS);
|
|
2265
|
+
const renderHead = () => {
|
|
2266
|
+
head.replaceChildren(h('tr', {}, h('th', { scope: 'col', class: 'player-col' }, t('show.stats.player')),
|
|
2267
|
+
...columns().map(([key, label]) => h('th', {
|
|
2268
|
+
scope: 'col',
|
|
2269
|
+
'aria-sort': key === sort ? (descending ? 'descending' : 'ascending') : 'none',
|
|
2270
|
+
}, h('button', {
|
|
2271
|
+
type: 'button',
|
|
2272
|
+
title: t('show.column.sort', { column: label.toLowerCase() }),
|
|
2273
|
+
onclick: () => {
|
|
2274
|
+
descending = sort === key ? !descending : true;
|
|
2275
|
+
sort = key;
|
|
2276
|
+
render();
|
|
2277
|
+
head.querySelector(`th[aria-sort]:not([aria-sort="none"]) button`)?.focus();
|
|
2278
|
+
},
|
|
2279
|
+
}, label)))));
|
|
2280
|
+
};
|
|
2281
|
+
const tabs = h('div', { class: 'stats-tabs', role: 'tablist', 'aria-label': t('show.stats.team') });
|
|
2282
|
+
const moreButton = h('button', {
|
|
2283
|
+
type: 'button', class: 'btn ghost', 'aria-controls': 'stats-roster',
|
|
2284
|
+
onclick: () => {
|
|
2285
|
+
more = !more;
|
|
2286
|
+
if (!more && MORE_COLUMNS.some(([key]) => key === sort)) sort = 'gradeRank';
|
|
2287
|
+
render();
|
|
2288
|
+
},
|
|
2289
|
+
});
|
|
2290
|
+
const roster = h('div', { class: 'stats-table', id: 'stats-roster', role: 'tabpanel', tabindex: '0' },
|
|
2291
|
+
h('table', {}, head, body));
|
|
2292
|
+
const render = () => {
|
|
2293
|
+
renderHead();
|
|
2294
|
+
const ordered = report.players.filter((p) => p.team === team).sort((a, b) => {
|
|
2295
|
+
const difference = (b[sort] ?? -1) - (a[sort] ?? -1);
|
|
2296
|
+
return difference * (descending ? 1 : -1) || a.k - b.k;
|
|
2297
|
+
});
|
|
2298
|
+
body.replaceChildren(...ordered.map((s) => {
|
|
2299
|
+
const who = info(s.k);
|
|
2300
|
+
const details = h('details', {},
|
|
2301
|
+
h('summary', {}, h('span', { class: 'shirt-number' }, String(who.number)), who.name,
|
|
2302
|
+
h('small', {}, ROLE_NAMES[s.role] || s.role)),
|
|
2303
|
+
h('div', { class: 'rating-inputs' },
|
|
2304
|
+
h('p', {}, s.grade ? t('show.rating.graded', { rating: fixed(s.rating, 2), grade: s.grade })
|
|
2305
|
+
: t('show.rating.ungraded', { rating: fixed(s.rating, 2) })),
|
|
2306
|
+
h('p', {}, t('show.rating.parts', {
|
|
2307
|
+
contribution: fixed(s.positive, 2), passing: fixed(s.passing, 2),
|
|
2308
|
+
sheet: fixed(s.sheet, 2), penalty: fixed(s.penalty, 2),
|
|
2309
|
+
})),
|
|
2310
|
+
...s.achievements.map((a) => h('p', {}, t('show.award.line', { name: a.label, reason: a.reason })))));
|
|
2311
|
+
const row = h('tr', {}, h('th', { scope: 'row', class: 'player-cell' }, details,
|
|
2312
|
+
s.achievements.length ? h('div', { class: 'player-awards' }, s.achievements.map((a) =>
|
|
2313
|
+
h('span', { class: 'award-chip', 'data-award': a.name, title: a.reason }, a.label))) : null));
|
|
2314
|
+
for (const [key] of columns()) row.append(h('td', {}, cell(s, key)));
|
|
2315
|
+
return row;
|
|
2316
|
+
}));
|
|
2317
|
+
for (const button of tabs.children) {
|
|
2318
|
+
const selected = Number(button.dataset.team) === team;
|
|
2319
|
+
button.setAttribute('aria-selected', String(selected));
|
|
2320
|
+
button.tabIndex = selected ? 0 : -1;
|
|
2321
|
+
}
|
|
2322
|
+
roster.setAttribute('aria-labelledby', `stats-tab-${team}`);
|
|
2323
|
+
moreButton.setAttribute('aria-pressed', String(more));
|
|
2324
|
+
moreButton.textContent = more ? t('show.stats.fewer') : t('show.stats.more');
|
|
2325
|
+
};
|
|
2326
|
+
for (const side of [0, 1]) {
|
|
2327
|
+
const players = report.players.filter((p) => p.team === side).length;
|
|
2328
|
+
const button = h('button', {
|
|
2329
|
+
type: 'button', role: 'tab', 'data-team': String(side), 'aria-controls': 'stats-roster', id: `stats-tab-${side}`,
|
|
2330
|
+
onclick: () => {
|
|
2331
|
+
team = side;
|
|
2332
|
+
render();
|
|
2333
|
+
},
|
|
2334
|
+
}, h('span', { class: `chart-key side-${side}`, 'aria-hidden': 'true' }), names[side],
|
|
2335
|
+
h('span', { class: 'tab-count' }, t('show.stats.players.count', { count: players })));
|
|
2336
|
+
button.addEventListener('keydown', (e) => {
|
|
2337
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
|
|
2338
|
+
e.preventDefault();
|
|
2339
|
+
team = 1 - team;
|
|
2340
|
+
render();
|
|
2341
|
+
tabs.children[team].focus();
|
|
2342
|
+
}
|
|
2343
|
+
});
|
|
2344
|
+
tabs.append(button);
|
|
2345
|
+
}
|
|
2346
|
+
|
|
2347
|
+
// The headline, the player of the match first, then the rarest achievements and team awards.
|
|
2348
|
+
const award = (name, who, side, why, cls = 'award') => h('li', { class: cls },
|
|
2349
|
+
h('span', { class: 'award-name' }, name),
|
|
2350
|
+
h('span', { class: 'award-who' }, who, side != null ? h('small', {}, names[side]) : null),
|
|
2351
|
+
h('span', { class: 'award-why' }, why));
|
|
2352
|
+
const headline = [];
|
|
2353
|
+
const mvp = facts ? playerOfMatch(report.players, facts.score) : null;
|
|
2354
|
+
if (mvp) {
|
|
2355
|
+
const who = info(mvp.k);
|
|
2356
|
+
const line = [t('show.count.goals', { count: mvp.goals }), t('show.count.assists', { count: mvp.assists }),
|
|
2357
|
+
mvp.goalkeeper || mvp.saves ? t('show.count.saves', { count: mvp.saves }) : t('show.count.tackles', { count: mvp.tackles })];
|
|
2358
|
+
headline.push(award(t('show.award.mvp'), `${who.number} ${who.name}`, mvp.team, line.join(', '), 'award mvp'));
|
|
2359
|
+
}
|
|
2360
|
+
const top = report.players
|
|
2361
|
+
.flatMap((s) => s.achievements.filter((a) => AWARD_ORDER.includes(a.name)).map((a) => ({ s, a })))
|
|
2362
|
+
.sort((x, y) => AWARD_ORDER.indexOf(x.a.name) - AWARD_ORDER.indexOf(y.a.name) || y.s.score - x.s.score)
|
|
2363
|
+
.slice(0, 4);
|
|
2364
|
+
for (const { s, a } of top) {
|
|
2365
|
+
const who = info(s.k);
|
|
2366
|
+
headline.push(award(a.label, `${who.number} ${who.name}`, s.team, a.brief));
|
|
2367
|
+
}
|
|
2368
|
+
for (const side of [0, 1]) {
|
|
2369
|
+
for (const a of report.teams[side]) headline.push(award(a.label, names[side], null, a.reason));
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
const section = (id, title, ...content) => h('section', { class: `stats-section stats-${id}`, 'aria-labelledby': `stats-${id}-title` },
|
|
2373
|
+
h('h3', { id: `stats-${id}-title` }, title), ...content);
|
|
2374
|
+
const root = h('section', { class: 'match-lab', 'aria-labelledby': 'stats-title' },
|
|
2375
|
+
h('header', { class: 'stats-heading' },
|
|
2376
|
+
h('div', { class: 'stats-result' }, h('h2', { id: 'stats-title' }, t('show.stats.title')), extra.scoreLine || null),
|
|
2377
|
+
h('button', { type: 'button', class: 'btn primary', onclick: advance }, icon('next'), extra.closeLabel || t('show.stats.continue'))),
|
|
2378
|
+
headline.length ? section('awards', t('show.stats.awards'), h('ol', { class: 'award-list' }, headline)) : null,
|
|
2379
|
+
facts ? section('teams', t('show.stats.teams'),
|
|
2380
|
+
h('div', { class: 'compare-names', 'aria-hidden': 'true' }, h('span', {}, names[0]), h('span', {}, names[1])),
|
|
2381
|
+
chartColors(comparisonTable(facts))) : null,
|
|
2382
|
+
section('players', t('show.stats.players'), h('div', { class: 'stats-toolbar' }, tabs, moreButton), roster),
|
|
2383
|
+
section('time', t('show.stats.time'),
|
|
2384
|
+
h('div', { class: 'stats-charts' }, ['possession', 'shots', 'pressure'].map((kind) => chart(report, kind, names, store)))),
|
|
2385
|
+
h('details', { class: 'rating-guide' }, h('summary', {}, t('show.guide.title')),
|
|
2386
|
+
h('p', {}, t('show.guide.grades')),
|
|
2387
|
+
h('p', {}, t('show.guide.rating')),
|
|
2388
|
+
h('p', {}, t('show.guide.charts'))));
|
|
2389
|
+
root.addEventListener('click', (e) => e.stopPropagation());
|
|
2390
|
+
root.addEventListener('keydown', (e) => {
|
|
2391
|
+
if (e.key !== 'Escape') e.stopPropagation();
|
|
2392
|
+
if (e.key === 'Enter') {
|
|
2393
|
+
e.preventDefault();
|
|
2394
|
+
const control = e.target.closest('button, summary');
|
|
2395
|
+
if (control)
|
|
2396
|
+
control.click();
|
|
2397
|
+
else
|
|
2398
|
+
advance();
|
|
2399
|
+
}
|
|
2400
|
+
});
|
|
2401
|
+
render();
|
|
2402
|
+
return root;
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
// Whether a team's name reads as plural, so the podium says win rather than wins.
|
|
2406
|
+
function plural(name) {
|
|
2407
|
+
const n = name.trim();
|
|
2408
|
+
return /[^s']s$/i.test(n) && !/ss$/i.test(n);
|
|
2409
|
+
}
|
|
2410
|
+
|
|
2411
|
+
// The line of a winning team, where a team whose English name reads as plural has its own message.
|
|
2412
|
+
function winLine(team, bare) {
|
|
2413
|
+
return plural(bare) ? t('show.result.win.plural', { team }) : t('show.result.win', { team });
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
// The stages of the scene at the final whistle in seconds. The camera of play stays on while the
|
|
2417
|
+
// play winds down under the full time card, then a wide shot, a close-up of the winners' hero,
|
|
2418
|
+
// one of the beaten keeper, and a wide shot as the players walk to the stands applauding the fans.
|
|
2419
|
+
// Times after the full time card comes up, which is once the play has wound down.
|
|
2420
|
+
const REACTION_SHOTS = [
|
|
2421
|
+
{ at: -Infinity, kind: 'live' },
|
|
2422
|
+
{ at: 0.6, kind: 'wide', snap: true },
|
|
2423
|
+
{ at: 3.8, kind: 'hero', snap: true },
|
|
2424
|
+
{ at: 7.0, kind: 'beaten', snap: true },
|
|
2425
|
+
{ at: 10.2, kind: 'stands', snap: true },
|
|
2426
|
+
];
|
|
2427
|
+
const REACTION_LENGTH = 16;
|
|
2428
|
+
const TITLE_SECONDS = 3.2;
|
|
2429
|
+
// The players react from the final whistle on, the wind down of play comes first.
|
|
2430
|
+
const REACTION_LEAD = 0;
|
|
2431
|
+
// The fade into the Home page after the show.
|
|
2432
|
+
const HOME_FADE_MS = 420;
|
|
2433
|
+
|
|
2434
|
+
// The show after the match, as on television. The players react at the final whistle under
|
|
2435
|
+
// the full time card, then the match facts, a reel of the goals, the player of the match and
|
|
2436
|
+
// the trophy with the podium, each part joined by the wipe. Enter or a click moves on, a goal
|
|
2437
|
+
// at a time in the reel, Esc ends the show.
|
|
2438
|
+
export class PostMatch {
|
|
2439
|
+
constructor(app) {
|
|
2440
|
+
this.app = app;
|
|
2441
|
+
this.step = -1;
|
|
2442
|
+
this.card = null;
|
|
2443
|
+
this.timer = null;
|
|
2444
|
+
this.react = null;
|
|
2445
|
+
this.wiping = false;
|
|
2446
|
+
this.hook = (pose, sample) => this.dress(pose, sample);
|
|
2447
|
+
}
|
|
2448
|
+
|
|
2449
|
+
get running() {
|
|
2450
|
+
return this.step >= 0;
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
start() {
|
|
2454
|
+
const app = this.app;
|
|
2455
|
+
if (this.running || !app.source || !app.settings.podium || !app.timeline) {
|
|
2456
|
+
return;
|
|
2457
|
+
}
|
|
2458
|
+
const tl = app.timeline;
|
|
2459
|
+
if (this.closeStats) {
|
|
2460
|
+
this.closeStats();
|
|
2461
|
+
}
|
|
2462
|
+
if (app.director.running) {
|
|
2463
|
+
app.director.stop(false);
|
|
2464
|
+
}
|
|
2465
|
+
if (app.poseHooks && !app.poseHooks.includes(this.hook)) {
|
|
2466
|
+
app.poseHooks.push(this.hook);
|
|
2467
|
+
}
|
|
2468
|
+
this.saved = { t: tl.t, camera: app.cameras.mode, focus: app.cameras.focusIndex, following: tl.following };
|
|
2469
|
+
this.statsStore = summaryStore(tl.store, app.source.kind === 'live');
|
|
2470
|
+
this.facts = matchFacts(this.statsStore, app.source.header);
|
|
2471
|
+
this.steps = ['reactions', 'facts', 'reel', 'spotlight', 'podium'];
|
|
2472
|
+
this.step = -1;
|
|
2473
|
+
this.wiping = false;
|
|
2474
|
+
document.getElementById('app').classList.add('post-show');
|
|
2475
|
+
// The bug holds the final score and clock while the show replays earlier moments.
|
|
2476
|
+
app.hud.freeze(tl.store.get(tl.last));
|
|
2477
|
+
tl.pause();
|
|
2478
|
+
this.next();
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
teamName(t) {
|
|
2482
|
+
return teamNames(this.app.source.header)[t];
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
playerName(k) {
|
|
2486
|
+
return playerInfo(this.app, k).name;
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2489
|
+
winner() {
|
|
2490
|
+
const f = this.facts;
|
|
2491
|
+
return f.score[0] === f.score[1] ? -1 : (f.score[0] > f.score[1] ? 0 : 1);
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
showCard(node) {
|
|
2495
|
+
this.clearCard();
|
|
2496
|
+
this.card = h('div', { class: 'post-card', 'data-prompt': '' }, node,
|
|
2497
|
+
h('div', { class: 'post-hint muted small' }, tn('show.post.hint.next')));
|
|
2498
|
+
this.card.addEventListener('click', () => this.advance());
|
|
2499
|
+
document.getElementById('watch').appendChild(this.card);
|
|
2500
|
+
release(this.app);
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
clearCard() {
|
|
2504
|
+
if (this.card) {
|
|
2505
|
+
this.card.remove();
|
|
2506
|
+
this.card = null;
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
// The heading of the cards, the two teams with their kit colors and badges and the score.
|
|
2511
|
+
scoreLine(f) {
|
|
2512
|
+
const app = this.app;
|
|
2513
|
+
const side = (t) => {
|
|
2514
|
+
const style = app.styles ? app.styles[t] : null;
|
|
2515
|
+
const chip = h('i', { class: 'post-chip' });
|
|
2516
|
+
chip.style.background = kitSwatch(style);
|
|
2517
|
+
return h('span', { class: `post-team side-${t}` }, t === 0 ? chip : null,
|
|
2518
|
+
style && style.badge ? h('b', { class: 'post-badge' }, style.badge) : null,
|
|
2519
|
+
this.teamName(t), t === 1 ? chip : null);
|
|
2520
|
+
};
|
|
2521
|
+
return h('div', { class: 'post-line' }, side(0), h('b', {}, `${f.score[0]} – ${f.score[1]}`), side(1));
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
// The next part behind the wipe, so no part cuts hard into the next.
|
|
2525
|
+
advance() {
|
|
2526
|
+
if (!this.running || this.wiping) {
|
|
2527
|
+
return;
|
|
2528
|
+
}
|
|
2529
|
+
this.wiping = true;
|
|
2530
|
+
this.app.director.sting('', () => {
|
|
2531
|
+
this.wiping = false;
|
|
2532
|
+
if (this.running) {
|
|
2533
|
+
this.next();
|
|
2534
|
+
}
|
|
2535
|
+
});
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
// The players at the final whistle, on the held last frame, with the cameras of the scene.
|
|
2539
|
+
startReactions() {
|
|
2540
|
+
const app = this.app;
|
|
2541
|
+
const tl = app.timeline;
|
|
2542
|
+
const store = tl.store;
|
|
2543
|
+
const header = app.source.header;
|
|
2544
|
+
let index = Math.max(store.first, Math.min(store.last, tl.index));
|
|
2545
|
+
// A live stream may be past the whistle already, the show starts from its frame.
|
|
2546
|
+
for (let i = index, n = 0; i >= store.first && n < 1200; i--, n++) {
|
|
2547
|
+
const f = store.get(i);
|
|
2548
|
+
if (f && (f.flags & 1)) {
|
|
2549
|
+
index = i;
|
|
2550
|
+
break;
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2553
|
+
tl.seek(index);
|
|
2554
|
+
tl.t = index;
|
|
2555
|
+
tl.pause();
|
|
2556
|
+
app.lastIndex = index;
|
|
2557
|
+
const frame = store.get(index);
|
|
2558
|
+
const winner = this.winner();
|
|
2559
|
+
const players = app.players;
|
|
2560
|
+
// The hero is the best player of the winners, or of the match on a draw, the beaten one
|
|
2561
|
+
// the keeper of the losers, or the best of the other team on a draw.
|
|
2562
|
+
const ranked = this.facts.stats.slice().sort((a, b) => b.score - a.score);
|
|
2563
|
+
const on = (s) => s && (frame.playerFlags[s.k] & 1);
|
|
2564
|
+
const hero = (winner >= 0 ? ranked.find((s) => s.team === winner && on(s)) : ranked.find(on)) || null;
|
|
2565
|
+
let beaten = null;
|
|
2566
|
+
if (winner >= 0) {
|
|
2567
|
+
const k = header.players.findIndex((p, i) => p.goalkeeper && p.team !== winner && (frame.playerFlags[i] & 1));
|
|
2568
|
+
beaten = k >= 0 ? k : (ranked.find((s) => s.team !== winner && on(s)) || {}).k;
|
|
2569
|
+
} else if (hero) {
|
|
2570
|
+
beaten = (ranked.find((s) => s.team !== hero.team && on(s)) || {}).k;
|
|
2571
|
+
}
|
|
2572
|
+
// The hero celebrates on his own, clear of the huddle, so his close-up shows him.
|
|
2573
|
+
const prev = store.get(index - 1);
|
|
2574
|
+
const choreo = new Reactions({
|
|
2575
|
+
frame, header, winner, seed: index * 17 + 3,
|
|
2576
|
+
prev: prev && !isCut(prev, frame) ? prev : null,
|
|
2577
|
+
sps: tl.sps,
|
|
2578
|
+
card: TITLE_SECONDS,
|
|
2579
|
+
radius: (k) => figureSize(players, k).radius,
|
|
2580
|
+
hasClip: clipTest(players),
|
|
2581
|
+
hero: winner >= 0 && hero ? hero.k : -1,
|
|
2582
|
+
});
|
|
2583
|
+
// The full time card waits for the play to wind down, the cut to the show hides under it.
|
|
2584
|
+
this.react = {
|
|
2585
|
+
index, clock: 0, choreo, hero: hero ? hero.k : -1, beaten: beaten != null ? beaten : -1, stage: -1,
|
|
2586
|
+
titled: false, titleAt: choreo.titleAt, titleDone: false, frame: store.get(index), winner,
|
|
2587
|
+
};
|
|
2588
|
+
this.hint = h('div', { class: 'post-skip', 'data-prompt': '' }, tn('show.post.hint.goon'));
|
|
2589
|
+
this.hint.addEventListener('click', () => this.advance());
|
|
2590
|
+
document.getElementById('watch').appendChild(this.hint);
|
|
2591
|
+
release(app);
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
stopReactions() {
|
|
2595
|
+
const app = this.app;
|
|
2596
|
+
const r = this.react;
|
|
2597
|
+
this.react = null;
|
|
2598
|
+
if (this.hint) {
|
|
2599
|
+
this.hint.remove();
|
|
2600
|
+
this.hint = null;
|
|
2601
|
+
}
|
|
2602
|
+
if (!r) {
|
|
2603
|
+
return;
|
|
2604
|
+
}
|
|
2605
|
+
if (r.titled && app.transition && app.transition.title) {
|
|
2606
|
+
app.transition.title.hide();
|
|
2607
|
+
}
|
|
2608
|
+
const players = app.players;
|
|
2609
|
+
if (players && typeof players.stopClip === 'function') {
|
|
2610
|
+
r.choreo.release((k) => players.stopClip(k));
|
|
2611
|
+
}
|
|
2612
|
+
}
|
|
2613
|
+
|
|
2614
|
+
// Each frame, from the director's update, the clock and the cameras of the scene.
|
|
2615
|
+
update(dt) {
|
|
2616
|
+
const r = this.react;
|
|
2617
|
+
if (!r || !this.running) {
|
|
2618
|
+
return;
|
|
2619
|
+
}
|
|
2620
|
+
const app = this.app;
|
|
2621
|
+
r.clock += dt;
|
|
2622
|
+
const title = app.transition && app.transition.title;
|
|
2623
|
+
if (!r.titleDone && r.clock >= r.titleAt) {
|
|
2624
|
+
r.titleDone = true;
|
|
2625
|
+
const header = app.source.header;
|
|
2626
|
+
if (title && typeof title.show === 'function') {
|
|
2627
|
+
const w = r.winner;
|
|
2628
|
+
const foot = w >= 0 ? winLine(this.teamName(w), bareTeamName(header, w)) : t('show.result.draw.shared');
|
|
2629
|
+
title.show(fullMatch(header) ? t('show.post.fulltime') : t('show.post.episode'), header, app.styles, r.frame, foot);
|
|
2630
|
+
r.titled = true;
|
|
2631
|
+
} else {
|
|
2632
|
+
this.showCard(h('div', { class: 'post-score' }, h('div', { class: 'post-kicker' }, fullMatch(header) ? t('show.post.fulltime') : t('show.post.episode')), this.scoreLine(this.facts)));
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
if (r.titled && r.clock >= r.titleAt + TITLE_SECONDS && title) {
|
|
2636
|
+
title.hide();
|
|
2637
|
+
r.titled = false;
|
|
2638
|
+
}
|
|
2639
|
+
let stage = 0;
|
|
2640
|
+
for (let i = 0; i < REACTION_SHOTS.length; i++) {
|
|
2641
|
+
if (r.clock >= r.titleAt + REACTION_SHOTS[i].at) {
|
|
2642
|
+
stage = i;
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
const shot = REACTION_SHOTS[stage];
|
|
2646
|
+
const director = app.director;
|
|
2647
|
+
const sh = director.shot;
|
|
2648
|
+
// Seeking or playing away from the whistle cancels the show where the viewer went.
|
|
2649
|
+
const tl = app.timeline;
|
|
2650
|
+
if (tl && !this.wiping && (tl.playing || Math.abs(tl.t - r.index) > 0.5)) {
|
|
2651
|
+
this.end({ home: false, restore: false });
|
|
2652
|
+
return;
|
|
2653
|
+
}
|
|
2654
|
+
if (stage !== r.stage) {
|
|
2655
|
+
sh.snap = !!shot.snap && r.stage >= 0;
|
|
2656
|
+
if (shot.kind !== 'live') {
|
|
2657
|
+
director.useScripted();
|
|
2658
|
+
}
|
|
2659
|
+
r.stage = stage;
|
|
2660
|
+
}
|
|
2661
|
+
if (shot.kind === 'live') {
|
|
2662
|
+
// The cameras of play follow the ball as it rolls to rest.
|
|
2663
|
+
return;
|
|
2664
|
+
}
|
|
2665
|
+
const pose = app.pose;
|
|
2666
|
+
// The head as drawn, which a clip may have taken down to the grass, else the neck node.
|
|
2667
|
+
const head = (k) => {
|
|
2668
|
+
const bone = app.players && typeof app.players.headBone === 'function' ? app.players.headBone(k) : null;
|
|
2669
|
+
if (bone) {
|
|
2670
|
+
const v = new THREE.Vector3().setFromMatrixPosition(bone.matrixWorld);
|
|
2671
|
+
if (Number.isFinite(v.y) && v.lengthSq() > 0) {
|
|
2672
|
+
return v.setY(Math.max(0.1, Math.min(2.6, v.y)));
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2675
|
+
const o = k * PLAYER_FLOATS + 3 * 7;
|
|
2676
|
+
return new THREE.Vector3(pose.nodes[o], Math.max(0.4, Math.min(2.4, pose.nodes[o + 2])), -pose.nodes[o + 1]);
|
|
2677
|
+
};
|
|
2678
|
+
const close = (k, dist, side) => {
|
|
2679
|
+
const s = r.choreo.state(k, Math.max(0, r.clock - REACTION_LEAD));
|
|
2680
|
+
const p = head(k);
|
|
2681
|
+
// Waist up on any model, nearer a short one, so a big hat does not fill the frame.
|
|
2682
|
+
const tall = figureSize(app.players, k).height;
|
|
2683
|
+
const d = dist * Math.max(0.95, Math.min(1.35, tall / 1.85));
|
|
2684
|
+
const face = new THREE.Vector3(Math.sin(s.heading), 0, Math.cos(s.heading));
|
|
2685
|
+
const right = new THREE.Vector3(-face.z, 0, face.x);
|
|
2686
|
+
sh.pos.copy(p).addScaledVector(face, d).addScaledVector(right, side);
|
|
2687
|
+
// A standing figure is framed by its middle, hat and all, one on the grass by its head.
|
|
2688
|
+
const standing = p.y > 0.55 * tall;
|
|
2689
|
+
const aim = standing ? Math.max(p.y * 0.8, tall * 0.55) : Math.max(0.15, p.y * 0.8);
|
|
2690
|
+
sh.pos.y = Math.max(0.9, aim + 0.3);
|
|
2691
|
+
sh.target.copy(p).setY(aim);
|
|
2692
|
+
sh.fov = 30;
|
|
2693
|
+
sh.rate = 3;
|
|
2694
|
+
};
|
|
2695
|
+
if (shot.kind === 'hero' && r.hero >= 0 && pose) {
|
|
2696
|
+
close(r.hero, 4.6, 1.2);
|
|
2697
|
+
} else if (shot.kind === 'beaten' && r.beaten >= 0 && pose) {
|
|
2698
|
+
close(r.beaten, 5.6, -1.3);
|
|
2699
|
+
} else if (shot.kind === 'stands' && pose) {
|
|
2700
|
+
// From the far touchline back at the players walking up to applaud the fans.
|
|
2701
|
+
let cx = 0;
|
|
2702
|
+
let n = 0;
|
|
2703
|
+
for (let k = 0; k < pose.players; k++) {
|
|
2704
|
+
if (r.choreo.plans[k]) {
|
|
2705
|
+
cx += pose.nodes[k * PLAYER_FLOATS];
|
|
2706
|
+
n++;
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
cx = n ? cx / n : 0;
|
|
2710
|
+
const drift = (r.clock - r.titleAt - shot.at) * 1.2;
|
|
2711
|
+
sh.pos.set(cx * 0.6 - 10 + drift, 4.2, -(HALF_H + 2.5));
|
|
2712
|
+
sh.target.set(cx * 0.6 + drift * 0.5, 1.4, -22);
|
|
2713
|
+
sh.fov = 44;
|
|
2714
|
+
sh.rate = 1.6;
|
|
2715
|
+
} else {
|
|
2716
|
+
sh.pos.set(0, 30, 60);
|
|
2717
|
+
sh.target.set(0, 0, 0);
|
|
2718
|
+
sh.fov = 44;
|
|
2719
|
+
sh.rate = 1.5;
|
|
2720
|
+
}
|
|
2721
|
+
confineShot(sh.pos);
|
|
2722
|
+
if (r.clock >= r.titleAt + REACTION_LENGTH && !this.wiping) {
|
|
2723
|
+
this.advance();
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
|
|
2727
|
+
// Dresses the held last frame while the players react.
|
|
2728
|
+
dress(pose, sample) {
|
|
2729
|
+
const r = this.react;
|
|
2730
|
+
if (r && sample.index === r.index) {
|
|
2731
|
+
const players = this.app.players;
|
|
2732
|
+
const clip = players && typeof players.playClip === 'function' ? (k, name, t, w) => players.playClip(k, name, t, w) : null;
|
|
2733
|
+
r.choreo.apply(pose, Math.max(0, r.clock - REACTION_LEAD), 1, clip);
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
next() {
|
|
2738
|
+
const app = this.app;
|
|
2739
|
+
clearTimeout(this.timer);
|
|
2740
|
+
this.clearCard();
|
|
2741
|
+
this.stopReactions();
|
|
2742
|
+
if (app.director.running) {
|
|
2743
|
+
app.director.stop(false);
|
|
2744
|
+
}
|
|
2745
|
+
if (app.spotlight.showing) {
|
|
2746
|
+
app.spotlight.hide(false);
|
|
2747
|
+
}
|
|
2748
|
+
if (app.podium.showing) {
|
|
2749
|
+
app.podium.hide();
|
|
2750
|
+
}
|
|
2751
|
+
this.step++;
|
|
2752
|
+
const name = this.steps[this.step];
|
|
2753
|
+
const f = this.facts;
|
|
2754
|
+
// A goal graphic left from the reel or the play of the match stays with its part.
|
|
2755
|
+
app.hud.hideGoal();
|
|
2756
|
+
if (!name) {
|
|
2757
|
+
this.end();
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
if (name === 'reactions') {
|
|
2761
|
+
this.startReactions();
|
|
2762
|
+
} else if (name === 'facts') {
|
|
2763
|
+
app.cameras.setMode('broadcast');
|
|
2764
|
+
app.cameras.jump();
|
|
2765
|
+
const header = app.source.header;
|
|
2766
|
+
const scorers = (team) => f.scorers.filter((g) => g.team === team).map((g) =>
|
|
2767
|
+
h('div', {}, g.scorer >= 0 && header.players[g.scorer].team !== team
|
|
2768
|
+
? t('show.facts.owngoal', { name: this.playerName(g.scorer), minute: g.minute })
|
|
2769
|
+
: t('show.facts.scorer', { name: g.scorer >= 0 ? this.playerName(g.scorer) : t('show.facts.unknown'), minute: g.minute })));
|
|
2770
|
+
const table = comparisonTable(f, app.styles || [null, null]);
|
|
2771
|
+
this.showCard(h('div', { class: 'post-facts' },
|
|
2772
|
+
h('div', { class: 'post-kicker' }, t('show.facts.title')),
|
|
2773
|
+
this.scoreLine(f),
|
|
2774
|
+
h('div', { class: 'post-scorers' }, h('div', {}, scorers(0)), h('div', {}, scorers(1))),
|
|
2775
|
+
table));
|
|
2776
|
+
this.timer = setTimeout(() => this.advance(), 12000);
|
|
2777
|
+
} else if (name === 'reel') {
|
|
2778
|
+
const queue = f.scorers.map((g) => ({ goal: { index: g.index, team: g.team }, shot: 'auto' }));
|
|
2779
|
+
if (!queue.length) {
|
|
2780
|
+
this.next();
|
|
2781
|
+
return;
|
|
2782
|
+
}
|
|
2783
|
+
// The wipe into the reel already ran, and its own last wipe leads to the spotlight.
|
|
2784
|
+
release(app);
|
|
2785
|
+
app.director.play(queue, { restore: false, wipe: false, onDone: () => this.next() });
|
|
2786
|
+
} else if (name === 'spotlight') {
|
|
2787
|
+
const mvp = playerOfMatch(f.stats, f.score);
|
|
2788
|
+
if (!mvp) {
|
|
2789
|
+
this.next();
|
|
2790
|
+
return;
|
|
2791
|
+
}
|
|
2792
|
+
app.spotlight.show(mvp);
|
|
2793
|
+
} else if (name === 'podium') {
|
|
2794
|
+
app.podium.show(f);
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
// The statistics screen on demand, from the last panel of the show, the card at the end of a
|
|
2799
|
+
// recording or the Match menu. It opens over what is on screen and closing it returns there.
|
|
2800
|
+
openStats() {
|
|
2801
|
+
const app = this.app;
|
|
2802
|
+
if (this.statsCard || !app.source || !app.timeline || !app.timeline.store.size) {
|
|
2803
|
+
return;
|
|
2804
|
+
}
|
|
2805
|
+
const header = app.source.header;
|
|
2806
|
+
const store = this.statsStore || summaryStore(app.timeline.store, app.source.kind === 'live');
|
|
2807
|
+
const f = this.statsStore && this.facts ? this.facts : matchFacts(store, header);
|
|
2808
|
+
const report = contribution(store, header, f);
|
|
2809
|
+
const back = document.activeElement;
|
|
2810
|
+
const hidden = [this.card, app.podium.overlay].filter((node) => node && !node.hidden);
|
|
2811
|
+
const timerWas = !!this.timer;
|
|
2812
|
+
clearTimeout(this.timer);
|
|
2813
|
+
for (const node of hidden) {
|
|
2814
|
+
node.hidden = true;
|
|
2815
|
+
}
|
|
2816
|
+
const close = () => {
|
|
2817
|
+
if (!this.statsCard) {
|
|
2818
|
+
return;
|
|
2819
|
+
}
|
|
2820
|
+
this.statsCard.remove();
|
|
2821
|
+
this.statsCard = null;
|
|
2822
|
+
for (const node of hidden) {
|
|
2823
|
+
node.hidden = false;
|
|
2824
|
+
}
|
|
2825
|
+
if (timerWas && this.running && this.steps[this.step] === 'facts') {
|
|
2826
|
+
this.timer = setTimeout(() => this.advance(), 6000);
|
|
2827
|
+
}
|
|
2828
|
+
if (back && back.isConnected && typeof back.focus === 'function') {
|
|
2829
|
+
back.focus();
|
|
2830
|
+
}
|
|
2831
|
+
};
|
|
2832
|
+
const names = [this.teamName(0), this.teamName(1)];
|
|
2833
|
+
const screen = statsScreen(report, names, (k) => playerInfo(app, k), store, close,
|
|
2834
|
+
{ facts: f, scoreLine: this.scoreLine(f), closeLabel: t('show.close') });
|
|
2835
|
+
this.statsCard = h('div', { class: 'post-card stats-card', tabindex: '-1', role: 'dialog', 'aria-labelledby': 'stats-title' }, screen);
|
|
2836
|
+
const colors = teamChartColors(app.styles);
|
|
2837
|
+
if (colors) {
|
|
2838
|
+
this.statsCard.style.setProperty('--chart-0', colors[0]);
|
|
2839
|
+
this.statsCard.style.setProperty('--chart-1', colors[1]);
|
|
2840
|
+
}
|
|
2841
|
+
this.statsCard.addEventListener('click', (e) => e.stopPropagation());
|
|
2842
|
+
this.statsCard.addEventListener('keydown', (e) => {
|
|
2843
|
+
// Focus starts on the dialog itself, where Enter closes it as it does anywhere away
|
|
2844
|
+
// from a control.
|
|
2845
|
+
if (e.key === 'Escape' || (e.key === 'Enter' && e.target === this.statsCard)) {
|
|
2846
|
+
e.preventDefault();
|
|
2847
|
+
e.stopPropagation();
|
|
2848
|
+
close();
|
|
2849
|
+
}
|
|
2850
|
+
});
|
|
2851
|
+
this.closeStats = close;
|
|
2852
|
+
document.getElementById('watch').appendChild(this.statsCard);
|
|
2853
|
+
release(app);
|
|
2854
|
+
// A frame later, after a menu that opened it has handed focus back.
|
|
2855
|
+
requestAnimationFrame(() => this.statsCard && this.statsCard.focus());
|
|
2856
|
+
}
|
|
2857
|
+
|
|
2858
|
+
// A button that opens the statistics screen, for the last panel and the end card.
|
|
2859
|
+
statsButton(className = 'btn') {
|
|
2860
|
+
return h('button', { type: 'button', class: className, onclick: (e) => {
|
|
2861
|
+
e.stopPropagation();
|
|
2862
|
+
this.openStats();
|
|
2863
|
+
} }, icon('stats'), t('show.stats.title'));
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
// Enter shows the next part, the next goal while the reel plays, or ends the show after
|
|
2867
|
+
// the podium.
|
|
2868
|
+
skip() {
|
|
2869
|
+
if (!this.running) {
|
|
2870
|
+
return;
|
|
2871
|
+
}
|
|
2872
|
+
const d = this.app.director;
|
|
2873
|
+
if (this.steps[this.step] === 'reel' && d.active && d.active.queue) {
|
|
2874
|
+
d.skip();
|
|
2875
|
+
return;
|
|
2876
|
+
}
|
|
2877
|
+
this.advance();
|
|
2878
|
+
}
|
|
2879
|
+
|
|
2880
|
+
// Ends the show. After the show the page fades to Home with the match still selected, a
|
|
2881
|
+
// cancel by seeking stays where the viewer went, and restore false keeps the timeline there.
|
|
2882
|
+
end({ home = true, restore = true } = {}) {
|
|
2883
|
+
const app = this.app;
|
|
2884
|
+
const wasRunning = this.running;
|
|
2885
|
+
clearTimeout(this.timer);
|
|
2886
|
+
if (this.closeStats) {
|
|
2887
|
+
this.closeStats();
|
|
2888
|
+
}
|
|
2889
|
+
this.clearCard();
|
|
2890
|
+
this.stopReactions();
|
|
2891
|
+
this.step = -1;
|
|
2892
|
+
this.statsStore = null;
|
|
2893
|
+
if (this.wiping) {
|
|
2894
|
+
this.wiping = false;
|
|
2895
|
+
app.director.cancelSting();
|
|
2896
|
+
}
|
|
2897
|
+
document.getElementById('app').classList.remove('post-show');
|
|
2898
|
+
if (app.director.running) {
|
|
2899
|
+
app.director.stop(false);
|
|
2900
|
+
}
|
|
2901
|
+
if (app.spotlight.showing) {
|
|
2902
|
+
app.spotlight.hide(false);
|
|
2903
|
+
}
|
|
2904
|
+
if (app.podium.showing) {
|
|
2905
|
+
app.podium.hide();
|
|
2906
|
+
}
|
|
2907
|
+
app.hud.unfreeze();
|
|
2908
|
+
const s = this.saved;
|
|
2909
|
+
const tl = app.timeline;
|
|
2910
|
+
if (s && tl) {
|
|
2911
|
+
app.cameras.focusIndex = s.focus;
|
|
2912
|
+
app.cameras.setMode(s.camera === 'scripted' ? (app.settings.camera || 'broadcast') : s.camera);
|
|
2913
|
+
if (restore) {
|
|
2914
|
+
if (s.following) {
|
|
2915
|
+
tl.goLive();
|
|
2916
|
+
} else {
|
|
2917
|
+
tl.seek(s.t);
|
|
2918
|
+
tl.pause();
|
|
2919
|
+
}
|
|
2920
|
+
app.lastIndex = tl.index;
|
|
2921
|
+
app.afterSeek();
|
|
2922
|
+
}
|
|
2923
|
+
app.updatePlayUi();
|
|
2924
|
+
}
|
|
2925
|
+
if (home && wasRunning) {
|
|
2926
|
+
this.fadeHome(app.source);
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
// A soft fade to the Home page, once the show is over, unless the viewer has opened another
|
|
2931
|
+
// match or another page in the meantime, or the page has no Home.
|
|
2932
|
+
fadeHome(source) {
|
|
2933
|
+
const app = this.app;
|
|
2934
|
+
if (typeof app.showPage !== 'function' || !document.getElementById('page-home')) {
|
|
2935
|
+
return;
|
|
2936
|
+
}
|
|
2937
|
+
let veil = document.getElementById('cuju-home-veil');
|
|
2938
|
+
if (!veil) {
|
|
2939
|
+
veil = document.createElement('div');
|
|
2940
|
+
veil.id = 'cuju-home-veil';
|
|
2941
|
+
veil.style.cssText = `position:fixed;inset:0;z-index:50;pointer-events:none;background:#0b0c0e;opacity:0;transition:opacity ${HOME_FADE_MS}ms ease`;
|
|
2942
|
+
document.body.appendChild(veil);
|
|
2943
|
+
}
|
|
2944
|
+
clearTimeout(this.homeTimer);
|
|
2945
|
+
const still = () => app.source === source && app.page === 'watch' && !this.running;
|
|
2946
|
+
// A frame later, so a show ended by opening another match does not fade at all.
|
|
2947
|
+
requestAnimationFrame(() => {
|
|
2948
|
+
if (!still()) {
|
|
2949
|
+
return;
|
|
2950
|
+
}
|
|
2951
|
+
veil.style.opacity = '1';
|
|
2952
|
+
this.homeTimer = setTimeout(() => {
|
|
2953
|
+
if (still()) {
|
|
2954
|
+
app.showPage('home');
|
|
2955
|
+
}
|
|
2956
|
+
veil.style.opacity = '0';
|
|
2957
|
+
}, HOME_FADE_MS + 40);
|
|
2958
|
+
});
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
// Full time, the winners on a podium in the center circle, dancing, confetti and the MVP cards.
|
|
2963
|
+
export class Podium {
|
|
2964
|
+
constructor(app) {
|
|
2965
|
+
this.app = app;
|
|
2966
|
+
this.group = null;
|
|
2967
|
+
this.overlay = null;
|
|
2968
|
+
this.clock = 0;
|
|
2969
|
+
}
|
|
2970
|
+
|
|
2971
|
+
get showing() {
|
|
2972
|
+
return !!this.overlay;
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
// A trophy ceremony passes `honour`, the side of the champion with a title and a line under
|
|
2976
|
+
// it, and the podium holds that side whatever the score of the match.
|
|
2977
|
+
show(f = null, honour = null) {
|
|
2978
|
+
const app = this.app;
|
|
2979
|
+
if (this.showing || !app.source) {
|
|
2980
|
+
return;
|
|
2981
|
+
}
|
|
2982
|
+
const header = app.source.header;
|
|
2983
|
+
const { stats } = matchStats(app.timeline.store, header);
|
|
2984
|
+
const last = app.timeline.store.get(app.timeline.last);
|
|
2985
|
+
app.hud.freeze(last);
|
|
2986
|
+
const winner = honour ? honour.team : last.scoreLeft === last.scoreRight ? -1 : (last.scoreLeft > last.scoreRight ? 0 : 1);
|
|
2987
|
+
const best = (team) => stats.filter((s) => s.team === team).sort((a, b) => b.score - a.score);
|
|
2988
|
+
if (!(app.presentation && app.presentation.reveal('winner', winner))) {
|
|
2989
|
+
app.sound.fanfare();
|
|
2990
|
+
}
|
|
2991
|
+
this.previousCamera = app.cameras.mode === 'scripted' ? (app.settings.camera || 'broadcast') : app.cameras.mode;
|
|
2992
|
+
if (winner >= 0) {
|
|
2993
|
+
this.buildScene(header, best(winner), winner);
|
|
2994
|
+
} else {
|
|
2995
|
+
this.buildDraw(header, [best(0), best(1)]);
|
|
2996
|
+
}
|
|
2997
|
+
injectShowStyle();
|
|
2998
|
+
const names = teamNames(header);
|
|
2999
|
+
const cards = winner >= 0 ? [this.card(best(winner)[0], header)] : [this.card(best(0)[0], header, true), this.card(best(1)[0], header, true)];
|
|
3000
|
+
const all = stats.slice().sort((a, b) => b.score - a.score);
|
|
3001
|
+
this.mvp = winner >= 0 ? best(winner)[0] : all[0];
|
|
3002
|
+
const title = honour ? honour.title : winner >= 0 ? winLine(names[winner], bareTeamName(header, winner)) : t('show.result.draw');
|
|
3003
|
+
this.overlay = h('div', { id: 'victory', class: honour ? 'ceremony' : winner >= 0 ? '' : 'draw', role: honour ? 'dialog' : null, 'aria-label': honour ? title : null },
|
|
3004
|
+
h('div', { class: 'victory-head' },
|
|
3005
|
+
h('div', { class: 'victory-title' }, title),
|
|
3006
|
+
h('div', { class: 'victory-score' }, honour ? honour.subtitle : `${names[0]} ${last.scoreLeft} – ${last.scoreRight} ${names[1]}`)),
|
|
3007
|
+
h('div', { class: 'victory-cards' }, cards),
|
|
3008
|
+
h('div', { class: 'victory-actions' }, app.postMatch.statsButton('btn ghost'),
|
|
3009
|
+
h('button', { class: 'btn', ...symbolOnly(t('show.close')), onclick: () => app.postMatch.end() }, icon('close'))));
|
|
3010
|
+
document.getElementById('watch').appendChild(this.overlay);
|
|
3011
|
+
}
|
|
3012
|
+
|
|
3013
|
+
// The card of a team's best player, compact when two share the panel after a draw.
|
|
3014
|
+
card(s, header, compact = false) {
|
|
3015
|
+
if (!s) {
|
|
3016
|
+
return h('div', { class: 'mvp-card' }, t('show.mvp.none'));
|
|
3017
|
+
}
|
|
3018
|
+
const app = this.app;
|
|
3019
|
+
const info = playerInfo(app, s.k);
|
|
3020
|
+
const style = app.styles ? app.styles[s.team] : null;
|
|
3021
|
+
const row = (label, value) => h('div', { class: 'stat' }, h('span', {}, label), h('b', {}, String(value)));
|
|
3022
|
+
void header;
|
|
3023
|
+
return h('div', { class: 'mvp-card', style: `border-top-color:${style ? css(style.kit.primary) : 'var(--accent)'}` },
|
|
3024
|
+
h('div', { class: 'mvp-label' }, t('show.mvp.label')),
|
|
3025
|
+
h('div', { class: 'mvp-name' }, h('span', { class: 'mvp-number' }, String(info.number)), info.name),
|
|
3026
|
+
h('div', { class: 'mvp-team' }, info.badge ? `${info.badge} ` : '', info.teamName),
|
|
3027
|
+
row(t('show.column.goals'), s.goals), row(t('show.column.assists'), s.assists), compact ? null : row(t('show.column.touches'), s.touches),
|
|
3028
|
+
row(t('show.column.passes'), s.passes ? t('show.stats.of', { done: s.passesCompleted, total: s.passes }) : 0), row(t('show.column.tackles'), s.tackles),
|
|
3029
|
+
s.goalkeeper || s.saves ? row(t('show.column.saves'), s.catches || s.parries ? t('show.mvp.saves', { saves: s.saves, count: s.catches }) : s.saves) : null,
|
|
3030
|
+
s.ownGoals ? row(t('show.column.owngoals'), s.ownGoals) : null);
|
|
3031
|
+
}
|
|
3032
|
+
|
|
3033
|
+
buildScene(header, ranked, team) {
|
|
3034
|
+
const app = this.app;
|
|
3035
|
+
const g = new THREE.Group();
|
|
3036
|
+
app.view.scene.add(g);
|
|
3037
|
+
this.group = g;
|
|
3038
|
+
// Steps and places sized for the team's biggest model, so big figures stand clear.
|
|
3039
|
+
const size = ranked.reduce((m, st) => {
|
|
3040
|
+
const f = figureSize(app.players, st.k);
|
|
3041
|
+
return { radius: Math.max(m.radius, f.radius), height: Math.max(m.height, f.height) };
|
|
3042
|
+
}, { radius: 0.35, height: 1.85 });
|
|
3043
|
+
const R = size.radius;
|
|
3044
|
+
const lift = Math.max(1, Math.min(1.7, size.height / 1.85));
|
|
3045
|
+
const stepW = Math.max(1.5, 2 * R + 0.5);
|
|
3046
|
+
const apart = stepW + 0.15;
|
|
3047
|
+
const stone = new THREE.MeshStandardMaterial({ color: 0xe8eaed, roughness: 0.6 });
|
|
3048
|
+
const steps = [
|
|
3049
|
+
{ x: 0, h: 0.9 * lift, label: 1 }, { x: -apart, h: 0.6 * lift, label: 2 }, { x: apart, h: 0.4 * lift, label: 3 },
|
|
3050
|
+
];
|
|
3051
|
+
for (const st of steps) {
|
|
3052
|
+
const box = new THREE.Mesh(new THREE.BoxGeometry(stepW, st.h, stepW), stone);
|
|
3053
|
+
box.position.set(st.x, st.h / 2, 0);
|
|
3054
|
+
box.castShadow = true;
|
|
3055
|
+
box.receiveShadow = true;
|
|
3056
|
+
g.add(box);
|
|
3057
|
+
}
|
|
3058
|
+
// Everyone of the team on a pose buffer, the best three dancing on the steps, the rest
|
|
3059
|
+
// in staggered rows behind them a body apart.
|
|
3060
|
+
const players = ranked.map((s, i) => ({ ...header.players[s.k], slot: i }));
|
|
3061
|
+
const pose = { players: players.length, nodes: new Float32Array(players.length * PLAYER_FLOATS) };
|
|
3062
|
+
const style = app.styles ? app.styles[team] : null;
|
|
3063
|
+
const random = seeded(team * 101 + players.length);
|
|
3064
|
+
const rest = Math.max(0, players.length - 3);
|
|
3065
|
+
const perRow = Math.max(4, Math.ceil(rest / 2));
|
|
3066
|
+
// Arms raised in a cheer reach past the resting radius, so neighbours stand a little wider.
|
|
3067
|
+
const spacing = 2 * R + 0.55;
|
|
3068
|
+
let width = 3 * stepW + 0.3;
|
|
3069
|
+
this.slots = players.map((p, i) => {
|
|
3070
|
+
if (i < 3) {
|
|
3071
|
+
return { x: steps[i].x, y: 0, z: steps[i].h, dance: showDance(style, p.index, random), phase: i * 0.37 };
|
|
3072
|
+
}
|
|
3073
|
+
const r = i - 3;
|
|
3074
|
+
const row = Math.floor(r / perRow);
|
|
3075
|
+
const inRow = Math.min(perRow, rest - row * perRow);
|
|
3076
|
+
const col = r - row * perRow;
|
|
3077
|
+
const x = (col - (inRow - 1) / 2) * spacing + (row % 2 ? spacing / 2 : 0);
|
|
3078
|
+
width = Math.max(width, inRow * spacing + spacing);
|
|
3079
|
+
const clap = roleName('clap');
|
|
3080
|
+
return {
|
|
3081
|
+
x, y: stepW / 2 + R + 0.6 + row * (2 * R + 0.5), z: 0,
|
|
3082
|
+
dance: i % 2 && clap ? clap : showDance(style, p.index, random), phase: random() * 2,
|
|
3083
|
+
};
|
|
3084
|
+
});
|
|
3085
|
+
this.frameShot(width, size.height, steps[0].h);
|
|
3086
|
+
this.pose = pose;
|
|
3087
|
+
this.clock = 0;
|
|
3088
|
+
const podiumHeader = { players: players.map((p) => ({ team: p.team, index: p.index, goalkeeper: p.goalkeeper, controlled: false })), teams: header.teams };
|
|
3089
|
+
const rigs = app.teamRigs || [null, null];
|
|
3090
|
+
this.players = new Players(g, podiumHeader, app.styles, app.assets, rigs);
|
|
3091
|
+
shareColors(this.players, app.players);
|
|
3092
|
+
this.frame = { playerFlags: new Uint8Array(players.length).fill(1), ownedPlayer: -1 };
|
|
3093
|
+
// KayKit figures left to chance celebrate with KayKit's clips, the best three jumping and
|
|
3094
|
+
// cheering on the steps, the rows behind cheering, waving to the fans and taunting.
|
|
3095
|
+
const has = clipTest(this.players);
|
|
3096
|
+
const stepClips = ['clip:Jump_Full_Long', 'clip:Cheering', 'clip:Cheering'];
|
|
3097
|
+
const rowClips = ['clip:Cheering', 'clip:Waving', 'clip:Jump_Full_Short', 'clip:Skeletons_Taunt_Longer', 'clip:Waving', 'clip:Push_Ups'];
|
|
3098
|
+
this.slots.forEach((slot, i) => {
|
|
3099
|
+
const p = players[i];
|
|
3100
|
+
if (!choseCelebration(style, p.index)) {
|
|
3101
|
+
const want = i < 3 ? stepClips[i] : rowClips[(i - 3) % rowClips.length];
|
|
3102
|
+
const pick = has(i, want) ? want : kaykitCelebration(has, i, random);
|
|
3103
|
+
if (pick) {
|
|
3104
|
+
slot.dance = pick;
|
|
3105
|
+
}
|
|
3106
|
+
}
|
|
3107
|
+
slot.dance = usableDance(this.players, i, slot.dance, random);
|
|
3108
|
+
});
|
|
3109
|
+
this.dance(0);
|
|
3110
|
+
this.confetti(g, style);
|
|
3111
|
+
if (app.players) {
|
|
3112
|
+
app.players.group.visible = false;
|
|
3113
|
+
}
|
|
3114
|
+
app.ball.mesh.visible = false;
|
|
3115
|
+
app.ball.blob.visible = false;
|
|
3116
|
+
app.ball.trail.visible = false;
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
// A draw, the best four of each team on a low stage, a half for each, their best player in
|
|
3120
|
+
// front applauding the other side, the rest behind cheering and waving to the fans.
|
|
3121
|
+
buildDraw(header, lists) {
|
|
3122
|
+
const app = this.app;
|
|
3123
|
+
const g = new THREE.Group();
|
|
3124
|
+
app.view.scene.add(g);
|
|
3125
|
+
this.group = g;
|
|
3126
|
+
const picks = lists.map((l) => l.slice(0, 4));
|
|
3127
|
+
const everyone = [...picks[0], ...picks[1]];
|
|
3128
|
+
if (!everyone.length) {
|
|
3129
|
+
app.cameras.setMode('tactical');
|
|
3130
|
+
return;
|
|
3131
|
+
}
|
|
3132
|
+
const size = everyone.reduce((m, st) => {
|
|
3133
|
+
const f = figureSize(app.players, st.k);
|
|
3134
|
+
return { radius: Math.max(m.radius, f.radius), height: Math.max(m.height, f.height) };
|
|
3135
|
+
}, { radius: 0.35, height: 1.85 });
|
|
3136
|
+
const R = size.radius;
|
|
3137
|
+
const spacing = 2 * R + 0.55;
|
|
3138
|
+
const stageH = 0.3;
|
|
3139
|
+
const rows = Math.max(1, Math.max(picks[0].length, picks[1].length) - 1);
|
|
3140
|
+
const half = R + 0.45 + rows * spacing * 0.9 + spacing * 0.45 + R + 0.4;
|
|
3141
|
+
const depth = 2 * spacing + 1.2;
|
|
3142
|
+
const styles = app.styles || [null, null];
|
|
3143
|
+
picks.forEach((list, team) => {
|
|
3144
|
+
const tint = styles[team] ? threeColorOf(styles[team].kit.primary).lerp(new THREE.Color(0xe8eaed), 0.82) : new THREE.Color(0xe8eaed);
|
|
3145
|
+
const box = new THREE.Mesh(new THREE.BoxGeometry(half, stageH, depth), new THREE.MeshStandardMaterial({ color: tint, roughness: 0.6 }));
|
|
3146
|
+
box.position.set((team === 0 ? -1 : 1) * (half / 2 + 0.05), stageH / 2, depth / 2 - spacing - 0.6);
|
|
3147
|
+
box.castShadow = true;
|
|
3148
|
+
box.receiveShadow = true;
|
|
3149
|
+
g.add(box);
|
|
3150
|
+
});
|
|
3151
|
+
const players = everyone.map((s) => header.players[s.k]);
|
|
3152
|
+
const pose = { players: players.length, nodes: new Float32Array(players.length * PLAYER_FLOATS) };
|
|
3153
|
+
const random = seeded(players.length * 7 + 5);
|
|
3154
|
+
this.slots = [];
|
|
3155
|
+
picks.forEach((list, team) => {
|
|
3156
|
+
const side = team === 0 ? -1 : 1;
|
|
3157
|
+
const style = styles[team];
|
|
3158
|
+
list.forEach((st, i) => {
|
|
3159
|
+
const p = header.players[st.k];
|
|
3160
|
+
// The best player stands in front near the middle and turns a little towards the
|
|
3161
|
+
// other team, the others stand in a row behind him.
|
|
3162
|
+
const front = i === 0;
|
|
3163
|
+
const x = front ? side * (R + 0.45) : side * (R + 0.45 + (i - 1) * spacing * 0.9 + spacing * 0.45);
|
|
3164
|
+
const y = front ? 0 : spacing;
|
|
3165
|
+
const heading = front ? -side * 0.45 : 0;
|
|
3166
|
+
const dance = front || i % 2 === 0 ? (roleName('clap') || showDance(style, p.index, random)) : showDance(style, p.index, random);
|
|
3167
|
+
this.slots.push({ x, y, z: stageH, heading, dance, phase: random() * 2, team, index: p.index, front });
|
|
3168
|
+
});
|
|
3169
|
+
});
|
|
3170
|
+
// Wider than the stage, so its right half stays clear of the panel of cards.
|
|
3171
|
+
this.frameShot((2 * half + 1) * 1.45, size.height, stageH);
|
|
3172
|
+
this.pose = pose;
|
|
3173
|
+
this.clock = 0;
|
|
3174
|
+
const podiumHeader = { players: players.map((p) => ({ team: p.team, index: p.index, goalkeeper: p.goalkeeper, controlled: false })), teams: header.teams };
|
|
3175
|
+
this.players = new Players(g, podiumHeader, app.styles, app.assets, app.teamRigs || [null, null]);
|
|
3176
|
+
shareColors(this.players, app.players);
|
|
3177
|
+
this.frame = { playerFlags: new Uint8Array(players.length).fill(1), ownedPlayer: -1 };
|
|
3178
|
+
const has = clipTest(this.players);
|
|
3179
|
+
this.slots.forEach((slot, i) => {
|
|
3180
|
+
if (!choseCelebration(styles[slot.team], slot.index) || slot.front) {
|
|
3181
|
+
const want = slot.front ? 'clip:Waving' : ['clip:Cheering', 'clip:Waving', 'clip:Idle_B'][i % 3];
|
|
3182
|
+
if (has(i, want)) {
|
|
3183
|
+
slot.dance = want;
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
slot.dance = usableDance(this.players, i, slot.dance, random);
|
|
3187
|
+
});
|
|
3188
|
+
this.dance(0);
|
|
3189
|
+
this.confetti(g, null, [styles[0] ? styles[0].kit.primary : [255, 111, 0], styles[1] ? styles[1].kit.primary : [255, 160, 0], [255, 255, 255]]);
|
|
3190
|
+
if (app.players) {
|
|
3191
|
+
app.players.group.visible = false;
|
|
3192
|
+
}
|
|
3193
|
+
app.ball.mesh.visible = false;
|
|
3194
|
+
app.ball.blob.visible = false;
|
|
3195
|
+
app.ball.trail.visible = false;
|
|
3196
|
+
}
|
|
3197
|
+
|
|
3198
|
+
// A shot that holds the whole podium and the rows behind it, whatever the size of the models.
|
|
3199
|
+
frameShot(width, height, top) {
|
|
3200
|
+
const app = this.app;
|
|
3201
|
+
const director = app.director;
|
|
3202
|
+
const sh = director.shot;
|
|
3203
|
+
const aspect = Math.max(0.5, app.view.aspect || 16 / 9);
|
|
3204
|
+
const fov = 40;
|
|
3205
|
+
// The camera widens the field of view of a narrow picture, so the distance is for that.
|
|
3206
|
+
const half = Math.tan(THREE.MathUtils.degToRad(aspectFov(fov, aspect) / 2));
|
|
3207
|
+
const tall = top + height * 1.15;
|
|
3208
|
+
const dist = Math.max(10, (width / 2 + 1) / (half * aspect), (tall / 2 + 1) / half);
|
|
3209
|
+
// The card of the MVP sits on the right, so the podium moves left of it.
|
|
3210
|
+
const shift = dist * half * aspect * 0.28;
|
|
3211
|
+
sh.target.set(shift, tall * 0.5, 0);
|
|
3212
|
+
sh.pos.set(shift, tall * 0.5 + dist * 0.12, dist);
|
|
3213
|
+
sh.fov = fov;
|
|
3214
|
+
sh.rate = 2;
|
|
3215
|
+
sh.snap = true;
|
|
3216
|
+
director.useScripted();
|
|
3217
|
+
app.cameras.jump();
|
|
3218
|
+
this.spread = width;
|
|
3219
|
+
}
|
|
3220
|
+
|
|
3221
|
+
// Poses everyone on the podium at time t and draws them.
|
|
3222
|
+
dance(t) {
|
|
3223
|
+
if (!this.players || !this.slots) {
|
|
3224
|
+
return;
|
|
3225
|
+
}
|
|
3226
|
+
const nodes = this.pose.nodes;
|
|
3227
|
+
this.slots.forEach((s, i) => {
|
|
3228
|
+
const o = i * PLAYER_FLOATS;
|
|
3229
|
+
posePlayer(s.dance, t + s.phase, nodes, o, s.x, s.y, s.heading || 0, 'show');
|
|
3230
|
+
for (let n = 0; n < 14; n++) {
|
|
3231
|
+
nodes[o + n * 7 + 2] += s.z;
|
|
3232
|
+
}
|
|
3233
|
+
if (s.dance && s.dance.startsWith('clip:') && typeof this.players.playClip === 'function') {
|
|
3234
|
+
this.players.playClip(i, s.dance, t + s.phase);
|
|
3235
|
+
}
|
|
3236
|
+
});
|
|
3237
|
+
this.players.update(this.pose, this.frame);
|
|
3238
|
+
}
|
|
3239
|
+
|
|
3240
|
+
confetti(group, style, mix = null) {
|
|
3241
|
+
const count = 600;
|
|
3242
|
+
const geo = new THREE.PlaneGeometry(0.09, 0.05);
|
|
3243
|
+
const mat = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide });
|
|
3244
|
+
const mesh = new THREE.InstancedMesh(geo, mat, count);
|
|
3245
|
+
const colors = mix || (style ? [style.kit.primary, style.kit.secondary, [255, 255, 255]] : [[255, 111, 0], [255, 160, 0], [232, 234, 237]]);
|
|
3246
|
+
this.bits = [];
|
|
3247
|
+
for (let i = 0; i < count; i++) {
|
|
3248
|
+
const c = colors[i % colors.length];
|
|
3249
|
+
mesh.setColorAt(i, new THREE.Color().setRGB(c[0] / 255, c[1] / 255, c[2] / 255, THREE.SRGBColorSpace));
|
|
3250
|
+
this.bits.push({
|
|
3251
|
+
p: new THREE.Vector3((Math.random() - 0.5) * Math.max(12, (this.spread || 0) + 4), 4 + Math.random() * 10, (Math.random() - 0.5) * 8),
|
|
3252
|
+
v: new THREE.Vector3((Math.random() - 0.5) * 0.6, -0.8 - Math.random() * 0.8, (Math.random() - 0.5) * 0.6),
|
|
3253
|
+
r: new THREE.Euler(Math.random() * 6, Math.random() * 6, Math.random() * 6),
|
|
3254
|
+
w: new THREE.Vector3(Math.random() * 6, Math.random() * 6, Math.random() * 6),
|
|
3255
|
+
});
|
|
3256
|
+
}
|
|
3257
|
+
mesh.frustumCulled = false;
|
|
3258
|
+
group.add(mesh);
|
|
3259
|
+
this.confettiMesh = mesh;
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3262
|
+
update(dt) {
|
|
3263
|
+
if (!this.confettiMesh) {
|
|
3264
|
+
return;
|
|
3265
|
+
}
|
|
3266
|
+
this.clock += dt;
|
|
3267
|
+
this.dance(this.clock);
|
|
3268
|
+
// Reduced motion keeps the dances and leaves the confetti out.
|
|
3269
|
+
const still = !!this.app.reducedMotion;
|
|
3270
|
+
this.confettiMesh.visible = !still;
|
|
3271
|
+
if (still) {
|
|
3272
|
+
return;
|
|
3273
|
+
}
|
|
3274
|
+
const m = new THREE.Matrix4();
|
|
3275
|
+
const q = new THREE.Quaternion();
|
|
3276
|
+
const one = new THREE.Vector3(1, 1, 1);
|
|
3277
|
+
this.bits.forEach((b, i) => {
|
|
3278
|
+
b.p.addScaledVector(b.v, dt);
|
|
3279
|
+
b.p.x += Math.sin(performance.now() / 700 + i) * dt * 0.3;
|
|
3280
|
+
if (b.p.y < 0.02) {
|
|
3281
|
+
b.p.y = 10 + Math.random() * 4;
|
|
3282
|
+
}
|
|
3283
|
+
b.r.x += b.w.x * dt;
|
|
3284
|
+
b.r.y += b.w.y * dt;
|
|
3285
|
+
b.r.z += b.w.z * dt;
|
|
3286
|
+
q.setFromEuler(b.r);
|
|
3287
|
+
m.compose(b.p, q, one);
|
|
3288
|
+
this.confettiMesh.setMatrixAt(i, m);
|
|
3289
|
+
});
|
|
3290
|
+
this.confettiMesh.instanceMatrix.needsUpdate = true;
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
hide() {
|
|
3294
|
+
const app = this.app;
|
|
3295
|
+
if (this.overlay) {
|
|
3296
|
+
this.overlay.remove();
|
|
3297
|
+
this.overlay = null;
|
|
3298
|
+
}
|
|
3299
|
+
if (this.group) {
|
|
3300
|
+
if (this.players) {
|
|
3301
|
+
this.players.dispose();
|
|
3302
|
+
this.players = null;
|
|
3303
|
+
}
|
|
3304
|
+
this.group.removeFromParent();
|
|
3305
|
+
this.group.traverse((obj) => {
|
|
3306
|
+
if (obj.geometry) {
|
|
3307
|
+
obj.geometry.dispose();
|
|
3308
|
+
}
|
|
3309
|
+
if (obj.material) {
|
|
3310
|
+
obj.material.dispose();
|
|
3311
|
+
}
|
|
3312
|
+
});
|
|
3313
|
+
this.group = null;
|
|
3314
|
+
this.confettiMesh = null;
|
|
3315
|
+
this.slots = null;
|
|
3316
|
+
}
|
|
3317
|
+
if (app.players) {
|
|
3318
|
+
app.players.group.visible = true;
|
|
3319
|
+
}
|
|
3320
|
+
app.ball.mesh.visible = true;
|
|
3321
|
+
app.ball.blob.visible = true;
|
|
3322
|
+
app.ball.trail.visible = app.ball.trailOn;
|
|
3323
|
+
if (this.previousCamera) {
|
|
3324
|
+
app.cameras.setMode(this.previousCamera);
|
|
3325
|
+
this.previousCamera = null;
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
|
|
3330
|
+
// The captions of the spotlight's clip, by the English name of what it shows.
|
|
3331
|
+
const SPOT_CAPTIONS = {
|
|
3332
|
+
Goal: t('show.spotlight.goal'), Assist: t('show.spotlight.assist'), Save: t('show.spotlight.save'),
|
|
3333
|
+
Tackle: t('show.spotlight.tackle'), 'On the ball': t('show.spotlight.ball'),
|
|
3334
|
+
};
|
|
3335
|
+
|
|
3336
|
+
// The MVP spotlight, the play of the match loops in the main view, slowed near its key moment,
|
|
3337
|
+
// while the MVP dances in a cone of light on a dark stage beside it with a name plate.
|
|
3338
|
+
export class Spotlight {
|
|
3339
|
+
constructor(app) {
|
|
3340
|
+
this.app = app;
|
|
3341
|
+
this.overlay = null;
|
|
3342
|
+
}
|
|
3343
|
+
|
|
3344
|
+
get showing() {
|
|
3345
|
+
return !!this.overlay;
|
|
3346
|
+
}
|
|
3347
|
+
|
|
3348
|
+
// The clip, the latest goal, else the latest assist, save or tackle, else the longest run.
|
|
3349
|
+
clip(s) {
|
|
3350
|
+
const last = (list) => (list.length ? list[list.length - 1] : null);
|
|
3351
|
+
let key = last(s.goalFrames);
|
|
3352
|
+
let what = 'Goal';
|
|
3353
|
+
if (key == null) {
|
|
3354
|
+
key = last(s.assistFrames);
|
|
3355
|
+
what = 'Assist';
|
|
3356
|
+
}
|
|
3357
|
+
if (key == null) {
|
|
3358
|
+
key = last(s.saveFrames);
|
|
3359
|
+
what = 'Save';
|
|
3360
|
+
}
|
|
3361
|
+
if (key == null) {
|
|
3362
|
+
key = last(s.tackleFrames);
|
|
3363
|
+
what = 'Tackle';
|
|
3364
|
+
}
|
|
3365
|
+
if (key != null) {
|
|
3366
|
+
// A goal's clip ends on the frame before it, the kick-off after it stays unseen.
|
|
3367
|
+
const end = what === 'Goal' || what === 'Assist' ? key - 1 : key + 12;
|
|
3368
|
+
return { begin: key - 60, end, key, what, camera: what === 'Save' ? 'goal' : 'lowside' };
|
|
3369
|
+
}
|
|
3370
|
+
if (s.run) {
|
|
3371
|
+
const end = Math.min(s.run.end + 10, s.run.start + 120);
|
|
3372
|
+
return { begin: s.run.start - 10, end, key: Math.min(s.run.end, end - 4), what: 'On the ball', camera: 'orbit' };
|
|
3373
|
+
}
|
|
3374
|
+
return null;
|
|
3375
|
+
}
|
|
3376
|
+
|
|
3377
|
+
show(s) {
|
|
3378
|
+
const app = this.app;
|
|
3379
|
+
const tl = app.timeline;
|
|
3380
|
+
if (!tl || this.showing) {
|
|
3381
|
+
return;
|
|
3382
|
+
}
|
|
3383
|
+
const clip = this.clip(s);
|
|
3384
|
+
this.state = {
|
|
3385
|
+
t: tl.t, playing: tl.playing, speed: tl.speed, direction: tl.direction, following: tl.following,
|
|
3386
|
+
camera: app.cameras.mode, focus: app.cameras.focusIndex,
|
|
3387
|
+
};
|
|
3388
|
+
app.hud.freeze(tl.store.get(tl.last));
|
|
3389
|
+
if (clip) {
|
|
3390
|
+
clip.begin = Math.max(tl.first, clip.begin);
|
|
3391
|
+
clip.end = Math.min(tl.last, clip.end);
|
|
3392
|
+
this.loop = clip;
|
|
3393
|
+
app.cameras.focusIndex = s.k;
|
|
3394
|
+
app.cameras.setMode(clip.camera);
|
|
3395
|
+
tl.following = false;
|
|
3396
|
+
tl.seek(clip.begin);
|
|
3397
|
+
tl.direction = 1;
|
|
3398
|
+
tl.playing = true;
|
|
3399
|
+
app.lastIndex = tl.index;
|
|
3400
|
+
app.afterSeek();
|
|
3401
|
+
}
|
|
3402
|
+
this.mvp = s;
|
|
3403
|
+
const info = playerInfo(app, s.k);
|
|
3404
|
+
const style = app.styles ? app.styles[s.team] : null;
|
|
3405
|
+
this.danceName = showDance(style, s.index);
|
|
3406
|
+
const stage = h('div', { class: 'spot-stage' });
|
|
3407
|
+
const stats = [
|
|
3408
|
+
t('show.count.goals', { count: s.goals }), t('show.count.assists', { count: s.assists }),
|
|
3409
|
+
t('show.count.passes', { count: s.passes }), t('show.count.tackles', { count: s.tackles }),
|
|
3410
|
+
s.goalkeeper || s.saves ? t('show.count.saves', { count: s.saves }) : null,
|
|
3411
|
+
].filter(Boolean).join(', ');
|
|
3412
|
+
this.overlay = h('div', { id: 'spotlight' },
|
|
3413
|
+
h('div', { class: 'mvp-flash', 'aria-hidden': 'true' }),
|
|
3414
|
+
h('div', { class: 'spot-side' },
|
|
3415
|
+
h('div', { class: 'mvp-rays', 'aria-hidden': 'true' }),
|
|
3416
|
+
mvpMedal(style ? [style.kit.primary, style.kit.secondary] : [[194, 65, 12], [248, 249, 250]]), stage,
|
|
3417
|
+
h('div', { class: 'nameplate', style: style ? `border-top-color:${css(style.kit.primary)}` : '' },
|
|
3418
|
+
h('div', { class: 'mvp-label' }, t('show.mvp.label')),
|
|
3419
|
+
h('div', { class: 'mvp-name' }, h('span', { class: 'mvp-number' }, String(info.number)), info.name),
|
|
3420
|
+
h('div', { class: 'mvp-team' }, info.badge ? `${info.badge} ` : '', info.teamName),
|
|
3421
|
+
h('div', { class: 'small muted' }, stats),
|
|
3422
|
+
h('button', { class: 'btn primary', onclick: () => app.postMatch.skip() }, icon('next'), t('show.spotlight.next')))),
|
|
3423
|
+
h('div', { class: 'spot-frame' }, h('div', { class: 'spot-caption' }, clip ? SPOT_CAPTIONS[clip.what] : t('show.award.mvp'))));
|
|
3424
|
+
document.getElementById('watch').appendChild(this.overlay);
|
|
3425
|
+
document.getElementById('app').classList.add('spot-show');
|
|
3426
|
+
this.buildStage(stage, s);
|
|
3427
|
+
if (!(app.presentation && app.presentation.reveal('mvp', s.team))) {
|
|
3428
|
+
app.sound.fanfare();
|
|
3429
|
+
}
|
|
3430
|
+
this.overlay.querySelector('button').focus();
|
|
3431
|
+
this.overlay.addEventListener('keydown', (e) => {
|
|
3432
|
+
if (e.key === 'Enter') {
|
|
3433
|
+
e.preventDefault();
|
|
3434
|
+
e.stopPropagation();
|
|
3435
|
+
app.postMatch.skip();
|
|
3436
|
+
}
|
|
3437
|
+
});
|
|
3438
|
+
this.overlay.addEventListener('click', (e) => {
|
|
3439
|
+
if (!e.target.closest('button')) app.postMatch.skip();
|
|
3440
|
+
});
|
|
3441
|
+
}
|
|
3442
|
+
|
|
3443
|
+
buildStage(stage, s) {
|
|
3444
|
+
const app = this.app;
|
|
3445
|
+
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
|
|
3446
|
+
renderer.outputColorSpace = THREE.SRGBColorSpace;
|
|
3447
|
+
// The neutral curve keeps the hue of a bright kit where filmic curves wash it pale.
|
|
3448
|
+
renderer.toneMapping = THREE.NeutralToneMapping !== undefined ? THREE.NeutralToneMapping : THREE.ACESFilmicToneMapping;
|
|
3449
|
+
renderer.toneMappingExposure = 1.05;
|
|
3450
|
+
renderer.shadowMap.enabled = true;
|
|
3451
|
+
renderer.setPixelRatio(Math.min(2, window.devicePixelRatio || 1));
|
|
3452
|
+
stage.appendChild(renderer.domElement);
|
|
3453
|
+
// A dark studio behind the figure, lit from above in the middle.
|
|
3454
|
+
stage.style.background = 'radial-gradient(ellipse 80% 70% at 50% 38%, #2b2e38 0%, #15161b 55%, #08090b 100%)';
|
|
3455
|
+
const scene = new THREE.Scene();
|
|
3456
|
+
// The figure's own size frames the shot, big models stand back further.
|
|
3457
|
+
const size = figureSize(app.players, s.k);
|
|
3458
|
+
const tall = size.height;
|
|
3459
|
+
const camera = new THREE.PerspectiveCamera(30, 1, 0.05, 80);
|
|
3460
|
+
const dist = 2.9 * tall + 0.3 + size.radius;
|
|
3461
|
+
camera.position.set(0, tall * 0.62, dist);
|
|
3462
|
+
camera.lookAt(0, tall * 0.5, 0);
|
|
3463
|
+
scene.add(new THREE.HemisphereLight(0xc4d2e8, 0x24201c, 0.55));
|
|
3464
|
+
// The key, a warm spot from above and in front, with the cone of light it throws, about
|
|
3465
|
+
// as bright on the figure as daylight on the pitch.
|
|
3466
|
+
const spot = new THREE.SpotLight(0xffe7c8, 220, 0, 0.4, 0.55, 2);
|
|
3467
|
+
spot.position.set(0.8, 7.5, 3.2);
|
|
3468
|
+
spot.target.position.set(0, tall * 0.45, 0);
|
|
3469
|
+
spot.castShadow = true;
|
|
3470
|
+
spot.shadow.mapSize.set(1024, 1024);
|
|
3471
|
+
spot.shadow.bias = -0.0005;
|
|
3472
|
+
scene.add(spot, spot.target);
|
|
3473
|
+
// A soft fill from the front left so faces under hats and hoods read, and a cool rim
|
|
3474
|
+
// from behind that lifts the figure off the dark.
|
|
3475
|
+
const fill = new THREE.DirectionalLight(0xfff6ec, 0.9);
|
|
3476
|
+
fill.position.set(-3, tall * 0.9, 6);
|
|
3477
|
+
scene.add(fill);
|
|
3478
|
+
const rim = new THREE.DirectionalLight(0xbcd6ff, 2.4);
|
|
3479
|
+
rim.position.set(1.8, tall * 1.7, -5);
|
|
3480
|
+
scene.add(rim);
|
|
3481
|
+
const rim2 = new THREE.DirectionalLight(0xffd8b0, 1.2);
|
|
3482
|
+
rim2.position.set(-2.2, tall * 1.2, -4);
|
|
3483
|
+
scene.add(rim2);
|
|
3484
|
+
const floor = new THREE.Mesh(new THREE.CircleGeometry(9, 64), new THREE.MeshStandardMaterial({ color: 0x101115, roughness: 0.92 }));
|
|
3485
|
+
floor.rotation.x = -Math.PI / 2;
|
|
3486
|
+
floor.receiveShadow = true;
|
|
3487
|
+
scene.add(floor);
|
|
3488
|
+
// A warm pool on the floor and a visible cone, both additive so they glow.
|
|
3489
|
+
const pool = new THREE.Mesh(new THREE.CircleGeometry(1.6 + size.radius, 48), new THREE.MeshBasicMaterial({
|
|
3490
|
+
color: 0xffc77a, transparent: true, opacity: 0.16, depthWrite: false, blending: THREE.AdditiveBlending,
|
|
3491
|
+
}));
|
|
3492
|
+
pool.rotation.x = -Math.PI / 2;
|
|
3493
|
+
pool.position.y = 0.01;
|
|
3494
|
+
scene.add(pool);
|
|
3495
|
+
const coneGeo = new THREE.ConeGeometry(2.0 + size.radius, 8, 48, 1, true);
|
|
3496
|
+
coneGeo.translate(0, -4, 0);
|
|
3497
|
+
const cone = new THREE.Mesh(coneGeo, beamMaterial(0xffd29a, 0.3));
|
|
3498
|
+
cone.position.set(0, 8, 0);
|
|
3499
|
+
scene.add(cone);
|
|
3500
|
+
// The floor fades into the dark of the studio rather than ending at an edge.
|
|
3501
|
+
scene.fog = new THREE.Fog(0x0a0b0e, dist + 1, dist + 9);
|
|
3502
|
+
const p = app.source.header.players[s.k];
|
|
3503
|
+
const header = { players: [{ team: p.team, index: p.index, goalkeeper: p.goalkeeper, controlled: false }], teams: app.source.header.teams };
|
|
3504
|
+
const players = new Players(scene, header, app.styles, app.assets, app.teamRigs || [null, null]);
|
|
3505
|
+
shareColors(players, app.players);
|
|
3506
|
+
// A KayKit player of the match left to chance cheers with KayKit's own clip.
|
|
3507
|
+
const style = app.styles ? app.styles[p.team] : null;
|
|
3508
|
+
if (!choseCelebration(style, p.index)) {
|
|
3509
|
+
const has = clipTest(players);
|
|
3510
|
+
this.danceName = has(0, 'clip:Cheering') ? 'clip:Cheering' : (kaykitCelebration(has, 0, Math.random) || this.danceName);
|
|
3511
|
+
}
|
|
3512
|
+
this.danceName = usableDance(players, 0, this.danceName);
|
|
3513
|
+
this.stageState = {
|
|
3514
|
+
renderer, scene, camera, players, stage, dist, clock: performance.now(),
|
|
3515
|
+
pose: { players: 1, nodes: new Float32Array(PLAYER_FLOATS) },
|
|
3516
|
+
frame: { playerFlags: new Uint8Array([1]), ownedPlayer: -1 },
|
|
3517
|
+
};
|
|
3518
|
+
}
|
|
3519
|
+
|
|
3520
|
+
update() {
|
|
3521
|
+
const app = this.app;
|
|
3522
|
+
if (!this.showing) {
|
|
3523
|
+
return;
|
|
3524
|
+
}
|
|
3525
|
+
const tl = app.timeline;
|
|
3526
|
+
const c = this.loop;
|
|
3527
|
+
if (c && tl) {
|
|
3528
|
+
tl.following = false;
|
|
3529
|
+
tl.direction = 1;
|
|
3530
|
+
tl.speed = tl.t > c.key - 8 && tl.t < c.key + 4 ? 0.35 : 1;
|
|
3531
|
+
if (tl.t >= c.end || !tl.playing) {
|
|
3532
|
+
tl.seek(c.begin);
|
|
3533
|
+
tl.playing = true;
|
|
3534
|
+
app.lastIndex = tl.index;
|
|
3535
|
+
app.afterSeek();
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
const st = this.stageState;
|
|
3539
|
+
if (!st) {
|
|
3540
|
+
return;
|
|
3541
|
+
}
|
|
3542
|
+
const w = st.stage.clientWidth;
|
|
3543
|
+
const hgt = st.stage.clientHeight;
|
|
3544
|
+
const ratio = st.renderer.getPixelRatio();
|
|
3545
|
+
if (w && hgt && (st.renderer.domElement.width !== Math.floor(w * ratio) || st.renderer.domElement.height !== Math.floor(hgt * ratio))) {
|
|
3546
|
+
st.renderer.setSize(w, hgt, false);
|
|
3547
|
+
st.camera.aspect = w / hgt;
|
|
3548
|
+
st.camera.updateProjectionMatrix();
|
|
3549
|
+
}
|
|
3550
|
+
// The loop of the play of the match shows the moves, not the goal graphic of the play.
|
|
3551
|
+
const goal = app.hud.el && app.hud.el.goal;
|
|
3552
|
+
if (goal && goal.classList.contains('show')) {
|
|
3553
|
+
app.hud.hideGoal();
|
|
3554
|
+
}
|
|
3555
|
+
const t = (performance.now() - st.clock) / 1000;
|
|
3556
|
+
const push = app.reducedMotion ? 0 : Math.pow(Math.max(0, 1 - t / 1.2), 3);
|
|
3557
|
+
st.camera.position.z = st.dist * (1 + push * 0.65);
|
|
3558
|
+
posePlayer(this.danceName, t, st.pose.nodes, 0, 0, 0, Math.sin(t * 0.4) * 0.2, 'show');
|
|
3559
|
+
if (this.danceName && this.danceName.startsWith('clip:') && typeof st.players.playClip === 'function') {
|
|
3560
|
+
st.players.playClip(0, this.danceName, t);
|
|
3561
|
+
}
|
|
3562
|
+
st.players.update(st.pose, st.frame);
|
|
3563
|
+
st.renderer.render(st.scene, st.camera);
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
hide(restore = true) {
|
|
3567
|
+
const app = this.app;
|
|
3568
|
+
if (!this.overlay) {
|
|
3569
|
+
return;
|
|
3570
|
+
}
|
|
3571
|
+
this.overlay.remove();
|
|
3572
|
+
this.overlay = null;
|
|
3573
|
+
document.getElementById('app').classList.remove('spot-show');
|
|
3574
|
+
if (this.stageState) {
|
|
3575
|
+
const st = this.stageState;
|
|
3576
|
+
st.players.dispose();
|
|
3577
|
+
st.scene.traverse((obj) => {
|
|
3578
|
+
if (obj.geometry) {
|
|
3579
|
+
obj.geometry.dispose();
|
|
3580
|
+
}
|
|
3581
|
+
if (obj.material) {
|
|
3582
|
+
obj.material.dispose();
|
|
3583
|
+
}
|
|
3584
|
+
if (obj.isLight && obj.shadow && obj.shadow.map) {
|
|
3585
|
+
obj.shadow.map.dispose();
|
|
3586
|
+
}
|
|
3587
|
+
});
|
|
3588
|
+
st.renderer.dispose();
|
|
3589
|
+
st.renderer.forceContextLoss();
|
|
3590
|
+
this.stageState = null;
|
|
3591
|
+
}
|
|
3592
|
+
const s = this.state;
|
|
3593
|
+
const tl = app.timeline;
|
|
3594
|
+
if (s && tl && restore) {
|
|
3595
|
+
tl.speed = s.speed;
|
|
3596
|
+
tl.direction = s.direction;
|
|
3597
|
+
app.cameras.focusIndex = s.focus;
|
|
3598
|
+
app.cameras.setMode(s.camera);
|
|
3599
|
+
if (s.following) {
|
|
3600
|
+
tl.goLive();
|
|
3601
|
+
} else {
|
|
3602
|
+
tl.seek(s.t);
|
|
3603
|
+
tl.playing = false;
|
|
3604
|
+
}
|
|
3605
|
+
app.lastIndex = tl.index;
|
|
3606
|
+
app.afterSeek();
|
|
3607
|
+
app.updatePlayUi();
|
|
3608
|
+
}
|
|
3609
|
+
if (tl && !restore) {
|
|
3610
|
+
tl.speed = s ? s.speed : 1;
|
|
3611
|
+
}
|
|
3612
|
+
this.loop = null;
|
|
3613
|
+
}
|
|
3614
|
+
}
|