Refactor SkinPropertyKey.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Cryville.Common.Pdt;
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Pdt;
|
||||
using Cryville.Crtr.Components;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
@@ -8,10 +10,11 @@ namespace Cryville.Crtr {
|
||||
public SkinInterpreter(string src, Binder binder) : base(src, typeof(PdtSkin), binder) { }
|
||||
|
||||
readonly List<SkinSelector> s = new List<SkinSelector>();
|
||||
readonly List<string> a = new List<string>();
|
||||
readonly HashSet<string> a = new HashSet<string>();
|
||||
readonly List<string> k = new List<string>(2);
|
||||
protected override object InterpretKey(Type type) {
|
||||
s.Clear(); a.Clear();
|
||||
string key = "";
|
||||
s.Clear(); a.Clear(); k.Clear();
|
||||
bool invalidKeyFlag = false, compKeyFlag = false;
|
||||
while (true) {
|
||||
int pp = Position;
|
||||
switch (cc) {
|
||||
@@ -22,19 +25,22 @@ namespace Cryville.Crtr {
|
||||
case '$':
|
||||
GetChar();
|
||||
s.Add(new SkinSelector.CreateObject());
|
||||
key = null;
|
||||
invalidKeyFlag = true;
|
||||
break;
|
||||
case '.':
|
||||
GetChar();
|
||||
if (cc == '.') {
|
||||
GetChar();
|
||||
s.Add(new SkinSelector.AtAnchor(GetIdentifier()));
|
||||
key = null;
|
||||
invalidKeyFlag = true;
|
||||
}
|
||||
else {
|
||||
var p3 = GetIdentifier();
|
||||
s.Add(new SkinSelector.Anchor(p3));
|
||||
if (key != null) key += "." + p3;
|
||||
if (!invalidKeyFlag) {
|
||||
if (k.Count != 1) invalidKeyFlag = true;
|
||||
else k.Add(p3);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '>':
|
||||
@@ -43,24 +49,61 @@ namespace Cryville.Crtr {
|
||||
break;
|
||||
case ';':
|
||||
case ':':
|
||||
return key;
|
||||
if (invalidKeyFlag) throw new FormatException("Invalid key format");
|
||||
if (a.Contains("has")) {
|
||||
if (k.Count != 1) throw new FormatException("Invalid anchor name");
|
||||
return new SkinPropertyKey.CreateAnchor {
|
||||
Name = IdentifierManager.SharedInstance.Request(k[0])
|
||||
};
|
||||
}
|
||||
else if (a.Contains("at")) {
|
||||
if (k.Count != 1) throw new FormatException("Invalid anchor name");
|
||||
return new SkinPropertyKey.SetAnchor {
|
||||
Name = IdentifierManager.SharedInstance.Request(k[0])
|
||||
};
|
||||
}
|
||||
switch (k.Count) {
|
||||
case 1:
|
||||
if (compKeyFlag) return new SkinPropertyKey.CreateComponent {
|
||||
Component = GetComponentByName(k[0])
|
||||
};
|
||||
else return new SkinPropertyKey.SetProperty {
|
||||
Component = typeof(TransformInterface),
|
||||
Name = IdentifierManager.SharedInstance.Request(k[0])
|
||||
};
|
||||
case 2:
|
||||
return new SkinPropertyKey.SetProperty {
|
||||
Component = GetComponentByName(k[0]),
|
||||
Name = IdentifierManager.SharedInstance.Request(k[1])
|
||||
};
|
||||
default:
|
||||
throw new FormatException("Unknown error"); // Unreachable
|
||||
}
|
||||
case '{':
|
||||
return new SkinSelectors(s, a);
|
||||
case '}':
|
||||
return null;
|
||||
case '*':
|
||||
GetChar();
|
||||
key += "*";
|
||||
compKeyFlag = true;
|
||||
break;
|
||||
default:
|
||||
var p4 = GetIdentifier();
|
||||
s.Add(new SkinSelector.ElementType(p4));
|
||||
if (key != null) key += p4;
|
||||
if (!invalidKeyFlag) {
|
||||
if (k.Count != 0) invalidKeyFlag = true;
|
||||
else k.Add(p4);
|
||||
}
|
||||
break;
|
||||
}
|
||||
ws();
|
||||
if (Position == pp) throw new FormatException("Invalid selector or key format");
|
||||
}
|
||||
}
|
||||
static Type GetComponentByName(string name) {
|
||||
Type result;
|
||||
if (GenericResources.Components.TryGetValue(name, out result)) return result;
|
||||
throw new ArgumentException(string.Format("Component type {0} not found", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user