Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88ae3012f7 | ||
| 2a1767ef74 |
3
.idea/copyright/profiles_settings.xml
generated
Normal file
3
.idea/copyright/profiles_settings.xml
generated
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<component name="CopyrightManager">
|
||||||
|
<settings default="OAPL notice" />
|
||||||
|
</component>
|
||||||
@@ -1,9 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* This code, and therefore this entire project, is licensed under
|
||||||
|
* the Open Autonomous Public License (OAPL) v1.0, or one that
|
||||||
|
* derives from that license.
|
||||||
|
* For more details, please refer to the LICENSE file.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Maple.
|
||||||
|
*/
|
||||||
|
|
||||||
package org.openautonomousconnection.luascript.hosts;
|
package org.openautonomousconnection.luascript.hosts;
|
||||||
|
|
||||||
|
import org.openautonomousconnection.luascript.type.AudioValue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract audio service host
|
||||||
|
*/
|
||||||
public interface AudioHost {
|
public interface AudioHost {
|
||||||
|
|
||||||
void play(File audioFile);
|
/**
|
||||||
|
* Load an audio file as a LuaValue (AudioValue type)
|
||||||
|
* @param audioFile audio media file
|
||||||
|
* @return reference object to media
|
||||||
|
*/
|
||||||
|
AudioValue load(File audioFile);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,12 @@ public class AudioTable extends ScriptTable {
|
|||||||
protected void define(HostServices services) {
|
protected void define(HostServices services) {
|
||||||
AudioHost audioHost = services.audio().orElseThrow(() -> new IllegalStateException("AudioHost not provided"));
|
AudioHost audioHost = services.audio().orElseThrow(() -> new IllegalStateException("AudioHost not provided"));
|
||||||
|
|
||||||
table().set("play", new OneArgFunction() {
|
table().set("load", new OneArgFunction() {
|
||||||
@Override
|
@Override
|
||||||
public LuaValue call(LuaValue arg) {
|
public LuaValue call(LuaValue arg) {
|
||||||
String fileName = arg.checkjstring();
|
String fileName = arg.checkjstring();
|
||||||
audioHost.play(new File(fileName));
|
|
||||||
return LuaValue.NIL;
|
return audioHost.load(new File(fileName));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* This code, and therefore this entire project, is licensed under
|
||||||
|
* the Open Autonomous Public License (OAPL) v1.0, or one that
|
||||||
|
* derives from that license.
|
||||||
|
* For more details, please refer to the LICENSE file.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 Maple.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.openautonomousconnection.luascript.type;
|
||||||
|
|
||||||
|
import javafx.scene.media.MediaPlayer;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import org.luaj.vm2.LuaFunction;
|
||||||
|
import org.luaj.vm2.LuaNumber;
|
||||||
|
import org.luaj.vm2.LuaTable;
|
||||||
|
import org.luaj.vm2.LuaValue;
|
||||||
|
import org.openautonomousconnection.luascript.tables.AudioTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Different from {@link AudioTable} in that this is an instance gathered from {@code AudioTable::load}
|
||||||
|
*/
|
||||||
|
public class AudioValue extends LuaTable {
|
||||||
|
@Getter @Setter
|
||||||
|
private MediaPlayer mediaPlayer;
|
||||||
|
|
||||||
|
public AudioValue(MediaPlayer mediaPlayer) {
|
||||||
|
this.mediaPlayer = mediaPlayer;
|
||||||
|
|
||||||
|
this.set("play", new LuaFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call() {
|
||||||
|
mediaPlayer.play();
|
||||||
|
|
||||||
|
return LuaValue.NIL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.set("stop", new LuaFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call() {
|
||||||
|
mediaPlayer.stop();
|
||||||
|
|
||||||
|
return LuaValue.NIL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.set("pause", new LuaFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call() {
|
||||||
|
mediaPlayer.pause();
|
||||||
|
|
||||||
|
return LuaValue.NIL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.set("setVolume", new LuaFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call(LuaValue volume) {
|
||||||
|
double v = volume.checkdouble();
|
||||||
|
|
||||||
|
mediaPlayer.setVolume(Math.clamp(v, 0, 1));
|
||||||
|
|
||||||
|
return LuaValue.NIL;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.set("getVolume", new LuaFunction() {
|
||||||
|
@Override
|
||||||
|
public LuaValue call() {
|
||||||
|
return LuaNumber.valueOf(mediaPlayer.getVolume());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user