Merge pull request 'Audio flag to prevent crashing when audio is disabled' (#22) from Onek8/LNXSDK:main into main

Reviewed-on: #22
This commit is contained in:
LeenkxTeam 2025-04-03 12:38:38 +00:00
commit 9478e4e957
6 changed files with 27 additions and 12 deletions

View File

@ -1,7 +1,7 @@
package leenkx.logicnode;
#if lnx_audio
import iron.object.SpeakerObject;
#end
class PauseSoundNode extends LogicNode {
public function new(tree: LogicTree) {
@ -9,9 +9,11 @@ class PauseSoundNode extends LogicNode {
}
override function run(from: Int) {
#if lnx_audio
var object: SpeakerObject = cast(inputs[1].get(), SpeakerObject);
if (object == null) return;
object.pause();
#end
runOutput(0);
}
}

View File

@ -1,7 +1,7 @@
package leenkx.logicnode;
#if lnx_audio
import iron.object.SpeakerObject;
#end
class PlaySoundNode extends LogicNode {
public function new(tree: LogicTree) {
@ -9,9 +9,11 @@ class PlaySoundNode extends LogicNode {
}
override function run(from: Int) {
#if lnx_audio
var object: SpeakerObject = cast(inputs[1].get(), SpeakerObject);
if (object == null) return;
object.play();
#end
runOutput(0);
}
}

View File

@ -16,15 +16,16 @@ class PlaySoundRawNode extends LogicNode {
public var property5: Bool;
public var property6: String;
#if lnx_audio
var sound: kha.Sound = null;
var channel: kha.audio1.AudioChannel = null;
#end
public function new(tree: LogicTree) {
super(tree);
}
override function run(from: Int) {
#if lnx_audio
switch (from) {
case Play:
if (property6 == 'Sound' ? sound == null : true) {
@ -63,6 +64,10 @@ class PlaySoundRawNode extends LogicNode {
case UpdateVolume:
if (channel != null) channel.volume = inputs[4].get();
}
#end
#if !lnx_audio
runOutput(0);
#end
}
function onUpdate() {

View File

@ -1,7 +1,7 @@
package leenkx.logicnode;
#if lnx_audio
import iron.object.SpeakerObject;
#end
class SetSoundNode extends LogicNode {
public function new(tree: LogicTree) {
@ -9,10 +9,12 @@ class SetSoundNode extends LogicNode {
}
override function run(from: Int) {
#if lnx_audio
var object: SpeakerObject = cast(inputs[1].get(), SpeakerObject);
var sound: String = inputs[2].get();
if (object == null || sound == null) return;
object.setSound(sound);
#end
runOutput(0);
}
}

View File

@ -1,7 +1,7 @@
package leenkx.logicnode;
#if lnx_audio
import iron.object.SpeakerObject;
#end
class SetVolumeSoundNode extends LogicNode {
public function new(tree: LogicTree) {
@ -9,9 +9,11 @@ class SetVolumeSoundNode extends LogicNode {
}
override function run(from: Int) {
#if lnx_audio
var object: SpeakerObject = cast(inputs[1].get(), SpeakerObject);
if (object == null) return;
object.setVolume(inputs[2].get());
#end
runOutput(0);
}
}

View File

@ -1,7 +1,7 @@
package leenkx.logicnode;
#if lnx_audio
import iron.object.SpeakerObject;
#end
class StopSoundNode extends LogicNode {
public function new(tree: LogicTree) {
@ -9,9 +9,11 @@ class StopSoundNode extends LogicNode {
}
override function run(from: Int) {
#if lnx_audio
var object: SpeakerObject = cast(inputs[1].get(), SpeakerObject);
if (object == null) return;
object.stop();
#end
runOutput(0);
}
}