From 694cd906451475a96b6ce8fe4522f7f38851625b Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 25 Jun 2024 12:29:09 -0500 Subject: [PATCH] feat: sound --- app/ecs-components/sound.js | 29 +++++++++++++++++++++++++++++ app/engine.js | 1 + app/react-components/ui.jsx | 5 +++++ public/assets/hoe/dig.wav | Bin 0 -> 11877 bytes public/assets/hoe/start.js | 3 ++- 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 app/ecs-components/sound.js create mode 100644 public/assets/hoe/dig.wav diff --git a/app/ecs-components/sound.js b/app/ecs-components/sound.js new file mode 100644 index 0000000..ed7b792 --- /dev/null +++ b/app/ecs-components/sound.js @@ -0,0 +1,29 @@ +import Schema from '@/ecs/schema.js'; + +export default function(Component) { + return class Sound extends Component { + mergeDiff(original, update) { + const merged = {}; + if (update.play) { + merged.play = [ + ...(original.play ?? []), + ...update.play, + ]; + } + return merged; + } + instanceFromSchema() { + const Component = this; + const Instance = super.instanceFromSchema(); + return class SoundInstance extends Instance { + play(source) { + Component.markChange(this.entity, 'play', [source]); + } + }; + } + static schema = new Schema({ + type: 'object', + properties: {}, + }); + } +} diff --git a/app/engine.js b/app/engine.js index 826fdb6..3671cf1 100644 --- a/app/engine.js +++ b/app/engine.js @@ -188,6 +188,7 @@ export default class Engine { Position: {x: 368, y: 368}, VisibleAabb: {}, Speed: {speed: 100}, + Sound: {}, Sprite: { anchor: {x: 0.5, y: 0.8}, animation: 'moving:down', diff --git a/app/react-components/ui.jsx b/app/react-components/ui.jsx index ef2404a..b72e838 100644 --- a/app/react-components/ui.jsx +++ b/app/react-components/ui.jsx @@ -159,6 +159,11 @@ export default function Ui({disconnected}) { for (const id in payload.ecs) { const entity = ecs.get(id); const update = payload.ecs[id]; + if (update.Sound?.play) { + for (const sound of update.Sound.play) { + (new Audio(sound)).play(); + } + } if (update?.MainEntity) { setMainEntity(localMainEntity = id); } diff --git a/public/assets/hoe/dig.wav b/public/assets/hoe/dig.wav new file mode 100644 index 0000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