Exception cleanup. Code cleanup.
This commit is contained in:
@@ -19,7 +19,8 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <returns>The operand at the specified index.</returns>
|
/// <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>
|
/// <exception cref="IndexOutOfRangeException"><paramref name="index" /> is not less than <see cref="LoadedOperandCount" /> or less than 0.</exception>
|
||||||
protected PdtVariableMemory GetOperand(int index) {
|
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;
|
int i = index + _loadindex;
|
||||||
return _operands[i];
|
return _operands[i];
|
||||||
}
|
}
|
||||||
@@ -33,11 +34,9 @@ namespace Cryville.Common.Pdt {
|
|||||||
_operands = new PdtVariableMemory[pc];
|
_operands = new PdtVariableMemory[pc];
|
||||||
}
|
}
|
||||||
PdtEvaluatorBase _etor;
|
PdtEvaluatorBase _etor;
|
||||||
bool _failure = false;
|
|
||||||
bool _rfreq = true;
|
bool _rfreq = true;
|
||||||
internal void Begin(PdtEvaluatorBase etor) {
|
internal void Begin(PdtEvaluatorBase etor) {
|
||||||
_etor = etor;
|
_etor = etor;
|
||||||
_failure = false;
|
|
||||||
_loadindex = ParamCount;
|
_loadindex = ParamCount;
|
||||||
}
|
}
|
||||||
internal void LoadOperand(PdtVariableMemory mem) {
|
internal void LoadOperand(PdtVariableMemory mem) {
|
||||||
@@ -51,10 +50,6 @@ namespace Cryville.Common.Pdt {
|
|||||||
if (_rfreq) _etor.DiscardStack();
|
if (_rfreq) _etor.DiscardStack();
|
||||||
throw new InvalidOperationException("Evaluation failed", ex);
|
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");
|
if (!_rfreq && !noset) throw new InvalidOperationException("Return frame not set");
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -69,10 +64,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <returns>The return frame.</returns>
|
/// <returns>The return frame.</returns>
|
||||||
/// <exception cref="InvalidOperationException">The return frame has already been requested.</exception>
|
/// <exception cref="InvalidOperationException">The return frame has already been requested.</exception>
|
||||||
protected PdtVariableMemory GetReturnFrame(int type, int len) {
|
protected PdtVariableMemory GetReturnFrame(int type, int len) {
|
||||||
if (_rfreq) {
|
if (_rfreq) throw new InvalidOperationException("Return frame requested twice");
|
||||||
_failure = true;
|
|
||||||
throw new InvalidOperationException("Return frame already requested");
|
|
||||||
}
|
|
||||||
_rfreq = true;
|
_rfreq = true;
|
||||||
return _etor.StackAlloc(type, _prmem, len);
|
return _etor.StackAlloc(type, _prmem, len);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,19 +28,19 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsNullable(int type) {
|
public override bool IsNullable(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte GetDimension(int type) {
|
public override byte GetDimension(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetTypeName(int type) {
|
public override string GetTypeName(int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: return "Mouse Position";
|
case 0: return "Mouse Position";
|
||||||
default: throw new ArgumentOutOfRangeException(nameof(type));
|
default: throw new ArgumentOutOfRangeException("type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,19 +28,19 @@ namespace Cryville.Common.Unity.Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool IsNullable(int type) {
|
public override bool IsNullable(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override byte GetDimension(int type) {
|
public override byte GetDimension(int type) {
|
||||||
if (type != 0) throw new ArgumentOutOfRangeException(nameof(type));
|
if (type != 0) throw new ArgumentOutOfRangeException("type");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetTypeName(int type) {
|
public override string GetTypeName(int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 0: return "Touch";
|
case 0: return "Touch";
|
||||||
default: throw new ArgumentOutOfRangeException(nameof(type));
|
default: throw new ArgumentOutOfRangeException("type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ namespace Cryville.Crtr {
|
|||||||
public virtual EventList GetEventsOfType(string type) {
|
public virtual EventList GetEventsOfType(string type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "motions": return new EventList<Chart.Motion>(motions);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
public Rect Rect {
|
public Rect Rect {
|
||||||
get { return Frame.frame; }
|
get { return Frame.Frame; }
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The ratio of width divided by height.
|
/// The ratio of width divided by height.
|
||||||
|
|||||||
@@ -63,13 +63,13 @@ namespace Cryville.Crtr.Components {
|
|||||||
case 1: x = _border.x; bx = b.x; break;
|
case 1: x = _border.x; bx = b.x; break;
|
||||||
case 2: x = _border.y; bx = b.y; break;
|
case 2: x = _border.y; bx = b.y; break;
|
||||||
case 3: x = 1; bx = 1; break;
|
case 3: x = 1; bx = 1; break;
|
||||||
default: throw new Exception();
|
default: throw new NotSupportedException("Built-in resource corrupted");
|
||||||
}
|
}
|
||||||
float y;
|
float y;
|
||||||
switch ((int)muv[i].y) {
|
switch ((int)muv[i].y) {
|
||||||
case 0: y = 0; break;
|
case 0: y = 0; break;
|
||||||
case 3: y = 1; 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);
|
uv[i] = frameInfo.Frame.GetUV(x, y);
|
||||||
bx -= 0.5f; y -= 0.5f;
|
bx -= 0.5f; y -= 0.5f;
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace Cryville.Crtr.Components {
|
|||||||
foreach (var f in m_frames) {
|
foreach (var f in m_frames) {
|
||||||
f.Value.Load();
|
f.Value.Load();
|
||||||
if (frameHeight == 0) frameHeight = f.Value.Rect.height;
|
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;
|
var tex = f.Value.Frame.Texture;
|
||||||
if (!meshes.ContainsKey(tex)) {
|
if (!meshes.ContainsKey(tex)) {
|
||||||
var m = new MeshWrapper();
|
var m = new MeshWrapper();
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ namespace Cryville.Crtr.Event {
|
|||||||
|
|
||||||
public void AttachHandler(ContainerHandler h) {
|
public void AttachHandler(ContainerHandler h) {
|
||||||
if (Handler != null)
|
if (Handler != null)
|
||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException("Handler attached twice");
|
||||||
Handler = h;
|
Handler = h;
|
||||||
h.cs = this;
|
h.cs = this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ namespace Cryville.Crtr.Extensions.Malody {
|
|||||||
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
public override IEnumerable<Resource> ConvertFrom(FileInfo file) {
|
||||||
List<Resource> result = new List<Resource>();
|
List<Resource> result = new List<Resource>();
|
||||||
MalodyChart src;
|
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)) {
|
using (var reader = new StreamReader(file.FullName)) {
|
||||||
src = JsonConvert.DeserializeObject<MalodyChart>(reader.ReadToEnd());
|
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];
|
var ruleset = "malody!" + MODES[src.meta.mode];
|
||||||
if (src.meta.mode == 0) {
|
if (src.meta.mode == 0) {
|
||||||
@@ -110,7 +110,7 @@ namespace Cryville.Crtr.Extensions.Malody {
|
|||||||
offset = -tev.offset / 1000f,
|
offset = -tev.offset / 1000f,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else throw new NotImplementedException();
|
else throw new NotImplementedException("Key sounds are not supported yet");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var rn = new Chart.Note() {
|
var rn = new Chart.Note() {
|
||||||
@@ -135,9 +135,9 @@ namespace Cryville.Crtr.Extensions.Malody {
|
|||||||
var sev = tev.StartEvent;
|
var sev = tev.StartEvent;
|
||||||
longEvents.Remove(sev);
|
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;
|
var endbeat = tm.FractionalBeatTime;
|
||||||
endbeat.b += 4;
|
endbeat.b += 4;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace Cryville.Crtr.Extensions.osu {
|
|||||||
if (line.StartsWith("osu file format v")) {
|
if (line.StartsWith("osu file format v")) {
|
||||||
version = int.Parse(line.Substring(17), CultureInfo.InvariantCulture);
|
version = int.Parse(line.Substring(17), CultureInfo.InvariantCulture);
|
||||||
if (version > 14) throw new NotSupportedException("osu! chart format version too high");
|
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");
|
else throw new NotSupportedException("Unrecognized osu! chart format");
|
||||||
flag = true;
|
flag = true;
|
||||||
@@ -143,9 +143,9 @@ namespace Cryville.Crtr.Extensions.osu {
|
|||||||
int rulesetID = int.Parse(pair.Value, CultureInfo.InvariantCulture);
|
int rulesetID = int.Parse(pair.Value, CultureInfo.InvariantCulture);
|
||||||
var ruleset = "osu!";
|
var ruleset = "osu!";
|
||||||
switch (rulesetID) {
|
switch (rulesetID) {
|
||||||
case 0: /*ruleset += "standard";*/ throw new NotSupportedException("osu!standard 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 NotSupportedException("osu!taiko 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 NotSupportedException("osu!catch mode is not supported yet");
|
case 2: /*ruleset += "catch";*/ throw new NotImplementedException("osu!catch mode is not supported yet");
|
||||||
case 3: ruleset += "mania"; break;
|
case 3: ruleset += "mania"; break;
|
||||||
}
|
}
|
||||||
meta.ruleset = chart.ruleset = ruleset;
|
meta.ruleset = chart.ruleset = ruleset;
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace Cryville.Crtr {
|
|||||||
protected override bool Collapse(int name, PdtVariableMemory param) {
|
protected override bool Collapse(int name, PdtVariableMemory param) {
|
||||||
if (name == _colop_and) return param.Type == PdtInternalType.Number && param.AsNumber() <= 0;
|
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 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; }
|
public ChartEvent ContextEvent { private get; set; }
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using Cryville.Common;
|
||||||
using Cryville.Common.Pdt;
|
using Cryville.Common.Pdt;
|
||||||
using Cryville.Crtr.Components;
|
using Cryville.Crtr.Components;
|
||||||
using Cryville.Crtr.Event;
|
using Cryville.Crtr.Event;
|
||||||
@@ -100,10 +101,16 @@ namespace Cryville.Crtr {
|
|||||||
SkinProperty GetPropOp(Transform obj, SkinPropertyKey key) {
|
SkinProperty GetPropOp(Transform obj, SkinPropertyKey key) {
|
||||||
var ctype = key.Component;
|
var ctype = key.Component;
|
||||||
var comp = (SkinComponent)obj.GetComponent(ctype);
|
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;
|
SkinProperty result;
|
||||||
if (!comp.Properties.TryGetValue(key.Name, out 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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,32 +3,18 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace Cryville.Crtr {
|
namespace Cryville.Crtr {
|
||||||
public class SpriteFrame {
|
public class SpriteFrame {
|
||||||
#pragma warning disable IDE1006
|
Rect m_frame;
|
||||||
Rect _frame;
|
public Rect Frame {
|
||||||
public Rect frame {
|
get { return m_frame; }
|
||||||
get { return _frame; }
|
set { m_frame = value; }
|
||||||
set { _frame = value; }
|
|
||||||
}
|
|
||||||
public Rect textureRect {
|
|
||||||
get { return _frame; }
|
|
||||||
set { _frame = value; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _rotated = false;
|
bool m_rotated = false;
|
||||||
public bool rotated {
|
public bool Rotated {
|
||||||
get { return _rotated; }
|
get { return m_rotated; }
|
||||||
set { _rotated = value; }
|
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 Rect _uv;
|
||||||
private Vector2[] cuv;
|
private Vector2[] cuv;
|
||||||
public Rect UV {
|
public Rect UV {
|
||||||
@@ -41,7 +27,7 @@ namespace Cryville.Crtr {
|
|||||||
float x1 = Mathf.Max(_uv.xMin, _uv.xMax);
|
float x1 = Mathf.Max(_uv.xMin, _uv.xMax);
|
||||||
float y0 = Mathf.Min(_uv.yMin, _uv.yMax);
|
float y0 = Mathf.Min(_uv.yMin, _uv.yMax);
|
||||||
float y1 = Mathf.Max(_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(x0, y1),
|
||||||
new Vector2(x1, y0),
|
new Vector2(x1, y0),
|
||||||
new Vector2(x0, y0),
|
new Vector2(x0, y0),
|
||||||
@@ -79,28 +65,17 @@ namespace Cryville.Crtr {
|
|||||||
public void Init() {
|
public void Init() {
|
||||||
if (Texture == null)
|
if (Texture == null)
|
||||||
throw new InvalidOperationException("Missing texture");
|
throw new InvalidOperationException("Missing texture");
|
||||||
_frame = new Rect(Vector2.zero, Size);
|
m_frame = new Rect(Vector2.zero, Size);
|
||||||
var w = _frame.width;
|
var w = m_frame.width;
|
||||||
var h = _frame.height;
|
var h = m_frame.height;
|
||||||
float x = _frame.x / w;
|
float x = m_frame.x / w;
|
||||||
float y = 1 - _frame.y / h;
|
float y = 1 - m_frame.y / h;
|
||||||
float tw = (_rotated ? _frame.height : _frame.width) / w;
|
float tw = (m_rotated ? m_frame.height : m_frame.width) / w;
|
||||||
float th = (_rotated ? _frame.width : _frame.height) / h;
|
float th = (m_rotated ? m_frame.width : m_frame.height) / h;
|
||||||
if (_rotated) UV = new Rect(x, y, tw, -th);
|
if (m_rotated) UV = new Rect(x, y, tw, -th);
|
||||||
else 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() { }
|
||||||
public SpriteFrame(Texture2D tex) {
|
public SpriteFrame(Texture2D tex) {
|
||||||
Texture = tex;
|
Texture = tex;
|
||||||
|
|||||||
Reference in New Issue
Block a user