-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da54090
commit ea694c7
Showing
15 changed files
with
233 additions
and
22 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import ./components/[ | ||
component, | ||
model_component, | ||
music_component, | ||
sound_component, | ||
sprite_component, | ||
text_component, | ||
transform_component, | ||
] | ||
|
||
export component | ||
export model_component | ||
export music_component | ||
export sound_component | ||
export sprite_component | ||
export text_component | ||
export transform_component |
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,18 @@ | ||
import ../../lib/audio | ||
|
||
import ./component_macros | ||
|
||
component MusicComponent: | ||
fields: | ||
music: Music | ||
|
||
create(musicPath: string): | ||
result.music = newMusic(musicPath) | ||
|
||
init: | ||
discard | ||
|
||
destroy: | ||
self.music.destroy() | ||
|
||
func music*(self: MusicComponent): auto = self.music |
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,18 @@ | ||
import ../../lib/audio | ||
|
||
import ./component_macros | ||
|
||
component SoundComponent: | ||
fields: | ||
sound: Sound | ||
|
||
create(soundPath: string): | ||
result.sound = newSound(soundPath) | ||
|
||
init: | ||
discard | ||
|
||
destroy: | ||
self.sound.destroy() | ||
|
||
func sound*(self: SoundComponent): auto = self.sound |
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
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,9 @@ | ||
import audio/[ | ||
music, | ||
sound, | ||
sound_device, | ||
] | ||
|
||
export music | ||
export sound | ||
export sound_device |
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,54 @@ | ||
import options | ||
|
||
from ../private/raylib import nil | ||
|
||
|
||
template injectRaylibMusic(self: typed; music: untyped) = | ||
if self.music.isNone: | ||
return | ||
let music: raylib.Music = self.music.unsafeGet() | ||
|
||
type | ||
Music* = ref object of RootObj | ||
music: Option[raylib.Music] | ||
|
||
func unload(self: Music) = | ||
if self.music.isSome: | ||
raylib.UnloadMusicStream(self.music.unsafeGet()) | ||
self.music = none[raylib.Music]() | ||
|
||
func destroy*(self: Music) = | ||
self.unload() | ||
|
||
func newMusic*(musicPath: string): Music = | ||
result = Music( | ||
music: some(raylib.LoadMusicStream(musicPath)) | ||
) | ||
|
||
func isPlaying*(self: Music): bool = | ||
self.injectRaylibMusic(music) | ||
result = raylib.IsMusicPlaying(music) | ||
|
||
func pause*(self: Music) = | ||
self.injectRaylibMusic(music) | ||
raylib.PauseMusicStream(music) | ||
|
||
func play*(self: Music) = | ||
self.injectRaylibMusic(music) | ||
raylib.PlayMusicStream(music) | ||
|
||
func resume*(self: Music) = | ||
self.injectRaylibMusic(music) | ||
raylib.ResumeMusicStream(music) | ||
|
||
func stop*(self: Music) = | ||
self.injectRaylibMusic(music) | ||
raylib.StopMusicStream(music) | ||
|
||
func `volume=`(self: Music; volume: float32) = | ||
self.injectRaylibMusic(music) | ||
raylib.SetMusicVolume(music, volume) | ||
|
||
func `pitch=`(self: Music; pitch: float32) = | ||
self.injectRaylibMusic(music) | ||
raylib.SetMusicPitch(music, pitch) |
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,54 @@ | ||
import options | ||
|
||
from ../private/raylib import nil | ||
|
||
|
||
template injectRaylibSound(self: typed; sound: untyped) = | ||
if self.sound.isNone: | ||
return | ||
let sound: raylib.Sound = self.sound.unsafeGet() | ||
|
||
type | ||
Sound* = ref object of RootObj | ||
sound: Option[raylib.Sound] | ||
|
||
func unload(self: Sound) = | ||
if self.sound.isSome: | ||
raylib.UnloadSound(self.sound.unsafeGet()) | ||
self.sound = none[raylib.Sound]() | ||
|
||
func destroy*(self: Sound) = | ||
self.unload() | ||
|
||
func newSound*(soundPath: string): Sound = | ||
result = Sound( | ||
sound: some(raylib.LoadSound(soundPath)) | ||
) | ||
|
||
func isPlaying*(self: Sound): bool = | ||
self.injectRaylibSound(sound) | ||
result = raylib.IsSoundPlaying(sound) | ||
|
||
func pause*(self: Sound) = | ||
self.injectRaylibSound(sound) | ||
raylib.PauseSound(sound) | ||
|
||
func play*(self: Sound) = | ||
self.injectRaylibSound(sound) | ||
raylib.PlaySound(sound) | ||
|
||
func resume*(self: Sound) = | ||
self.injectRaylibSound(sound) | ||
raylib.ResumeSound(sound) | ||
|
||
func stop*(self: Sound) = | ||
self.injectRaylibSound(sound) | ||
raylib.StopSound(sound) | ||
|
||
func `volume=`(self: Sound; volume: float32) = | ||
self.injectRaylibSound(sound) | ||
raylib.SetSoundVolume(sound, volume) | ||
|
||
func `pitch=`(self: Sound; pitch: float32) = | ||
self.injectRaylibSound(sound) | ||
raylib.SetSoundPitch(sound, pitch) |
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,9 @@ | ||
from ../private/raylib import nil | ||
|
||
func initialize*() = raylib.InitAudioDevice() | ||
|
||
func isReady*(): bool = raylib.IsAudioDeviceReady() | ||
|
||
func close*() = raylib.CloseAudioDevice() | ||
|
||
func setMasterVolume*(volume: float32) = raylib.SetMasterVolume(volume) |
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