private static AttributeDefinitionDraft CreateEnumAttributeDefinitionDraft()
        {
            AttributeDefinitionDraft attributeDefinitionDraft = new AttributeDefinitionDraft();

            attributeDefinitionDraft.Name  = "enum-attribute-name";
            attributeDefinitionDraft.Label = new LocalizedString()
            {
                { "en", "enum-attribute-label" }
            };
            attributeDefinitionDraft.IsRequired = false;
            EnumAttributeType enumAttributeType = new EnumAttributeType();

            enumAttributeType.Values = new List <PlainEnumValue>();
            enumAttributeType.Values.Add(new PlainEnumValue()
            {
                Key = "enum-key-1", Label = "enum-label-1"
            });
            enumAttributeType.Values.Add(new PlainEnumValue()
            {
                Key = "enum-key-2", Label = "enum-label-2"
            });
            enumAttributeType.Values.Add(new PlainEnumValue()
            {
                Key = "enum-key-3", Label = "enum-label-3"
            });
            attributeDefinitionDraft.Type         = enumAttributeType;
            attributeDefinitionDraft.IsSearchable = true;
            return(attributeDefinitionDraft);
        }
예제 #2
0
파일: Item.cs 프로젝트: Tonaplo/RPG
        /// <summary>
        /// This function adds an Attribute to an item. Weapons and Armor can have 3 Attribute + their AttackDamage/Armor. BattleCharms can have 4 Attributes
        /// </summary>
        /// <param name="type">The type of Attribute being added</param>
        /// <param name="value">The value of the Attribute being added</param>
        public void AddAttributeToItem(EnumAttributeType type, int value)
        {
            if (value == 0)
                value = 1;

            if (this.stats.Count < 4 && !this.stats.Any(p => p.Type.Equals(type)))
                this.stats.Add(new UnitAttribute(type, value));
            else if (this.stats.Count >= 4)
            {
            }
        }
예제 #3
0
        public virtual bool validAttribute(string key, string attribute, KElement.EnumValidationLevel level)
        {
            EnumAttributeType typ = getAttributeType(key);

            if (typ == null) // unknown attributes are by definition valid, the
            // check is done in the unknown method
            {
                return(true);
            }

            // get the correct enumeration lists
            ValuedEnum enu = null;

            if ((typ == EnumAttributeType.enumeration) || (typ == EnumAttributeType.enumerations))
            {
                enu = getAttributeEnum(key);
            }
            else if (typ == EnumAttributeType.JDFJMFVersion)
            {
                enu = EnumVersion.getEnum(0);
            }

            EnumAttributeValidity val = getAttributeValidity(key);

            if (val == EnumAttributeValidity.Unknown)
            {
                return(attribute == null);
            }
            else if (val == EnumAttributeValidity.Deprecated)
            {
                return((attribute == null) || EnumValidationLevel.isNoWarn(level));
            }
            else if (val == EnumAttributeValidity.None) // prerelease may be set
            // by schema validating
            // parser
            {
                return((attribute == null) || attribute.Equals(getAttributeDefault(key)) || EnumValidationLevel.isNoWarn(level));
            }
            else if ((val == EnumAttributeValidity.Optional) || ((level != EnumValidationLevel.Complete) && (level != EnumValidationLevel.RecursiveComplete)))
            {
                return((attribute == null) || validStringForType(attribute, typ, enu));
            }
            else if (val == EnumAttributeValidity.Required)
            {
                return((attribute != null) && validStringForType(attribute, typ, enu));
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// This function adds an Attribute to an item. Weapons and Armor can have 3 Attribute + their AttackDamage/Armor. BattleCharms can have 4 Attributes
        /// </summary>
        /// <param name="type">The type of Attribute being added</param>
        /// <param name="value">The value of the Attribute being added</param>
        public void AddAttributeToItem(EnumAttributeType type, int value)
        {
            if (value == 0)
            {
                value = 1;
            }

            if (this.stats.Count < 4 && !this.stats.Any(p => p.Type.Equals(type)))
            {
                this.stats.Add(new UnitAttribute(type, value));
            }
            else if (this.stats.Count >= 4)
            {
            }
        }
예제 #5
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="name">名称</param>
 /// <param name="alias">别名</param>
 /// <param name="dataType">数据类型</param>
 /// <param name="value">值</param>
 /// <param name="defaultValue">默认值</param>
 /// <param name="remark">备注</param>
 /// <param name="valueSet">值的可选集</param>
 /// <param name="isVisible">是否可见</param>
 /// <param name="readOnly">是否只读</param>
 /// <param name="dataSourceCode">数据源编码</param>
 /// <param name="isNeedPrecursor">是否需要前驱依赖,0和1</param>
 /// <param name="attributeType">属性类别,枚举:EnumAttributeType:一般属性和运行时属性</param>
 public Property(string name, string alias, EnumValueMetaType dataType, object value = null,
                 object defaultValue = null, string remark      = "", object[] valueSet   = null, int isVisible = 1, int readOnly = 0,
                 int required        = 1, string dataSourceCode = "", int isNeedPrecursor = 0, EnumAttributeType attributeType = EnumAttributeType.NORMAL)
 {
     this.Name            = name;
     this.Alias           = alias;
     this.DataType        = (int)dataType;
     this.DataTypeDesc    = EnumUtil.GetEnumDescription(dataType);
     this.DataTypeCode    = EnumUtil.GetEnumName <EnumValueMetaType>(this.DataType);
     this.Value           = value;
     this.DefaultValue    = defaultValue;
     this.ValueSet        = valueSet;
     this.IsVisible       = isVisible;
     this.Remark          = remark;
     this.ReadOnly        = readOnly;
     this.Required        = required;
     this.DataSourceCode  = dataSourceCode;
     this.IsNeedPrecursor = isNeedPrecursor;
     this.Type            = attributeType;
 }
예제 #6
0
        public static bool validStringForType(string val, EnumAttributeType iType, ValuedEnum enu)
        {
            if (val == null)
            {
                return(false);
            }

            try
            {
                if (iType == AttributeInfo.EnumAttributeType.Any)
                {
                    return(true);
                }
                if (iType == AttributeInfo.EnumAttributeType.string_)
                {
                    return(val.Length < 1024);
                }
                if (iType == AttributeInfo.EnumAttributeType.shortString)
                {
                    return(val.Length < 64);
                }
                if (iType == AttributeInfo.EnumAttributeType.ID)
                {
                    return(StringUtil.isID(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.NMTOKEN)
                {
                    return(StringUtil.isNMTOKEN(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.NMTOKENS)
                {
                    return(StringUtil.isNMTOKENS(val, false));
                }
                if (iType == AttributeInfo.EnumAttributeType.IDREF)
                {
                    return(StringUtil.isID(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.IDREFS)
                {
                    return(StringUtil.isNMTOKENS(val, true));
                }
                if (iType == AttributeInfo.EnumAttributeType.boolean_)
                {
                    return(StringUtil.isBoolean(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.double_)
                {
                    return(StringUtil.isNumber(val));
                }
                if (iType == AttributeInfo.EnumAttributeType.integer)
                {
                    return(StringUtil.isInteger(val));
                }
                // integer or unbounded
                if (iType == AttributeInfo.EnumAttributeType.unbounded)
                {
                    return(JDFConstants.UNBOUNDED.Equals(val) || StringUtil.isInteger(val));
                }

                if ((iType == AttributeInfo.EnumAttributeType.URI) || (iType == AttributeInfo.EnumAttributeType.URL))
                {
                    return(UrlUtil.isIRL(val));
                }
                else if (iType == AttributeInfo.EnumAttributeType.RegExp)
                {
                    return(true);
                }

                else if ((iType == AttributeInfo.EnumAttributeType.enumeration) || (iType == AttributeInfo.EnumAttributeType.JDFJMFVersion))
                {
                    if (enu != null)
                    {
                        ValuedEnum ve = (ValuedEnum)EnumUtils.getEnum(enu.GetType(), val);
                        return(ve != null);
                    }
                    // limp along if something went wrong
                    return(StringUtil.isNMTOKEN(val));
                }
                else if (iType == AttributeInfo.EnumAttributeType.enumerations)
                {
                    if (enu != null)
                    {
                        VString vs = new VString(StringUtil.tokenize(val, JDFConstants.BLANK, false));
                        for (int i = 0; i < vs.Count; i++)
                        {
                            ValuedEnum ve = (ValuedEnum)EnumUtils.getEnum(enu.GetType(), vs.stringAt(i));
                            // there was an invalid token
                            if (ve == null)
                            {
                                return(false);
                            }
                        }
                        // all were ok
                        return(true);
                    }
                    // limp along if something went wrong
                    return(StringUtil.isNMTOKENS(val, false));
                }
                else if (iType == AttributeInfo.EnumAttributeType.IntegerRange)
                {
                    new JDFIntegerRange(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.IntegerList)
                {
                    new JDFIntegerList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.IntegerRangeList)
                {
                    new JDFIntegerRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.NumberRange)
                {
                    new JDFNumberRange(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.NumberRangeList)
                {
                    new JDFNumberRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.NumberList)
                {
                    new JDFNumberList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.matrix)
                {
                    new JDFMatrix(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.rectangle)
                {
                    new JDFRectangle(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.shape)
                {
                    new JDFShape(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.XYPair)
                {
                    new JDFXYPair(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.XYPairRange)
                {
                    new JDFXYPairRange(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.XYPairRangeList)
                {
                    new JDFXYPairRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.dateTime)
                {
                    new JDFDate(val);
                    return(val.IndexOf("T") == 10); // pure dates are not valid
                }
                else if (iType == AttributeInfo.EnumAttributeType.duration)
                {
                    new JDFDuration(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.DurationRangeList)
                {
                    new JDFDurationRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.DateTimeRangeList)
                {
                    new JDFDateTimeRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.RectangleRangeList)
                {
                    new JDFRectangleRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.ShapeRangeList)
                {
                    new JDFShapeRangeList(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.CMYKColor)
                {
                    new JDFCMYKColor(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.LabColor)
                {
                    new JDFLabColor(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.RGBColor)
                {
                    new JDFRGBColor(val);
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.language)
                {
                    return(validLanguageString(val));
                }
                else if (iType == AttributeInfo.EnumAttributeType.languages)
                {
                    VString v = new VString(StringUtil.tokenize(val, JDFConstants.BLANK, false));
                    for (int i = 0; i < v.Count; i++)
                    {
                        if (!validLanguageString(v[i]))
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.PDFPath)
                {
                    // TODO better regexp
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.XPath)
                {
                    // TODO better regexp
                    return(true);
                }
                else if (iType == AttributeInfo.EnumAttributeType.hexBinary)
                {
                    return(StringUtil.matches(val, JDFConstants.REGEXP_HEXBINARY));
                }
                else if (iType == AttributeInfo.EnumAttributeType.TransferFunction)
                {
                    JDFNumberList nl = new JDFNumberList(val);
                    return(nl.Count % 2 == 0);
                }
                else
                {
                    // TODO check if we are complete
                    Console.WriteLine("validStringForType: unknown type:" + iType.getName());
                    return(false);
                }
            }
            catch (FormatException)
            {
                return(false);
            }
        }
예제 #7
0
 ///
 ///		 * <returns> true if test is a range data type </returns>
 ///
 public static bool isRange(EnumAttributeType test)
 {
     return(EnumAttributeType.DateTimeRange.Equals(test) || EnumAttributeType.DateTimeRangeList.Equals(test) || EnumAttributeType.DurationRange.Equals(test) || EnumAttributeType.DurationRangeList.Equals(test) || EnumAttributeType.IntegerRange.Equals(test) || EnumAttributeType.IntegerRangeList.Equals(test) || EnumAttributeType.NameRange.Equals(test) || EnumAttributeType.NameRangeList.Equals(test) || EnumAttributeType.NumberRange.Equals(test) || EnumAttributeType.NumberRangeList.Equals(test) || EnumAttributeType.RectangleRange.Equals(test) || EnumAttributeType.RectangleRangeList.Equals(test) || EnumAttributeType.ShapeRange.Equals(test) || EnumAttributeType.ShapeRangeList.Equals(test) || EnumAttributeType.XYPairRange.Equals(test) || EnumAttributeType.XYPairRangeList.Equals(test));
 }
예제 #8
0
 /// <summary>
 /// The full constructor for a UnitAttribute
 /// </summary>
 /// <param name="_type">The type of Attribute being returned</param>
 /// <param name="_value">The value of the attribute. NOTE: When creating EPOCHAL items, this value should be set to the HIGHEST POSSIBLE value you want for that item</param>
 public UnitAttribute(EnumAttributeType _type, int _value)
 {
     this.type     = _type;
     this.intValue = _value;
 }
예제 #9
0
 /// <summary>
 /// Returns the domain ID for the given attribute type.
 /// </summary>
 /// <param name="kind">The attribute kind</param>
 /// <param name="enumAttrType">For enums, enumAttrType must be valid. Otherwise it may be null.</param>
 /// <returns></returns>
 protected String GetDomainID(AttributeKind kind, EnumAttributeType enumAttrType)
 {
     switch(kind)
     {
         case AttributeKind.BooleanAttr: return "DM_bool";
         case AttributeKind.DoubleAttr: return "DM_double";
         case AttributeKind.FloatAttr: return "DM_float";
         case AttributeKind.ByteAttr: return "DM_byte";
         case AttributeKind.ShortAttr: return "DM_short";
         case AttributeKind.IntegerAttr: return "DM_int";
         case AttributeKind.LongAttr: return "DM_long";
         case AttributeKind.StringAttr: return "DM_string";
         case AttributeKind.EnumAttr: return "DM_enum_" + enumAttrType.Name;
         default:
             throw new Exception("Unsupported attribute value type: \"" + kind + "\"");
     }
 }
예제 #10
0
        protected void WriteEnumType(EnumAttributeType enumType)
        {
            String enumid = GetDomainID(enumType);
            WriteGXLNode(enumid, "Enum");

            foreach(EnumMember member in enumType.Members)
            {
                String memberid = "EV_";
                if((int) member.Value < 0) memberid += "_" + (-member.Value);
                else memberid += member.Value.ToString();
                memberid += "_" + member.Name;
                WriteGXLNode(memberid, "EnumVal", new Attr("value", "string", member.Name));
                WriteGXLEdge(enumid, memberid, "containsValue");
            }
        }
예제 #11
0
 protected String GetDomainID(EnumAttributeType enumAttrType)
 {
     return GetDomainID(AttributeKind.EnumAttr, enumAttrType);
 }
예제 #12
0
 public static ErrorCode ModifySession(EnumAttributeType attributeType)
 {
     return(new ErrorCode());
 }
예제 #13
0
 public static ErrorCode AddAttributeDefinitionBin(string name, EnumAttributeType type, EnumAttributeMaxSize maxSize)
 {
     return(new ErrorCode());
 }
예제 #14
0
 public static ErrorCode AddAttributeDefinitionInt(string name, EnumAttributeType type)
 {
     return(new ErrorCode());
 }
예제 #15
0
        private object ParseEnumValue(EnumAttributeType enumAttrType)
        {
            string enumName = ParseText();
            string enumValue;
            if(LookaheadToken() == TokenKind.DOUBLECOLON)
            {
                Match(TokenKind.DOUBLECOLON);
                enumValue = ParseText();
                if(LookaheadToken() == TokenKind.DOUBLECOLON)
                {
                    enumName = enumName + "::" + enumValue; // package::type::value
                    Match(TokenKind.DOUBLECOLON);
                    enumValue = ParseText();
                }
            }
            else
            {
                if(enumName.Contains("::"))
                {
                    enumValue = enumName.Substring(enumName.LastIndexOf(':') + 1);
                    enumName = enumName.Substring(0, enumName.LastIndexOf(':') - 1);
                }
                else
                {
                    enumValue = enumName;
                    enumName = enumAttrType.PackagePrefixedName;
                }
            }

            if(enumAttrType.PackagePrefixedName != enumName)
                throw GetSyntaxException("", "enum type " + enumAttrType.PackagePrefixedName);

            object value;
            int val;
            if(Int32.TryParse(enumValue, out val))
                value = Enum.ToObject(enumAttrType.EnumType, val);
            else
                value = Enum.Parse(enumAttrType.EnumType, enumValue);
            if(value == null)
                throw GetSyntaxException("Unknown enum member", "member of " + enumAttrType.PackagePrefixedName);

            return value;
        }
예제 #16
0
 public UnitAttribute(EnumAttributeType _type)
 {
     this.type = _type;
 }
예제 #17
0
 /// <summary>
 /// The full constructor for a UnitAttribute
 /// </summary>
 /// <param name="_type">The type of Attribute being returned</param>
 /// <param name="_value">The value of the attribute. NOTE: When creating EPOCHAL items, this value should be set to the HIGHEST POSSIBLE value you want for that item</param>
 public UnitAttribute(EnumAttributeType _type, int _value)
 {
     this.type = _type;
     this.intValue = _value;
 }
예제 #18
0
 public CharAttribute(EnumAttributeType type)
 {
     this.type = type;
     this.max = 0;
     this.current = this.max;
 }
예제 #19
0
 public CharAttribute(EnumAttributeType type, int value)
 {
     this.type = type;
     this.current = value;
     this.max = value;
 }
예제 #20
0
            ///
            ///		 * <param name="enumName"> the name of the enum object to return </param>
            ///		 * <returns> the enum object if enumName is valid. Otherwise null </returns>
            ///
            public static EnumAttributeType getEnum(string enumName)
            {
                EnumAttributeType eat = (EnumAttributeType)getEnum(typeof(EnumAttributeType), enumName);

                return((eat == null) ? EnumAttributeType.Any : eat);
            }
예제 #21
0
        public IAttribute ToAttribute(IWorldAccessor resolver)
        {
            if (type == EnumAttributeType.Unknown)
            {
                if (elems != null)
                {
                    type = EnumAttributeType.Tree;
                }
                else if (values != null)
                {
                    type = EnumAttributeType.StringArray;
                }
                else
                {
                    type = EnumAttributeType.String;
                }
            }

            switch (type)
            {
            case EnumAttributeType.Bool:
            {
                return(new BoolAttribute(value == "true"));
            }

            case EnumAttributeType.Int:
            {
                int val = 0;
                int.TryParse(value, out val);
                return(new IntAttribute(val));
            }

            case EnumAttributeType.Double:
            {
                double val = 0;
                double.TryParse(value, out val);
                return(new DoubleAttribute(val));
            }

            case EnumAttributeType.Float:
            {
                float val = 0;
                float.TryParse(value, NumberStyles.Any, GlobalConstants.DefaultCultureInfo, out val);
                return(new FloatAttribute(val));
            }

            case EnumAttributeType.String:
                return(new StringAttribute(value));

            case EnumAttributeType.StringArray:
                return(new StringArrayAttribute(values));

            case EnumAttributeType.Tree:
                ITreeAttribute tree = new TreeAttribute();
                if (elems == null)
                {
                    return(tree);
                }

                foreach (var val in elems)
                {
                    IAttribute attribute = val.Value.ToAttribute(resolver);
                    if (attribute == null)
                    {
                        continue;
                    }
                    tree[val.Key] = attribute;
                }

                return(tree);

            case EnumAttributeType.Itemstack:
                if (elems == null)
                {
                    return(null);
                }

                bool haveClass     = elems.ContainsKey("class") && elems["class"].type == EnumAttributeType.String;
                bool haveItemCode  = elems.ContainsKey("code") && elems["code"].type == EnumAttributeType.String;
                bool haveStackSize = elems.ContainsKey("quantity") && elems["quantity"].type == EnumAttributeType.Int;

                if (!haveClass || !haveItemCode || !haveStackSize)
                {
                    return(null);
                }

                EnumItemClass itemclass;
                try
                {
                    itemclass = (EnumItemClass)Enum.Parse(typeof(EnumItemClass), elems["class"].value);
                } catch (Exception)
                {
                    return(null);
                }

                int quantity = 0;
                if (!int.TryParse(elems["quantity"].value, out quantity))
                {
                    return(null);
                }

                ItemStack itemstack;

                if (itemclass == EnumItemClass.Block)
                {
                    Block block = resolver.GetBlock(new AssetLocation(elems["code"].value));
                    if (block == null)
                    {
                        return(null);
                    }
                    itemstack = new ItemStack(block, quantity);
                }
                else
                {
                    Item item = resolver.GetItem(new AssetLocation(elems["code"].value));
                    if (item == null)
                    {
                        return(null);
                    }
                    itemstack = new ItemStack(item, quantity);
                }

                if (elems.ContainsKey("attributes"))
                {
                    IAttribute attributes = elems["attributes"].ToAttribute(resolver);
                    if (attributes is ITreeAttribute)
                    {
                        itemstack.Attributes = (ITreeAttribute)attributes;
                    }
                }

                return(new ItemstackAttribute(itemstack));
            }

            return(null);
        }
예제 #22
0
 public UnitAttribute(EnumAttributeType _type)
 {
     this.type = _type;
 }