Example #1
0
        private IEnumerable <object> ApplyToPropertyOverDuration(float duration, ObjectProperty property, object value)
        {
            float timer = duration;

            while (timer > 0.0f)
            {
                ApplyToProperty(property, value, CoroutineManager.UnscaledDeltaTime);

                timer -= CoroutineManager.DeltaTime;

                yield return(CoroutineStatus.Running);
            }

            yield return(CoroutineStatus.Success);
        }
Example #2
0
        public override XElement Save(XElement parentElement)
        {
            XElement element = new XElement("Item");

            element.Add(new XAttribute("name", prefab.Name),
                        new XAttribute("ID", ID));

            System.Diagnostics.Debug.Assert(Submarine != null);

            if (ResizeHorizontal || ResizeVertical)
            {
                element.Add(new XAttribute("rect",
                                           (int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
                                           (int)(rect.Y - Submarine.HiddenSubPosition.Y) + "," +
                                           rect.Width + "," + rect.Height));
            }
            else
            {
                element.Add(new XAttribute("rect",
                                           (int)(rect.X - Submarine.HiddenSubPosition.X) + "," +
                                           (int)(rect.Y - Submarine.HiddenSubPosition.Y)));
            }

            if (linkedTo != null && linkedTo.Count > 0)
            {
                string[] linkedToIDs = new string[linkedTo.Count];

                for (int i = 0; i < linkedTo.Count; i++)
                {
                    linkedToIDs[i] = linkedTo[i].ID.ToString();
                }

                element.Add(new XAttribute("linked", string.Join(",", linkedToIDs)));
            }


            ObjectProperty.SaveProperties(this, element);

            foreach (ItemComponent ic in components)
            {
                ic.Save(element);
            }

            parentElement.Add(element);

            return(element);
        }
Example #3
0
        private LevelGenerationParams(XElement element)
        {
            Name             = element == null ? "default" : element.Name.ToString();
            ObjectProperties = ObjectProperty.InitProperties(this, element);

            Vector3 colorVector = ToolBox.GetAttributeVector3(element, "BackgroundColor", new Vector3(50, 46, 20));

            BackgroundColor = new Color((int)colorVector.X, (int)colorVector.Y, (int)colorVector.Z);

            VoronoiSiteInterval = ToolBox.GetAttributeVector2(element, "VoronoiSiteInterval", new Vector2(3000, 3000));

            VoronoiSiteVariance = ToolBox.GetAttributeVector2(element, "VoronoiSiteVariance", new Vector2(voronoiSiteInterval.X, voronoiSiteInterval.Y) * 0.4f);

            MainPathNodeIntervalRange = ToolBox.GetAttributeVector2(element, "MainPathNodeIntervalRange", new Vector2(5000.0f, 10000.0f));

            SmallTunnelLengthRange = ToolBox.GetAttributeVector2(element, "SmallTunnelLengthRange", new Vector2(5000.0f, 10000.0f));
        }
Example #4
0
        private void ApplyToProperty(ObjectProperty property, object value, float deltaTime)
        {
            if (disableDeltaTime || setValue)
            {
                deltaTime = 1.0f;
            }

            Type type = value.GetType();

            if (type == typeof(float) ||
                (type == typeof(int) && property.GetValue() is float))
            {
                float floatValue = Convert.ToSingle(value) * deltaTime;

                if (!setValue)
                {
                    floatValue += (float)property.GetValue();
                }
                property.TrySetValue(floatValue);
            }
            else if (type == typeof(int) && value is int)
            {
                int intValue = (int)((int)value * deltaTime);
                if (!setValue)
                {
                    intValue += (int)property.GetValue();
                }
                property.TrySetValue(intValue);
            }
            else if (type == typeof(bool) && value is bool)
            {
                property.TrySetValue((bool)value);
            }
            else if (type == typeof(string))
            {
                property.TrySetValue((string)value);
            }
            else
            {
                DebugConsole.ThrowError("Couldn't apply value " + value.ToString() + " (" + type + ") to property \"" + property.Name + "\" (" + property.GetValue().GetType() + ")! "
                                        + "Make sure the type of the value set in the config files matches the type of the property.");
            }
        }
        private LevelGenerationParams(XElement element)
        {
            Name             = element == null ? "default" : element.Name.ToString();
            ObjectProperties = ObjectProperty.InitProperties(this, element);

            Vector3 colorVector = element.GetAttributeVector3("BackgroundColor", new Vector3(50, 46, 20));

            BackgroundColor = new Color((int)colorVector.X, (int)colorVector.Y, (int)colorVector.Z);

            colorVector = element.GetAttributeVector3("WallColor", new Vector3(255, 255, 255));
            WallColor   = new Color((int)colorVector.X, (int)colorVector.Y, (int)colorVector.Z);

            VoronoiSiteInterval = element.GetAttributeVector2("VoronoiSiteInterval", new Vector2(3000, 3000));

            VoronoiSiteVariance = element.GetAttributeVector2("VoronoiSiteVariance", new Vector2(voronoiSiteInterval.X, voronoiSiteInterval.Y) * 0.4f);

            MainPathNodeIntervalRange = element.GetAttributeVector2("MainPathNodeIntervalRange", new Vector2(5000.0f, 10000.0f));

            SmallTunnelLengthRange = element.GetAttributeVector2("SmallTunnelLengthRange", new Vector2(5000.0f, 10000.0f));

            string biomeStr = element.GetAttributeString("biomes", "");

            if (string.IsNullOrWhiteSpace(biomeStr))
            {
                allowedBiomes = new List <Biome>(biomes);
            }
            else
            {
                string[] biomeNames = biomeStr.Split(',');
                for (int i = 0; i < biomeNames.Length; i++)
                {
                    string biomeName     = biomeNames[i].Trim().ToLowerInvariant();
                    Biome  matchingBiome = biomes.Find(b => b.Name.ToLowerInvariant() == biomeName);
                    if (matchingBiome == null)
                    {
                        DebugConsole.ThrowError("Error in level generation parameters: biome \"" + biomeName + "\" not found.");
                        continue;
                    }

                    allowedBiomes.Add(matchingBiome);
                }
            }
        }
Example #6
0
        public static Dictionary <string, ObjectProperty> InitProperties(IPropertyObject obj, XElement element)
        {
            var properties = TypeDescriptor.GetProperties(obj.GetType()).Cast <PropertyDescriptor>();

            Dictionary <string, ObjectProperty> dictionary = new Dictionary <string, ObjectProperty>();

            foreach (var property in properties)
            {
                ObjectProperty objProperty = new ObjectProperty(property, obj);
                dictionary.Add(property.Name.ToLowerInvariant(), objProperty);

                //set the value of the property to the default value if there is one
                foreach (var ini in property.Attributes.OfType <HasDefaultValue>())
                {
                    objProperty.TrySetValue(ini.defaultValue);
                    break;
                }
            }

            if (element != null)
            {
                //go through all the attributes in the xml element
                //and set the value of the matching property if it is initializable
                foreach (XAttribute attribute in element.Attributes())
                {
                    ObjectProperty property = null;
                    if (!dictionary.TryGetValue(attribute.Name.ToString().ToLowerInvariant(), out property))
                    {
                        continue;
                    }
                    if (!property.Attributes.OfType <HasDefaultValue>().Any())
                    {
                        continue;
                    }
                    property.TrySetValue(attribute.Value);
                }
            }

            return(dictionary);
        }
Example #7
0
        public Hull(MapEntityPrefab prefab, Rectangle rectangle, Submarine submarine)
            : base(prefab, submarine)
        {
            rect = rectangle;

            OxygenPercentage = 100.0f;

            fireSources = new List <FireSource>();

            properties = ObjectProperty.GetProperties(this);

            int arraySize = (rectangle.Width / WaveWidth + 1);

            waveY   = new float[arraySize];
            waveVel = new float[arraySize];

            leftDelta  = new float[arraySize];
            rightDelta = new float[arraySize];

            surface = rect.Y - rect.Height;

            aiTarget = new AITarget(this);

            hullList.Add(this);

            ConnectedGaps = new List <Gap>();

            if (submarine == null || !submarine.Loading)
            {
                Item.UpdateHulls();
                Gap.UpdateHulls();
            }

            WaterVolume = 0.0f;

            InsertToList();
        }