Random Code Refactoring
This commit is contained in:
parent
775681fe70
commit
542ece5ed4
|
@ -380,46 +380,34 @@ namespace HeavenStudio.Editor
|
|||
{
|
||||
var path = Path.Combine(paths);
|
||||
|
||||
if (path != String.Empty)
|
||||
{
|
||||
if (path == string.Empty) return;
|
||||
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)
|
||||
{
|
||||
if (entry.Name == "remix.json")
|
||||
{
|
||||
using (var stream = entry.Open())
|
||||
{
|
||||
byte[] bytes;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
stream.CopyTo(ms);
|
||||
bytes = ms.ToArray();
|
||||
string json = Encoding.UTF8.GetString(bytes);
|
||||
LoadRemix(json);
|
||||
using var stream = entry.Open();
|
||||
using var reader = new StreamReader(stream);
|
||||
LoadRemix(reader.ReadToEnd());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (entry.Name == "song.ogg")
|
||||
case "song.ogg":
|
||||
{
|
||||
using (var stream = entry.Open())
|
||||
{
|
||||
byte[] bytes;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
stream.CopyTo(ms);
|
||||
bytes = ms.ToArray();
|
||||
using var stream = entry.Open();
|
||||
using var memoryStream = new MemoryStream();
|
||||
stream.CopyTo(memoryStream);
|
||||
var bytes = memoryStream.ToArray();
|
||||
Conductor.instance.musicSource.clip = OggVorbis.VorbisPlugin.ToAudioClip(bytes, "music");
|
||||
loadedMusic = true;
|
||||
Timeline.FitToSong();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,7 +419,6 @@ namespace HeavenStudio.Editor
|
|||
UpdateEditorStatus(false);
|
||||
CommandManager.instance.Clear();
|
||||
Timeline.FitToSong();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using Starpelly;
|
||||
|
||||
|
@ -47,135 +47,139 @@ namespace HeavenStudio.Editor
|
|||
this.propertyName = propertyName;
|
||||
this.caption.text = caption;
|
||||
|
||||
var objType = type.GetType();
|
||||
|
||||
if (objType == typeof(EntityTypes.Integer))
|
||||
switch (type)
|
||||
{
|
||||
var integer = ((EntityTypes.Integer)type);
|
||||
|
||||
case EntityTypes.Integer integer:
|
||||
slider.minValue = integer.min;
|
||||
slider.maxValue = integer.max;
|
||||
|
||||
slider.value = Mathf.RoundToInt(System.Convert.ToSingle(parameterManager.entity[propertyName]));
|
||||
slider.wholeNumbers = true;
|
||||
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
|
||||
inputField.text = slider.value.ToString();
|
||||
|
||||
slider.onValueChanged.AddListener(delegate
|
||||
slider.onValueChanged.AddListener(
|
||||
_ =>
|
||||
{
|
||||
inputField.text = slider.value.ToString();
|
||||
parameterManager.entity[propertyName] = (int) slider.value;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
inputField.onSelect.AddListener(delegate
|
||||
{
|
||||
Editor.instance.editingInputField = true;
|
||||
});
|
||||
inputField.onSelect.AddListener(
|
||||
_ =>
|
||||
Editor.instance.editingInputField = true
|
||||
);
|
||||
|
||||
inputField.onEndEdit.AddListener(delegate
|
||||
inputField.onEndEdit.AddListener(
|
||||
_ =>
|
||||
{
|
||||
slider.value = Mathf.RoundToInt(System.Convert.ToSingle(System.Convert.ToSingle(inputField.text)));
|
||||
slider.value = Convert.ToSingle(inputField.text);
|
||||
parameterManager.entity[propertyName] = (int) slider.value;
|
||||
Editor.instance.editingInputField = false;
|
||||
});
|
||||
}
|
||||
else if (objType == typeof(EntityTypes.Float))
|
||||
{
|
||||
var fl = ((EntityTypes.Float)type);
|
||||
);
|
||||
break;
|
||||
|
||||
case EntityTypes.Float fl:
|
||||
slider.minValue = fl.min;
|
||||
slider.maxValue = fl.max;
|
||||
|
||||
slider.value = System.Convert.ToSingle(parameterManager.entity[propertyName]);
|
||||
slider.value = Convert.ToSingle(parameterManager.entity[propertyName]);
|
||||
inputField.text = slider.value.ToString("G");
|
||||
|
||||
slider.onValueChanged.AddListener(delegate
|
||||
slider.onValueChanged.AddListener(
|
||||
_ =>
|
||||
{
|
||||
var newValue = (float)System.Math.Round(slider.value, 4);
|
||||
var newValue = (float) Math.Round(slider.value, 4);
|
||||
inputField.text = newValue.ToString("G");
|
||||
parameterManager.entity[propertyName] = newValue;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
inputField.onSelect.AddListener(delegate
|
||||
{
|
||||
Editor.instance.editingInputField = true;
|
||||
});
|
||||
inputField.onSelect.AddListener(
|
||||
_ =>
|
||||
Editor.instance.editingInputField = true
|
||||
);
|
||||
|
||||
inputField.onEndEdit.AddListener(delegate
|
||||
inputField.onEndEdit.AddListener(
|
||||
_ =>
|
||||
{
|
||||
slider.value = (float)System.Math.Round(System.Convert.ToSingle(inputField.text), 4);
|
||||
slider.value = (float) Math.Round(Convert.ToSingle(inputField.text), 4);
|
||||
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
|
||||
);
|
||||
break;
|
||||
|
||||
toggle.onValueChanged.AddListener(delegate
|
||||
{
|
||||
parameterManager.entity[propertyName] = toggle.isOn;
|
||||
});
|
||||
}
|
||||
else if (objType.IsEnum)
|
||||
{
|
||||
List<TMP_Dropdown.OptionData> dropDownData = new List<TMP_Dropdown.OptionData>();
|
||||
var vals = Enum.GetValues(objType);
|
||||
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();
|
||||
case bool _:
|
||||
// ' (bool)type ' always results in false
|
||||
toggle.isOn = Convert.ToBoolean(parameterManager.entity[propertyName]);
|
||||
|
||||
optionData.text = name;
|
||||
toggle.onValueChanged.AddListener(
|
||||
_ => parameterManager.entity[propertyName] = toggle.isOn
|
||||
);
|
||||
break;
|
||||
|
||||
dropDownData.Add(optionData);
|
||||
case Color _:
|
||||
colorPreview.colorPicker.onColorChanged += _ =>
|
||||
parameterManager.entity[propertyName] = colorPreview.colorPicker.color;
|
||||
|
||||
if ((int)vals.GetValue(i) == (int)parameterManager.entity[propertyName])
|
||||
selected = i;
|
||||
}
|
||||
dropdown.AddOptions(dropDownData);
|
||||
dropdown.value = selected;
|
||||
var paramCol = (Color) parameterManager.entity[propertyName];
|
||||
|
||||
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];
|
||||
|
||||
ColorBTN.onClick.AddListener(delegate
|
||||
ColorBTN.onClick.AddListener(
|
||||
() =>
|
||||
{
|
||||
ColorTable.gameObject.SetActive(true);
|
||||
colorTableActive = true;
|
||||
colorPreview.ChangeColor(paramCol);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
colorPreview.ChangeColor(paramCol);
|
||||
ColorTable.gameObject.SetActive(false);
|
||||
}
|
||||
//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]);
|
||||
break;
|
||||
|
||||
inputFieldString.onSelect.AddListener(delegate
|
||||
{
|
||||
Editor.instance.editingInputField = true;
|
||||
});
|
||||
case string _:
|
||||
inputFieldString.text = (string) parameterManager.entity[propertyName];
|
||||
|
||||
inputFieldString.onEndEdit.AddListener(delegate
|
||||
{
|
||||
// Debug.Log("setting " + propertyName + " to: " + inputFieldString.text);
|
||||
inputFieldString.onSelect.AddListener(
|
||||
_ =>
|
||||
Editor.instance.editingInputField = true
|
||||
);
|
||||
inputFieldString.onEndEdit.AddListener(
|
||||
_ =>
|
||||
{;
|
||||
parameterManager.entity[propertyName] = inputFieldString.text;
|
||||
Editor.instance.editingInputField = false;
|
||||
});
|
||||
}
|
||||
);
|
||||
break;
|
||||
|
||||
case Enum enumKind:
|
||||
var enumType = enumKind.GetType();
|
||||
var enumVals = Enum.GetValues(enumType);
|
||||
var enumNames = Enum.GetNames(enumType).ToList();
|
||||
|
||||
// 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