# Lua Radio Player Dev
Lua-first audio player prototype for Barotrauma multiplayer.
## What this mod does
- Adds item `luaradio_player`.
- Uses pure Lua GUI for track select/play/stop/mode/volume.
- Uses server-authoritative network state sync.
- Plays audio with `SoundManager.LoadSound` + `Sound.Play`.
## Quick test
1. Put `.ogg` files in `LocalMods/LuaRadioPlayerDev/Audio/`.
2. Enable this mod in game.
3. Spawn item: `spawnitem luaradio_player`.
4. Hold/select the item to open Lua UI.
5. Choose track and press `Play`.
## Logs
- Runtime logs are written to `LocalMods/LuaRadioPlayerDev/Logs/luaradio.log`.
- The same log lines are also printed to the game console.
- High-frequency runtime logs are now debug-only by default.
- You can enable debug logs from Lua with:
- `LuaRadioPlayer.SetDebugLogging(true)`
- Disable again: `LuaRadioPlayer.SetDebugLogging(false)`
## Multiplayer model
- Client sends control action to server.
- Server validates item access and broadcasts playback state.
- Clients resolve local track path and play at the same logical start time.
## External pack API (for other mods)
Call this from another mod script after Lua auto-load:
```lua
if LuaRadioPlayer ~= nil then
LuaRadioPlayer.RegisterPack("my_pack", {
title = "My Pack",
rootPath = table.pack(...)[1],
tracks = {
{ id = "track01", title = "Track 01", file = "Audio/track01.ogg", volume = 1.0, range = 1200 },
{ id = "track02", title = "Track 02", file = "Audio/track02.ogg", volume = 0.8, range = 1000 }
}
})
end
```
You can also omit `tracks` and let it auto-scan:
```lua
LuaRadioPlayer.RegisterPack("my_pack", {
rootPath = table.pack(...)[1],
audioDir = "Audio"
})
```
## Auto-pack template
- A ready example mod is provided at:
- `LuaRadioAutoPackTemplate`
- It auto-scans its own `Audio/auto` folder and registers tracks into LuaRadioPlayer.
# Lua Radio Player Dev
面向 Barotrauma 联机场景的 Lua 唱片机原型模组。
## 模组功能
- 新增物品:`luaradio_player`
- 使用纯 Lua 绘制 UI(选曲、播放、停止、模式、音量)
- 使用服务器权威状态同步(客户端发请求,服务器校验并广播)
- 通过 `LoadSound + Play` 进行音频播放
## 快速开始
1. 将音频文件放入 `LocalMods/LuaRadioPlayerDev/Audio/`
2. 在游戏中启用本模组
3. 控制台刷出物品:`spawnitem luaradio_player`
4. 手持该物品并按约定操作打开 UI
5. 选中曲目后点击 `Play`
## 日志说明
- 日志文件:`LocalMods/LuaRadioPlayerDev/Logs/luaradio.log`
- 同时会输出到游戏控制台
- 高频日志默认关闭(仅保留关键日志)
- 可在 Lua 中开启/关闭调试日志:
- 开启:`LuaRadioPlayer.SetDebugLogging(true)`
- 关闭:`LuaRadioPlayer.SetDebugLogging(false)`
## 联机同步模型
- 客户端发送控制请求(播放/停止/音量/模式)
- 服务器校验玩家是否有权限控制该物品
- 服务器广播状态(是否播放、曲目、音量、模式、时间戳)
- 客户端按同一逻辑起始时间进行本地播放
## 供其他模组接入的 API
在其他模组脚本中(Lua 自动加载后)调用:
```lua
if LuaRadioPlayer ~= nil then
LuaRadioPlayer.RegisterPack("my_pack", {
title = "我的曲包",
rootPath = table.pack(...)[1],
tracks = {
{ id = "track01", title = "Track 01", file = "Audio/track01.ogg", volume = 1.0, range = 1200 },
{ id = "track02", title = "Track 02", file = "Audio/track02.ogg", volume = 0.8, range = 1000 }
}
})
end
```
也可以不手写 `tracks`,让系统自动扫描目录:
```lua
LuaRadioPlayer.RegisterPack("my_pack", {
rootPath = table.pack(...)[1],
audioDir = "Audio"
})
```
## 自动曲包样板
- 已提供样板模组:`LuaRadioAutoPackTemplate`
- 样板会自动扫描自己的 `Audio/auto` 并注册到 LuaRadioPlayer 列表