Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions Assets/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using ArtNet;
using Klak.Spout;
using SFB;
Expand Down Expand Up @@ -33,8 +34,11 @@ public class Loader : MonoBehaviour
ISerializer ymlserializer;
public UIController uiController;

private const string CONFIG_FILE_REGEX = "-{1,2}[Cc]onfig-[Ff]ile=";

void Start()
{

//TODO: Make this configurable. This is here because even though its not resizable, unity can get in a fucked state and remember the wrong resolution
Screen.SetResolution(1200, 600, false);
spoutReceiver = FindObjectOfType<SpoutReceiver>();
Expand Down Expand Up @@ -78,6 +82,8 @@ void Start()
ymldeserializer = SetupBuilder<DeserializerBuilder>().Build();

SetupDynamicUI();

ReadCLIConfigFile();
}

void Update()
Expand Down Expand Up @@ -178,12 +184,23 @@ public void LoadShowConfiguration()
return;
}

//read from the first path
var content = System.IO.File.ReadAllText(paths[0]);
LoadShowConfigurationFile(paths[0]);
}

public void LoadShowConfigurationFile(string path)
{
if (!System.IO.File.Exists(path))
{
Debug.LogError("File not found");
return;
}

//read from the path
var content = System.IO.File.ReadAllText(path);

if (string.IsNullOrEmpty(content))
{
Debug.LogError("File is empty or not found.");
Debug.LogError("File is empty.");
return;
}

Expand All @@ -199,6 +216,19 @@ public void LoadShowConfiguration()
StartCoroutine(DeferredLoad(content));
}

public void ReadCLIConfigFile()
{
Regex cliConfigFileRegex = new Regex(CONFIG_FILE_REGEX);
string configFilePath = Environment.GetCommandLineArgs()
.FirstOrDefault((argument) => cliConfigFileRegex.IsMatch(argument));

if (configFilePath != null)
{
Debug.Log($"Config file path is: {cliConfigFileRegex.Replace(configFilePath, "")}");
LoadShowConfigurationFile(cliConfigFileRegex.Replace(configFilePath, ""));
}
}

public static void UnloadShowConf()
{
//deconstruct all generators before we lose references to them
Expand All @@ -218,15 +248,15 @@ public static void UnloadShowConf()
showconf.Deserializer.Deconstruct();
}

IEnumerator DeferredLoad(string content)
IEnumerator DeferredLoad(string content, Action preCallback = null)
{
//returning 0 will make it wait 1 frame
yield return new WaitForEndOfFrame();

//yayyyyy double load to fix dumb race condition bullshit
showconf = ymldeserializer.Deserialize<ShowConfiguration>(content);

LoadShowConf();
LoadShowConf(preCallback);
}

public static void ReloadShowConf()
Expand All @@ -235,8 +265,11 @@ public static void ReloadShowConf()
LoadShowConf();
}

public static void LoadShowConf()
public static void LoadShowConf(Action preCallback = null)
{
if (preCallback != null)
preCallback();

//run initialization on all generators
foreach (var generator in showconf.Generators)
{
Expand Down Expand Up @@ -340,7 +373,7 @@ Action<int> Delete<T>(List<T> list) where T : class, IConstructable, IUserInterf
private static void SetFramerate(int targetFramerate)
{
//check bounds
if (targetFramerate < 1 || targetFramerate > 60)
if (targetFramerate < 1 || targetFramerate > 144)
{
Debug.LogWarning($"Target framerate {targetFramerate} is out of bounds. Setting to default 60.");
targetFramerate = 60;
Expand Down