Exception cleanup. Code cleanup.

This commit is contained in:
2022-12-23 15:20:16 +08:00
parent ff5928b556
commit 356f4df9a9
13 changed files with 51 additions and 77 deletions

View File

@@ -19,7 +19,8 @@ namespace Cryville.Common.Pdt {
/// <returns>The operand at the specified index.</returns>
/// <exception cref="IndexOutOfRangeException"><paramref name="index" /> is not less than <see cref="LoadedOperandCount" /> or less than 0.</exception>
protected PdtVariableMemory GetOperand(int index) {
if (index >= LoadedOperandCount || index < 0) throw new IndexOutOfRangeException();
if (index >= LoadedOperandCount || index < 0)
throw new ArgumentOutOfRangeException("index");
int i = index + _loadindex;
return _operands[i];
}
@@ -33,11 +34,9 @@ namespace Cryville.Common.Pdt {
_operands = new PdtVariableMemory[pc];
}
PdtEvaluatorBase _etor;
bool _failure = false;
bool _rfreq = true;
internal void Begin(PdtEvaluatorBase etor) {
_etor = etor;
_failure = false;
_loadindex = ParamCount;
}
internal void LoadOperand(PdtVariableMemory mem) {
@@ -51,10 +50,6 @@ namespace Cryville.Common.Pdt {
if (_rfreq) _etor.DiscardStack();
throw new InvalidOperationException("Evaluation failed", ex);
}
if (_failure) {
if (_rfreq) _etor.DiscardStack();
throw new InvalidOperationException("Evaluation failed");
}
if (!_rfreq && !noset) throw new InvalidOperationException("Return frame not set");
}
/// <summary>
@@ -69,10 +64,7 @@ namespace Cryville.Common.Pdt {
/// <returns>The return frame.</returns>
/// <exception cref="InvalidOperationException">The return frame has already been requested.</exception>
protected PdtVariableMemory GetReturnFrame(int type, int len) {
if (_rfreq) {
_failure = true;
throw new InvalidOperationException("Return frame already requested");
}
if (_rfreq) throw new InvalidOperationException("Return frame requested twice");
_rfreq = true;
return _etor.StackAlloc(type, _prmem, len);
}

View File

@@ -28,19 +28,19 @@ namespace Cryville.Common.Unity.Input {
}
public override bool IsNullable(int type) {
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
if (type != 0) throw new ArgumentOutOfRangeException("type");
return false;
}
public override byte GetDimension(int type) {
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
if (type != 0) throw new ArgumentOutOfRangeException("type");
return 2;
}
public override string GetTypeName(int type) {
switch (type) {
case 0: return "Mouse Position";
default: throw new ArgumentOutOfRangeException(nameof(type));
default: throw new ArgumentOutOfRangeException("type");
}
}

View File

@@ -28,19 +28,19 @@ namespace Cryville.Common.Unity.Input {
}
public override bool IsNullable(int type) {
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
if (type != 0) throw new ArgumentOutOfRangeException("type");
return true;
}
public override byte GetDimension(int type) {
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
if (type != 0) throw new ArgumentOutOfRangeException("type");
return 2;
}
public override string GetTypeName(int type) {
switch (type) {
case 0: return "Touch";
default: throw new ArgumentOutOfRangeException(nameof(type));
default: throw new ArgumentOutOfRangeException("type");
}
}

View File

@@ -203,7 +203,7 @@ namespace Cryville.Crtr {
public virtual EventList GetEventsOfType(string type) {
switch (type) {
case "motions": return new EventList<Chart.Motion>(motions);
default: throw new ArgumentException("Unknown type");
default: throw new ArgumentException(string.Format("Unknown event type {0}", type));
}
}
}

View File

@@ -19,7 +19,7 @@ namespace Cryville.Crtr.Components {
private set;
}
public Rect Rect {
get { return Frame.frame; }
get { return Frame.Frame; }
}
/// <summary>
/// The ratio of width divided by height.

View File

@@ -63,13 +63,13 @@ namespace Cryville.Crtr.Components {
case 1: x = _border.x; bx = b.x; break;
case 2: x = _border.y; bx = b.y; break;
case 3: x = 1; bx = 1; break;
default: throw new Exception();
default: throw new NotSupportedException("Built-in resource corrupted");
}
float y;
switch ((int)muv[i].y) {
case 0: y = 0; break;
case 3: y = 1; break;
default: throw new Exception();
default: throw new NotSupportedException("Built-in resource corrupted");
}
uv[i] = frameInfo.Frame.GetUV(x, y);
bx -= 0.5f; y -= 0.5f;

View File

@@ -79,7 +79,7 @@ namespace Cryville.Crtr.Components {
foreach (var f in m_frames) {
f.Value.Load();
if (frameHeight == 0) frameHeight = f.Value.Rect.height;
else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height");
else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height for text component");
var tex = f.Value.Frame.Texture;
if (!meshes.ContainsKey(tex)) {
var m = new MeshWrapper();

View File

@@ -205,7 +205,7 @@ namespace Cryville.Crtr.Event {
public void AttachHandler(ContainerHandler h) {
if (Handler != null)
throw new InvalidOperationException();
throw new InvalidOperationException("Handler attached twice");
Handler = h;
h.cs = this;
}

View File

@@ -18,11 +18,11 @@ namespace Cryville.Crtr.Extensions.Malody {
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
List<Resource> result = new List<Resource>();
MalodyChart src;
if (file.Extension != ".mc") throw new NotImplementedException("mcz file is not supported");
if (file.Extension != ".mc") throw new NotImplementedException("mcz file is not supported yet");
using (var reader = new StreamReader(file.FullName)) {
src = JsonConvert.DeserializeObject<MalodyChart>(reader.ReadToEnd());
}
if (src.meta.mode != 0) throw new NotImplementedException("The chart mode is not supported");
if (src.meta.mode != 0) throw new NotImplementedException(string.Format("{0} mode is not supported yet", MODES[src.meta.mode]));
var ruleset = "malody!" + MODES[src.meta.mode];
if (src.meta.mode == 0) {
@@ -110,7 +110,7 @@ namespace Cryville.Crtr.Extensions.Malody {
offset = -tev.offset / 1000f,
});
}
else throw new NotImplementedException();
else throw new NotImplementedException("Key sounds are not supported yet");
}
else {
var rn = new Chart.Note() {
@@ -135,9 +135,9 @@ namespace Cryville.Crtr.Extensions.Malody {
var sev = tev.StartEvent;
longEvents.Remove(sev);
}
else throw new NotSupportedException();
else throw new NotSupportedException("Unrecognized long event");
}
else throw new NotSupportedException();
else throw new NotSupportedException("Unrecognized event");
}
var endbeat = tm.FractionalBeatTime;
endbeat.b += 4;

View File

@@ -45,7 +45,7 @@ namespace Cryville.Crtr.Extensions.osu {
if (line.StartsWith("osu file format v")) {
version = int.Parse(line.Substring(17), CultureInfo.InvariantCulture);
if (version > 14) throw new NotSupportedException("osu! chart format version too high");
else if (version < 5) throw new NotSupportedException("osu! chart format version too low"); // TODO apply offset
else if (version < 5) throw new NotImplementedException("osu! chart format version too low"); // TODO apply offset
}
else throw new NotSupportedException("Unrecognized osu! chart format");
flag = true;
@@ -143,9 +143,9 @@ namespace Cryville.Crtr.Extensions.osu {
int rulesetID = int.Parse(pair.Value, CultureInfo.InvariantCulture);
var ruleset = "osu!";
switch (rulesetID) {
case 0: /*ruleset += "standard";*/ throw new NotSupportedException("osu!standard mode is not supported yet");
case 1: /*ruleset += "taiko";*/ throw new NotSupportedException("osu!taiko mode is not supported yet");
case 2: /*ruleset += "catch";*/ throw new NotSupportedException("osu!catch mode is not supported yet");
case 0: /*ruleset += "standard";*/ throw new NotImplementedException("osu!standard mode is not supported yet");
case 1: /*ruleset += "taiko";*/ throw new NotImplementedException("osu!taiko mode is not supported yet");
case 2: /*ruleset += "catch";*/ throw new NotImplementedException("osu!catch mode is not supported yet");
case 3: ruleset += "mania"; break;
}
meta.ruleset = chart.ruleset = ruleset;

View File

@@ -86,7 +86,7 @@ namespace Cryville.Crtr {
protected override bool Collapse(int name, PdtVariableMemory param) {
if (name == _colop_and) return param.Type == PdtInternalType.Number && param.AsNumber() <= 0;
else if (name == _colop_or) return param.Type != PdtInternalType.Number || param.AsNumber() > 0;
else throw new KeyNotFoundException(string.Format("Undefined collapse operator {0}", name));
else throw new KeyNotFoundException(string.Format("Undefined collapse operator {0}", IdentifierManager.SharedInstance.Retrieve(name)));
}
public ChartEvent ContextEvent { private get; set; }

View File

@@ -1,3 +1,4 @@
using Cryville.Common;
using Cryville.Common.Pdt;
using Cryville.Crtr.Components;
using Cryville.Crtr.Event;
@@ -100,10 +101,16 @@ namespace Cryville.Crtr {
SkinProperty GetPropOp(Transform obj, SkinPropertyKey key) {
var ctype = key.Component;
var comp = (SkinComponent)obj.GetComponent(ctype);
if (comp == null) throw new InvalidOperationException("Component instance not found");
if (comp == null) throw new InvalidOperationException(string.Format(
"Trying to set property {0} but the component is not found",
IdentifierManager.SharedInstance.Retrieve(key.Name)
));
SkinProperty result;
if (!comp.Properties.TryGetValue(key.Name, out result))
throw new ArgumentException(string.Format("Property {0} not found on component", key.Name));
throw new ArgumentException(string.Format(
"Property {0} not found on component",
IdentifierManager.SharedInstance.Retrieve(key.Name)
));
return result;
}
}

View File

@@ -3,32 +3,18 @@ using UnityEngine;
namespace Cryville.Crtr {
public class SpriteFrame {
#pragma warning disable IDE1006
Rect _frame;
public Rect frame {
get { return _frame; }
set { _frame = value; }
}
public Rect textureRect {
get { return _frame; }
set { _frame = value; }
Rect m_frame;
public Rect Frame {
get { return m_frame; }
set { m_frame = value; }
}
bool _rotated = false;
public bool rotated {
get { return _rotated; }
set { _rotated = value; }
bool m_rotated = false;
public bool Rotated {
get { return m_rotated; }
set { m_rotated = value; }
}
public bool textureRotated {
get { return _rotated; }
set { _rotated = value; }
}
#pragma warning restore IDE1006
public Vector2 offset;
public Rect sourceColorRect;
public Vector2 sourceSize;
private Rect _uv;
private Vector2[] cuv;
public Rect UV {
@@ -41,7 +27,7 @@ namespace Cryville.Crtr {
float x1 = Mathf.Max(_uv.xMin, _uv.xMax);
float y0 = Mathf.Min(_uv.yMin, _uv.yMax);
float y1 = Mathf.Max(_uv.yMin, _uv.yMax);
if (_rotated) cuv = new Vector2[]{
if (m_rotated) cuv = new Vector2[]{
new Vector2(x0, y1),
new Vector2(x1, y0),
new Vector2(x0, y0),
@@ -79,28 +65,17 @@ namespace Cryville.Crtr {
public void Init() {
if (Texture == null)
throw new InvalidOperationException("Missing texture");
_frame = new Rect(Vector2.zero, Size);
var w = _frame.width;
var h = _frame.height;
float x = _frame.x / w;
float y = 1 - _frame.y / h;
float tw = (_rotated ? _frame.height : _frame.width) / w;
float th = (_rotated ? _frame.width : _frame.height) / h;
if (_rotated) UV = new Rect(x, y, tw, -th);
m_frame = new Rect(Vector2.zero, Size);
var w = m_frame.width;
var h = m_frame.height;
float x = m_frame.x / w;
float y = 1 - m_frame.y / h;
float tw = (m_rotated ? m_frame.height : m_frame.width) / w;
float th = (m_rotated ? m_frame.width : m_frame.height) / h;
if (m_rotated) UV = new Rect(x, y, tw, -th);
else UV = new Rect(x, y, tw, -th);
}
public void Init(int w, int h, Texture2D _base) {
if (Texture != null)
throw new InvalidOperationException("Missing texture");
Texture = _base;
float x = _frame.x / w;
float y = 1 - _frame.y / h;
float tw = (_rotated ? _frame.height : _frame.width) / w;
float th = (_rotated ? _frame.width : _frame.height) / h;
if (_rotated) UV = new Rect(x, y, tw, -th);
else UV = new Rect(x, y, tw, -th);
}
public SpriteFrame() { }
public SpriteFrame(Texture2D tex) {
Texture = tex;