-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add AudioEvent component * add 'getAudioState' helper for AudioStream component * fix comments
- Loading branch information
1 parent
0048266
commit f417f2c
Showing
12 changed files
with
169 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Entity, IEngine } from '../../engine' | ||
import { LastWriteWinElementSetComponentDefinition } from '../../engine/component' | ||
import { AudioStream, PBAudioEvent, AudioEvent as defineAudioEventComponent } from '../generated/index.gen' | ||
import { PBAudioStream } from '../generated/pb/decentraland/sdk/components/audio_stream.gen' | ||
|
||
/** | ||
* @public | ||
*/ | ||
export interface AudioStreamComponentDefinitionExtended | ||
extends LastWriteWinElementSetComponentDefinition<PBAudioStream> { | ||
/** | ||
* @public | ||
* | ||
* Set playing=true the sound `$name` | ||
* @param entity - entity with AudioStream component | ||
* @param src - the path to the sound to play | ||
* @param resetCursor - the sound starts at 0 or continues from the current cursor position | ||
* @returns true in successful playing, false if it doesn't find the AudioStream component | ||
*/ | ||
getAudioState(entity: Entity): PBAudioEvent | undefined | ||
} | ||
|
||
export function defineAudioStreamComponent( | ||
engine: Pick<IEngine, 'defineComponentFromSchema' | 'defineValueSetComponentFromSchema'> | ||
): AudioStreamComponentDefinitionExtended { | ||
const theComponent = AudioStream(engine) | ||
const AudioEvent = defineAudioEventComponent(engine) | ||
|
||
return { | ||
...theComponent, | ||
getAudioState(entity: Entity) { | ||
const AudioStream = theComponent.getMutableOrNull(entity) | ||
if (!AudioStream || !AudioEvent.has(entity)) return undefined | ||
|
||
const lastEvent = Array.from(AudioEvent.get(entity)).pop() | ||
return lastEvent | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { components, Engine, MediaState } from '../../../packages/@dcl/ecs/src' | ||
import { testSchemaSerializationIdentity } from './assertion' | ||
|
||
describe('Generated AudioEvent ProtoBuf', () => { | ||
it('should serialize', () => { | ||
const newEngine = Engine() | ||
const AudioEvent = components.AudioEvent(newEngine) | ||
|
||
testSchemaSerializationIdentity(AudioEvent.schema, { | ||
timestamp: 5, | ||
state: MediaState.MS_LOADING | ||
}) | ||
|
||
testSchemaSerializationIdentity(AudioEvent.schema, { | ||
timestamp: 10, | ||
state: MediaState.MS_PLAYING | ||
}) | ||
|
||
testSchemaSerializationIdentity(AudioEvent.schema, { | ||
timestamp: 30, | ||
state: MediaState.MS_PLAYING | ||
}) | ||
|
||
testSchemaSerializationIdentity(AudioEvent.schema, AudioEvent.schema.create()) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters