refactor: Update Unity to 2022.3.62
This commit is contained in:
@@ -25,7 +25,7 @@ namespace Cryville.Crtr {
|
||||
public int d;
|
||||
|
||||
[JsonIgnore]
|
||||
public double Decimal { get { return b + (double)n / d; } }
|
||||
public readonly double Decimal { get { return b + (double)n / d; } }
|
||||
|
||||
public int CompareTo(BeatTime other) {
|
||||
var c = b.CompareTo(other.b);
|
||||
@@ -34,15 +34,15 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
if (!(obj is BeatTime)) return false;
|
||||
return Equals((BeatTime)obj);
|
||||
if (obj is not BeatTime other) return false;
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
public bool Equals(BeatTime other) {
|
||||
return b.Equals(other.b) && ((double)n / d).Equals((double)other.n / other.d);
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
public override readonly int GetHashCode() {
|
||||
return Decimal.GetHashCode();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,28 +4,27 @@ using System.Linq;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.Actions {
|
||||
public class ActionManager {
|
||||
readonly Dictionary<Type, List<IResourceAction>> _actions = new Dictionary<Type, List<IResourceAction>>();
|
||||
readonly Dictionary<IResourceAction, int> _refCounts = new Dictionary<IResourceAction, int>();
|
||||
readonly Dictionary<Type, List<IResourceAction>> _actions = new();
|
||||
readonly Dictionary<IResourceAction, int> _refCounts = new();
|
||||
|
||||
public event Action Changed;
|
||||
|
||||
class ActionPriorityComparer : IComparer<IResourceAction> {
|
||||
public static readonly ActionPriorityComparer Instance = new ActionPriorityComparer();
|
||||
public static readonly ActionPriorityComparer Instance = new();
|
||||
public int Compare(IResourceAction x, IResourceAction y) {
|
||||
return x.Priority.CompareTo(y.Priority);
|
||||
}
|
||||
}
|
||||
|
||||
void Register(Type type, IResourceAction action) {
|
||||
List<IResourceAction> actions;
|
||||
if (!_actions.TryGetValue(type, out actions)) {
|
||||
if (!_actions.TryGetValue(type, out List<IResourceAction> actions)) {
|
||||
_actions.Add(type, actions = new List<IResourceAction>());
|
||||
}
|
||||
int index = actions.BinarySearch(action, ActionPriorityComparer.Instance);
|
||||
if (index < 0) index = ~index;
|
||||
actions.Insert(index, action);
|
||||
if (_refCounts.ContainsKey(action)) _refCounts[action]++;
|
||||
else _refCounts[action] = 0;
|
||||
else _refCounts[action] = 1;
|
||||
Changed?.Invoke();
|
||||
}
|
||||
public void Register(IResourceAction action) {
|
||||
@@ -36,8 +35,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
}
|
||||
|
||||
public void Unregister(Type type, IResourceAction action) {
|
||||
List<IResourceAction> actions;
|
||||
if (!_actions.TryGetValue(type, out actions)) return;
|
||||
if (!_actions.TryGetValue(type, out List<IResourceAction> actions)) return;
|
||||
if (--_refCounts[action] > 0) return;
|
||||
actions.Remove(action);
|
||||
Changed?.Invoke();
|
||||
@@ -54,9 +52,8 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
}
|
||||
IEnumerable<IResourceAction> GetActions(Uri uri, IResourceMeta res, Type type) {
|
||||
if (type == null) return Enumerable.Empty<IResourceAction>();
|
||||
List<IResourceAction> actions;
|
||||
IEnumerable<IResourceAction> result;
|
||||
if (_actions.TryGetValue(type, out actions))
|
||||
if (_actions.TryGetValue(type, out List<IResourceAction> actions))
|
||||
result = actions.Where(i => i.CanInvoke(uri, res));
|
||||
else
|
||||
result = Enumerable.Empty<IResourceAction>();
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
|
||||
public override int Priority { get { return -50; } }
|
||||
|
||||
static readonly Dictionary<string, int> _rulesetTabs = new Dictionary<string, int>();
|
||||
static readonly Dictionary<string, int> _rulesetTabs = new();
|
||||
|
||||
public override bool CanInvoke(Uri uri, IChartDetail resource) {
|
||||
return true;
|
||||
@@ -20,15 +20,13 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
}
|
||||
|
||||
public static bool HasTab(string ruleset) {
|
||||
int tabId;
|
||||
var master = ResourceBrowserMaster.Instance;
|
||||
if (master == null) return false;
|
||||
return _rulesetTabs.TryGetValue(ruleset, out tabId) && master.HasTab(tabId);
|
||||
return _rulesetTabs.TryGetValue(ruleset, out int tabId) && master.HasTab(tabId);
|
||||
}
|
||||
public static void Invoke(string ruleset, Action<RulesetConfig> overrides = null) {
|
||||
var master = ResourceBrowserMaster.Instance;
|
||||
int tabId;
|
||||
if (_rulesetTabs.TryGetValue(ruleset, out tabId) && master.TryOpenTab(tabId))
|
||||
if (_rulesetTabs.TryGetValue(ruleset, out int tabId) && master.TryOpenTab(tabId))
|
||||
return;
|
||||
var browser = Object.Instantiate(master.m_configBrowserPrefab).GetComponent<RulesetConfigBrowser>();
|
||||
try {
|
||||
|
||||
@@ -8,15 +8,15 @@ namespace Cryville.Crtr.Browsing.Actions {
|
||||
public abstract bool CanInvoke(Uri uri, T resource);
|
||||
public bool CanInvoke(Uri uri, IResourceMeta resource) {
|
||||
if (resource == null) throw new ArgumentNullException("resource");
|
||||
if (!(resource is T)) throw new ArgumentException("Mismatched resource type.");
|
||||
return CanInvoke(uri, (T)resource);
|
||||
if (resource is not T res) throw new ArgumentException("Mismatched resource type.");
|
||||
return CanInvoke(uri, res);
|
||||
}
|
||||
|
||||
public abstract void Invoke(Uri uri, T resource);
|
||||
public void Invoke(Uri uri, IResourceMeta resource) {
|
||||
if (resource == null) throw new ArgumentNullException("resource");
|
||||
if (!(resource is T)) throw new ArgumentException("Mismatched resource type.");
|
||||
Invoke(uri, (T)resource);
|
||||
if (resource is not T res) throw new ArgumentException("Mismatched resource type.");
|
||||
Invoke(uri, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,18 +10,17 @@ namespace Cryville.Crtr.Browsing {
|
||||
internal static class ExtensionManager {
|
||||
static bool _init;
|
||||
static readonly Dictionary<string, List<ResourceConverter>> _converters
|
||||
= new Dictionary<string, List<ResourceConverter>>();
|
||||
= new();
|
||||
public static ISet<string> GetSupportedFormats() {
|
||||
return new HashSet<string>(_converters.Keys);
|
||||
}
|
||||
public static bool TryGetConverters(string extension, out IEnumerable<ResourceConverter> converters) {
|
||||
List<ResourceConverter> outResult;
|
||||
bool result = _converters.TryGetValue(extension, out outResult);
|
||||
bool result = _converters.TryGetValue(extension, out List<ResourceConverter> outResult);
|
||||
converters = outResult;
|
||||
return result;
|
||||
}
|
||||
static readonly Dictionary<string, string> _localRes
|
||||
= new Dictionary<string, string>();
|
||||
= new();
|
||||
public static IReadOnlyDictionary<string, string> GetLocalResourcePaths() {
|
||||
return _localRes;
|
||||
}
|
||||
@@ -62,8 +61,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
var buf = new byte[stream.Length];
|
||||
stream.Read(buf, 0, buf.Length);
|
||||
var asm = Assembly.Load(buf);
|
||||
if (asm == null) throw new TypeLoadException("Failed to load the module");
|
||||
var asm = Assembly.Load(buf) ?? throw new TypeLoadException("Failed to load the module");
|
||||
asms.Add(asm.GetName().Name);
|
||||
foreach (var type in asm.GetTypes()) {
|
||||
if (typeof(ExtensionInterface).IsAssignableFrom(type)) {
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
public FileSystemEntry this[int index] { get { return _filteredItems[index]; } }
|
||||
IResourceMeta IResourceManager.this[int index] { get { return this[index]; } }
|
||||
|
||||
readonly List<string> _dirParts = new List<string>();
|
||||
readonly List<string> _dirParts = new();
|
||||
readonly IList<string> m_dirParts;
|
||||
public IList<string> CurrentDirectory { get { return m_dirParts; } }
|
||||
public int Count { get { return _filteredItems.Length; } }
|
||||
@@ -136,8 +136,7 @@ namespace Cryville.Crtr.Browsing {
|
||||
public IEnumerable<MetaProperty> Properties {
|
||||
get {
|
||||
yield return new MetaProperty("Name", _name);
|
||||
if (FileSystemInfo is FileInfo) {
|
||||
var file = (FileInfo)FileSystemInfo;
|
||||
if (FileSystemInfo is FileInfo file) {
|
||||
yield return new MetaProperty("Size", new Qualified<long>(file.Length, "B"));
|
||||
}
|
||||
yield return new MetaProperty("Write.Time", FileSystemInfo.LastWriteTime);
|
||||
|
||||
@@ -10,11 +10,11 @@ namespace Cryville.Crtr.Browsing.Legacy {
|
||||
internal abstract class LegacyResourceManager<T> : IPathedResourceManager<T> where T : IResourceMeta {
|
||||
protected readonly LegacyResourceStore _store;
|
||||
DirectoryInfo _cd;
|
||||
readonly FileSystemWatcher _watcher = new FileSystemWatcher();
|
||||
readonly FileSystemWatcher _watcher = new();
|
||||
DirectoryInfo[] _items = new DirectoryInfo[0];
|
||||
DirectoryInfo[] _filteredItems = new DirectoryInfo[0];
|
||||
string _filter = string.Empty;
|
||||
readonly List<string> _dirParts = new List<string>();
|
||||
readonly List<string> _dirParts = new();
|
||||
readonly IList<string> m_dirParts;
|
||||
public IList<string> CurrentDirectory { get { return m_dirParts; } }
|
||||
public int Count { get { return _filteredItems.Length; } }
|
||||
|
||||
@@ -34,8 +34,7 @@ namespace Cryville.Crtr.Browsing.Legacy {
|
||||
}
|
||||
public bool ImportFrom(Uri uri) {
|
||||
var file = new FileInfo(uri.LocalPath);
|
||||
IEnumerable<ResourceConverter> converters;
|
||||
if (!ExtensionManager.TryGetConverters(file.Extension, out converters)) return false;
|
||||
if (!ExtensionManager.TryGetConverters(file.Extension, out IEnumerable<ResourceConverter> converters)) return false;
|
||||
foreach (var converter in converters) {
|
||||
var resources = new List<Resource>();
|
||||
var ses = new ConversionSession {
|
||||
@@ -69,8 +68,7 @@ namespace Cryville.Crtr.Browsing.Legacy {
|
||||
coverFile.CopyTo(Path.Combine(dir.FullName, tres.Meta.cover), true);
|
||||
}
|
||||
}
|
||||
else if (res is FileResource) {
|
||||
var tres = (FileResource)res;
|
||||
else if (res is FileResource tres) {
|
||||
DirectoryInfo dest;
|
||||
bool singleFileFlag = false;
|
||||
if (res is ChartResource)
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
OnReset();
|
||||
}
|
||||
protected override void OnReset() {
|
||||
if (_cover != null) _cover.Cancel();
|
||||
_cover?.Cancel();
|
||||
if (m_icon.sprite != null && m_icon.sprite != m_iconPlaceholder) {
|
||||
Destroy(m_icon.sprite.texture);
|
||||
Destroy(m_icon.sprite);
|
||||
|
||||
@@ -79,8 +79,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
protected override void OnEnable() {
|
||||
base.OnEnable();
|
||||
m_layoutMinWidth = GetTargetLayoutMinWidth();
|
||||
if (_tweener == null)
|
||||
_tweener = new PropertyTweener<float>(
|
||||
_tweener ??= new PropertyTweener<float>(
|
||||
() => m_layoutMinWidth,
|
||||
v => UpdateLayoutMinWidth(v),
|
||||
Tweeners.Float.With(EasingFunctions.OutQuad)
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
}
|
||||
|
||||
void DestroyDynamicResources() {
|
||||
if (_image != null) _image.Cancel();
|
||||
_image?.Cancel();
|
||||
if (m_cover.sprite != null && m_cover.sprite != m_coverPlaceholder) {
|
||||
Destroy(m_cover.sprite.texture);
|
||||
Destroy(m_cover.sprite);
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
IResourceAction _importAction;
|
||||
readonly IResourceAction[] _importActionArray = new IResourceAction[1];
|
||||
|
||||
readonly HashSet<int> _selectedItems = new HashSet<int>();
|
||||
readonly Dictionary<int, BrowserItem> _items = new Dictionary<int, BrowserItem>();
|
||||
readonly HashSet<int> _selectedItems = new();
|
||||
readonly Dictionary<int, BrowserItem> _items = new();
|
||||
|
||||
bool _destroyed;
|
||||
protected virtual void Start() {
|
||||
@@ -52,10 +52,10 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
}
|
||||
|
||||
void OnEnable() {
|
||||
if (_manager != null) _manager.Activate();
|
||||
_manager?.Activate();
|
||||
}
|
||||
void OnDisable() {
|
||||
if (_manager != null) _manager.Deactivate();
|
||||
_manager?.Deactivate();
|
||||
}
|
||||
|
||||
public void Init(IPathedResourceManager<IResourceMeta> manager) {
|
||||
|
||||
@@ -21,8 +21,8 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
internal GameObject m_configBrowserPrefab;
|
||||
|
||||
BrowserTab _currentTab;
|
||||
readonly Dictionary<int, BrowserTab> _tabMap = new Dictionary<int, BrowserTab>();
|
||||
readonly Dictionary<BrowserTab, ResourceBrowser> _tabs = new Dictionary<BrowserTab, ResourceBrowser>();
|
||||
readonly Dictionary<int, BrowserTab> _tabMap = new();
|
||||
readonly Dictionary<BrowserTab, ResourceBrowser> _tabs = new();
|
||||
|
||||
public ActionManager Actions { get; private set; }
|
||||
|
||||
@@ -77,8 +77,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
return _tabMap.ContainsKey(id);
|
||||
}
|
||||
public bool TryOpenTab(int id) {
|
||||
BrowserTab tab;
|
||||
if (_tabMap.TryGetValue(id, out tab)) {
|
||||
if (_tabMap.TryGetValue(id, out BrowserTab tab)) {
|
||||
OnTabClicked(tab);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -31,21 +31,21 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
|
||||
public void Load(string rulesetName, Action<RulesetConfig> overrides = null) {
|
||||
RulesetName = rulesetName;
|
||||
FileInfo file = new FileInfo(Path.Combine(
|
||||
FileInfo file = new(Path.Combine(
|
||||
Game.GameDataPath, "rulesets", rulesetName, ".umgr"
|
||||
));
|
||||
if (!file.Exists) {
|
||||
throw new FileNotFoundException("Ruleset for the resource not found\nMake sure you have imported the ruleset");
|
||||
}
|
||||
DirectoryInfo dir = file.Directory;
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
using (StreamReader reader = new(file.FullName, Encoding.UTF8)) {
|
||||
_ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
if (_ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
|
||||
_ruleset.LoadPdt(dir);
|
||||
}
|
||||
FileInfo cfgfile = new FileInfo(Path.Combine(
|
||||
FileInfo cfgfile = new(Path.Combine(
|
||||
Game.GameDataPath, "config", "rulesets", rulesetName + ".json"
|
||||
));
|
||||
if (!cfgfile.Exists) {
|
||||
@@ -53,11 +53,10 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
_rscfg = new RulesetConfig();
|
||||
}
|
||||
else {
|
||||
using (StreamReader cfgreader = new StreamReader(cfgfile.FullName, Encoding.UTF8)) {
|
||||
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
}
|
||||
using StreamReader cfgreader = new(cfgfile.FullName, Encoding.UTF8);
|
||||
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
}
|
||||
|
||||
overrides?.Invoke(_rscfg);
|
||||
@@ -92,12 +91,11 @@ namespace Cryville.Crtr.Browsing.UI {
|
||||
void OnDisable() {
|
||||
if (_loaded) {
|
||||
m_inputConfigPanel.SaveTo(_rscfg.inputs);
|
||||
FileInfo cfgFile = new FileInfo(Path.Combine(
|
||||
FileInfo cfgFile = new(Path.Combine(
|
||||
Game.GameDataPath, "config", "rulesets", RulesetName + ".json"
|
||||
));
|
||||
using (StreamWriter cfgWriter = new StreamWriter(cfgFile.FullName, false, Encoding.UTF8)) {
|
||||
cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
using StreamWriter cfgWriter = new(cfgFile.FullName, false, Encoding.UTF8);
|
||||
cfgWriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@ using UnityEngine;
|
||||
namespace Cryville.Crtr {
|
||||
public static class BuiltinResources {
|
||||
public static Dictionary<string, Type> Components
|
||||
= new Dictionary<string, Type>();
|
||||
= new();
|
||||
public static Dictionary<string, Shader> Shaders
|
||||
= new Dictionary<string, Shader>();
|
||||
= new();
|
||||
public static Dictionary<string, Mesh> Meshes
|
||||
= new Dictionary<string, Mesh>();
|
||||
= new();
|
||||
public static Dictionary<string, Material> Materials
|
||||
= new Dictionary<string, Material>();
|
||||
= new();
|
||||
|
||||
static bool loaded;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public abstract class ChartEvent {
|
||||
public BeatTime? time;
|
||||
|
||||
|
||||
[JsonIgnore]
|
||||
public float BeatPosition {
|
||||
get {
|
||||
@@ -27,7 +27,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
public BeatTime? endtime;
|
||||
|
||||
|
||||
[JsonIgnore]
|
||||
public float EndBeatPosition {
|
||||
get {
|
||||
@@ -35,10 +35,10 @@ namespace Cryville.Crtr {
|
||||
return (float)endtime.Value.Decimal + BeatOffset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[JsonIgnore]
|
||||
public float BeatOffset;
|
||||
|
||||
|
||||
[JsonIgnore]
|
||||
public abstract int Priority { get; }
|
||||
|
||||
@@ -66,8 +66,7 @@ namespace Cryville.Crtr {
|
||||
[JsonIgnore]
|
||||
public ReleaseEvent ReleaseEvent {
|
||||
get {
|
||||
if (relev == null) relev = new ReleaseEvent(this);
|
||||
return relev;
|
||||
return relev ??= new ReleaseEvent(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,15 +95,15 @@ namespace Cryville.Crtr {
|
||||
SubmitPropOp("endtime", new PropOp.BeatTime(v => endtime = v));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ReleaseEvent : ChartEvent {
|
||||
public readonly ChartEvent Original;
|
||||
|
||||
|
||||
public ReleaseEvent(ChartEvent orig) {
|
||||
Original = orig;
|
||||
time = orig.endtime;
|
||||
}
|
||||
|
||||
|
||||
public override int Priority {
|
||||
get {
|
||||
return Original.Priority + 1;
|
||||
@@ -112,7 +111,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
public abstract class EventContainer : ChartEvent {
|
||||
public List<Chart.Motion> motions = new List<Chart.Motion>();
|
||||
public List<Chart.Motion> motions = new();
|
||||
|
||||
[JsonIgnore]
|
||||
public Clip Clip { get; private set; }
|
||||
@@ -120,7 +119,7 @@ namespace Cryville.Crtr {
|
||||
public EventContainer() {
|
||||
SubmitPropOp("clip", new PropOp.Clip(v => Clip = v));
|
||||
}
|
||||
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual IEnumerable<ChartEvent> Events {
|
||||
get {
|
||||
@@ -128,12 +127,10 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public virtual EventList GetEventsOfType(string type) {
|
||||
switch (type) {
|
||||
case "motions": return new EventList<Chart.Motion>(motions);
|
||||
default: throw new ArgumentException(string.Format("Unknown event type \"{0}\"", type));
|
||||
}
|
||||
}
|
||||
public virtual EventList GetEventsOfType(string type) => type switch {
|
||||
"motions" => new EventList<Chart.Motion>(motions),
|
||||
_ => throw new ArgumentException(string.Format("Unknown event type \"{0}\"", type)),
|
||||
};
|
||||
}
|
||||
public abstract class EventList : ChartEvent {
|
||||
public IList<ChartEvent> Events { get; private set; }
|
||||
@@ -178,8 +175,8 @@ namespace Cryville.Crtr {
|
||||
|
||||
public string ruleset;
|
||||
|
||||
public List<Group> groups = new List<Group>();
|
||||
|
||||
public List<Group> groups = new();
|
||||
|
||||
public override IEnumerable<ChartEvent> Events {
|
||||
get {
|
||||
return base.Events
|
||||
@@ -189,33 +186,29 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public override EventList GetEventsOfType(string type) {
|
||||
switch (type) {
|
||||
case "groups": return new EventList<Group>(groups);
|
||||
default: return base.GetEventsOfType(type);
|
||||
}
|
||||
}
|
||||
public override EventList GetEventsOfType(string type) => type switch {
|
||||
"groups" => new EventList<Group>(groups),
|
||||
_ => base.GetEventsOfType(type),
|
||||
};
|
||||
|
||||
public override int Priority { get { return 10; } }
|
||||
|
||||
public class Group : EventContainer {
|
||||
public List<Track> tracks = new List<Track>();
|
||||
public List<Note> notes = new List<Note>();
|
||||
public List<Track> tracks = new();
|
||||
public List<Note> notes = new();
|
||||
public override IEnumerable<ChartEvent> Events {
|
||||
get {
|
||||
return base.Events
|
||||
return base.Events
|
||||
.Concat(notes.Cast<ChartEvent>()
|
||||
.Concat(tracks.Cast<ChartEvent>()
|
||||
));
|
||||
}
|
||||
}
|
||||
public override EventList GetEventsOfType(string type) {
|
||||
switch (type) {
|
||||
case "tracks": return new EventList<Track>(tracks);
|
||||
case "notes": return new EventList<Note>(notes);
|
||||
default: return base.GetEventsOfType(type);
|
||||
}
|
||||
}
|
||||
public override EventList GetEventsOfType(string type) => type switch {
|
||||
"tracks" => new EventList<Track>(tracks),
|
||||
"notes" => new EventList<Note>(notes),
|
||||
_ => base.GetEventsOfType(type),
|
||||
};
|
||||
public override int Priority { get { return 12; } }
|
||||
}
|
||||
|
||||
@@ -228,8 +221,8 @@ namespace Cryville.Crtr {
|
||||
string m_motion;
|
||||
[JsonRequired]
|
||||
public string motion {
|
||||
get { return m_motion == null ? ToString() : m_motion; }
|
||||
set { LoadFromString(value); }
|
||||
get => m_motion ?? ToString();
|
||||
set => LoadFromString(value);
|
||||
}
|
||||
#pragma warning restore IDE1006
|
||||
private void LoadFromString(string s) {
|
||||
@@ -264,12 +257,11 @@ namespace Cryville.Crtr {
|
||||
[JsonIgnore]
|
||||
public Identifier Name {
|
||||
get {
|
||||
if (name == default(Identifier)) throw new InvalidOperationException("Motion name not set");
|
||||
if (name == default) throw new InvalidOperationException("Motion name not set");
|
||||
return name;
|
||||
}
|
||||
private set {
|
||||
MotionRegistry reg;
|
||||
if (!ChartPlayer.motionRegistry.TryGetValue(value, out reg))
|
||||
if (!ChartPlayer.motionRegistry.TryGetValue(value, out MotionRegistry reg))
|
||||
throw new ArgumentException("Invalid motion name");
|
||||
Node = new MotionNode { Value = reg.InitValue };
|
||||
name = value;
|
||||
@@ -293,7 +285,7 @@ namespace Cryville.Crtr {
|
||||
SubmitPropOp("name", new PropOp.Identifier(v => {
|
||||
var n = new Identifier(v);
|
||||
if (name == n) { }
|
||||
else if (name == default(Identifier)) Name = n;
|
||||
else if (name == default) Name = n;
|
||||
else throw new RulesetViolationException(string.Format(
|
||||
"Motion name not matched, expected {0}, got {1}", n, Name
|
||||
));
|
||||
@@ -306,7 +298,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
public class Note : EventContainer {
|
||||
public List<Judge> judges = new List<Judge>();
|
||||
public List<Judge> judges = new();
|
||||
public override IEnumerable<ChartEvent> Events {
|
||||
get {
|
||||
return base.Events
|
||||
@@ -315,12 +307,10 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
|
||||
public override EventList GetEventsOfType(string type) {
|
||||
switch (type) {
|
||||
case "judges": return new EventList<Judge>(judges);
|
||||
default: return base.GetEventsOfType(type);
|
||||
}
|
||||
}
|
||||
public override EventList GetEventsOfType(string type) => type switch {
|
||||
"judges" => new EventList<Judge>(judges),
|
||||
_ => base.GetEventsOfType(type),
|
||||
};
|
||||
public override int Priority { get { return 20; } }
|
||||
}
|
||||
|
||||
@@ -345,7 +335,7 @@ namespace Cryville.Crtr {
|
||||
|
||||
// TODO [Obsolete]
|
||||
public List<Signature> sigs; // Signatures
|
||||
// TODO [Obsolete]
|
||||
// TODO [Obsolete]
|
||||
public class Signature : ChartEvent {
|
||||
public float? tempo;
|
||||
|
||||
|
||||
@@ -11,11 +11,11 @@ namespace Cryville.Crtr {
|
||||
public static IMotionStringParser MotionStringParser { get; private set; }
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
|
||||
var obj = JToken.ReadFrom(reader);
|
||||
switch (obj["format"].ToObject<int>()) {
|
||||
case 2: MotionStringParser = MotionStringParser2.Instance; break;
|
||||
case 3: MotionStringParser = MotionStringParser3.Instance; break;
|
||||
default: throw new FormatException("Unsupported chart format");
|
||||
}
|
||||
MotionStringParser = obj["format"].ToObject<int>() switch {
|
||||
2 => MotionStringParser2.Instance,
|
||||
3 => MotionStringParser3.Instance,
|
||||
_ => throw new FormatException("Unsupported chart format"),
|
||||
};
|
||||
return base.ReadJson(obj.CreateReader(), objectType, existingValue, serializer);
|
||||
}
|
||||
public override Chart Create(Type objectType) {
|
||||
@@ -28,12 +28,11 @@ namespace Cryville.Crtr {
|
||||
static MotionStringParser2 _instance;
|
||||
public static MotionStringParser2 Instance {
|
||||
get {
|
||||
if (_instance == null)
|
||||
_instance = new MotionStringParser2();
|
||||
_instance ??= new MotionStringParser2();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
static readonly PdtFragmentInterpreter _itor = new PdtFragmentInterpreter();
|
||||
static readonly PdtFragmentInterpreter _itor = new();
|
||||
static readonly PropOp _vecop = new VectorOp(v => _vecbuf = v);
|
||||
static float[] _vecbuf;
|
||||
public void Parse(string str, out Identifier name, out MotionNode node) {
|
||||
@@ -74,12 +73,11 @@ namespace Cryville.Crtr {
|
||||
static MotionStringParser3 _instance;
|
||||
public static MotionStringParser3 Instance {
|
||||
get {
|
||||
if (_instance == null)
|
||||
_instance = new MotionStringParser3();
|
||||
_instance ??= new MotionStringParser3();
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
static readonly PdtFragmentInterpreter _itor = new PdtFragmentInterpreter();
|
||||
static readonly PdtFragmentInterpreter _itor = new();
|
||||
static readonly PropOp _vecop = new VectorOp(v => _vecbuf = v);
|
||||
static float[] _vecbuf;
|
||||
public void Parse(string str, out Identifier name, out MotionNode node) {
|
||||
|
||||
@@ -97,12 +97,12 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
void OnDestroy() {
|
||||
if (cbus != null) cbus.Dispose();
|
||||
if (bbus != null) bbus.Dispose();
|
||||
if (tbus != null) tbus.Dispose();
|
||||
if (nbus != null) nbus.Dispose();
|
||||
if (loadThread != null) loadThread.Abort();
|
||||
if (inputProxy != null) inputProxy.Dispose();
|
||||
cbus?.Dispose();
|
||||
bbus?.Dispose();
|
||||
tbus?.Dispose();
|
||||
nbus?.Dispose();
|
||||
loadThread?.Abort();
|
||||
inputProxy?.Dispose();
|
||||
if (texs != null) foreach (var t in texs) Texture.Destroy(t.Value);
|
||||
Game.MainLogger.RemoveListener(loggerListener);
|
||||
loggerListener.Dispose();
|
||||
@@ -200,24 +200,22 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
readonly TargetString statusstr = new TargetString();
|
||||
readonly StringBuffer statusbuf = new StringBuffer();
|
||||
readonly TargetString logsstr = new TargetString();
|
||||
readonly StringBuffer logsbuf = new StringBuffer();
|
||||
readonly List<string> logEntries = new List<string>();
|
||||
readonly StringBuffer statusbuf = new();
|
||||
readonly StringBuffer logsbuf = new();
|
||||
readonly List<string> logEntries = new();
|
||||
readonly ArrayPool<char> logBufferPool = new();
|
||||
int logsLength = 0;
|
||||
LogHandler d_addLogEntry;
|
||||
void AddLogEntry(int level, string module, string msg) {
|
||||
string color;
|
||||
switch (level) {
|
||||
case 0: color = "#888888"; break;
|
||||
case 1: color = "#bbbbbb"; break;
|
||||
case 2: color = "#0088ff"; break;
|
||||
case 3: color = "#ffff00"; break;
|
||||
case 4: color = "#ff0000"; break;
|
||||
case 5: color = "#bb0000"; break;
|
||||
default: color = "#ff00ff"; break;
|
||||
}
|
||||
string color = level switch {
|
||||
0 => "#888888",
|
||||
1 => "#bbbbbb",
|
||||
2 => "#0088ff",
|
||||
3 => "#ffff00",
|
||||
4 => "#ff0000",
|
||||
5 => "#bb0000",
|
||||
_ => "#ff00ff",
|
||||
};
|
||||
var l = string.Format(
|
||||
"\n<color={1}bb><{2}> {3}</color>",
|
||||
DateTime.UtcNow.ToString("s"), color, module, msg
|
||||
@@ -235,10 +233,10 @@ namespace Cryville.Crtr {
|
||||
foreach (var l in logEntries) {
|
||||
logsbuf.Append(l);
|
||||
}
|
||||
logsstr.Length = logsbuf.Count;
|
||||
var larr = logsstr.TrustedAsArray();
|
||||
logsbuf.CopyTo(0, larr, 0, logsbuf.Count);
|
||||
logs.SetText(larr, 0, logsbuf.Count);
|
||||
var lbuf = logBufferPool.Rent(logsbuf.Count);
|
||||
logsbuf.CopyTo(0, lbuf, 0, logsbuf.Count);
|
||||
logs.SetText(lbuf, 0, logsbuf.Count);
|
||||
logBufferPool.Return(lbuf);
|
||||
|
||||
statusbuf.Clear();
|
||||
statusbuf.AppendFormat(
|
||||
@@ -286,14 +284,15 @@ namespace Cryville.Crtr {
|
||||
);
|
||||
if (judge != null) {
|
||||
statusbuf.Append("\n== Scores ==\n");
|
||||
var fullScoreStr = judge.GetFullFormattedScoreString();
|
||||
statusbuf.Append(fullScoreStr.TrustedAsArray(), 0, fullScoreStr.Length);
|
||||
var fullScoreStrLen = judge.GetFullFormattedScoreString(logBufferPool, out char[] fullScoreStr);
|
||||
statusbuf.Append(fullScoreStr, 0, fullScoreStrLen);
|
||||
logBufferPool.Return(fullScoreStr);
|
||||
}
|
||||
}
|
||||
statusstr.Length = statusbuf.Count;
|
||||
var sarr = statusstr.TrustedAsArray();
|
||||
statusbuf.CopyTo(0, sarr, 0, statusbuf.Count);
|
||||
status.SetText(sarr, 0, statusbuf.Count);
|
||||
var buf = logBufferPool.Rent(statusbuf.Count);
|
||||
statusbuf.CopyTo(0, buf, 0, statusbuf.Count);
|
||||
status.SetText(buf, 0, statusbuf.Count);
|
||||
logBufferPool.Return(buf);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -386,8 +385,7 @@ namespace Cryville.Crtr {
|
||||
|
||||
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
|
||||
var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1));
|
||||
float dist;
|
||||
hitPlane.Raycast(r0, out dist);
|
||||
hitPlane.Raycast(r0, out float dist);
|
||||
var p0 = r0.GetPoint(dist);
|
||||
var r1 = Camera.main.ViewportPointToRay(new Vector3(1, 1, 1));
|
||||
hitPlane.Raycast(r1, out dist);
|
||||
@@ -397,18 +395,18 @@ namespace Cryville.Crtr {
|
||||
screenSize = new Vector2(Screen.width, Screen.height);
|
||||
frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
|
||||
|
||||
FileInfo chartFile = new FileInfo(Settings.Default.LoadChart);
|
||||
FileInfo chartFile = new(Settings.Default.LoadChart);
|
||||
|
||||
FileInfo rulesetFile = new FileInfo(Path.Combine(
|
||||
FileInfo rulesetFile = new(Path.Combine(
|
||||
Game.GameDataPath, "rulesets", Settings.Default.LoadRuleset
|
||||
));
|
||||
if (!rulesetFile.Exists) throw new FileNotFoundException("Ruleset for the chart not found\nMake sure you have imported the ruleset");
|
||||
|
||||
FileInfo rulesetConfigFile = new FileInfo(Path.Combine(
|
||||
FileInfo rulesetConfigFile = new(Path.Combine(
|
||||
Game.GameDataPath, "config", "rulesets", Settings.Default.LoadRulesetConfig
|
||||
));
|
||||
if (!rulesetConfigFile.Exists) throw new FileNotFoundException("Ruleset config not found\nPlease open the config to generate");
|
||||
using (StreamReader cfgreader = new StreamReader(rulesetConfigFile.FullName, Encoding.UTF8)) {
|
||||
using (StreamReader cfgreader = new(rulesetConfigFile.FullName, Encoding.UTF8)) {
|
||||
_rscfg = JsonConvert.DeserializeObject<RulesetConfig>(cfgreader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
@@ -416,11 +414,11 @@ namespace Cryville.Crtr {
|
||||
sv = _rscfg.generic.ScrollVelocity;
|
||||
soundOffset += _rscfg.generic.SoundOffset;
|
||||
|
||||
FileInfo skinFile = new FileInfo(Path.Combine(
|
||||
FileInfo skinFile = new(Path.Combine(
|
||||
Game.GameDataPath, "skins", rulesetFile.Directory.Name, _rscfg.generic.Skin, ".umgs"
|
||||
));
|
||||
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
|
||||
using (StreamReader reader = new StreamReader(skinFile.FullName, Encoding.UTF8)) {
|
||||
using (StreamReader reader = new(skinFile.FullName, Encoding.UTF8)) {
|
||||
skin = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
@@ -446,7 +444,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
IEnumerator<float> LoadTextures(List<string> queue) {
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
Stopwatch stopwatch = new();
|
||||
stopwatch.Start();
|
||||
#if UNITY_5_4_OR_NEWER
|
||||
DownloadHandlerTexture texHandler = null;
|
||||
@@ -499,7 +497,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
IEnumerator<float> Prehandle() {
|
||||
Stopwatch timer = new Stopwatch();
|
||||
Stopwatch timer = new();
|
||||
timer.Reset(); timer.Start();
|
||||
Game.MainLogger.Log(0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return 0;
|
||||
cbus.BroadcastPreInit();
|
||||
@@ -618,73 +616,72 @@ namespace Cryville.Crtr {
|
||||
{ new Identifier("track") , new MotionRegistry(typeof(Vec1)) },
|
||||
};
|
||||
|
||||
using (StreamReader reader = new StreamReader(info.chartFile.FullName, Encoding.UTF8)) {
|
||||
PdtEvaluator.Instance.Reset();
|
||||
using StreamReader reader = new(info.chartFile.FullName, Encoding.UTF8);
|
||||
PdtEvaluator.Instance.Reset();
|
||||
|
||||
LoadRuleset(info.rulesetFile); loadPregress = .05f;
|
||||
LoadRuleset(info.rulesetFile); loadPregress = .05f;
|
||||
|
||||
chart = JsonConvert.DeserializeObject<Chart>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
chart = JsonConvert.DeserializeObject<Chart>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Applying ruleset (iteration 1)"); loadPregress = .10f;
|
||||
pruleset.PrePatch(chart);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Applying ruleset (iteration 1)"); loadPregress = .10f;
|
||||
pruleset.PrePatch(chart);
|
||||
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Batching events"); loadPregress = .20f;
|
||||
var batcher = new EventBatcher(chart);
|
||||
batcher.Forward();
|
||||
cbus = batcher.Batch(); loadPregress = .30f;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Batching events"); loadPregress = .20f;
|
||||
var batcher = new EventBatcher(chart);
|
||||
batcher.Forward();
|
||||
cbus = batcher.Batch(); loadPregress = .30f;
|
||||
|
||||
LoadSkin(info.skinFile);
|
||||
LoadSkin(info.skinFile);
|
||||
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
|
||||
judge = new Judge(this, pruleset);
|
||||
PdtEvaluator.Instance.ContextJudge = judge;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
|
||||
judge = new Judge(this, pruleset);
|
||||
PdtEvaluator.Instance.ContextJudge = judge;
|
||||
|
||||
inputProxy = new InputProxy(pruleset, judge, screenSize);
|
||||
inputProxy.LoadFrom(_rscfg.inputs);
|
||||
if (!inputProxy.IsCompleted()) {
|
||||
Game.MainLogger.Log(2, "Game", "Input config not completed. Input disabled");
|
||||
inputProxy.Clear();
|
||||
}
|
||||
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Attaching handlers"); loadPregress = .40f;
|
||||
var ch = new ChartHandler(chart);
|
||||
cbus.RootState.AttachHandler(ch);
|
||||
foreach (var gs in cbus.RootState.Children) {
|
||||
var gh = new GroupHandler((Chart.Group)gs.Key, ch);
|
||||
gs.Value.AttachHandler(gh);
|
||||
foreach (var ts in gs.Value.Children) {
|
||||
ContainerHandler th;
|
||||
if (ts.Key is Chart.Note) {
|
||||
th = new NoteHandler((Chart.Note)ts.Key, gh);
|
||||
}
|
||||
else {
|
||||
th = new TrackHandler((Chart.Track)ts.Key, gh);
|
||||
}
|
||||
ts.Value.AttachHandler(th);
|
||||
}
|
||||
}
|
||||
cbus.AttachSystems(pskin, judge);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Prehandling (iteration 1)"); loadPregress = .60f;
|
||||
using (var pbus = cbus.Clone(16)) {
|
||||
pbus.Forward();
|
||||
}
|
||||
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 1)"); loadPregress = .70f;
|
||||
bbus = cbus.Clone(1, -clippingDist);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 2)"); loadPregress = .80f;
|
||||
tbus = bbus.Clone(2);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 3)"); loadPregress = .90f;
|
||||
nbus = bbus.Clone(3);
|
||||
loadPregress = 1;
|
||||
inputProxy = new InputProxy(pruleset, judge, screenSize);
|
||||
inputProxy.LoadFrom(_rscfg.inputs);
|
||||
if (!inputProxy.IsCompleted()) {
|
||||
Game.MainLogger.Log(2, "Game", "Input config not completed. Input disabled");
|
||||
inputProxy.Clear();
|
||||
}
|
||||
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Attaching handlers"); loadPregress = .40f;
|
||||
var ch = new ChartHandler(chart);
|
||||
cbus.RootState.AttachHandler(ch);
|
||||
foreach (var gs in cbus.RootState.Children) {
|
||||
var gh = new GroupHandler((Chart.Group)gs.Key, ch);
|
||||
gs.Value.AttachHandler(gh);
|
||||
foreach (var ts in gs.Value.Children) {
|
||||
ContainerHandler th;
|
||||
if (ts.Key is Chart.Note) {
|
||||
th = new NoteHandler((Chart.Note)ts.Key, gh);
|
||||
}
|
||||
else {
|
||||
th = new TrackHandler((Chart.Track)ts.Key, gh);
|
||||
}
|
||||
ts.Value.AttachHandler(th);
|
||||
}
|
||||
}
|
||||
cbus.AttachSystems(pskin, judge);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Prehandling (iteration 1)"); loadPregress = .60f;
|
||||
using (var pbus = cbus.Clone(16)) {
|
||||
pbus.Forward();
|
||||
}
|
||||
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 1)"); loadPregress = .70f;
|
||||
bbus = cbus.Clone(1, -clippingDist);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 2)"); loadPregress = .80f;
|
||||
tbus = bbus.Clone(2);
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Cloning states (type 3)"); loadPregress = .90f;
|
||||
nbus = bbus.Clone(3);
|
||||
loadPregress = 1;
|
||||
}
|
||||
|
||||
void LoadRuleset(FileInfo file) {
|
||||
DirectoryInfo dir = file.Directory;
|
||||
Game.MainLogger.Log(0, "Load/WorkerThread", "Loading ruleset: {0}", file);
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
using (StreamReader reader = new(file.FullName, Encoding.UTF8)) {
|
||||
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
|
||||
MissingMemberHandling = MissingMemberHandling.Error
|
||||
});
|
||||
|
||||
@@ -12,8 +12,7 @@ namespace Cryville.Crtr.Config {
|
||||
readonly object _target;
|
||||
|
||||
public DefaultPropertyMasterAdapter(object target) {
|
||||
if (target == null) throw new ArgumentNullException("target");
|
||||
_target = target;
|
||||
_target = target ?? throw new ArgumentNullException("target");
|
||||
}
|
||||
|
||||
public string DefaultCategory { get { return "miscellaneous"; } }
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.ComponentModel;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class RulesetConfig {
|
||||
public Generic generic = new Generic();
|
||||
public Generic generic = new();
|
||||
public class Generic {
|
||||
[Category("basic")]
|
||||
[JsonProperty("skin")]
|
||||
@@ -30,9 +30,9 @@ namespace Cryville.Crtr.Config {
|
||||
}
|
||||
}
|
||||
public Dictionary<string, object> configs
|
||||
= new Dictionary<string, object>();
|
||||
= new();
|
||||
public Dictionary<string, InputEntry> inputs
|
||||
= new Dictionary<string, InputEntry>();
|
||||
= new();
|
||||
public class InputEntry {
|
||||
public string handler;
|
||||
public int type;
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
internal class RulesetConfigPropertyMasterAdapter : IPropertyMasterAdapter {
|
||||
readonly List<RulesetConfigPropertyAdapter> _props = new List<RulesetConfigPropertyAdapter>();
|
||||
readonly List<RulesetConfigPropertyAdapter> _props = new();
|
||||
readonly RulesetConfigStore _store;
|
||||
public PdtEvaluator Evaluator { get; private set; }
|
||||
|
||||
@@ -43,11 +43,11 @@ namespace Cryville.Crtr.Config {
|
||||
_master = master;
|
||||
_def = def;
|
||||
Name = (string)key.Name;
|
||||
switch (_def.type) {
|
||||
case ConfigType.number: Type = PropertyType.Number; break;
|
||||
case ConfigType.number_stepped: Type = PropertyType.NumberStepped; break;
|
||||
default: Type = PropertyType.Unknown; break;
|
||||
}
|
||||
Type = _def.type switch {
|
||||
ConfigType.number => PropertyType.Number,
|
||||
ConfigType.number_stepped => PropertyType.NumberStepped,
|
||||
_ => PropertyType.Unknown,
|
||||
};
|
||||
_rangeOp = new PropOp.Clip(v => {
|
||||
m_range[0] = (double)v.Behind;
|
||||
m_range[1] = (double)v.Ahead;
|
||||
@@ -85,7 +85,7 @@ namespace Cryville.Crtr.Config {
|
||||
|
||||
public bool SetMapped { get { return false; } }
|
||||
|
||||
readonly PropStores.Float _numst = new PropStores.Float();
|
||||
readonly PropStores.Float _numst = new();
|
||||
public object MapValue(object value) {
|
||||
_numst.Value = (float)(double)value;
|
||||
if (_def.value == null) return _numst.Value;
|
||||
|
||||
@@ -6,8 +6,8 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Cryville.Crtr.Config {
|
||||
public class RulesetConfigStore {
|
||||
readonly IntKeyedDictionary<PropSrc> _srcs = new IntKeyedDictionary<PropSrc>();
|
||||
readonly Dictionary<string, int> _revMap = new Dictionary<string, int>();
|
||||
readonly IntKeyedDictionary<PropSrc> _srcs = new();
|
||||
readonly Dictionary<string, int> _revMap = new();
|
||||
readonly Dictionary<string, object> _values;
|
||||
public RulesetConfigStore(Dictionary<Identifier, ConfigDefinition> defs, Dictionary<string, object> values) {
|
||||
_values = values;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Cryville.Crtr.Config.UI {
|
||||
|
||||
PdtRuleset _ruleset;
|
||||
InputProxy _proxy;
|
||||
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
|
||||
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new();
|
||||
|
||||
public void Load(PdtRuleset ruleset, RulesetConfig rulesetConfig) {
|
||||
_ruleset = ruleset;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Cryville.Crtr.Config.UI {
|
||||
int _targetDim;
|
||||
PhysicalDimension? _targetPDim;
|
||||
bool _targetNotNull;
|
||||
readonly Dictionary<InputSource, InputDialogEntry> _recvsrcs = new Dictionary<InputSource, InputDialogEntry>();
|
||||
readonly Dictionary<InputSource, InputDialogEntry> _recvsrcs = new();
|
||||
void ShowInternal(Action<InputSource?> callback, string message, InputDefinition def, InputProxy proxy) {
|
||||
_active = true;
|
||||
_callback = callback;
|
||||
@@ -56,7 +56,7 @@ namespace Cryville.Crtr.Config.UI {
|
||||
var result = new PhysicalDimension();
|
||||
foreach (var comp in comps) {
|
||||
int dim = 1;
|
||||
if (comp.Length > 1) dim = int.Parse(comp.Substring(1));
|
||||
if (comp.Length > 1) dim = int.Parse(comp[1..]);
|
||||
switch (comp[0]) {
|
||||
case 'T': result.Time += dim; break;
|
||||
case 'L': result.Length += dim; break;
|
||||
@@ -98,8 +98,7 @@ namespace Cryville.Crtr.Config.UI {
|
||||
Action<InputEvent> _d_HandleInputEvent;
|
||||
void HandleInputEvent(InputEvent ev) {
|
||||
InputSource src = ev.Identifier.Source;
|
||||
InputDialogEntry entry;
|
||||
if (!_recvsrcs.TryGetValue(src, out entry)) {
|
||||
if (!_recvsrcs.TryGetValue(src, out InputDialogEntry entry)) {
|
||||
_recvsrcs.Add(src, entry = AddSourceItem(src));
|
||||
if (_proxy.IsUsed(src)) {
|
||||
entry.Status |= InputDeviceStatus.Used;
|
||||
|
||||
@@ -74,8 +74,7 @@ namespace Cryville.Crtr.Config.UI {
|
||||
Dictionary<int, InputVector> _activeInputs;
|
||||
public void OnInputEvent(InputEvent ev) {
|
||||
var id = ev.Identifier.Id;
|
||||
InputVector lastVec;
|
||||
if (!_activeInputs.TryGetValue(id, out lastVec)) {
|
||||
if (!_activeInputs.TryGetValue(id, out InputVector lastVec)) {
|
||||
if (ev.To.IsNull) return;
|
||||
_activeInputs.Add(id, lastVec = ev.To.Vector);
|
||||
}
|
||||
|
||||
@@ -111,9 +111,8 @@ namespace Cryville.Crtr.Config.UI {
|
||||
}
|
||||
|
||||
float GetRatioFromPos(Vector2 pos) {
|
||||
Vector2 lp;
|
||||
RectTransform handleArea = parent.m_handleArea;
|
||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(handleArea, pos, cam, out lp)) {
|
||||
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(handleArea, pos, cam, out Vector2 lp)) {
|
||||
lp -= handleArea.rect.position;
|
||||
return Mathf.Clamp01(lp.x / handleArea.rect.width);
|
||||
}
|
||||
@@ -121,8 +120,7 @@ namespace Cryville.Crtr.Config.UI {
|
||||
}
|
||||
|
||||
void SetValueFromPos(Vector2 pos) {
|
||||
double min, max;
|
||||
parent.GetRange(out min, out max);
|
||||
parent.GetRange(out double min, out double max);
|
||||
double ratio = GetRatioFromPos(pos);
|
||||
double result = parent.GetValue(ratio, Time.deltaTime, min, max);
|
||||
if (result < min) result = min;
|
||||
|
||||
@@ -34,14 +34,13 @@ namespace Cryville.Crtr.Config.UI {
|
||||
}
|
||||
}
|
||||
|
||||
readonly Dictionary<string, List<IPropertyAdapter>> _categories = new Dictionary<string, List<IPropertyAdapter>>();
|
||||
readonly Dictionary<string, List<IPropertyAdapter>> _categories = new();
|
||||
public void LoadProperties() {
|
||||
_categories.Clear();
|
||||
_invalidated = false;
|
||||
if (Adapter == null) return;
|
||||
foreach (var p in Adapter.GetProperties()) {
|
||||
string category = p.Category;
|
||||
if (category == null) category = Adapter.DefaultCategory;
|
||||
string category = p.Category ?? Adapter.DefaultCategory;
|
||||
if (!_categories.ContainsKey(category))
|
||||
_categories.Add(category, new List<IPropertyAdapter>());
|
||||
_categories[category].Add(p);
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace Cryville.Crtr.Event {
|
||||
protected override TransformHandler Parent { get { return null; } }
|
||||
|
||||
readonly Chart chart;
|
||||
readonly List<LibavFileAudioSource> sounds = new List<LibavFileAudioSource>();
|
||||
readonly List<LibavFileAudioSource> sounds = new();
|
||||
|
||||
public ChartHandler(Chart _chart) {
|
||||
chart = _chart;
|
||||
@@ -25,8 +25,7 @@ namespace Cryville.Crtr.Event {
|
||||
if (s.CloneType == 16) {
|
||||
if (ev == null) { }
|
||||
else if (ev.Unstamped == null) { }
|
||||
else if (ev.Unstamped is Chart.Sound) {
|
||||
Chart.Sound tev = (Chart.Sound)ev.Unstamped;
|
||||
else if (ev.Unstamped is Chart.Sound tev) {
|
||||
var dir = new DirectoryInfo(Path.Combine(Game.GameDataPath, "songs", StringUtils.EscapeFileName(tev.id)));
|
||||
var files = dir.GetFiles();
|
||||
var source = new LibavFileAudioSource(files[0].FullName);
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
protected Transform RootTransform;
|
||||
|
||||
readonly List<SkinComponent> _comps = new List<SkinComponent>();
|
||||
readonly List<SkinComponent> _comps = new();
|
||||
protected IEnumerable<SkinComponent> Components { get { return _comps; } }
|
||||
|
||||
public Vector3 Position { get; protected set; }
|
||||
@@ -68,7 +68,7 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
static readonly int _var_current_time = IdentifierManager.Shared.Request("current_time");
|
||||
static readonly int _var_invisible_bounds = IdentifierManager.Shared.Request("invisible_bounds");
|
||||
public readonly IntKeyedDictionary<PropSrc> PropSrcs = new IntKeyedDictionary<PropSrc>();
|
||||
public readonly IntKeyedDictionary<PropSrc> PropSrcs = new();
|
||||
SkinContainer skinContainer;
|
||||
protected Judge judge;
|
||||
public void AttachSystems(PdtSkin skin, Judge judge) {
|
||||
@@ -76,9 +76,9 @@ namespace Cryville.Crtr.Event {
|
||||
this.judge = judge;
|
||||
}
|
||||
|
||||
public readonly IntKeyedDictionary<List<Anchor>> Anchors = new IntKeyedDictionary<List<Anchor>>();
|
||||
public readonly IntKeyedDictionary<Anchor> DynamicAnchors = new IntKeyedDictionary<Anchor>();
|
||||
public readonly IntKeyedDictionary<double> DynamicAnchorSetTime = new IntKeyedDictionary<double>();
|
||||
public readonly IntKeyedDictionary<List<Anchor>> Anchors = new();
|
||||
public readonly IntKeyedDictionary<Anchor> DynamicAnchors = new();
|
||||
public readonly IntKeyedDictionary<double> DynamicAnchorSetTime = new();
|
||||
Anchor a_cur;
|
||||
Anchor a_head;
|
||||
Anchor a_tail;
|
||||
@@ -98,8 +98,7 @@ namespace Cryville.Crtr.Event {
|
||||
DynamicAnchors.Add(name, result);
|
||||
DynamicAnchorSetTime.Add(name, double.NaN);
|
||||
}
|
||||
List<Anchor> list;
|
||||
if (!Anchors.TryGetValue(name, out list))
|
||||
if (!Anchors.TryGetValue(name, out List<Anchor> list))
|
||||
Anchors.Add(name, list = new List<Anchor>());
|
||||
list.Add(result);
|
||||
return result;
|
||||
@@ -158,8 +157,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
#endregion
|
||||
public virtual void Update(ContainerState s, StampedEvent ev) {
|
||||
if (ev is StampedEvent.Anchor) {
|
||||
var tev = (StampedEvent.Anchor)ev;
|
||||
if (ev is StampedEvent.Anchor tev) {
|
||||
if (tev.Target == a_head) {
|
||||
if (s.CloneType == 2) SetGraphicalActive(true, s);
|
||||
else SetPreGraphicalActive(true, s);
|
||||
@@ -234,7 +232,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
static readonly SimpleObjectPool<StampedEvent.Anchor> anchorEvPool
|
||||
= new SimpleObjectPool<StampedEvent.Anchor>(1024);
|
||||
= new(1024);
|
||||
void PushAnchorEvent(ContainerState state, double time, Anchor anchor, int priority = 0, bool forced = false) {
|
||||
var tev = anchorEvPool.Rent();
|
||||
tev.Time = time;
|
||||
@@ -245,8 +243,8 @@ namespace Cryville.Crtr.Event {
|
||||
state.Bus.PushTempEvent(tev);
|
||||
}
|
||||
public virtual void Discard(ContainerState s, StampedEvent ev) {
|
||||
if (ev is StampedEvent.Anchor) {
|
||||
ReturnAnchorEvent((StampedEvent.Anchor)ev);
|
||||
if (ev is StampedEvent.Anchor anchor) {
|
||||
ReturnAnchorEvent(anchor);
|
||||
}
|
||||
}
|
||||
void ReturnAnchorEvent(StampedEvent.Anchor ev) {
|
||||
@@ -264,8 +262,7 @@ namespace Cryville.Crtr.Event {
|
||||
Anchor _openedAnchor;
|
||||
public int OpenedAnchorName { get { return _openedAnchor == null ? 0 : _openedAnchor.Name; } }
|
||||
public bool TryGetAnchorsByName(int name, out IReadOnlyCollection<Anchor> result) {
|
||||
List<Anchor> anchors;
|
||||
var ret = Anchors.TryGetValue(name, out anchors);
|
||||
var ret = Anchors.TryGetValue(name, out List<Anchor> anchors);
|
||||
result = anchors;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ namespace Cryville.Crtr.Event {
|
||||
public ushort Depth;
|
||||
|
||||
public Dictionary<EventContainer, ContainerState> Children
|
||||
= new Dictionary<EventContainer, ContainerState>();
|
||||
= new();
|
||||
HashSet<EventContainer> ActiveChildren
|
||||
= new HashSet<EventContainer>();
|
||||
= new();
|
||||
public Dictionary<Type, List<ContainerState>> TypedChildren
|
||||
= new Dictionary<Type, List<ContainerState>>();
|
||||
= new();
|
||||
|
||||
public ContainerState GetChild(int index, Type handlerType) {
|
||||
var list = TypedChildren[handlerType];
|
||||
@@ -110,8 +110,7 @@ namespace Cryville.Crtr.Event {
|
||||
void AddChild(EventContainer c, ContainerState parent) {
|
||||
parent.Children.Add(c, this);
|
||||
Type t = c.GetType();
|
||||
List<ContainerState> tc;
|
||||
if (!parent.TypedChildren.TryGetValue(t, out tc))
|
||||
if (!parent.TypedChildren.TryGetValue(t, out List<ContainerState> tc))
|
||||
parent.TypedChildren.Add(t, tc = new List<ContainerState>());
|
||||
tc.Add(this);
|
||||
}
|
||||
@@ -159,15 +158,13 @@ namespace Cryville.Crtr.Event {
|
||||
if (dest.m_active) dest.Bus.NotifyActiveChanged(dest);
|
||||
|
||||
foreach (var mv in Values) {
|
||||
RealtimeMotionValue dv;
|
||||
if (dest.Values.TryGetValue(mv.Key, out dv)) mv.Value.CopyTo(dv, false);
|
||||
if (dest.Values.TryGetValue(mv.Key, out RealtimeMotionValue dv)) mv.Value.CopyTo(dv, false);
|
||||
else dest.Values.Add(mv.Key, mv.Value.Clone());
|
||||
}
|
||||
|
||||
foreach (var cv in dest.CachedValues) cv.Value.Valid = false;
|
||||
foreach (var cv in CachedValues) {
|
||||
MotionCache dv;
|
||||
if (!dest.CachedValues.TryGetValue(cv.Key, out dv)) {
|
||||
if (!dest.CachedValues.TryGetValue(cv.Key, out MotionCache dv)) {
|
||||
dest.CachedValues.Add(cv.Key, dv = dest._mcpa.Rent(cv.Key));
|
||||
}
|
||||
cv.Value.CopyTo(dv);
|
||||
@@ -229,13 +226,12 @@ namespace Cryville.Crtr.Event {
|
||||
#region Motion
|
||||
readonly CategorizedPoolAccessor<int, RealtimeMotionValue> _rmvpa;
|
||||
readonly CategorizedPoolAccessor<int, MotionCache> _mcpa;
|
||||
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new Dictionary<StampedEvent, RealtimeMotionValue>(4);
|
||||
Dictionary<StampedEvent, RealtimeMotionValue> PlayingMotions = new(4);
|
||||
IntKeyedDictionary<RealtimeMotionValue> Values;
|
||||
IntKeyedDictionary<MotionCache> CachedValues;
|
||||
|
||||
void InvalidateMotion(int name) {
|
||||
MotionCache cache;
|
||||
if (!CachedValues.TryGetValue(name, out cache))
|
||||
if (!CachedValues.TryGetValue(name, out MotionCache cache))
|
||||
CachedValues.Add(name, cache = _mcpa.Rent(name));
|
||||
cache.Valid = false;
|
||||
foreach (var c in ActiveChildren)
|
||||
@@ -243,8 +239,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
public Vector GetComputedValue(int key) {
|
||||
MotionCache tr;
|
||||
if (!CachedValues.TryGetValue(key, out tr))
|
||||
if (!CachedValues.TryGetValue(key, out MotionCache tr))
|
||||
CachedValues.Add(key, tr = _mcpa.Rent(key));
|
||||
Vector r = tr.Value;
|
||||
if (tr.Valid) return r;
|
||||
@@ -322,8 +317,8 @@ namespace Cryville.Crtr.Event {
|
||||
|
||||
public void Discard(StampedEvent ev) {
|
||||
Handler.Discard(this, ev);
|
||||
if (ev is StampedEvent.RelativeMotion) {
|
||||
ReturnRelativeMotionEvent((StampedEvent.RelativeMotion)ev);
|
||||
if (ev is StampedEvent.RelativeMotion motion) {
|
||||
ReturnRelativeMotionEvent(motion);
|
||||
}
|
||||
else if (ev.Origin is StampedEvent.RelativeMotion) {
|
||||
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
|
||||
@@ -345,8 +340,7 @@ namespace Cryville.Crtr.Event {
|
||||
_rmvpa.Return(mv);
|
||||
}
|
||||
}
|
||||
else if (ev is StampedEvent.RelativeMotion) {
|
||||
var tev = (StampedEvent.RelativeMotion)ev;
|
||||
else if (ev is StampedEvent.RelativeMotion tev) {
|
||||
var mv = _rmvpa.Rent(tev.Name);
|
||||
mv.CloneTypeFlag = CloneType;
|
||||
Values[tev.Name].CopyTo(mv, true);
|
||||
@@ -369,13 +363,13 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
else if (ev.Origin != null) {
|
||||
var oev = ev.Origin;
|
||||
if (oev is StampedEvent.RelativeMotion) {
|
||||
if (oev is StampedEvent.RelativeMotion motion) {
|
||||
Update(ev);
|
||||
var mv = PlayingMotions[oev];
|
||||
if (mv.CloneTypeFlag == CloneType) _rmvpa.Return(mv);
|
||||
PlayingMotions.Remove(oev);
|
||||
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
|
||||
ReturnRelativeMotionEvent((StampedEvent.RelativeMotion)oev);
|
||||
ReturnRelativeMotionEvent(motion);
|
||||
}
|
||||
else {
|
||||
var nev = oev.Unstamped;
|
||||
@@ -385,8 +379,7 @@ namespace Cryville.Crtr.Event {
|
||||
if (mv.CloneTypeFlag == CloneType) _rmvpa.Return(mv);
|
||||
PlayingMotions.Remove(oev);
|
||||
}
|
||||
else if (nev is EventContainer) {
|
||||
var cev = (EventContainer)nev;
|
||||
else if (nev is EventContainer cev) {
|
||||
var ccs = Children[cev];
|
||||
UpdateMotions();
|
||||
ccs.LogicalActive = false;
|
||||
@@ -455,8 +448,8 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
}
|
||||
}
|
||||
static readonly PropStores.Float _ttimest = new PropStores.Float();
|
||||
static readonly PropStores.Vector4 _transst = new PropStores.Vector4();
|
||||
static readonly PropStores.Float _ttimest = new();
|
||||
static readonly PropStores.Vector4 _transst = new();
|
||||
Vector4 GetTransition(float time, PdtExpression transition) {
|
||||
if (time >= 1) return Vector4.one;
|
||||
if (transition == null) return new Vector4(time, time, time, time);
|
||||
@@ -495,9 +488,9 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
static readonly SimpleObjectPool<StampedEvent.RelativeMotion> relmEvPool
|
||||
= new SimpleObjectPool<StampedEvent.RelativeMotion>(1024);
|
||||
= new(1024);
|
||||
static readonly SimpleObjectPool<StampedEvent.Temporary> erelmEvPool
|
||||
= new SimpleObjectPool<StampedEvent.Temporary>(1024);
|
||||
= new(1024);
|
||||
public void PreAnchor() {
|
||||
PushRelativeMotions(Handler.ns.Bus);
|
||||
Handler.PreAnchor();
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Cryville.Crtr.Event {
|
||||
private set;
|
||||
}
|
||||
|
||||
readonly List<StampedEvent> queue = new List<StampedEvent>();
|
||||
readonly List<StampedEvent> queue = new();
|
||||
public int Count {
|
||||
get { return queue.Count; }
|
||||
}
|
||||
|
||||
@@ -12,16 +12,16 @@ namespace Cryville.Crtr.Event {
|
||||
readonly Chart chart;
|
||||
ContainerState rootState;
|
||||
readonly Dictionary<ChartEvent, ContainerState> containerMap
|
||||
= new Dictionary<ChartEvent, ContainerState>();
|
||||
= new();
|
||||
readonly Dictionary<EventContainer, ContainerState> stateMap
|
||||
= new Dictionary<EventContainer, ContainerState>();
|
||||
= new();
|
||||
readonly Dictionary<ChartEvent, StampedEvent> map
|
||||
= new Dictionary<ChartEvent, StampedEvent>();
|
||||
= new();
|
||||
readonly Dictionary<EventContainer, List<StampedEvent>> coeventMap
|
||||
= new Dictionary<EventContainer, List<StampedEvent>>();
|
||||
readonly HashSet<ChartEvent> coevents = new HashSet<ChartEvent>();
|
||||
readonly List<StampedEvent> stampedEvents = new List<StampedEvent>();
|
||||
readonly List<EventBatch> batches = new List<EventBatch>();
|
||||
= new();
|
||||
readonly HashSet<ChartEvent> coevents = new();
|
||||
readonly List<StampedEvent> stampedEvents = new();
|
||||
readonly List<EventBatch> batches = new();
|
||||
|
||||
double beat;
|
||||
float tempo;
|
||||
@@ -58,8 +58,8 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
Events.Add(ev);
|
||||
containerMap.Add(ev, cs);
|
||||
if (ev is EventContainer)
|
||||
AddEventContainer((EventContainer)ev, cs);
|
||||
if (ev is EventContainer container)
|
||||
AddEventContainer(container, cs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,17 +104,16 @@ namespace Cryville.Crtr.Event {
|
||||
var pev = map[oev];
|
||||
pev.ReleaseEvent = sev;
|
||||
sev.Origin = pev;
|
||||
if (oev is EventContainer) {
|
||||
if (oev is EventContainer container) {
|
||||
stampedEvents.Add(new StampedEvent.ClipAhead {
|
||||
Container = con,
|
||||
Origin = pev,
|
||||
Time = etime + ((EventContainer)oev).Clip.Ahead,
|
||||
Time = etime + container.Clip.Ahead,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (con != null && coevents.Contains(ev)) {
|
||||
List<StampedEvent> cevs;
|
||||
if (!coeventMap.TryGetValue(con, out cevs)) {
|
||||
if (!coeventMap.TryGetValue(con, out List<StampedEvent> cevs)) {
|
||||
coeventMap.Add(con, cevs = new List<StampedEvent>());
|
||||
}
|
||||
cevs.Add(sev);
|
||||
@@ -168,9 +167,8 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
void BatchCoevents(StampedEvent ev, List<StampedEvent> ocevs = null) {
|
||||
if (!(ev.Unstamped is EventContainer)) return;
|
||||
List<StampedEvent> cevs;
|
||||
if (coeventMap.TryGetValue((EventContainer)ev.Unstamped, out cevs)) {
|
||||
if (ev.Unstamped is not EventContainer container) return;
|
||||
if (coeventMap.TryGetValue(container, out List<StampedEvent> cevs)) {
|
||||
var rootFlag = ocevs == null;
|
||||
if (rootFlag) ev.Coevents = ocevs = new List<StampedEvent>();
|
||||
foreach (var cev in cevs) {
|
||||
|
||||
@@ -12,11 +12,11 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
Dictionary<EventContainer, ContainerState> states
|
||||
= new Dictionary<EventContainer, ContainerState>();
|
||||
= new();
|
||||
HashSet<ContainerState> activeStates
|
||||
= new HashSet<ContainerState>();
|
||||
= new();
|
||||
HashSet<ContainerState> invalidatedStates
|
||||
= new HashSet<ContainerState>();
|
||||
= new();
|
||||
public int ActiveStateCount { get { return activeStates.Count; } }
|
||||
|
||||
public EventBus(ContainerState root, List<EventBatch> b) : base(b) {
|
||||
@@ -84,14 +84,14 @@ namespace Cryville.Crtr.Event {
|
||||
s.Value.AttachSystems(skin, judge);
|
||||
}
|
||||
|
||||
List<StampedEvent.Temporary> tempEvents = new List<StampedEvent.Temporary>();
|
||||
List<StampedEvent.Temporary> tempEvents = new();
|
||||
public void PushTempEvent(StampedEvent.Temporary ev) {
|
||||
var index = tempEvents.BinarySearch(ev);
|
||||
if (index < 0) index = ~index;
|
||||
tempEvents.Insert(index, ev);
|
||||
}
|
||||
|
||||
readonly StampedEvent.Temporary _dummyEvent = new StampedEvent.Temporary();
|
||||
readonly StampedEvent.Temporary _dummyEvent = new();
|
||||
public void StripTempEvents() {
|
||||
_dummyEvent.Time = Time;
|
||||
var index = tempEvents.BinarySearch(_dummyEvent);
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
class Vector3Operator : IVectorOperator<Vector3> {
|
||||
public static Vector3Operator Instance = new Vector3Operator();
|
||||
public static Vector3Operator Instance = new();
|
||||
|
||||
public Vector3 Add(Vector3 lhs, Vector3 rhs) {
|
||||
return lhs + rhs;
|
||||
|
||||
@@ -21,8 +21,9 @@ namespace Cryville.Crtr.Event {
|
||||
_reg = ChartPlayer.motionRegistry[name];
|
||||
}
|
||||
protected override MotionCache Construct() {
|
||||
var result = new MotionCache();
|
||||
result.Value = (Vector)Activator.CreateInstance(_reg.Type);
|
||||
var result = new MotionCache {
|
||||
Value = (Vector)Activator.CreateInstance(_reg.Type)
|
||||
};
|
||||
return result;
|
||||
}
|
||||
protected override void Reset(MotionCache obj) {
|
||||
|
||||
@@ -17,15 +17,15 @@ namespace Cryville.Crtr.Event {
|
||||
public override string TypeName { get { return "note"; } }
|
||||
|
||||
SectionalGameObject[] sgos;
|
||||
readonly Dictionary<Chart.Judge, JudgeState> judges = new Dictionary<Chart.Judge, JudgeState>();
|
||||
readonly Dictionary<Chart.Judge, JudgeState> judges = new();
|
||||
class JudgeState {
|
||||
static readonly int _var_judge_result = IdentifierManager.Shared.Request("judge_result");
|
||||
static readonly int _var_judge_time_absolute = IdentifierManager.Shared.Request("judge_time_absolute");
|
||||
static readonly int _var_judge_time_relative = IdentifierManager.Shared.Request("judge_time_relative");
|
||||
public Anchor StaticAnchor { get; private set; }
|
||||
readonly PropStores.Float _jtabsst = new PropStores.Float();
|
||||
readonly PropStores.Float _jtrelst = new PropStores.Float();
|
||||
readonly PropStores.Identifier _resultst = new PropStores.Identifier();
|
||||
readonly PropStores.Float _jtabsst = new();
|
||||
readonly PropStores.Float _jtrelst = new();
|
||||
readonly PropStores.Identifier _resultst = new();
|
||||
public JudgeState(NoteHandler handler, int name) {
|
||||
StaticAnchor = handler.RegisterAnchor(handler.judge.judgeMap[name], false, 3);
|
||||
}
|
||||
@@ -147,8 +147,7 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
internal void ReportJudge(JudgeEvent ev, float time, Identifier result) {
|
||||
JudgeState state;
|
||||
if (!judges.TryGetValue(ev.BaseEvent, out state)) return;
|
||||
if (!judges.TryGetValue(ev.BaseEvent, out JudgeState state)) return;
|
||||
state.MarkJudged(time, (float)(ev.StartTime - time), result.Key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,21 +48,19 @@ namespace Cryville.Crtr.Event {
|
||||
}
|
||||
|
||||
public MotionNode GetRelativeNode(short id) {
|
||||
MotionNode result;
|
||||
RelativeNodes.TryGetValue(id, out result);
|
||||
RelativeNodes.TryGetValue(id, out MotionNode result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetRelativeNode(MotionNode node) {
|
||||
MotionNode cnode;
|
||||
if (!RelativeNodes.TryGetValue(node.Id, out cnode)) {
|
||||
if (!RelativeNodes.TryGetValue(node.Id, out MotionNode cnode)) {
|
||||
cnode = MotionNodePool.Shared.Rent(_type);
|
||||
cnode.Id = node.Id;
|
||||
RelativeNodes.Add(node.Id, cnode);
|
||||
}
|
||||
if (node.Time != null) node.Time.CopyTo(cnode.Time);
|
||||
if (node.EndTime != null) node.EndTime.CopyTo(cnode.EndTime);
|
||||
if (node.Value != null) node.Value.CopyTo(cnode.Value);
|
||||
node.Time?.CopyTo(cnode.Time);
|
||||
node.EndTime?.CopyTo(cnode.EndTime);
|
||||
node.Value?.CopyTo(cnode.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace Cryville.Crtr.Event {
|
||||
protected abstract TransformHandler Parent { get; }
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
sgos = Components.Where(c => c is SectionalGameObject).Cast<SectionalGameObject>().ToArray();
|
||||
sgos = Components.OfType<SectionalGameObject>().ToArray();
|
||||
}
|
||||
|
||||
SectionalGameObject[] sgos;
|
||||
|
||||
@@ -12,9 +12,8 @@ namespace Cryville.Crtr.Extensions {
|
||||
|
||||
public override void Convert(FileInfo file, ConversionSession ses) {
|
||||
try {
|
||||
using (var stream = file.OpenRead()) {
|
||||
ModuleDefinition.ReadModule(stream, new ReaderParameters(ReadingMode.Immediate));
|
||||
}
|
||||
using var stream = file.OpenRead();
|
||||
ModuleDefinition.ReadModule(stream, new ReaderParameters(ReadingMode.Immediate));
|
||||
}
|
||||
catch (BadImageFormatException ex) {
|
||||
throw new FormatException("Invalid extension.", ex);
|
||||
|
||||
@@ -13,19 +13,17 @@ namespace Cryville.Crtr.Extensions.Umg {
|
||||
public override void Convert(FileInfo file, ConversionSession ses) {
|
||||
var meta = Path.Combine(file.Directory.FullName, "meta.json");
|
||||
if (!File.Exists(meta)) throw new FileNotFoundException("Meta file for the chart not found");
|
||||
using (StreamReader reader = new StreamReader(meta, Encoding.UTF8)) {
|
||||
var data = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
ses.AddResource(new ChartResource(data.name, file));
|
||||
}
|
||||
using StreamReader reader = new(meta, Encoding.UTF8);
|
||||
var data = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
ses.AddResource(new ChartResource(data.name, file));
|
||||
}
|
||||
}
|
||||
public class ChartResource : FileResource {
|
||||
public ChartResource(string name, FileInfo master) : base(name, master) {
|
||||
using (var reader = new StreamReader(master.FullName)) {
|
||||
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")));
|
||||
if (meta.cover != null) Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
|
||||
}
|
||||
using var reader = new StreamReader(master.FullName);
|
||||
var meta = JsonConvert.DeserializeObject<ChartMeta>(reader.ReadToEnd());
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".json")));
|
||||
if (meta.cover != null) Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.cover)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,18 +12,16 @@ namespace Cryville.Crtr.Extensions.Umg {
|
||||
}
|
||||
|
||||
public override void Convert(FileInfo file, ConversionSession ses) {
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
var data = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd());
|
||||
ses.AddResource(new RulesetResource(data.name, file));
|
||||
}
|
||||
using StreamReader reader = new(file.FullName, Encoding.UTF8);
|
||||
var data = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd());
|
||||
ses.AddResource(new RulesetResource(data.name, file));
|
||||
}
|
||||
}
|
||||
public class RulesetResource : FileResource {
|
||||
public RulesetResource(string name, FileInfo master) : base(name, master) {
|
||||
using (var reader = new StreamReader(master.FullName)) {
|
||||
var meta = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd());
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||
}
|
||||
using var reader = new StreamReader(master.FullName);
|
||||
var meta = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd());
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,22 +12,20 @@ namespace Cryville.Crtr.Extensions.Umg {
|
||||
}
|
||||
|
||||
public override void Convert(FileInfo file, ConversionSession ses) {
|
||||
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
|
||||
var data = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd());
|
||||
ses.AddResource(new SkinResource(data.name, file));
|
||||
}
|
||||
using StreamReader reader = new(file.FullName, Encoding.UTF8);
|
||||
var data = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd());
|
||||
ses.AddResource(new SkinResource(data.name, file));
|
||||
}
|
||||
}
|
||||
public class SkinResource : FileResource {
|
||||
public string RulesetName { get; private set; }
|
||||
public SkinResource(string name, FileInfo master) : base(name, master) {
|
||||
using (var reader = new StreamReader(master.FullName)) {
|
||||
var meta = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd());
|
||||
RulesetName = meta.ruleset;
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||
foreach (var frame in meta.frames) {
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
|
||||
}
|
||||
using var reader = new StreamReader(master.FullName);
|
||||
var meta = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd());
|
||||
RulesetName = meta.ruleset;
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, meta.data + ".pdt")));
|
||||
foreach (var frame in meta.frames) {
|
||||
Attachments.Add(new FileInfo(Path.Combine(master.Directory.FullName, frame)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ namespace Cryville.Crtr {
|
||||
public static SimpleSequencerSource AudioSequencer;
|
||||
public static SimpleSequencerSession AudioSession;
|
||||
public static InputManager InputManager;
|
||||
public static readonly NetworkTaskWorker NetworkTaskWorker = new NetworkTaskWorker();
|
||||
public static readonly NetworkTaskWorker NetworkTaskWorker = new();
|
||||
|
||||
public static readonly JsonSerializerSettings GlobalJsonSerializerSettings
|
||||
= new JsonSerializerSettings() {
|
||||
= new() {
|
||||
DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
};
|
||||
|
||||
@@ -168,10 +168,9 @@ namespace Cryville.Crtr {
|
||||
if (!dir.Exists || Settings.Default.LastRunVersion != Application.version) {
|
||||
Directory.CreateDirectory(dir.FullName);
|
||||
var defaultData = Resources.Load<TextAsset>("default");
|
||||
using (var zip = ZipFile.Read(defaultData.bytes)) {
|
||||
zip.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
|
||||
zip.ExtractAll(Settings.Default.GameDataPath);
|
||||
}
|
||||
using var zip = ZipFile.Read(defaultData.bytes);
|
||||
zip.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
|
||||
zip.ExtractAll(Settings.Default.GameDataPath);
|
||||
}
|
||||
|
||||
Settings.Default.LastRunVersion = Application.version;
|
||||
@@ -193,18 +192,16 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
static readonly Encoding _encoding = new UTF8Encoding(false, true);
|
||||
static readonly XmlReaderSettings _xmlSettings = new XmlReaderSettings {
|
||||
static readonly XmlReaderSettings _xmlSettings = new() {
|
||||
DtdProcessing = DtdProcessing.Ignore,
|
||||
};
|
||||
static XDocument LoadXmlDocument(string path) {
|
||||
return LoadXmlDocument(Resources.Load<TextAsset>(path));
|
||||
}
|
||||
static XDocument LoadXmlDocument(TextAsset asset) {
|
||||
using (var stream = new MemoryStream(_encoding.GetBytes(asset.text))) {
|
||||
using (var reader = XmlReader.Create(stream, _xmlSettings)) {
|
||||
return XDocument.Load(reader);
|
||||
}
|
||||
}
|
||||
using var stream = new MemoryStream(_encoding.GetBytes(asset.text));
|
||||
using var reader = XmlReader.Create(stream, _xmlSettings);
|
||||
return XDocument.Load(reader);
|
||||
}
|
||||
|
||||
static bool _shutdown;
|
||||
@@ -233,15 +230,13 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
|
||||
static void OnInternalLog(string condition, string stackTrace, LogType type) {
|
||||
int l;
|
||||
switch (type) {
|
||||
case LogType.Log: l = 1; break;
|
||||
case LogType.Assert: l = 2; break;
|
||||
case LogType.Warning: l = 3; break;
|
||||
case LogType.Error:
|
||||
case LogType.Exception: l = 4; break;
|
||||
default: l = 1; break;
|
||||
}
|
||||
var l = type switch {
|
||||
LogType.Log => 1,
|
||||
LogType.Assert => 2,
|
||||
LogType.Warning => 3,
|
||||
LogType.Error or LogType.Exception => 4,
|
||||
_ => 1,
|
||||
};
|
||||
MainLogger.Log(l, "Internal", "{0}\n{1}", condition, stackTrace);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public class JsonPdtExpConverter : JsonConverter<PdtExpression> {
|
||||
static readonly PdtFragmentInterpreter _itor = new PdtFragmentInterpreter();
|
||||
static readonly PdtFragmentInterpreter _itor = new();
|
||||
public override PdtExpression ReadJson(JsonReader reader, Type objectType, PdtExpression existingValue, bool hasExistingValue, JsonSerializer serializer) {
|
||||
_itor.SetSource((string)reader.Value);
|
||||
return _itor.GetExp();
|
||||
|
||||
@@ -6,19 +6,19 @@ using System.Globalization;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
public struct MotionRegistry {
|
||||
public readonly struct MotionRegistry {
|
||||
readonly Type m_Type;
|
||||
public Type Type {
|
||||
public readonly Type Type {
|
||||
get { return m_Type; }
|
||||
}
|
||||
|
||||
readonly Vector m_InitValue;
|
||||
public Vector InitValue {
|
||||
public readonly Vector InitValue {
|
||||
get { return m_InitValue.Clone(); }
|
||||
}
|
||||
|
||||
readonly Vector m_GlobalInitValue;
|
||||
public Vector GlobalInitValue {
|
||||
public readonly Vector GlobalInitValue {
|
||||
get { return m_GlobalInitValue.Clone(); }
|
||||
}
|
||||
|
||||
@@ -43,9 +43,9 @@ namespace Cryville.Crtr {
|
||||
public Vector Value;
|
||||
|
||||
public void Init(Type type) {
|
||||
if (Time == null) Time = new Vec1(float.NegativeInfinity);
|
||||
if (EndTime == null) EndTime = new Vec1(float.NegativeInfinity);
|
||||
if (Value == null) Value = (Vector)Activator.CreateInstance(type);
|
||||
Time ??= new Vec1(float.NegativeInfinity);
|
||||
EndTime ??= new Vec1(float.NegativeInfinity);
|
||||
Value ??= (Vector)Activator.CreateInstance(type);
|
||||
}
|
||||
|
||||
public void CopyTo(MotionNode dest) {
|
||||
@@ -407,8 +407,7 @@ namespace Cryville.Crtr {
|
||||
values = new float[] { op.AsNumber() };
|
||||
}
|
||||
else if (op.Type == PdtInternalType.Vector) {
|
||||
int type;
|
||||
op.GetArraySuffix(out type, out _);
|
||||
op.GetArraySuffix(out int type, out _);
|
||||
if (type != PdtInternalType.Number)
|
||||
throw new InvalidOperationException("Not a vector of numbers");
|
||||
values = new float[(op.Length - sizeof(int)) / sizeof(float)];
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Cryville.Crtr.Network {
|
||||
if (_shutdown) Application.Quit();
|
||||
}
|
||||
}
|
||||
static readonly Uri BaseUri = new Uri("https://www.cryville.world/api/crtr/index");
|
||||
static readonly Uri BaseUri = new("https://www.cryville.world/api/crtr/index");
|
||||
List<VersionInfo> _versions;
|
||||
void ThreadLogic() {
|
||||
try {
|
||||
@@ -48,10 +48,9 @@ namespace Cryville.Crtr.Network {
|
||||
void CheckVersion() {
|
||||
using (var client = new Https11Client(BaseUri)) {
|
||||
client.Connect();
|
||||
using (var response = client.Request("GET", new Uri(BaseUri, "versions"))) {
|
||||
var data = Encoding.UTF8.GetString(response.MessageBody.ReadToEnd());
|
||||
_versions = JsonConvert.DeserializeObject<List<VersionInfo>>(data, Game.GlobalJsonSerializerSettings);
|
||||
}
|
||||
using var response = client.Request("GET", new Uri(BaseUri, "versions"));
|
||||
var data = Encoding.UTF8.GetString(response.MessageBody.ReadToEnd());
|
||||
_versions = JsonConvert.DeserializeObject<List<VersionInfo>>(data, Game.GlobalJsonSerializerSettings);
|
||||
}
|
||||
var availableVersions = _versions.Where(v => v.platforms.ContainsKey(PlatformConfig.Name)).ToArray();
|
||||
var versionIndex = new Dictionary<string, int>(availableVersions.Length);
|
||||
@@ -132,15 +131,12 @@ namespace Cryville.Crtr.Network {
|
||||
}
|
||||
void Download(VersionResourceInfo diff, string path) {
|
||||
var uri = new Uri(diff.url);
|
||||
using (var client = new Https11Client(uri)) {
|
||||
client.Connect();
|
||||
using (var response = client.Request("GET", uri)) {
|
||||
var data = response.MessageBody.ReadToEnd();
|
||||
using (var file = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None)) {
|
||||
file.Write(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
using var client = new Https11Client(uri);
|
||||
client.Connect();
|
||||
using var response = client.Request("GET", uri);
|
||||
var data = response.MessageBody.ReadToEnd();
|
||||
using var file = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);
|
||||
file.Write(data);
|
||||
}
|
||||
void ExecuteUpdate(List<string> diffPaths) {
|
||||
#if UNITY_EDITOR
|
||||
|
||||
@@ -10,10 +10,10 @@ namespace Cryville.Crtr {
|
||||
void Awake() {
|
||||
_image = GetComponent<Image>();
|
||||
}
|
||||
static Color _idleColor = new Color(1, 1, 1, .5f);
|
||||
static Color _tickColor1 = new Color(1, 1, 1, 1);
|
||||
static Color _tickColor2 = new Color(1, 1, 1, .8f);
|
||||
static Color _suspendedColor = new Color(1, 0, 0, 1);
|
||||
static Color _idleColor = new(1, 1, 1, .5f);
|
||||
static Color _tickColor1 = new(1, 1, 1, 1);
|
||||
static Color _tickColor2 = new(1, 1, 1, .8f);
|
||||
static Color _suspendedColor = new(1, 0, 0, 1);
|
||||
void Update() {
|
||||
var status = Game.NetworkTaskWorker.TickBackgroundTasks();
|
||||
if (_image == null) return;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Cryville.Crtr {
|
||||
return result;
|
||||
}
|
||||
else if (type.Equals(typeof(string))) {
|
||||
string result = default(string);
|
||||
string result = default;
|
||||
PdtEvaluator.Instance.Evaluate(new PropOp.String(r => result = r), exp);
|
||||
return result;
|
||||
}
|
||||
@@ -36,12 +36,12 @@ namespace Cryville.Crtr {
|
||||
return result;
|
||||
}
|
||||
else if (type.Equals(typeof(Clip))) {
|
||||
Clip result = default(Clip);
|
||||
Clip result = default;
|
||||
PdtEvaluator.Instance.Evaluate(new PropOp.Clip(r => result = r), exp);
|
||||
return result;
|
||||
}
|
||||
else if (type.Equals(typeof(Identifier))) {
|
||||
Identifier result = default(Identifier);
|
||||
Identifier result = default;
|
||||
PdtEvaluator.Instance.Evaluate(new pop_identstr(r => result = r), exp);
|
||||
return result;
|
||||
}
|
||||
@@ -51,8 +51,7 @@ namespace Cryville.Crtr {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
else if (value is string) {
|
||||
var exp = (string)value;
|
||||
else if (value is string exp) {
|
||||
if (type.Equals(typeof(Identifier))) {
|
||||
return new Identifier(exp);
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@ namespace Cryville.Crtr {
|
||||
static PdtEvaluator m_instance;
|
||||
public static PdtEvaluator Instance {
|
||||
get {
|
||||
if (m_instance == null) m_instance = new PdtEvaluator();
|
||||
m_instance ??= new PdtEvaluator();
|
||||
return m_instance;
|
||||
}
|
||||
}
|
||||
|
||||
readonly Dictionary<PdtOperatorSignature, PdtOperator> _shortops = new Dictionary<PdtOperatorSignature, PdtOperator>();
|
||||
readonly IntKeyedDictionary<PdtOperator> _ctxops = new IntKeyedDictionary<PdtOperator>();
|
||||
readonly Dictionary<PdtOperatorSignature, PdtOperator> _shortops = new();
|
||||
readonly IntKeyedDictionary<PdtOperator> _ctxops = new();
|
||||
|
||||
static readonly byte[] _nullbuf = new byte[0];
|
||||
readonly byte[] _numbuf = new byte[4];
|
||||
@@ -43,8 +43,7 @@ namespace Cryville.Crtr {
|
||||
else if (name == _var_false) { LoadNum(0); type = PdtInternalType.Number; value = _numbuf; }
|
||||
else if (name == _var_null) { LoadIdent(0); type = PdtInternalType.Undefined; value = _numbuf; }
|
||||
else {
|
||||
PropSrc prop; PropStores.Float variable;
|
||||
if (ContextEvent != null && ContextEvent.PropSrcs.TryGetValue(name, out prop)) {
|
||||
if (ContextEvent != null && ContextEvent.PropSrcs.TryGetValue(name, out PropSrc prop)) {
|
||||
prop.Get(out type, out value);
|
||||
}
|
||||
else if (ContextState != null && ChartPlayer.motionRegistry.ContainsKey(new Identifier(name))) {
|
||||
@@ -57,7 +56,7 @@ namespace Cryville.Crtr {
|
||||
prop.Get(out type, out value);
|
||||
RevokePotentialConstant();
|
||||
}
|
||||
else if (ContextSkinContainer != null && ContextSkinContainer.Variables.TryGetValue(name, out variable)) {
|
||||
else if (ContextSkinContainer != null && ContextSkinContainer.Variables.TryGetValue(name, out PropStores.Float variable)) {
|
||||
variable.Source.Get(out type, out value);
|
||||
}
|
||||
else if (ContextRulesetConfig != null && ContextRulesetConfig.TryGetMappedSource(name, out prop)) {
|
||||
@@ -94,8 +93,7 @@ namespace Cryville.Crtr {
|
||||
static readonly int _func_int_map = IdentifierManager.Shared.Request("int_map");
|
||||
static readonly int _func_map = IdentifierManager.Shared.Request("map");
|
||||
protected override PdtOperator GetOperator(PdtOperatorSignature sig) {
|
||||
PdtOperator result;
|
||||
if (_shortops.TryGetValue(sig, out result)) {
|
||||
if (_shortops.TryGetValue(sig, out PdtOperator result)) {
|
||||
return result;
|
||||
}
|
||||
else if (_ctxops.TryGetValue(sig.Name, out result)) {
|
||||
@@ -135,7 +133,7 @@ namespace Cryville.Crtr {
|
||||
public Judge ContextJudge { get; set; }
|
||||
public PropSrc ContextSelfValue { get; set; }
|
||||
|
||||
readonly Stack<int> ContextCascadeBlocks = new Stack<int>();
|
||||
readonly Stack<int> ContextCascadeBlocks = new();
|
||||
public void ContextCascadeInsertBlock() {
|
||||
ContextCascadeBlocks.Push(_cascadeHeight);
|
||||
}
|
||||
@@ -155,10 +153,9 @@ namespace Cryville.Crtr {
|
||||
ContextCascade[_cascadeHeight - 1][key] = value;
|
||||
}
|
||||
public PropSrc ContextCascadeLookup(int name) {
|
||||
PropSrc result;
|
||||
for (int i = _cascadeHeight - 1; i >= ContextCascadeBlocks.Peek(); i--) {
|
||||
var cas = ContextCascade[i];
|
||||
if (cas.TryGetValue(name, out result)) {
|
||||
if (cas.TryGetValue(name, out PropSrc result)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -226,13 +223,13 @@ namespace Cryville.Crtr {
|
||||
_ctxops.Add(IdentifierManager.Shared.Request("circle"), new func_sphere(() => ContextSelfValue));
|
||||
_ctxops.Add(IdentifierManager.Shared.Request("sphere"), new func_sphere(() => ContextSelfValue));
|
||||
|
||||
Func<int, PropSrc> cccb = k => ContextCascadeLookup(k);
|
||||
PropSrc cccb(int k) => ContextCascadeLookup(k);
|
||||
_ctxops.Add(IdentifierManager.Shared.Request("attack_timing"), new func_attack_timing(cccb));
|
||||
_ctxops.Add(IdentifierManager.Shared.Request("release_timing"), new func_release_timing(cccb));
|
||||
_ctxops.Add(IdentifierManager.Shared.Request("enter_timing"), new func_enter_timing(cccb));
|
||||
_ctxops.Add(IdentifierManager.Shared.Request("leave_timing"), new func_leave_timing(cccb));
|
||||
|
||||
Func<int, PdtExpression> jacb = k => ContextJudge._areaFuncs[new Identifier(k)];
|
||||
PdtExpression jacb(int k) => ContextJudge._areaFuncs[new Identifier(k)];
|
||||
_ctxops.Add(IdentifierManager.Shared.Request("attack_timed_area"), new func_attack_timed_area(cccb, jacb, this));
|
||||
_ctxops.Add(IdentifierManager.Shared.Request("release_timed_area"), new func_release_timed_area(cccb, jacb, this));
|
||||
_ctxops.Add(IdentifierManager.Shared.Request("enter_timed_area"), new func_enter_or_leave_timed_area(cccb, jacb, this, true));
|
||||
@@ -450,9 +447,8 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
protected override unsafe void Execute() {
|
||||
var ctx = _ctxcb();
|
||||
float dist;
|
||||
var ray = new Ray(ctx.position, ctx.rotation * Vector3.forward);
|
||||
ChartPlayer.frustumPlanes[(int)GetOperand(0).AsNumber()].Raycast(ray, out dist);
|
||||
ChartPlayer.frustumPlanes[(int)GetOperand(0).AsNumber()].Raycast(ray, out float dist);
|
||||
var ret = GetReturnFrame(PdtInternalType.Vector, sizeof(Vector3) + sizeof(int));
|
||||
ret.Set(ray.GetPoint(dist));
|
||||
ret.SetArraySuffix(PdtInternalType.Number);
|
||||
@@ -465,12 +461,11 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
protected override unsafe void Execute() {
|
||||
var ret = GetReturnFrame(PdtInternalType.Number, sizeof(float));
|
||||
float v;
|
||||
switch (LoadedOperandCount) {
|
||||
case 0: v = oputil.AsNumber(_ctxcb()); break;
|
||||
case 1: v = GetOperand(0).AsNumber(); break;
|
||||
default: throw new ArgumentException("Argument count not 0 or 1");
|
||||
}
|
||||
var v = LoadedOperandCount switch {
|
||||
0 => oputil.AsNumber(_ctxcb()),
|
||||
1 => GetOperand(0).AsNumber(),
|
||||
_ => throw new ArgumentException("Argument count not 0 or 1"),
|
||||
};
|
||||
ret.SetNumber(Mathf.Floor(v));
|
||||
}
|
||||
}
|
||||
@@ -506,12 +501,11 @@ namespace Cryville.Crtr {
|
||||
protected override unsafe void Execute() {
|
||||
var ret = GetReturnFrame(PdtInternalType.Number, sizeof(float));
|
||||
float a = GetOperand(0).AsNumber();
|
||||
float b;
|
||||
switch (LoadedOperandCount) {
|
||||
case 1: b = oputil.AsNumber(_ctxcb()); break;
|
||||
case 2: b = GetOperand(1).AsNumber(); break;
|
||||
default: throw new ArgumentException("Argument count not 2 or 3");
|
||||
}
|
||||
var b = LoadedOperandCount switch {
|
||||
1 => oputil.AsNumber(_ctxcb()),
|
||||
2 => GetOperand(1).AsNumber(),
|
||||
_ => throw new ArgumentException("Argument count not 2 or 3"),
|
||||
};
|
||||
ret.SetNumber(Mathf.Min(a, b));
|
||||
}
|
||||
}
|
||||
@@ -523,12 +517,11 @@ namespace Cryville.Crtr {
|
||||
protected override unsafe void Execute() {
|
||||
var ret = GetReturnFrame(PdtInternalType.Number, sizeof(float));
|
||||
var a = GetOperand(0).AsNumber();
|
||||
float b;
|
||||
switch (LoadedOperandCount) {
|
||||
case 1: b = oputil.AsNumber(_ctxcb()); break;
|
||||
case 2: b = GetOperand(1).AsNumber(); break;
|
||||
default: throw new ArgumentException("Argument count not 2 or 3");
|
||||
}
|
||||
var b = LoadedOperandCount switch {
|
||||
1 => oputil.AsNumber(_ctxcb()),
|
||||
2 => GetOperand(1).AsNumber(),
|
||||
_ => throw new ArgumentException("Argument count not 2 or 3"),
|
||||
};
|
||||
ret.SetNumber(Mathf.Max(a, b));
|
||||
}
|
||||
}
|
||||
@@ -539,12 +532,11 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
protected override unsafe void Execute() {
|
||||
var ret = GetReturnFrame(PdtInternalType.Number, sizeof(float));
|
||||
float arg;
|
||||
switch (LoadedOperandCount) {
|
||||
case 0: arg = oputil.AsNumber(_ctxcb()); break;
|
||||
case 1: arg = GetOperand(0).AsNumber(); break;
|
||||
default: throw new ArgumentException("Argument count not 0 or 1");
|
||||
}
|
||||
var arg = LoadedOperandCount switch {
|
||||
0 => oputil.AsNumber(_ctxcb()),
|
||||
1 => GetOperand(0).AsNumber(),
|
||||
_ => throw new ArgumentException("Argument count not 0 or 1"),
|
||||
};
|
||||
ret.SetNumber(Mathf.Abs(arg));
|
||||
}
|
||||
}
|
||||
@@ -623,12 +615,11 @@ namespace Cryville.Crtr {
|
||||
protected override unsafe void Execute() {
|
||||
float x1 = GetOperand(0).AsNumber(), y1 = GetOperand(1).AsNumber();
|
||||
float x2 = GetOperand(2).AsNumber(), y2 = GetOperand(3).AsNumber();
|
||||
float time;
|
||||
switch (LoadedOperandCount) {
|
||||
case 4: time = oputil.AsNumber(_ctxcb()); break;
|
||||
case 5: time = GetOperand(4).AsNumber(); break;
|
||||
default: throw new ArgumentException("Argument count not 4 or 5");
|
||||
}
|
||||
var time = LoadedOperandCount switch {
|
||||
4 => oputil.AsNumber(_ctxcb()),
|
||||
5 => GetOperand(4).AsNumber(),
|
||||
_ => throw new ArgumentException("Argument count not 4 or 5"),
|
||||
};
|
||||
GetReturnFrame(PdtInternalType.Number, sizeof(float))
|
||||
.SetNumber(CubicBezier.Evaluate(time, x1, y1, x2, y2, 1e-3f));
|
||||
}
|
||||
@@ -642,12 +633,11 @@ namespace Cryville.Crtr {
|
||||
_ctxcb = ctxcb;
|
||||
}
|
||||
protected override void Execute() {
|
||||
float time;
|
||||
switch (LoadedOperandCount) {
|
||||
case 0: time = oputil.AsNumber(_ctxcb()); break;
|
||||
case 1: time = GetOperand(0).AsNumber(); break;
|
||||
default: throw new ArgumentException("Argument count not 0 or 1");
|
||||
}
|
||||
var time = LoadedOperandCount switch {
|
||||
0 => oputil.AsNumber(_ctxcb()),
|
||||
1 => GetOperand(0).AsNumber(),
|
||||
_ => throw new ArgumentException("Argument count not 0 or 1"),
|
||||
};
|
||||
GetReturnFrame(PdtInternalType.Number, sizeof(float))
|
||||
.SetNumber(CubicBezier.Evaluate(time, x1, y1, x2, y2, 1e-3f));
|
||||
}
|
||||
@@ -1003,8 +993,7 @@ namespace Cryville.Crtr {
|
||||
static unsafe class oputil {
|
||||
public static float AsNumber(PropSrc src) {
|
||||
if (src == null) throw new ArgumentNullException("src");
|
||||
int type; byte[] value;
|
||||
src.Get(out type, out value);
|
||||
src.Get(out int type, out byte[] value);
|
||||
if (type != PdtInternalType.Number && type != PdtInternalType.Vector)
|
||||
throw new ArgumentException("Not a number");
|
||||
fixed (byte* ptr = value) {
|
||||
@@ -1013,8 +1002,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public static Vector4? AsVector(PropSrc src) {
|
||||
if (src == null) throw new ArgumentNullException("src");
|
||||
int type; byte[] value;
|
||||
src.Get(out type, out value);
|
||||
src.Get(out int type, out byte[] value);
|
||||
if (type == PdtInternalType.Vector) {
|
||||
fixed (byte* ptr = value) {
|
||||
return *(Vector4*)ptr;
|
||||
@@ -1032,13 +1020,13 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public static Vector4? AsVector(PdtVariableMemory op) {
|
||||
if (op.Type == PdtInternalType.Vector) {
|
||||
switch ((op.Length - sizeof(int)) / sizeof(float)) {
|
||||
case 0: return null;
|
||||
case 1: return new Vector4(op.AsNumber(), 0, 0, 0);
|
||||
case 2: return new Vector4(op.AsNumber(), op.AsNumber(sizeof(float)), 0, 0);
|
||||
case 3: return new Vector4(op.AsNumber(), op.AsNumber(sizeof(float)), op.AsNumber(2 * sizeof(float)), 0);
|
||||
default: return new Vector4(op.AsNumber(), op.AsNumber(sizeof(float)), op.AsNumber(2 * sizeof(float)), op.AsNumber(3 * sizeof(float)));
|
||||
}
|
||||
return ((op.Length - sizeof(int)) / sizeof(float)) switch {
|
||||
0 => null,
|
||||
1 => (Vector4?)new Vector4(op.AsNumber(), 0, 0, 0),
|
||||
2 => (Vector4?)new Vector4(op.AsNumber(), op.AsNumber(sizeof(float)), 0, 0),
|
||||
3 => (Vector4?)new Vector4(op.AsNumber(), op.AsNumber(sizeof(float)), op.AsNumber(2 * sizeof(float)), 0),
|
||||
_ => (Vector4?)new Vector4(op.AsNumber(), op.AsNumber(sizeof(float)), op.AsNumber(2 * sizeof(float)), op.AsNumber(3 * sizeof(float))),
|
||||
};
|
||||
}
|
||||
else if (op.Type == PdtInternalType.Number) {
|
||||
return new Vector4(op.AsNumber(), 0, 0, 0);
|
||||
|
||||
@@ -65,8 +65,7 @@ namespace Cryville.Crtr {
|
||||
public StringArray(Action<string[]> cb) : base(cb) { }
|
||||
protected override unsafe void Execute() {
|
||||
var op = GetOperand(0);
|
||||
int arrtype; int len;
|
||||
op.GetArraySuffix(out arrtype, out len);
|
||||
op.GetArraySuffix(out int arrtype, out int len);
|
||||
if (arrtype != PdtInternalType.String) throw new InvalidCastException("Not an array of strings");
|
||||
var result = new string[len];
|
||||
int o = 0;
|
||||
@@ -100,7 +99,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
public class Enum : Fixed<object> {
|
||||
readonly Type _type;
|
||||
readonly IntKeyedDictionary<int> _cache = new IntKeyedDictionary<int>();
|
||||
readonly IntKeyedDictionary<int> _cache = new();
|
||||
public Enum(Type type, Action<object> cb) : base(cb) {
|
||||
if (!type.IsEnum)
|
||||
throw new ArgumentException("Type is not enum");
|
||||
@@ -117,7 +116,7 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
public class Enum<T> : Fixed<T> {
|
||||
static readonly IntKeyedDictionary<int> _cache = new IntKeyedDictionary<int>();
|
||||
static readonly IntKeyedDictionary<int> _cache = new();
|
||||
readonly Func<int, T> _caster;
|
||||
static Enum() {
|
||||
if (!typeof(T).IsEnum)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user