diff --git a/build/web/autofocus.js b/build/web/autofocus.js new file mode 100644 index 0000000000000000000000000000000000000000..bd59c5069600d882aa67626d3d1d4c2cb5c8b8c1 --- /dev/null +++ b/build/web/autofocus.js @@ -0,0 +1,31 @@ +document.addEventListener('DOMContentLoaded', function() { + if ('MutationObserver' in window) { + const config = { + attributes: false, + childList: true, + subtree: false, + } + + function onElementAdded(mutationsList, observer) { + for (const mutation of mutationsList) { + if (mutation.type === 'childList') { + if (mutation.addedNodes.length > 0) { + for (const node of mutation.addedNodes) { + if (node.nodeName.toLowerCase() === 'canvas') { + node.focus(); + if (window.focusHandler) { + window.focusHandler.disconnect() + delete window.focusHandler + } + return + } + } + } + } + } + } + + window.focusHandler = new MutationObserver(onElementAdded) + window.focusHandler.observe(document.body, config) + } +}) diff --git a/game_core/index.html b/game_core/index.html index 7e303d29c7e2aa014fd4a3bf873b2e09b1414a74..ea8e997b61896868564fe7747edd45ef9352b0d6 100644 --- a/game_core/index.html +++ b/game_core/index.html @@ -103,5 +103,7 @@ </main> <link data-trunk rel="inline" href="../build/web/audio.js"/> +<link data-trunk rel="inline" href="../build/web/autofocus.js"/> + </body> </html> \ No newline at end of file diff --git a/game_core/src/assets/resources.rs b/game_core/src/assets/resources.rs index d7e078c9fbeaa46ce01e7ca6fca583bf9ff98c23..fb22eab99655c264f6ad156543292a180ab0256a 100644 --- a/game_core/src/assets/resources.rs +++ b/game_core/src/assets/resources.rs @@ -33,9 +33,9 @@ impl SpriteSheetConfig { #[derive(Default)] pub struct AssetHandles { - pub(crate) images: HashMap<String, Handle<Image>>, - pub(crate) atlas: HashMap<String, Handle<TextureAtlas>>, - pub(crate) sounds: HashMap<String, Handle<AudioSource>>, + pub images: HashMap<String, Handle<Image>>, + pub atlas: HashMap<String, Handle<TextureAtlas>>, + pub sounds: HashMap<String, Handle<AudioSource>>, } impl SuppliesAudio for AssetHandles {