Skip to content

Commit

Permalink
Removed Resource Property for Sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiWorm0 committed Aug 23, 2022
1 parent cfc1a25 commit 470e697
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 53 deletions.
21 changes: 14 additions & 7 deletions LevelImposter/Core/Builders/AmbientSoundBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,31 @@ public void Build(LIElement elem, GameObject obj)
}

// AudioClip
if (elem.properties.soundID == null)
if (elem.properties.sounds == null)
{
LILogger.Warn("Ambient sound missing audio data");
LILogger.Warn("Ambient sound missing audio listing");
return;
}
string resource = MapUtils.GetResource(elem.properties.soundID);
if (resource == null)

if (elem.properties.sounds.Length <= 0)
{
LILogger.Warn("Ambient sound missing audio elements");
return;
}

LISound soundData = elem.properties.sounds[0];
if (soundData.data == null)
{
LILogger.Warn("Ambient sound missing resource data [" + elem.properties.soundID + "]");
LILogger.Warn("Ambient sound missing audio data [" + soundData.id + "]");
return;
}
AudioClip clip = MapUtils.ConvertToAudio(elem.name, resource);
AudioClip clip = MapUtils.ConvertToAudio(elem.name, soundData.data);

// Sound Player
AmbientSoundPlayer ambientPlayer = obj.AddComponent<AmbientSoundPlayer>();
ambientPlayer.HitAreas = colliders;
ambientPlayer.AmbientSound = clip;
ambientPlayer.MaxVolume = elem.properties.soundVolume == null ? 1 : (float)elem.properties.soundVolume;
ambientPlayer.MaxVolume = soundData.volume;
}

public void PostBuild() {}
Expand Down
50 changes: 24 additions & 26 deletions LevelImposter/Core/Builders/StepSoundBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,40 @@ public void Build(LIElement elem, GameObject obj)
return;

// AudioClip
if (elem.properties.soundIDs == null)
if (elem.properties.sounds == null)
{
LILogger.Warn("Step sound missing audio data");
LILogger.Warn("Step sound missing audio listing");
return;
}

SoundGroup soundGroup = ScriptableObject.CreateInstance<SoundGroup>();
soundGroup.Clips = new AudioClip[elem.properties.soundIDs.Length];
for (int i = 0; i < elem.properties.soundIDs.Length; i++)
soundGroup.Clips = new AudioClip[elem.properties.sounds.Length];
for (int i = 0; i < elem.properties.sounds.Length; i++)
{
string resourceID = elem.properties.soundIDs[i];
AudioClip clip = GetResource(elem.name, resourceID);
LISound sound = elem.properties.sounds[i];

if (sound.data == null)
{
LILogger.Warn("Step sound missing audio data [" + sound.id + "]");
continue;
}

AudioClip clip;
if (sound.isPreset)
{
SoundData soundData;
AssetDB.sounds.TryGetValue(sound.data, out soundData);
clip = soundData.Clip;
}
else
{
clip = MapUtils.ConvertToAudio(elem.name, sound.data);
}

if (clip != null)
soundGroup.Clips[i] = clip;
else
LILogger.Warn("Step sound missing resource data [" + resourceID + "]");
LILogger.Warn("Step sound has corrupt audio data [" + sound.id + "]");
}

// Colliders
Expand All @@ -55,24 +72,5 @@ public void Build(LIElement elem, GameObject obj)
}

public void PostBuild() {}

private AudioClip GetResource(string name, string resourceID)
{
string resource = MapUtils.GetResource(resourceID);
if (resource != null)
{
AudioClip clip = MapUtils.ConvertToAudio(name, resource);
return clip;
}

SoundData sound;
AssetDB.sounds.TryGetValue(resourceID, out sound);
if (sound != null)
{
return sound.Clip;
}

return null;
}
}
}
1 change: 0 additions & 1 deletion LevelImposter/Core/Models/LIMapProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ namespace LevelImposter.Core
public class LIMapProperties
{
public string? bgColor { get; set; }
public Dictionary<string, string> resources { get; set; } = new();
}
}
4 changes: 1 addition & 3 deletions LevelImposter/Core/Models/LIProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ public class LIProperties
public bool? noShadowsBehaviour { get; set; }

// Sound
public string? soundID { get; set; }
public string[]? soundIDs { get; set; }
public float? soundVolume { get; set; }
public LISound[]? sounds { get; set; }
public int? soundPriority { get; set; }

// Vent
Expand Down
16 changes: 16 additions & 0 deletions LevelImposter/Core/Models/LISound.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

namespace LevelImposter.Core
{
[Serializable]
public class LISound
{
public Guid id { get; set; }
public string? data { get; set; }
public float volume { get; set; }
public bool isPreset { get; set; }
}
}
16 changes: 0 additions & 16 deletions LevelImposter/Core/Utils/MapUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,22 +115,6 @@ public static void Rename(TaskTypes system, string name)
taskRenames[system] = name;
}

/// <summary>
/// Grabs a map resource from id
/// </summary>
/// <param name="resourceID">ID of the resource</param>
/// <returns>Resource of ID</returns>
public static string GetResource(string resourceID)
{
var resources = LIShipStatus.Instance.currentMap.properties.resources;
if (resources == null)
return null;

string resource;
resources.TryGetValue(resourceID, out resource);
return resource;
}

/// <summary>
/// Converts a base64 encoded string into a byte array
/// </summary>
Expand Down

0 comments on commit 470e697

Please sign in to comment.