Exemplo n.º 1
0
        public RepresentedModel(Type classWithProps)
        {
            schema = new ValueMap<string, RepresentedModelValue>();
            PropertyInfo[] props = classWithProps.GetProperties();

            foreach (PropertyInfo prop in props)
            {
                if (prop.CanRead && prop.CanWrite)
                {
                    FieldDescription[] attrs = (FieldDescription[])prop.GetCustomAttributes(typeof(FieldDescription), true);
                    bool isnull;
                    FieldType itv = GetRType(prop.PropertyType, out isnull);
                    RepresentedModelValue sch_v = new RepresentedModelValue(itv)
                    {
                        propertyDescriptor = prop
                    };
                    if (attrs.Length > 0)
                    {
                        FieldDescription at = attrs[0];
                        if (!at.Ignore)
                        {
                            sch_v.Description = at.Description;
                            sch_v.Required = at.Required;
                            sch_v.Inherited = at.Inherited;

                            schema.Add(prop.Name, sch_v);
                        }
                    }
                    else
                    {
                        schema.Add(prop.Name, sch_v);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public ValueMap <string, object> GetValueMap(TQItemSelector order)
        {
            ValueMap <string, object> result = new ValueMap <string, object>();

            if (Holder == null)
            {
                SetProps();
            }
            foreach (KeyValuePair <string, TQItemSelectorParam> rule in order.parameters)
            {
                object valobj;
                if (Holder.TryGetValue(rule.Key, out valobj))
                {
                    result.Add(rule.Key, valobj);
                }
                else
                {
                    result.Add(rule.Key, null);
                }
//                result.Add(rule.Key, Holder[rule.Key]);
            }

            // extra data - without any order
            foreach (KeyValuePair <string, object> hdpair in Holder)
            //foreach (System.Collections.DictionaryEntry hdpair in Holder)
            {
                string k = (string)hdpair.Key;
                if (!order.parameters.ContainsKey(k))
                {
                    result.Add(k, hdpair.Value);
                }
            }
            return(result);
        }
 private void WriteToGround(int2 key, DungeonTheme theme, string tile)
 {
     ValueMap.Add(key, new Dungeon.MapValue
     {
         Theme     = theme,
         Index     = (DungeonTile.Index)Convert.ToInt32(tile),
         IsSpecial = true,
     });
 }
 /// <summary>
 /// Generate a value map from a double array.
 /// Dimension 0 is read as Column
 /// Dimension 1 is read as Row
 /// </summary>
 /// <param name="valueMap"></param>
 public void GenerateGround(DungeonTheme theme, int[,] valueMap)
 {
     for (var x = 0; x < valueMap.GetLength(0); x++)
     {
         for (var y = 0; y < valueMap.GetLength(1); y++)
         {
             var key = new int2(x, y);
             ValueMap.Add(key, new Dungeon.MapValue
             {
                 Theme     = theme,
                 Index     = (DungeonTile.Index)valueMap[y, x],
                 IsSpecial = true,
             });
         }
     }
 }
Exemplo n.º 5
0
        private void AddDecoration(Dungeon dungeon)
        {
            foreach (var decorator in _meta.DecorationMeta)
            {
                foreach (var kvp in decorator.ValueMap)
                {
                    var globalKey = new int2(kvp.Key.x + _meta.CenterX, kvp.Key.y + _meta.CenterY);
                    if (dungeon.ValueMap.ContainsKey(globalKey))
                    {
                        var oldValue = dungeon.ValueMap[globalKey];
                        oldValue.Room.ValueMap.Remove(globalKey);

                        kvp.Value.Room = this;
                        dungeon.ValueMap[globalKey] = kvp.Value;
                        ValueMap.Add(globalKey, kvp.Value);
                    }
                    else
                    {
                        kvp.Value.Room = this;
                        dungeon.ValueMap.Add(globalKey, kvp.Value);
                        ValueMap.Add(globalKey, kvp.Value);
                    }
                }

                foreach (var kvp in decorator.ItemMap)
                {
                    var globalKey = new int2(kvp.Key.x + _meta.CenterX, kvp.Key.y + _meta.CenterY);
                    var item      = dungeon.SpawnItemInWorld(kvp.Value, globalKey);
                    if (decorator.ItemSpecialsMap.ContainsKey(kvp.Key))
                    {
                        item.AddSpecial(decorator.ItemSpecialsMap[kvp.Key]);
                    }
                }

                foreach (var kvp in decorator.CharacterMap)
                {
                    var globalKey = new int2(kvp.Key.x + _meta.CenterX, kvp.Key.y + _meta.CenterY);
                    var character = dungeon.SpawnAi(kvp.Value.Item1, kvp.Value.Item2, globalKey);
                    if (decorator.CharacterSpecialsMap.ContainsKey(kvp.Key))
                    {
                        character.AddSpecial(decorator.CharacterSpecialsMap[kvp.Key]);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private void AddCircularFloor(Dungeon dungeon)
        {
            var halfWidth  = _meta.Width / 2;
            var halfHeight = _meta.Height / 2;

            for (var dx = -halfWidth; dx <= halfWidth; dx++)
            {
                for (var dy = -halfHeight; dy <= halfHeight; dy++)
                {
                    var x   = _meta.CenterX + dx;
                    var y   = _meta.CenterY + dy;
                    var key = new int2(x, y);

                    if (dungeon.ValueMap.ContainsKey(key))
                    {
                        var tile = dungeon.ValueMap[key];
                        if (tile.Index != DungeonTile.Index.Wall)
                        {
                            tile.Theme = _meta.Theme;
                            tile.Index = DungeonTile.Index.Floor;
                            if (tile.Room != this)
                            {
                                tile.Room.ValueMap.Remove(key);
                                tile.Room = this;
                                tile.Room.ValueMap.Add(key, tile);
                            }
                        }
                    }
                    else
                    {
                        var tile = new Dungeon.MapValue
                        {
                            Theme = _meta.Theme,
                            Index = DungeonTile.Index.Floor,
                            Room  = this,
                        };

                        dungeon.ValueMap.Add(key, tile);
                        ValueMap.Add(key, tile);
                    }
                }
            }
        }
Exemplo n.º 7
0
 public void Push(TaskMessage item)
 {
     try
     {
         ValueMap <string, object> vmap = item.GetValueMap(this.selector);
         if (comparer.internalComparer.Check(item.Holder))
         {
             lock (MessageQueue)
             {
                 vmap.Add("__idx", Counter);
                 MessageQueue.Add(vmap);
                 Counter++;
             }
         }
     }
     catch (OutOfMemoryException excOverfl)
     {
         throw new QueueOverflowException(excOverfl);
     }
 }
Exemplo n.º 8
0
        public static ValueMap DecodeEnumerations(ISymbolEnumerator symbols)
        {
            Symbol current = symbols.NextNonEOLSymbol();
            current.Expect(Symbol.OpenBracket);

            ValueMap map = new ValueMap();
            do
            {
                current = symbols.NextNonEOLSymbol();
                string identifier = current.ToString();

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.OpenParentheses);

                current = symbols.NextNonEOLSymbol();
                Int64 enumValue;
                if (Int64.TryParse(current.ToString(), out enumValue))
                {
                    try
                    {
                        // Have to include the number as it seems repeated identifiers are allowed ??
                        map.Add(enumValue, String.Format("{0}({1})", identifier, enumValue));
                    }
                    catch (ArgumentException ex)
                    {
                        current.Assert(false, ex.Message);
                    }
                }
                else
                {
                    // Need to get "DefinedValue".
                }

                current = symbols.NextNonEOLSymbol();
                current.Expect(Symbol.CloseParentheses);

                current = symbols.NextNonEOLSymbol();
            } while (current == Symbol.Comma);

            current.Expect(Symbol.CloseBracket);

            return map;
        }