Пример #1
0
        public ItemPrefab(XElement element, string filePath)
        {
            configFile    = filePath;
            ConfigElement = element;

            name = element.GetAttributeString("name", "");
            if (name == "")
            {
                DebugConsole.ThrowError("Unnamed item in " + filePath + "!");
            }

            DebugConsole.Log("    " + name);

            Description = element.GetAttributeString("description", "");

            interactThroughWalls = element.GetAttributeBool("interactthroughwalls", false);
            interactDistance     = element.GetAttributeFloat("interactdistance", 120.0f);    // Default to 120 as the new item picking method is tuned to this number
            interactPriority     = element.GetAttributeFloat("interactpriority", 0.0f);

            isLinkable = element.GetAttributeBool("linkable", false);

            resizeHorizontal = element.GetAttributeBool("resizehorizontal", false);
            resizeVertical   = element.GetAttributeBool("resizevertical", false);

            focusOnSelected = element.GetAttributeBool("focusonselected", false);

            offsetOnSelected = element.GetAttributeFloat("offsetonselected", 0.0f);

            CanUseOnSelf = element.GetAttributeBool("canuseonself", false);


            Health          = element.GetAttributeFloat("health", 100.0f);
            Indestructible  = element.GetAttributeBool("indestructible", false);
            FireProof       = element.GetAttributeBool("fireproof", false);
            ImpactTolerance = element.GetAttributeFloat("impacttolerance", 0.0f);

            string aliases = element.GetAttributeString("aliases", "");

            if (!string.IsNullOrWhiteSpace(aliases))
            {
                Aliases = aliases.Split(',');
            }

            MapEntityCategory category;

            if (!Enum.TryParse(element.GetAttributeString("category", "Misc"), true, out category))
            {
                category = MapEntityCategory.Misc;
            }

            Category = category;


            string spriteColorStr = element.GetAttributeString("spritecolor", "1.0,1.0,1.0,1.0");

            SpriteColor = new Color(XMLExtensions.ParseToVector4(spriteColorStr));

            price = element.GetAttributeInt("price", 0);

            Triggers = new List <Rectangle>();

            DeconstructItems = new List <DeconstructItem>();
            DeconstructTime  = 1.0f;

            tags = new List <string>();
            tags.AddRange(element.GetAttributeString("tags", "").Split(','));

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString().ToLowerInvariant())
                {
                case "sprite":
                    string spriteFolder = "";
                    if (!subElement.GetAttributeString("texture", "").Contains("/"))
                    {
                        spriteFolder = Path.GetDirectoryName(filePath);
                    }

                    canSpriteFlipX = subElement.GetAttributeBool("canflipx", true);

                    sprite = new Sprite(subElement, spriteFolder);
                    size   = sprite.size;
                    break;

                case "deconstruct":
                    DeconstructTime = subElement.GetAttributeFloat("time", 10.0f);

                    foreach (XElement deconstructItem in subElement.Elements())
                    {
                        string deconstructItemName  = deconstructItem.GetAttributeString("name", "not found");
                        bool   requireFullCondition = deconstructItem.GetAttributeBool("requirefullcondition", false);

                        DeconstructItems.Add(new DeconstructItem(deconstructItemName, requireFullCondition));
                    }

                    break;

                case "trigger":
                    Rectangle trigger = new Rectangle(0, 0, 10, 10);

                    trigger.X = subElement.GetAttributeInt("x", 0);
                    trigger.Y = subElement.GetAttributeInt("y", 0);

                    trigger.Width  = subElement.GetAttributeInt("width", 0);
                    trigger.Height = subElement.GetAttributeInt("height", 0);

                    Triggers.Add(trigger);

                    break;
                }
            }

            list.Add(this);
        }
Пример #2
0
        public static StructurePrefab Load(XElement element)
        {
            StructurePrefab sp = new StructurePrefab();

            sp.name = element.Name.ToString();

            sp.tags = new List <string>();
            sp.tags.AddRange(element.GetAttributeString("tags", "").Split(','));

            foreach (XElement subElement in element.Elements())
            {
                switch (subElement.Name.ToString())
                {
                case "sprite":
                    sp.sprite = new Sprite(subElement);

                    if (subElement.GetAttributeBool("fliphorizontal", false))
                    {
                        sp.sprite.effects = SpriteEffects.FlipHorizontally;
                    }
                    if (subElement.GetAttributeBool("flipvertical", false))
                    {
                        sp.sprite.effects = SpriteEffects.FlipVertically;
                    }

                    sp.canSpriteFlipX = subElement.GetAttributeBool("canflipx", true);

                    break;

                case "backgroundsprite":
                    sp.BackgroundSprite = new Sprite(subElement);

                    if (subElement.GetAttributeBool("fliphorizontal", false))
                    {
                        sp.BackgroundSprite.effects = SpriteEffects.FlipHorizontally;
                    }
                    if (subElement.GetAttributeBool("flipvertical", false))
                    {
                        sp.BackgroundSprite.effects = SpriteEffects.FlipVertically;
                    }

                    break;
                }
            }

            MapEntityCategory category;

            if (!Enum.TryParse(element.GetAttributeString("category", "Structure"), true, out category))
            {
                category = MapEntityCategory.Structure;
            }

            sp.Category = category;

            sp.Description = element.GetAttributeString("description", "");

            sp.size   = Vector2.Zero;
            sp.size.X = element.GetAttributeFloat("width", 0.0f);
            sp.size.Y = element.GetAttributeFloat("height", 0.0f);

            string spriteColorStr = element.GetAttributeString("spritecolor", "1.0,1.0,1.0,1.0");

            sp.SpriteColor = new Color(XMLExtensions.ParseToVector4(spriteColorStr));

            sp.maxHealth = element.GetAttributeFloat("health", 100.0f);

            sp.resizeHorizontal = element.GetAttributeBool("resizehorizontal", false);
            sp.resizeVertical   = element.GetAttributeBool("resizevertical", false);

            sp.isPlatform     = element.GetAttributeBool("platform", false);
            sp.stairDirection = (Direction)Enum.Parse(typeof(Direction), element.GetAttributeString("stairdirection", "None"), true);

            sp.castShadow = element.GetAttributeBool("castshadow", false);

            sp.hasBody = element.GetAttributeBool("body", false);

            return(sp);
        }