示例#1
0
 /// <summary>
 /// Gives the Level Designer the chance to change Settings.
 /// </summary>
 protected virtual void DoSettings(KeyValueStore levelSettings, KeyValueStore[] slotSettings)
 {
 }
示例#2
0
 /// <summary>
 /// Initialize a new KeyValueStore with another KeyValueStore-Instance as source.
 /// </summary>
 /// <param name="keyValueStore">Source KeyValueStore</param>
 public KeyValueStore(KeyValueStore keyValueStore) : this()
 {
 }
示例#3
0
        /// <summary>
        /// Merge information with the given KeyValueStore-Instance.
        /// </summary>
        /// <param name="keyValueStore">Source KeyValueStore</param>
        public void Merge(KeyValueStore keyValueStore)
        {
            //merge storage dictonary
            foreach (var key in keyValueStore.Storage.Keys)
            {
                ValueDescriptionEntry newVDE;
                keyValueStore.Storage.TryGetValue(key, out newVDE);
                if (Storage.Keys.Contains(key))
                {
                    ValueDescriptionEntry orgVDE;
                    Storage.TryGetValue(key, out orgVDE);
                    if (orgVDE == null)
                    {
                        orgVDE = new ValueDescriptionEntry();
                    }
                    if (string.IsNullOrEmpty(newVDE.Value))
                    {
                        newVDE.Value = orgVDE.Value;
                    }
                    if (string.IsNullOrEmpty(newVDE.Description))
                    {
                        newVDE.Value = orgVDE.Description;
                    }

                    Storage[key] = newVDE;
                }
                else
                {
                    Storage.Add(key, newVDE != null ? newVDE : new ValueDescriptionEntry());
                }
            }

            //merge common dictonary
            foreach (var key in keyValueStore.Common.Keys)
            {
                string newValue;
                keyValueStore.Common.TryGetValue(key, out newValue);

                if (Common.Keys.Contains(key))
                {
                    string orgValue;
                    Common.TryGetValue(key, out orgValue);

                    if (string.IsNullOrEmpty(newValue))
                    {
                        newValue = orgValue;
                    }

                    Common[key] = newValue;
                }
                else
                {
                    Common.Add(key, newValue);
                }
            }

            //merge loadingError Diconary
            foreach (var key in keyValueStore.LoadingErrors.Keys)
            {
                List <string> newErrorList;
                keyValueStore.LoadingErrors.TryGetValue(key, out newErrorList);

                if (LoadingErrors.Keys.Contains(key))
                {
                    List <string> orgErrorList;
                    LoadingErrors.TryGetValue(key, out orgErrorList);

                    foreach (var item in orgErrorList)
                    {
                        if (!newErrorList.Contains(item))
                        {
                            newErrorList.Add(item);
                        }
                    }


                    LoadingErrors[key] = newErrorList;
                }
                else
                {
                    LoadingErrors.Add(key, newErrorList);
                }
            }
        }
示例#4
0
        private static KeyValueStore Load(Stream stream, string source)
        {
            KeyValueStore locaKeyValueStore = new KeyValueStore();
            List <string> locaErrors        = new List <string>();

            using (StreamReader sr = new StreamReader(stream))
            {
                int    currentLine    = 0;
                string currentTypeKey = "";

                while (sr.Peek() >= 0)
                {
                    currentLine++;
                    bool   waitforTypeKey = false;
                    string rawData        = sr.ReadLine();
                    string editedData     = rawData.TrimStart(' ').TrimEnd(' ');

                    if (editedData.StartsWith("["))
                    {
                        if (editedData.IndexOf(']') == -1)
                        {
                            waitforTypeKey = true;
                            locaErrors.Add("ERROR Line " + currentLine.ToString() + ": missing ']' (end of TypeKey deklaration)");
                            continue;
                        }

                        currentTypeKey = editedData.Substring(1, editedData.IndexOf(']') - 1).TrimStart(' ').TrimEnd(' ');
                        continue;
                    }
                    else if (waitforTypeKey)
                    {
                        continue;
                    }
                    else if (editedData.Contains("="))
                    {
                        string key = editedData.Substring(0, editedData.IndexOf('=')).TrimEnd(' ');
                        editedData = editedData.Remove(0, editedData.IndexOf('=') + 1);

                        if (currentTypeKey == "Common")
                        {
                            locaKeyValueStore.Common.Add(key, editedData.TrimStart(' ').TrimEnd(' '));
                            continue;
                        }
                        ValueDescriptionEntry VDE = new ValueDescriptionEntry();

                        if (editedData.IndexOf("//") >= 0)
                        {
                            VDE.Value       = editedData.Substring(0, editedData.IndexOf("//")).TrimStart(' ').TrimEnd(' ');
                            VDE.Description = editedData.Remove(0, editedData.IndexOf("//") + 2).TrimStart(' ').TrimEnd(' ');
                        }
                        else
                        {
                            VDE.Value = editedData.TrimStart(' ').TrimEnd(' ');
                        }

                        if (string.IsNullOrWhiteSpace(VDE.Value))
                        {
                            locaErrors.Add("WARNING Line " + currentLine.ToString() + ": missing Value");
                        }
                        if (string.IsNullOrWhiteSpace(VDE.Description))
                        {
                            locaErrors.Add("WARNING Line " + currentLine.ToString() + ": missing Description");
                        }

                        locaKeyValueStore.Set(FullKey(currentTypeKey, key), VDE);
                    }
                    else if (string.IsNullOrWhiteSpace(editedData))
                    {
                        continue;
                    }
                    else
                    {
                        locaErrors.Add("ERROR Line " + currentLine.ToString() + ": could not be deserialized, make sure it matches the Format([TYPEKEY] or KEY=VALUE//DESCRIPTION)");
                    }
                }
            }

            if (locaErrors.Count > 0)
            {
                locaKeyValueStore.LoadingErrors.Add(source, locaErrors);
            }


            return(locaKeyValueStore);
        }
示例#5
0
 /// <summary>
 /// Default Constructor.
 /// </summary>
 /// <param name="resolver">Reference to the Type Resolver</param>
 /// <param name="settings">Settings for the current Context</param>
 /// <param name="random">Randomizer for the current Context</param>
 public SimulationContext(ITypeResolver resolver, KeyValueStore settings, Random random = null)
 {
     Resolver = resolver;
     Settings = settings;
     Random   = random;
 }