refactor: Update Unity to 2022.3.62

This commit is contained in:
2025-06-21 01:22:02 +08:00
parent d71bf7d4a5
commit 283783954f
112 changed files with 778 additions and 907 deletions

View File

@@ -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>();

View File

@@ -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 {

View File

@@ -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);
}
}
}

View File

@@ -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)) {

View File

@@ -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);

View File

@@ -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; } }

View File

@@ -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)

View File

@@ -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);

View File

@@ -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)

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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;
}

View File

@@ -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));
}
}