Refactor SkinPropertyKey.
This commit is contained in:
@@ -1,13 +1,8 @@
|
||||
using Cryville.Common;
|
||||
using Cryville.Common.Pdt;
|
||||
using Cryville.Crtr.Browsing;
|
||||
using Cryville.Crtr.Components;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Cryville.Crtr {
|
||||
@@ -37,7 +32,6 @@ namespace Cryville.Crtr {
|
||||
|
||||
public class PdtSkin : SkinElement { }
|
||||
|
||||
[Binder(typeof(SkinElementBinder))]
|
||||
public class SkinElement {
|
||||
[ElementList]
|
||||
public Dictionary<SkinSelectors, SkinElement> elements
|
||||
@@ -67,36 +61,4 @@ namespace Cryville.Crtr {
|
||||
}
|
||||
}
|
||||
}
|
||||
public struct SkinPropertyKey {
|
||||
public Type Component;
|
||||
public int Name;
|
||||
}
|
||||
public class SkinElementBinder : EmptyBinder {
|
||||
public override object ChangeType(object value, Type type, CultureInfo culture) {
|
||||
if (value is string && type == typeof(SkinPropertyKey)) {
|
||||
var cp = ((string)value).Split('.');
|
||||
switch (cp.Length) {
|
||||
case 1:
|
||||
var key = cp[0];
|
||||
if (key[0] == '*')
|
||||
return new SkinPropertyKey { Component = GetComponentByName(key.Substring(1)) };
|
||||
else
|
||||
return new SkinPropertyKey { Component = typeof(TransformInterface), Name = IdentifierManager.SharedInstance.Request(key) };
|
||||
case 2:
|
||||
return new SkinPropertyKey { Component = GetComponentByName(cp[0]), Name = IdentifierManager.SharedInstance.Request(cp[1]) };
|
||||
}
|
||||
}
|
||||
return base.ChangeType(value, type, culture);
|
||||
}
|
||||
|
||||
static readonly char[] nssep = new char[]{':'};
|
||||
Type GetComponentByName(string name) {
|
||||
var nstuple = name.Split(nssep, 2);
|
||||
var ns = nssep.Length == 2 ? nstuple[0] : "generic";
|
||||
name = nssep.Length == 2 ? nstuple[1] : nstuple[0];
|
||||
if (ns == "generic")
|
||||
return GenericResources.Components[name];
|
||||
throw new ArgumentException(string.Format("Component type {0} not found", name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user