|
|
@@ -3,58 +3,38 @@ using System; |
|
|
|
using FMOD.Studio; |
|
|
|
using FMODUnity; |
|
|
|
using Gamecraft.Wires; |
|
|
|
using RobocraftX.Common; |
|
|
|
using RobocraftX.Blocks; |
|
|
|
using Svelto.ECS; |
|
|
|
using Unity.Mathematics; |
|
|
|
|
|
|
|
using GamecraftModdingAPI; |
|
|
|
using GamecraftModdingAPI.Tests; |
|
|
|
using GamecraftModdingAPI.Utility; |
|
|
|
|
|
|
|
namespace GamecraftModdingAPI.Blocks |
|
|
|
{ |
|
|
|
public class MusicBlock : Block |
|
|
|
{ |
|
|
|
public static MusicBlock PlaceNew(float3 position, |
|
|
|
float3 rotation = default, BlockColors color = BlockColors.Default, byte darkness = 0, |
|
|
|
int uscale = 1, float3 scale = default, Player player = null) |
|
|
|
{ |
|
|
|
if (PlacementEngine.IsInGame && GameState.IsBuildMode()) |
|
|
|
{ |
|
|
|
EGID id = PlacementEngine.PlaceBlock(BlockIDs.MusicBlock, color, darkness, |
|
|
|
position, uscale, scale, player, rotation); |
|
|
|
return new MusicBlock(id); |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
public MusicBlock(EGID id) : base(id) |
|
|
|
{ |
|
|
|
if (!BlockEngine.GetBlockInfoExists<MusicBlockDataEntityStruct>(this.Id)) |
|
|
|
{ |
|
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public MusicBlock(uint id) : base(id) |
|
|
|
public MusicBlock(uint id) : base(new EGID(id, CommonExclusiveGroups.BUILD_MUSIC_BLOCK_GROUP)) |
|
|
|
{ |
|
|
|
if (!BlockEngine.GetBlockInfoExists<MusicBlockDataEntityStruct>(this.Id)) |
|
|
|
{ |
|
|
|
throw new BlockTypeException($"Block is not a {this.GetType().Name} block"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public byte TrackIndex |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id).trackIndx; |
|
|
|
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct st) => st.trackIndx); |
|
|
|
} |
|
|
|
|
|
|
|
set |
|
|
|
{ |
|
|
|
ref MusicBlockDataEntityStruct msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id); |
|
|
|
msdes.trackIndx = value; |
|
|
|
BlockEngine.SetBlockInfo(this, |
|
|
|
(ref MusicBlockDataEntityStruct msdes, byte val) => msdes.trackIndx = val, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -62,22 +42,24 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
ref MusicBlockDataEntityStruct msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id); |
|
|
|
return msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx); |
|
|
|
return BlockEngine.GetBlockInfo(this, |
|
|
|
(MusicBlockDataEntityStruct msdes) => msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx)); |
|
|
|
} |
|
|
|
|
|
|
|
set |
|
|
|
{ |
|
|
|
ref MusicBlockDataEntityStruct msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id); |
|
|
|
for (byte i = 0; i < msdes.fmod2DEventPaths.Count<Guid>(); i++) |
|
|
|
BlockEngine.SetBlockInfo(this, (ref MusicBlockDataEntityStruct msdes, Guid val) => |
|
|
|
{ |
|
|
|
Guid track = msdes.fmod2DEventPaths.Get<Guid>(i); |
|
|
|
if (track == value) |
|
|
|
for (byte i = 0; i < msdes.fmod2DEventPaths.Count<Guid>(); i++) |
|
|
|
{ |
|
|
|
msdes.trackIndx = i; |
|
|
|
break; |
|
|
|
Guid track = msdes.fmod2DEventPaths.Get<Guid>(i); |
|
|
|
if (track == val) |
|
|
|
{ |
|
|
|
msdes.trackIndx = i; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -85,13 +67,15 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
ref MusicBlockDataEntityStruct msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id); |
|
|
|
Guid[] tracks = new Guid[msdes.fmod2DEventPaths.Count<Guid>()]; |
|
|
|
for (byte i = 0; i < tracks.Length; i++) |
|
|
|
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) => |
|
|
|
{ |
|
|
|
tracks[i] = msdes.fmod2DEventPaths.Get<Guid>(i); |
|
|
|
} |
|
|
|
return tracks; |
|
|
|
Guid[] tracks = new Guid[msdes.fmod2DEventPaths.Count<Guid>()]; |
|
|
|
for (byte i = 0; i < tracks.Length; i++) |
|
|
|
{ |
|
|
|
tracks[i] = msdes.fmod2DEventPaths.Get<Guid>(i); |
|
|
|
} |
|
|
|
return tracks; |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -99,13 +83,13 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id).tweakableVolume; |
|
|
|
return BlockEngine.GetBlockInfo(this, (MusicBlockDataEntityStruct msdes) => msdes.tweakableVolume); |
|
|
|
} |
|
|
|
|
|
|
|
set |
|
|
|
{ |
|
|
|
ref MusicBlockDataEntityStruct msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id); |
|
|
|
msdes.tweakableVolume = value; |
|
|
|
BlockEngine.SetBlockInfo(this, |
|
|
|
(ref MusicBlockDataEntityStruct msdes, float val) => msdes.tweakableVolume = val, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -113,13 +97,15 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return (ChannelType)BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id).channelType; |
|
|
|
Assert.Log("Block exists: " + Exists); |
|
|
|
return BlockEngine.GetBlockInfo(this, |
|
|
|
(MusicBlockDataEntityStruct msdes) => (ChannelType) msdes.channelType); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
set |
|
|
|
{ |
|
|
|
ref MusicBlockDataEntityStruct msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id); |
|
|
|
msdes.channelType = (byte)value; |
|
|
|
BlockEngine.SetBlockInfo(this, |
|
|
|
(ref MusicBlockDataEntityStruct msdes, ChannelType val) => msdes.channelType = (byte) val, value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -127,30 +113,33 @@ namespace GamecraftModdingAPI.Blocks |
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
return BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id).isPlaying; |
|
|
|
return BlockEngine.GetBlockInfo(this, |
|
|
|
(MusicBlockDataEntityStruct msdes) => msdes.isPlaying); |
|
|
|
} |
|
|
|
|
|
|
|
set |
|
|
|
{ |
|
|
|
ref MusicBlockDataEntityStruct msdes = ref BlockEngine.GetBlockInfo<MusicBlockDataEntityStruct>(Id); |
|
|
|
if (msdes.isPlaying == value) return; |
|
|
|
if (value) |
|
|
|
{ |
|
|
|
// start playing |
|
|
|
EventInstance inst = RuntimeManager.CreateInstance(msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx)); |
|
|
|
inst.setVolume(msdes.tweakableVolume / 100f); |
|
|
|
inst.start(); |
|
|
|
msdes.eventHandle = inst.handle; |
|
|
|
} |
|
|
|
else |
|
|
|
BlockEngine.SetBlockInfo(this, (ref MusicBlockDataEntityStruct msdes, bool val) => |
|
|
|
{ |
|
|
|
// stop playing |
|
|
|
EventInstance inst = default(EventInstance); |
|
|
|
inst.handle = msdes.eventHandle; |
|
|
|
inst.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); |
|
|
|
inst.release(); |
|
|
|
} |
|
|
|
msdes.isPlaying = value; |
|
|
|
if (msdes.isPlaying == val) return; |
|
|
|
if (val) |
|
|
|
{ |
|
|
|
// start playing |
|
|
|
EventInstance inst = RuntimeManager.CreateInstance(msdes.fmod2DEventPaths.Get<Guid>(msdes.trackIndx)); |
|
|
|
inst.setVolume(msdes.tweakableVolume / 100f); |
|
|
|
inst.start(); |
|
|
|
msdes.eventHandle = inst.handle; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// stop playing |
|
|
|
EventInstance inst = default(EventInstance); |
|
|
|
inst.handle = msdes.eventHandle; |
|
|
|
inst.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); |
|
|
|
inst.release(); |
|
|
|
} |
|
|
|
msdes.isPlaying = val; |
|
|
|
}, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |