mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-14 05:35:08 +00:00
Random Code Refactoring
This commit is contained in:
parent
775681fe70
commit
542ece5ed4
2 changed files with 147 additions and 156 deletions
|
@ -380,58 +380,45 @@ namespace HeavenStudio.Editor
|
||||||
{
|
{
|
||||||
var path = Path.Combine(paths);
|
var path = Path.Combine(paths);
|
||||||
|
|
||||||
if (path != String.Empty)
|
if (path == string.Empty) return;
|
||||||
{
|
loadedMusic = false;
|
||||||
loadedMusic = false;
|
|
||||||
|
|
||||||
using (FileStream zipFile = File.Open(path, FileMode.Open))
|
using var zipFile = File.Open(path, FileMode.Open);
|
||||||
|
using var archive = new ZipArchive(zipFile, ZipArchiveMode.Read);
|
||||||
|
|
||||||
|
foreach (var entry in archive.Entries)
|
||||||
|
switch (entry.Name)
|
||||||
{
|
{
|
||||||
using (var archive = new ZipArchive(zipFile, ZipArchiveMode.Read))
|
case "remix.json":
|
||||||
{
|
{
|
||||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
using var stream = entry.Open();
|
||||||
{
|
using var reader = new StreamReader(stream);
|
||||||
if (entry.Name == "remix.json")
|
LoadRemix(reader.ReadToEnd());
|
||||||
{
|
|
||||||
using (var stream = entry.Open())
|
break;
|
||||||
{
|
}
|
||||||
byte[] bytes;
|
case "song.ogg":
|
||||||
using (var ms = new MemoryStream())
|
{
|
||||||
{
|
using var stream = entry.Open();
|
||||||
stream.CopyTo(ms);
|
using var memoryStream = new MemoryStream();
|
||||||
bytes = ms.ToArray();
|
stream.CopyTo(memoryStream);
|
||||||
string json = Encoding.UTF8.GetString(bytes);
|
var bytes = memoryStream.ToArray();
|
||||||
LoadRemix(json);
|
Conductor.instance.musicSource.clip = OggVorbis.VorbisPlugin.ToAudioClip(bytes, "music");
|
||||||
}
|
loadedMusic = true;
|
||||||
}
|
Timeline.FitToSong();
|
||||||
}
|
|
||||||
else if (entry.Name == "song.ogg")
|
break;
|
||||||
{
|
|
||||||
using (var stream = entry.Open())
|
|
||||||
{
|
|
||||||
byte[] bytes;
|
|
||||||
using (var ms = new MemoryStream())
|
|
||||||
{
|
|
||||||
stream.CopyTo(ms);
|
|
||||||
bytes = ms.ToArray();
|
|
||||||
Conductor.instance.musicSource.clip = OggVorbis.VorbisPlugin.ToAudioClip(bytes, "music");
|
|
||||||
loadedMusic = true;
|
|
||||||
Timeline.FitToSong();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loadedMusic)
|
if (!loadedMusic)
|
||||||
Conductor.instance.musicSource.clip = null;
|
Conductor.instance.musicSource.clip = null;
|
||||||
|
|
||||||
currentRemixPath = path;
|
currentRemixPath = path;
|
||||||
remixName = Path.GetFileName(path);
|
remixName = Path.GetFileName(path);
|
||||||
UpdateEditorStatus(false);
|
UpdateEditorStatus(false);
|
||||||
CommandManager.instance.Clear();
|
CommandManager.instance.Clear();
|
||||||
Timeline.FitToSong();
|
Timeline.FitToSong();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +460,7 @@ namespace HeavenStudio.Editor
|
||||||
private void UpdateEditorStatus(bool updateTime)
|
private void UpdateEditorStatus(bool updateTime)
|
||||||
{
|
{
|
||||||
if (discordDuringTesting || !Application.isEditor)
|
if (discordDuringTesting || !Application.isEditor)
|
||||||
DiscordRPC.DiscordRPC.UpdateActivity("In Editor", $"{remixName}", updateTime);
|
DiscordRPC.DiscordRPC.UpdateActivity("In Editor", $"{remixName}", updateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetJson()
|
public string GetJson()
|
||||||
|
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using Starpelly;
|
using Starpelly;
|
||||||
|
|
||||||
|
@ -47,135 +47,139 @@ namespace HeavenStudio.Editor
|
||||||
this.propertyName = propertyName;
|
this.propertyName = propertyName;
|
||||||
this.caption.text = caption;
|
this.caption.text = caption;
|
||||||
|
|
||||||
var objType = type.GetType();
|
switch (type)
|
||||||
|
|
||||||
if (objType == typeof(EntityTypes.Integer))
|
|
||||||
{
|
{
|
||||||
var integer = ((EntityTypes.Integer)type);
|
case EntityTypes.Integer integer:
|
||||||
|
slider.minValue = integer.min;
|
||||||
|
slider.maxValue = integer.max;
|
||||||
|
|
||||||
slider.minValue = integer.min;
|
slider.wholeNumbers = true;
|
||||||
slider.maxValue = integer.max;
|
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
|
||||||
|
|
||||||
slider.value = Mathf.RoundToInt(System.Convert.ToSingle(parameterManager.entity[propertyName]));
|
|
||||||
inputField.text = slider.value.ToString();
|
|
||||||
|
|
||||||
slider.onValueChanged.AddListener(delegate
|
|
||||||
{
|
|
||||||
inputField.text = slider.value.ToString();
|
inputField.text = slider.value.ToString();
|
||||||
parameterManager.entity[propertyName] = (int)slider.value;
|
|
||||||
});
|
|
||||||
|
|
||||||
inputField.onSelect.AddListener(delegate
|
slider.onValueChanged.AddListener(
|
||||||
{
|
_ =>
|
||||||
Editor.instance.editingInputField = true;
|
{
|
||||||
});
|
inputField.text = slider.value.ToString();
|
||||||
|
parameterManager.entity[propertyName] = (int) slider.value;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
inputField.onEndEdit.AddListener(delegate
|
inputField.onSelect.AddListener(
|
||||||
{
|
_ =>
|
||||||
slider.value = Mathf.RoundToInt(System.Convert.ToSingle(System.Convert.ToSingle(inputField.text)));
|
Editor.instance.editingInputField = true
|
||||||
parameterManager.entity[propertyName] = (int)slider.value;
|
);
|
||||||
Editor.instance.editingInputField = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (objType == typeof(EntityTypes.Float))
|
|
||||||
{
|
|
||||||
var fl = ((EntityTypes.Float)type);
|
|
||||||
|
|
||||||
slider.minValue = fl.min;
|
inputField.onEndEdit.AddListener(
|
||||||
slider.maxValue = fl.max;
|
_ =>
|
||||||
|
{
|
||||||
|
slider.value = Convert.ToSingle(inputField.text);
|
||||||
|
parameterManager.entity[propertyName] = (int) slider.value;
|
||||||
|
Editor.instance.editingInputField = false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
slider.value = System.Convert.ToSingle(parameterManager.entity[propertyName]);
|
case EntityTypes.Float fl:
|
||||||
inputField.text = slider.value.ToString("G");
|
slider.minValue = fl.min;
|
||||||
|
slider.maxValue = fl.max;
|
||||||
|
|
||||||
slider.onValueChanged.AddListener(delegate
|
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
|
||||||
{
|
inputField.text = slider.value.ToString("G");
|
||||||
var newValue = (float)System.Math.Round(slider.value, 4);
|
|
||||||
inputField.text = newValue.ToString("G");
|
|
||||||
parameterManager.entity[propertyName] = newValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
inputField.onSelect.AddListener(delegate
|
slider.onValueChanged.AddListener(
|
||||||
{
|
_ =>
|
||||||
Editor.instance.editingInputField = true;
|
{
|
||||||
});
|
var newValue = (float) Math.Round(slider.value, 4);
|
||||||
|
inputField.text = newValue.ToString("G");
|
||||||
|
parameterManager.entity[propertyName] = newValue;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
inputField.onEndEdit.AddListener(delegate
|
inputField.onSelect.AddListener(
|
||||||
{
|
_ =>
|
||||||
slider.value = (float)System.Math.Round(System.Convert.ToSingle(inputField.text), 4);
|
Editor.instance.editingInputField = true
|
||||||
parameterManager.entity[propertyName] = slider.value;
|
);
|
||||||
Editor.instance.editingInputField = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if(type is bool)
|
|
||||||
{
|
|
||||||
toggle.isOn = System.Convert.ToBoolean(parameterManager.entity[propertyName]); // ' (bool)type ' always results in false
|
|
||||||
|
|
||||||
toggle.onValueChanged.AddListener(delegate
|
inputField.onEndEdit.AddListener(
|
||||||
{
|
_ =>
|
||||||
parameterManager.entity[propertyName] = toggle.isOn;
|
{
|
||||||
});
|
slider.value = (float) Math.Round(Convert.ToSingle(inputField.text), 4);
|
||||||
}
|
parameterManager.entity[propertyName] = slider.value;
|
||||||
else if (objType.IsEnum)
|
Editor.instance.editingInputField = false;
|
||||||
{
|
}
|
||||||
List<TMP_Dropdown.OptionData> dropDownData = new List<TMP_Dropdown.OptionData>();
|
);
|
||||||
var vals = Enum.GetValues(objType);
|
break;
|
||||||
var selected = 0;
|
|
||||||
for (int i = 0; i < vals.Length; i++)
|
|
||||||
{
|
|
||||||
string name = Enum.GetNames(objType)[i];
|
|
||||||
TMP_Dropdown.OptionData optionData = new TMP_Dropdown.OptionData();
|
|
||||||
|
|
||||||
optionData.text = name;
|
case bool _:
|
||||||
|
// ' (bool)type ' always results in false
|
||||||
|
toggle.isOn = Convert.ToBoolean(parameterManager.entity[propertyName]);
|
||||||
|
|
||||||
dropDownData.Add(optionData);
|
toggle.onValueChanged.AddListener(
|
||||||
|
_ => parameterManager.entity[propertyName] = toggle.isOn
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
if ((int)vals.GetValue(i) == (int)parameterManager.entity[propertyName])
|
case Color _:
|
||||||
selected = i;
|
colorPreview.colorPicker.onColorChanged += _ =>
|
||||||
}
|
parameterManager.entity[propertyName] = colorPreview.colorPicker.color;
|
||||||
dropdown.AddOptions(dropDownData);
|
|
||||||
dropdown.value = selected;
|
|
||||||
|
|
||||||
dropdown.onValueChanged.AddListener(delegate
|
|
||||||
{
|
|
||||||
parameterManager.entity[propertyName] = (int)Enum.GetValues(objType).GetValue(dropdown.value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (objType == typeof(Color))
|
|
||||||
{
|
|
||||||
colorPreview.colorPicker.onColorChanged += delegate
|
|
||||||
{
|
|
||||||
parameterManager.entity[propertyName] = (Color)colorPreview.colorPicker.color;
|
|
||||||
};
|
|
||||||
|
|
||||||
Color paramCol = (Color)parameterManager.entity[propertyName];
|
var paramCol = (Color) parameterManager.entity[propertyName];
|
||||||
|
|
||||||
|
ColorBTN.onClick.AddListener(
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
ColorTable.gameObject.SetActive(true);
|
||||||
|
colorTableActive = true;
|
||||||
|
colorPreview.ChangeColor(paramCol);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
ColorBTN.onClick.AddListener(delegate
|
|
||||||
{
|
|
||||||
ColorTable.gameObject.SetActive(true);
|
|
||||||
colorTableActive = true;
|
|
||||||
colorPreview.ChangeColor(paramCol);
|
colorPreview.ChangeColor(paramCol);
|
||||||
});
|
ColorTable.gameObject.SetActive(false);
|
||||||
|
break;
|
||||||
|
|
||||||
colorPreview.ChangeColor(paramCol);
|
case string _:
|
||||||
ColorTable.gameObject.SetActive(false);
|
inputFieldString.text = (string) parameterManager.entity[propertyName];
|
||||||
}
|
|
||||||
//why the FUCK wasn't this a thing before lmao
|
|
||||||
else if(objType == typeof(string))
|
|
||||||
{
|
|
||||||
// Debug.Log("entity " + propertyName + " is: " + (string)(parameterManager.entity[propertyName]));
|
|
||||||
inputFieldString.text = (string)(parameterManager.entity[propertyName]);
|
|
||||||
|
|
||||||
inputFieldString.onSelect.AddListener(delegate
|
inputFieldString.onSelect.AddListener(
|
||||||
{
|
_ =>
|
||||||
Editor.instance.editingInputField = true;
|
Editor.instance.editingInputField = true
|
||||||
});
|
);
|
||||||
|
inputFieldString.onEndEdit.AddListener(
|
||||||
|
_ =>
|
||||||
|
{;
|
||||||
|
parameterManager.entity[propertyName] = inputFieldString.text;
|
||||||
|
Editor.instance.editingInputField = false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
inputFieldString.onEndEdit.AddListener(delegate
|
case Enum enumKind:
|
||||||
{
|
var enumType = enumKind.GetType();
|
||||||
// Debug.Log("setting " + propertyName + " to: " + inputFieldString.text);
|
var enumVals = Enum.GetValues(enumType);
|
||||||
parameterManager.entity[propertyName] = inputFieldString.text;
|
var enumNames = Enum.GetNames(enumType).ToList();
|
||||||
Editor.instance.editingInputField = false;
|
|
||||||
});
|
// Can we assume non-holey enum?
|
||||||
|
// If we can we can simplify to dropdown.value = (int) parameterManager.entity[propertyName]
|
||||||
|
var currentlySelected = (int) parameterManager.entity[propertyName];
|
||||||
|
var selected = enumVals
|
||||||
|
.Cast<object>()
|
||||||
|
.ToList()
|
||||||
|
.FindIndex(val => (int) val == currentlySelected);
|
||||||
|
|
||||||
|
dropdown.AddOptions(enumNames);
|
||||||
|
dropdown.value = selected;
|
||||||
|
|
||||||
|
dropdown.onValueChanged.AddListener(_ =>
|
||||||
|
parameterManager.entity[propertyName] = Enum.ToObject(enumType, dropdown.value)
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException(
|
||||||
|
nameof(type), type, "I don't know how to make a property of this type!"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue