Skip to content

Commit

Permalink
Removed experiment specfic ParameterLoader and generalized scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Averimon committed Nov 18, 2024
1 parent 784cfa0 commit 2a022b0
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 289 deletions.

This file was deleted.

This file was deleted.

120 changes: 0 additions & 120 deletions unity/Assets/Maroon/reusableScripts/Config/ConfigLoader.cs

This file was deleted.

11 changes: 0 additions & 11 deletions unity/Assets/Maroon/reusableScripts/Config/ConfigLoader.cs.meta

This file was deleted.

13 changes: 1 addition & 12 deletions unity/Assets/Maroon/reusableScripts/Config/JsonFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private IEnumerator LoadAllConfigs()
string basePath = $"{baseDomain}/StreamingAssets/Config/3DMotionSimulation/";
string configListUrl = $"{baseDomain}/configs.php";

List<TextAsset> assets = new List<TextAsset>();
List<string> httpFiles = new List<string>();
UnityWebRequest uwr = UnityWebRequest.Get(configListUrl);

Expand All @@ -76,18 +77,6 @@ private IEnumerator LoadAllConfigs()
}

OnFilesInitialized.Invoke(assets);

/*if(Maroon.GlobalEntities.BootstrappingManager.Instance.UrlParameters.TryGetValue(WebGlUrlParameter.Config, out string config))
{
if (!ChangeConfig(config))
{
ChangeConfig("Default");
}
}
else
{
ChangeConfig("Default");
}*/
}
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,47 @@ private void Start()
#endif
}

public List<string> GetJsonNames()
{
List<string> names = new List<string>();
foreach (TextAsset file in _jsonFile)
{
names.Add(file.name);
}

return names;
}

public int IndexOfJson(string name)
{
string lowerName = name.ToLower().Replace(" ", "");
for (int i = 0; i < _jsonFile.Count; i++)
{
if (_jsonFile[i].name.ToLower() == lowerName)
{
return i;
}
}

Debug.LogError("No file with name " + name + " found.");
return -1;
}

/// <summary>
/// Method for when the JSON files are not set in the inspector but are loaded from an external source.
/// </summary>
/// <param name="jsonFiles">List of JSON files to load</param>
public void InitJSONfiles(List<TextAsset> jsonFiles)
{
if (_jsonFile.Count > 0)
{
Debug.LogWarning("JSON files have already been initialized. Action denied.");
return;
}

_jsonFile = jsonFiles;
}

#region Loading of Parameters
/// <summary>
/// Method for loading intern JSON-File
Expand All @@ -68,6 +109,21 @@ public ExperimentParameters LoadJsonFromFileIndex(int index)
return LoadJsonFromString(data);
}

public ExperimentParameters LoadJsonFromFileName(string name)
{
string lowerName = name.ToLower().Replace(" ", "");
foreach (TextAsset file in _jsonFile)
{
if (file.name.ToLower() == lowerName)
{
return LoadJsonFromString(file.text);
}
}

Debug.LogError("No file with name " + name + " found.");
return null;
}

/// <summary>
/// Method for loading JSON string
/// </summary>
Expand Down Expand Up @@ -95,6 +151,7 @@ private ExperimentParameters ConvertJsonToExperimentParameters(string data)
// if we allow loading of some sort of external JSON file in the future, then we need to assign a custom SerializationBinder here
};

// TODO: ExperimentParamters is expected but ThreeDExperimentParameters is received
return JsonConvert.DeserializeObject<ExperimentParameters>(data, settings);
}
#endregion
Expand Down
Loading

0 comments on commit 2a022b0

Please sign in to comment.