FreeTrainの進化系を目指す
画像オーバーライドの定義と管理:一応実装完了
| @@ -9,11 +9,32 @@ | ||
| 9 | 9 | using System.Drawing; |
| 10 | 10 | using System.IO; |
| 11 | 11 | using nft.core; |
| 12 | +using nft.core.view; | |
| 12 | 13 | |
| 13 | 14 | namespace nft.contributions.graphics |
| 14 | 15 | { |
| 15 | - public class CtbImageResource : Contribution | |
| 16 | + public class CtbImageResource : Contribution { | |
| 17 | + protected ConditionedResource<ImageResource> conditionedResource; | |
| 18 | + | |
| 19 | + public CtbImageResource(Plugin owner, ParamsReader contrib) : base(owner, contrib) | |
| 20 | + { | |
| 21 | + conditionedResource = ConditionedResourceFactory.LoadAsConditiondResources<ImageResource>(contrib, new ResourceParser<ImageResource>(Parse)); | |
| 22 | + } | |
| 23 | + | |
| 24 | + protected ImageResource Parse(ParamsReader reader) { | |
| 25 | + return new ImageResource(Parent, reader); | |
| 26 | + } | |
| 27 | + | |
| 28 | + public ConditionedResource<ImageResource> Data { | |
| 29 | + get { | |
| 30 | + return conditionedResource; | |
| 31 | + } | |
| 32 | + } | |
| 33 | + } | |
| 34 | + | |
| 35 | + public class ImageResource | |
| 16 | 36 | { |
| 37 | + protected ResourceKey res_key; | |
| 17 | 38 | protected WeakReference reffer; |
| 18 | 39 | protected Color colorkey; |
| 19 | 40 | protected bool auto_color_key; |
| @@ -20,7 +41,7 @@ | ||
| 20 | 41 | protected string src_text; |
| 21 | 42 | protected IFileSource file; |
| 22 | 43 | |
| 23 | - public CtbImageResource(Plugin owner, ParamsReader contrib) :base(owner, contrib) | |
| 44 | + public ImageResource(Plugin owner, ParamsReader contrib) | |
| 24 | 45 | { |
| 25 | 46 | reffer = null; |
| 26 | 47 | ParamsReader nd = contrib["src"]; |
| @@ -36,7 +57,7 @@ | ||
| 36 | 57 | { |
| 37 | 58 | colorkey = StringParseUtil.CreateColor(ckey.InnerText); |
| 38 | 59 | } |
| 39 | - | |
| 60 | + res_key = ResourceKey.CreateKey(owner, SrcText); | |
| 40 | 61 | } |
| 41 | 62 | |
| 42 | 63 | protected string SrcText |
| @@ -58,13 +79,12 @@ | ||
| 58 | 79 | return (IImageSrc)reffer.Target; |
| 59 | 80 | } else { |
| 60 | 81 | // Image file might be shared by contributions in the same plugin. So assign plugin key. |
| 61 | - ResourceKey key = ResourceKey.CreateKey(Parent, SrcText); | |
| 62 | 82 | IImageSrc img; |
| 63 | 83 | if (auto_color_key) { |
| 64 | 84 | // use left-bottom pixel as color-key |
| 65 | - img = GraphicManagerEx.GraphicManager.LoadImageFromFileWithDefaultColorKey(key, File); | |
| 85 | + img = GraphicManagerEx.GraphicManager.LoadImageFromFileWithDefaultColorKey(res_key, File); | |
| 66 | 86 | } else { |
| 67 | - img = GraphicManagerEx.GraphicManager.LoadImageFromFile(key, File, colorkey); | |
| 87 | + img = GraphicManagerEx.GraphicManager.LoadImageFromFile(res_key, File, colorkey); | |
| 68 | 88 | } |
| 69 | 89 | reffer = new WeakReference(img); |
| 70 | 90 | return img; |
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | /// <summary> |
| 8 | 8 | /// 画像などのオーバライドテーブルを保持する |
| 9 | 9 | /// </summary> |
| 10 | + /// 2014/03/02 現時点で未使用、破棄の方向 | |
| 10 | 11 | /// <typeparam name="Type"></typeparam> |
| 11 | 12 | public class OverrideTable<Type> { |
| 12 | 13 | public delegate Type ElementParser(XmlElement e); |
| @@ -32,8 +32,8 @@ | ||
| 32 | 32 | { |
| 33 | 33 | CtbImageResource ir1 = PluginManager.theInstance.GetContribution(@"test\tex112x136x96") as CtbImageResource; |
| 34 | 34 | CtbImageResource ir2 = PluginManager.theInstance.GetContribution(@"test\tex32x48x56") as CtbImageResource; |
| 35 | - ITexture tx1 = GM.CreateStaticTexture(ResourceKey.CreateKey(ir1, ir2.ID), ir1.ImageSrc); | |
| 36 | - ITexture tx2 = GM.CreateStaticTexture(ResourceKey.CreateKey(ir2, ir2.ID), ir2.ImageSrc); | |
| 35 | + ITexture tx1 = GM.CreateStaticTexture(ResourceKey.CreateKey(ir1, ir2.ID), ir1.Data.Default.ImageSrc); | |
| 36 | + ITexture tx2 = GM.CreateStaticTexture(ResourceKey.CreateKey(ir2, ir2.ID), ir2.Data.Default.ImageSrc); | |
| 37 | 37 | ICubicStructure st1 = GM.CreateStructure(0, null, tx1, new Point3D(112, 96, 136)); |
| 38 | 38 | ICubicStructure st2 = GM.CreateStructure(0, null, tx2, new Point3D(32, 56, 48)); |
| 39 | 39 | st1.Location = new PointF3D(40f, -20f, -40f); |
| @@ -1,71 +0,0 @@ | ||
| 1 | -using System; | |
| 2 | -using System.Collections.Generic; | |
| 3 | -using System.Text; | |
| 4 | -using nft.framework.drawing; | |
| 5 | -using nft.framework; | |
| 6 | -using nft.framework.plugin; | |
| 7 | - | |
| 8 | -namespace nft.core.view | |
| 9 | -{ | |
| 10 | - public delegate T ResourceParser<T>(ParamsReader reader); | |
| 11 | - | |
| 12 | - public class ConditionedResourceFactory | |
| 13 | - { | |
| 14 | - static private readonly string VALUE_NODE = "default|value"; | |
| 15 | - static private readonly string CONDITION_NODE = "condition"; | |
| 16 | - static private readonly string CONDITION_TYPE_ATTR = "when"; | |
| 17 | - | |
| 18 | - static private Dictionary<string, IConditionFactory> factories = new Dictionary<string, IConditionFactory>(); | |
| 19 | - | |
| 20 | - public static void RegisterConditionFactory(string name, IConditionFactory fct){ | |
| 21 | - factories.Add(name, fct); | |
| 22 | - } | |
| 23 | - | |
| 24 | - public static ConditionedResource<T> LoadAsConditiondResources<T>(ParamsReader resource, ResourceParser<T> callback){ | |
| 25 | - ParamsReader dnode = resource[VALUE_NODE]; | |
| 26 | - T _default = callback(dnode.IsNull ? resource : dnode); | |
| 27 | - ParamsReader conds = resource[CONDITION_NODE]; | |
| 28 | - if (conds.IsNull) { | |
| 29 | - return new ConditionedResource<T>(_default); | |
| 30 | - } else { | |
| 31 | - NestedConditionsResouceRoot<T> ret = new NestedConditionsResouceRoot<T>(_default); | |
| 32 | - foreach (ParamsReader child in conds.Each) { | |
| 33 | - ConditionedResource<T> temp = LoadChildConditions(resource, callback); | |
| 34 | - ret.AddChild(temp); | |
| 35 | - } | |
| 36 | - return AdaptOptimization<T>(ret); | |
| 37 | - } | |
| 38 | - } | |
| 39 | - | |
| 40 | - #region private functions | |
| 41 | - private static ConditionedResource<T> LoadChildConditions<T>(ParamsReader resource, ResourceParser<T> callback){ | |
| 42 | - ISceneCondition sc = GetConditionFor(resource); | |
| 43 | - ParamsReader dnode = resource[VALUE_NODE]; | |
| 44 | - T _default = callback(dnode.IsNull ? resource : dnode); | |
| 45 | - ParamsReader conds = resource[CONDITION_NODE]; | |
| 46 | - if (conds.IsNull) { | |
| 47 | - return new SingleConditionResouce<T>(sc,_default); | |
| 48 | - } else { | |
| 49 | - NestedConditionsResouce<T> ret = new NestedConditionsResouce<T>(sc, _default); | |
| 50 | - foreach (ParamsReader child in conds.Each) { | |
| 51 | - ConditionedResource<T> temp = LoadChildConditions(resource, callback); | |
| 52 | - ret.AddChild(temp); | |
| 53 | - } | |
| 54 | - return AdaptOptimization<T>(ret); | |
| 55 | - } | |
| 56 | - } | |
| 57 | - | |
| 58 | - private static ConditionedResource<T> AdaptOptimization<T>(NestedConditionsResouceRoot<T> orig) { | |
| 59 | - return orig; | |
| 60 | - } | |
| 61 | - | |
| 62 | - private static ISceneCondition GetConditionFor(ParamsReader reader) { | |
| 63 | - ParamsReader pr2 = reader[CONDITION_TYPE_ATTR]; | |
| 64 | - if (pr2.IsNull) throw new PluginXmlException(reader, ""); | |
| 65 | - string attr = pr2.InnerText; | |
| 66 | - | |
| 67 | - return null; | |
| 68 | - } | |
| 69 | - #endregion | |
| 70 | - } | |
| 71 | -} |
| @@ -1,85 +0,0 @@ | ||
| 1 | -using System; | |
| 2 | -using System.Collections.Generic; | |
| 3 | -using System.Text; | |
| 4 | - | |
| 5 | -namespace nft.core.view | |
| 6 | -{ | |
| 7 | - public class ConditionedResource<T> | |
| 8 | - { | |
| 9 | - internal protected T Default; | |
| 10 | - | |
| 11 | - public ConditionedResource(T _default) { | |
| 12 | - this.Default = _default; | |
| 13 | - } | |
| 14 | - | |
| 15 | - public T this[ISceneParams p] { | |
| 16 | - get { | |
| 17 | - T result = this.Default; | |
| 18 | - Choose(p, ref result); | |
| 19 | - return result; | |
| 20 | - } | |
| 21 | - } | |
| 22 | - | |
| 23 | - internal protected virtual bool Choose(ISceneParams p, ref T res){ | |
| 24 | - res = Default; | |
| 25 | - return true; | |
| 26 | - } | |
| 27 | - } | |
| 28 | - | |
| 29 | - internal class SingleConditionResouce<T> : ConditionedResource<T> | |
| 30 | - { | |
| 31 | - protected readonly ISceneCondition Condition; | |
| 32 | - internal SingleConditionResouce(ISceneCondition cond, T val) :base(val){ | |
| 33 | - this.Condition = cond; | |
| 34 | - } | |
| 35 | - | |
| 36 | - internal protected override bool Choose(ISceneParams p, ref T res) { | |
| 37 | - if (Condition.IsMatch(p)) { | |
| 38 | - res = Default; | |
| 39 | - return true; | |
| 40 | - } else { | |
| 41 | - return false; | |
| 42 | - } | |
| 43 | - } | |
| 44 | - } | |
| 45 | - | |
| 46 | - internal class NestedConditionsResouceRoot<T> : ConditionedResource<T> | |
| 47 | - { | |
| 48 | - internal protected readonly List<ConditionedResource<T>> children; | |
| 49 | - internal NestedConditionsResouceRoot(T val) | |
| 50 | - : base(val) { | |
| 51 | - this.children = new List<ConditionedResource<T>>(); | |
| 52 | - } | |
| 53 | - | |
| 54 | - internal protected override bool Choose(ISceneParams p, ref T res) { | |
| 55 | - foreach (ConditionedResource<T> cc in children) { | |
| 56 | - if (cc.Choose(p, ref res)) { | |
| 57 | - return true; | |
| 58 | - } | |
| 59 | - } | |
| 60 | - res = Default; | |
| 61 | - return true; | |
| 62 | - } | |
| 63 | - | |
| 64 | - public void AddChild(ConditionedResource<T> child) { | |
| 65 | - children.Add(child); | |
| 66 | - } | |
| 67 | - } | |
| 68 | - | |
| 69 | - internal class NestedConditionsResouce<T> : NestedConditionsResouceRoot<T> | |
| 70 | - { | |
| 71 | - internal protected readonly ISceneCondition Condition; | |
| 72 | - internal NestedConditionsResouce(ISceneCondition cond, T val) | |
| 73 | - : base(val) { | |
| 74 | - this.Condition = cond; | |
| 75 | - } | |
| 76 | - | |
| 77 | - internal protected override bool Choose(ISceneParams p, ref T res) { | |
| 78 | - if (Condition.IsMatch(p)) { | |
| 79 | - return base.Choose(p, ref res); | |
| 80 | - } else { | |
| 81 | - return false; | |
| 82 | - } | |
| 83 | - } | |
| 84 | - } | |
| 85 | -} |
| @@ -45,13 +45,30 @@ | ||
| 45 | 45 | bool IsMatch(ISceneParams p); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public interface IComparablesCondition { | |
| 49 | - IComparable From { get; } | |
| 50 | - | |
| 48 | + /// <summary> | |
| 49 | + /// This interface should be declared for the ISceneConditions which based on | |
| 50 | + /// 'Time' (based on the Calendar in the game) condition(s). | |
| 51 | + /// If there are several ITimeRangeConditions with the same ConditionType, They can union to include them all. | |
| 52 | + /// Which can be a new ITimeRangeCondition. | |
| 53 | + /// | |
| 54 | + /// このインターフェースはTimeクラスを条件としたISceneConditionで実装されることを想定している | |
| 55 | + /// もし、同じConditionTypeを持つ複数のITimeRangeConditionが存在するなら、 | |
| 56 | + /// その両方を同時に含む期間を定義することができ、それを条件とした新たなITimeRangeConditionとなりうる。 | |
| 57 | + /// </summary> | |
| 58 | + public interface ITimeRangeCondition { | |
| 51 | 59 | /// <summary> |
| 52 | - /// Until is null when the condition check only if a value match. | |
| 60 | + /// returns true if this condition is after the scene | |
| 53 | 61 | /// </summary> |
| 54 | - IComparable Until { get; } | |
| 62 | + /// <param name="p"></param> | |
| 63 | + /// <returns></returns> | |
| 64 | + bool IsAfter(ISceneParams p); | |
| 65 | + | |
| 66 | + /// <summary> | |
| 67 | + /// returns true if this condition is before the scene | |
| 68 | + /// </summary> | |
| 69 | + /// <param name="p"></param> | |
| 70 | + /// <returns></returns> | |
| 71 | + bool IsBefore(ISceneParams p); | |
| 55 | 72 | } |
| 56 | 73 | |
| 57 | 74 | } |
| @@ -0,0 +1,103 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | +using nft.framework.drawing; | |
| 5 | +using nft.framework; | |
| 6 | +using nft.framework.plugin; | |
| 7 | +using nft.core.schedule; | |
| 8 | +using System.Diagnostics; | |
| 9 | + | |
| 10 | +namespace nft.core.view | |
| 11 | +{ | |
| 12 | + public delegate T ResourceParser<T>(ParamsReader reader); | |
| 13 | + | |
| 14 | + public class ConditionedResourceFactory | |
| 15 | + { | |
| 16 | + static private readonly string VALUE_NODE = "default|value"; | |
| 17 | + static private readonly string CONDITION_NODE = "condition"; | |
| 18 | + static private readonly string CONDITION_DESC_ATTR = "when"; | |
| 19 | + | |
| 20 | + static private List<IConditionFactory> factories = new List<IConditionFactory>(); | |
| 21 | + | |
| 22 | + public static void RegisterConditionFactory(IConditionFactory fct){ | |
| 23 | + factories.Add(fct); | |
| 24 | + } | |
| 25 | + | |
| 26 | + private static string debug_indent = ""; | |
| 27 | + public static ConditionedResource<T> LoadAsConditiondResources<T>(ParamsReader resource, ResourceParser<T> callback){ | |
| 28 | + ParamsReader dnode = resource[VALUE_NODE]; | |
| 29 | + T _default = callback(dnode.IsNull ? resource : dnode); | |
| 30 | + ParamsReader conds = resource[CONDITION_NODE]; | |
| 31 | +#if DEBUG | |
| 32 | + debug_indent = ""; | |
| 33 | + Debug.WriteLine("default value = " + _default); | |
| 34 | +#endif | |
| 35 | + if (conds.IsNull) { | |
| 36 | + Debug.WriteLine("NO condition"); | |
| 37 | + return new ConditionedResource<T>(_default); | |
| 38 | + } else { | |
| 39 | + NestedConditionsResouceRoot<T> ret = new NestedConditionsResouceRoot<T>(_default); | |
| 40 | + Debug.WriteLine("+condition:"+ret); | |
| 41 | + foreach (ParamsReader child in conds.Each) { | |
| 42 | + ConditionedResource<T> temp = LoadChildConditions(child, callback); | |
| 43 | + ret.AddChild(temp); | |
| 44 | + } | |
| 45 | + return ApplyOptimization<T>(ret); | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 49 | + #region private functions | |
| 50 | + private static ConditionedResource<T> LoadChildConditions<T>(ParamsReader resource, ResourceParser<T> callback){ | |
| 51 | + ISceneCondition sc = GetConditionFor(resource); | |
| 52 | + ParamsReader dnode = resource[VALUE_NODE]; | |
| 53 | + T _default = callback(dnode.IsNull ? resource : dnode); | |
| 54 | +#if DEBUG | |
| 55 | + string indent_saved = debug_indent; | |
| 56 | + debug_indent += " "; | |
| 57 | + Debug.WriteLine(debug_indent+"value=" + _default); | |
| 58 | +#endif | |
| 59 | + ParamsReader conds = resource[CONDITION_NODE]; | |
| 60 | + if (conds.IsNull) { | |
| 61 | + return new SingleConditionResouce<T>(sc,_default); | |
| 62 | + } else { | |
| 63 | + NestedConditionsResouce<T> ret = new NestedConditionsResouce<T>(sc, _default); | |
| 64 | +#if DEBUG | |
| 65 | + Debug.WriteLine(debug_indent + "+condition:" + ret); | |
| 66 | +#endif | |
| 67 | + foreach (ParamsReader child in conds.Each) { | |
| 68 | + ConditionedResource<T> temp = LoadChildConditions(child, callback); | |
| 69 | + ret.AddChild(temp); | |
| 70 | + } | |
| 71 | +#if DEBUG | |
| 72 | + debug_indent = indent_saved; | |
| 73 | +#endif | |
| 74 | + return ApplyOptimization<T>(ret); | |
| 75 | + } | |
| 76 | + } | |
| 77 | + | |
| 78 | + private static ConditionedResource<T> ApplyOptimization<T>(NestedConditionsResouceRoot<T> orig) { | |
| 79 | + return orig; | |
| 80 | + } | |
| 81 | + | |
| 82 | + private static ISceneCondition GetConditionFor(ParamsReader reader) { | |
| 83 | + ISceneCondition sc = null; | |
| 84 | + foreach (IConditionFactory cf in factories) { | |
| 85 | + sc = cf.GetCondition(reader); | |
| 86 | + if (sc != null) { | |
| 87 | + Debug.WriteLine(""); | |
| 88 | + return sc; | |
| 89 | + } | |
| 90 | + } | |
| 91 | + // find from primitive conditions. | |
| 92 | + ParamsReader pr2 = reader[CONDITION_DESC_ATTR]; | |
| 93 | + if (pr2.IsNull) throw new PluginXmlException(reader, CONDITION_DESC_ATTR+" must be specified."); | |
| 94 | + string attr = pr2.InnerText; | |
| 95 | + sc = PrimitiveConditions.GetByName(attr); | |
| 96 | + if (sc == null) { | |
| 97 | + throw new PluginXmlException(reader, "Unresolved condition description : "+attr); | |
| 98 | + } | |
| 99 | + return sc; | |
| 100 | + } | |
| 101 | + #endregion | |
| 102 | + } | |
| 103 | +} |
| @@ -0,0 +1,85 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Text; | |
| 4 | + | |
| 5 | +namespace nft.core.view | |
| 6 | +{ | |
| 7 | + public class ConditionedResource<T> | |
| 8 | + { | |
| 9 | + internal protected T Default; | |
| 10 | + | |
| 11 | + public ConditionedResource(T _default) { | |
| 12 | + this.Default = _default; | |
| 13 | + } | |
| 14 | + | |
| 15 | + public T this[ISceneParams p] { | |
| 16 | + get { | |
| 17 | + T result = this.Default; | |
| 18 | + Choose(p, ref result); | |
| 19 | + return result; | |
| 20 | + } | |
| 21 | + } | |
| 22 | + | |
| 23 | + internal protected virtual bool Choose(ISceneParams p, ref T res){ | |
| 24 | + res = Default; | |
| 25 | + return true; | |
| 26 | + } | |
| 27 | + } | |
| 28 | + | |
| 29 | + internal class SingleConditionResouce<T> : ConditionedResource<T> | |
| 30 | + { | |
| 31 | + protected readonly ISceneCondition Condition; | |
| 32 | + internal SingleConditionResouce(ISceneCondition cond, T val) :base(val){ | |
| 33 | + this.Condition = cond; | |
| 34 | + } | |
| 35 | + | |
| 36 | + internal protected override bool Choose(ISceneParams p, ref T res) { | |
| 37 | + if (Condition.IsMatch(p)) { | |
| 38 | + res = Default; | |
| 39 | + return true; | |
| 40 | + } else { | |
| 41 | + return false; | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + internal class NestedConditionsResouceRoot<T> : ConditionedResource<T> | |
| 47 | + { | |
| 48 | + internal protected readonly List<ConditionedResource<T>> children; | |
| 49 | + internal NestedConditionsResouceRoot(T val) | |
| 50 | + : base(val) { | |
| 51 | + this.children = new List<ConditionedResource<T>>(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + internal protected override bool Choose(ISceneParams p, ref T res) { | |
| 55 | + foreach (ConditionedResource<T> cc in children) { | |
| 56 | + if (cc.Choose(p, ref res)) { | |
| 57 | + return true; | |
| 58 | + } | |
| 59 | + } | |
| 60 | + res = Default; | |
| 61 | + return true; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void AddChild(ConditionedResource<T> child) { | |
| 65 | + children.Add(child); | |
| 66 | + } | |
| 67 | + } | |
| 68 | + | |
| 69 | + internal class NestedConditionsResouce<T> : NestedConditionsResouceRoot<T> | |
| 70 | + { | |
| 71 | + internal protected readonly ISceneCondition Condition; | |
| 72 | + internal NestedConditionsResouce(ISceneCondition cond, T val) | |
| 73 | + : base(val) { | |
| 74 | + this.Condition = cond; | |
| 75 | + } | |
| 76 | + | |
| 77 | + internal protected override bool Choose(ISceneParams p, ref T res) { | |
| 78 | + if (Condition.IsMatch(p)) { | |
| 79 | + return base.Choose(p, ref res); | |
| 80 | + } else { | |
| 81 | + return false; | |
| 82 | + } | |
| 83 | + } | |
| 84 | + } | |
| 85 | +} |
| @@ -85,9 +85,9 @@ | ||
| 85 | 85 | _until = AdjustType(_until, t); |
| 86 | 86 | _from = AdjustType(_from, t); |
| 87 | 87 | if (_until.CompareTo(_from) > 0) { |
| 88 | - cond = new RangeCondition(groupname, name, ex, _from, _until); | |
| 88 | + cond = new TimeRangeCondition(groupname, name, ex, _from, _until); | |
| 89 | 89 | } else { |
| 90 | - cond = new BoudaryRangeCondition(groupname, name, ex, _from, _until); | |
| 90 | + cond = new BoudaryTimeRangeCondition(groupname, name, ex, _from, _until); | |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | RegisterCondtion(cond); |
| @@ -110,9 +110,9 @@ | ||
| 110 | 110 | _until = AdjustType(_until, t); |
| 111 | 111 | _from = AdjustType(_from, t); |
| 112 | 112 | if (_until.CompareTo(_from) > 0) { |
| 113 | - cond = new RangeCondition(groupname, name, ex, _from, _until); | |
| 113 | + cond = new TimeRangeCondition(groupname, name, ex, _from, _until); | |
| 114 | 114 | } else { |
| 115 | - cond = new BoudaryRangeCondition(groupname, name, ex, _from, _until); | |
| 115 | + cond = new BoudaryTimeRangeCondition(groupname, name, ex, _from, _until); | |
| 116 | 116 | } |
| 117 | 117 | } |
| 118 | 118 | } |
| @@ -258,7 +258,7 @@ | ||
| 258 | 258 | |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - public abstract class ComparebleSceneCondition : CacheableSceneCondition, IComparablesCondition { | |
| 261 | + public abstract class ComparebleSceneCondition : CacheableSceneCondition { | |
| 262 | 262 | protected IConditionValueExtracter extracter; |
| 263 | 263 | |
| 264 | 264 | protected ComparebleSceneCondition(string groupname, string name):base(groupname, name) { |
| @@ -273,16 +273,6 @@ | ||
| 273 | 273 | return extracter.ConditionType; |
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | - | |
| 277 | - #region IComparablesCondition implementation | |
| 278 | - public abstract IComparable From { get; } | |
| 279 | - | |
| 280 | - public virtual IComparable Until { | |
| 281 | - get { | |
| 282 | - return null; | |
| 283 | - } | |
| 284 | - } | |
| 285 | - #endregion | |
| 286 | 276 | } |
| 287 | 277 | |
| 288 | 278 | public class EqualityCondition : ComparebleSceneCondition { |
| @@ -295,17 +285,39 @@ | ||
| 295 | 285 | protected override bool IsMatchCore(ISceneParams p) { |
| 296 | 286 | return extracter.GetTestValue(p).CompareTo(match)==0; |
| 297 | 287 | } |
| 288 | + } | |
| 298 | 289 | |
| 299 | - public override IComparable From { | |
| 300 | - get { | |
| 301 | - return match; | |
| 302 | - } | |
| 290 | + public class TimeEqualityCondition : EqualityCondition, ITimeRangeCondition { | |
| 291 | + public TimeEqualityCondition(string groupname, string name, IConditionValueExtracter ext, IComparable v) | |
| 292 | + : base(groupname, name, ext, v) { | |
| 303 | 293 | } |
| 294 | + | |
| 295 | + #region ITimeRangeCondition implementation | |
| 296 | + // These result are not cached | |
| 297 | + | |
| 298 | + /// <summary> | |
| 299 | + /// returns true if this condition is after the scene | |
| 300 | + /// </summary> | |
| 301 | + /// <param name="p"></param> | |
| 302 | + /// <returns></returns> | |
| 303 | + public bool IsAfter(ISceneParams p) { | |
| 304 | + return extracter.GetTestValue(p).CompareTo(match) < 0; | |
| 305 | + } | |
| 306 | + | |
| 307 | + /// <summary> | |
| 308 | + /// returns true if this condition is before the scene | |
| 309 | + /// </summary> | |
| 310 | + /// <param name="p"></param> | |
| 311 | + /// <returns></returns> | |
| 312 | + public bool IsBefore(ISceneParams p) { | |
| 313 | + return extracter.GetTestValue(p).CompareTo(match) > 0; | |
| 314 | + } | |
| 315 | + #endregion | |
| 304 | 316 | } |
| 305 | 317 | |
| 306 | - public class RangeCondition : ComparebleSceneCondition { | |
| 318 | + public class TimeRangeCondition : ComparebleSceneCondition, ITimeRangeCondition { | |
| 307 | 319 | protected IComparable from, until; |
| 308 | - public RangeCondition(string groupname, string name, IConditionValueExtracter ext, IComparable from, IComparable until) | |
| 320 | + public TimeRangeCondition(string groupname, string name, IConditionValueExtracter ext, IComparable from, IComparable until) | |
| 309 | 321 | : base(groupname, name, ext) { |
| 310 | 322 | this.from = from; |
| 311 | 323 | this.until = until; |
| @@ -316,17 +328,27 @@ | ||
| 316 | 328 | return v.CompareTo(from) >= 0 && v.CompareTo(until) < 0; //from <= v && v < until; |
| 317 | 329 | } |
| 318 | 330 | |
| 319 | - public override IComparable From { | |
| 320 | - get { | |
| 321 | - return from; | |
| 322 | - } | |
| 331 | + #region ITimeRangeCondition implementation | |
| 332 | + // These result are not cached | |
| 333 | + | |
| 334 | + /// <summary> | |
| 335 | + /// returns true if this condition is after the scene | |
| 336 | + /// </summary> | |
| 337 | + /// <param name="p"></param> | |
| 338 | + /// <returns></returns> | |
| 339 | + public bool IsAfter(ISceneParams p) { | |
| 340 | + return extracter.GetTestValue(p).CompareTo(from) < 0; | |
| 323 | 341 | } |
| 324 | 342 | |
| 325 | - public override IComparable Until { | |
| 326 | - get { | |
| 327 | - return until; | |
| 328 | - } | |
| 343 | + /// <summary> | |
| 344 | + /// returns true if this condition is before the scene | |
| 345 | + /// </summary> | |
| 346 | + /// <param name="p"></param> | |
| 347 | + /// <returns></returns> | |
| 348 | + public bool IsBefore(ISceneParams p) { | |
| 349 | + return extracter.GetTestValue(p).CompareTo(until) > 0; | |
| 329 | 350 | } |
| 351 | + #endregion | |
| 330 | 352 | } |
| 331 | 353 | |
| 332 | 354 | /// <summary> |
| @@ -334,9 +356,9 @@ | ||
| 334 | 356 | /// For example, from at 23 o'clock to at 1 o'clock of the next day. |
| 335 | 357 | /// This condition is given with arguments from=23, to=1. |
| 336 | 358 | /// </summary> |
| 337 | - public class BoudaryRangeCondition : ComparebleSceneCondition { | |
| 359 | + public class BoudaryTimeRangeCondition : ComparebleSceneCondition, ITimeRangeCondition { | |
| 338 | 360 | protected IComparable from, until; |
| 339 | - public BoudaryRangeCondition(string groupname, string name, IConditionValueExtracter ext, IComparable from, IComparable until) | |
| 361 | + public BoudaryTimeRangeCondition(string groupname, string name, IConditionValueExtracter ext, IComparable from, IComparable until) | |
| 340 | 362 | : base(groupname, name, ext) { |
| 341 | 363 | this.from = from; |
| 342 | 364 | this.until = until; |
| @@ -347,17 +369,27 @@ | ||
| 347 | 369 | return v.CompareTo(until) < 0 || v.CompareTo(from) >= 0; //v < until || from <= v; |
| 348 | 370 | } |
| 349 | 371 | |
| 350 | - public override IComparable From { | |
| 351 | - get { | |
| 352 | - return from; | |
| 353 | - } | |
| 372 | + #region ITimeRangeCondition implementation | |
| 373 | + // These result are not cached | |
| 374 | + | |
| 375 | + /// <summary> | |
| 376 | + /// returns true if this condition is after the scene | |
| 377 | + /// </summary> | |
| 378 | + /// <param name="p"></param> | |
| 379 | + /// <returns></returns> | |
| 380 | + public bool IsAfter(ISceneParams p) { | |
| 381 | + return extracter.GetTestValue(p).CompareTo(from) < 0; | |
| 354 | 382 | } |
| 355 | 383 | |
| 356 | - public override IComparable Until { | |
| 357 | - get { | |
| 358 | - return until; | |
| 359 | - } | |
| 384 | + /// <summary> | |
| 385 | + /// returns true if this condition is before the scene | |
| 386 | + /// </summary> | |
| 387 | + /// <param name="p"></param> | |
| 388 | + /// <returns></returns> | |
| 389 | + public bool IsBefore(ISceneParams p) { | |
| 390 | + return extracter.GetTestValue(p).CompareTo(until) > 0; | |
| 360 | 391 | } |
| 392 | + #endregion | |
| 361 | 393 | } |
| 362 | 394 | |
| 363 | 395 | public class WeatherCondition : CacheableSceneCondition { |