Exemplo n.º 1
0
        public ItemPrefab(XElement element, string filePath)
        {
            configFile    = filePath;
            ConfigElement = element;

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

            DebugConsole.Log("    " + name);

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

            pickThroughWalls = ToolBox.GetAttributeBool(element, "pickthroughwalls", false);
            pickDistance     = ToolBox.GetAttributeFloat(element, "pickdistance", 0.0f);

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

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

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

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

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

            FireProof = ToolBox.GetAttributeBool(element, "fireproof", false);

            ImpactTolerance = ToolBox.GetAttributeFloat(element, "impacttolerance", 0.0f);

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

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

            MapEntityCategory category;

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

            Category = category;


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

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

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

            Triggers = new List <Rectangle>();

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

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

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

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

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

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

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

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

                    break;

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

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

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

                    Triggers.Add(trigger);

                    break;
                }
            }

            list.Add(this);
        }
Exemplo n.º 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(ToolBox.GetAttributeString(element, "tags", "").Split(','));

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

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

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

                    break;

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

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

                    break;
                }
            }

            MapEntityCategory category;

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

            sp.Category = category;

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

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

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

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

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

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

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

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

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

            return(sp);
        }