示例#1
0
        private void Load(IFileStore store)
        {
            var kvp = new KeyValuePairs();

            using (var stream = store.OpenTextFile(m_path))
            {
                kvp.Load(stream);
            }

            m_vertexShaderPath = kvp.GetString("vertex_shader");
            string[] vertexShaderDefines = kvp.ContainsKey("vertex_shader_defines") ? kvp.GetString("vertex_shader_defines").Split(',') : null;
            string   vertexShaderCode    = Preprocess(store, m_vertexShaderPath, vertexShaderDefines);

            m_fragmentShaderPath = kvp.GetString("fragment_shader");
            string[] fragmentShaderDefines = kvp.ContainsKey("fragment_shader_defines") ? kvp.GetString("fragment_shader_defines").Split(',') : null;
            string   fragmentShaderCode    = Preprocess(store, m_fragmentShaderPath, fragmentShaderDefines);

            m_vertexShader = GL.CreateShader(ShaderType.VertexShader);
            GL.ShaderSource(m_vertexShader, vertexShaderCode);
            GL.CompileShader(m_vertexShader);
            CheckCompileResult(m_vertexShader);

            m_fragmentShader = GL.CreateShader(ShaderType.FragmentShader);
            GL.ShaderSource(m_fragmentShader, fragmentShaderCode);
            GL.CompileShader(m_fragmentShader);
            CheckCompileResult(m_fragmentShader);

            m_program = GL.CreateProgram();
            GL.AttachShader(m_program, m_vertexShader);
            GL.AttachShader(m_program, m_fragmentShader);
            GL.LinkProgram(m_program);
            TestLink(m_program);

            m_blendMode = kvp.GetEnum("blend_mode", BlendMode.Overwrite);
        }
示例#2
0
        public void ReloadInfo()
        {
            // Set default info
            Title              = "Untitled Mod";
            Version            = new Version(1, 0, 0);
            MinimumGameVersion = new Version(0, 0, 0);
            Author             = null;
            AuthorTwitter      = null;
            AutoLoad           = false;
            SteamWorkshopID    = null;
            SteamUserID        = null;

            // Reload the index
            if (m_contents != null)
            {
                m_contents.ReloadIndex();
            }

            // Parse info.txt
            var infoPath = "info.txt";

            if (m_contents != null && m_contents.FileExists(infoPath))
            {
                var kvp = new KeyValuePairs();
                using (var stream = m_contents.OpenTextFile(infoPath))
                {
                    kvp.Load(stream);
                }

                Title              = kvp.GetString("title", Title);
                Version            = kvp.GetVersion("version", Version);
                MinimumGameVersion = kvp.GetVersion("game_version", MinimumGameVersion);
                Author             = kvp.GetString("author", null);
                AuthorTwitter      = kvp.GetString("author_twitter", null);
                AutoLoad           = kvp.GetBool("autoload", false);
                if (kvp.ContainsKey("steam_workshop_id"))
                {
                    SteamWorkshopID = kvp.GetULong("steam_workshop_id");
                }
                else
                {
                    SteamWorkshopID = null;
                }
                if (kvp.ContainsKey("steam_user_id"))
                {
                    SteamUserID = kvp.GetULong("steam_user_id");
                }
                else
                {
                    SteamUserID = null;
                }
            }

            // Reload the index
            m_assets.Name = Title;
            m_assets.FileStore.ReloadIndex();
        }
示例#3
0
 public IAnimation GetAnim(string key)
 {
     if (m_kvp.ContainsKey(key))
     {
         return(LuaAnimation.Get(m_kvp.GetString(key)));
     }
     if (m_kvp.ContainsKey("default"))
     {
         return(LuaAnimation.Get(m_kvp.GetString("default")));
     }
     return(null);
 }
示例#4
0
 public string GetSound(string key)
 {
     if (m_kvp.ContainsKey(key))
     {
         return(m_kvp.GetString(key));
     }
     if (m_kvp.ContainsKey("default"))
     {
         return(m_kvp.GetString("default"));
     }
     return(null);
 }
示例#5
0
 public SpawnTileBehaviour(Tile tile, KeyValuePairs kvp) : base(tile, kvp)
 {
     m_colour         = kvp.GetString("colour", "grey");
     m_immobile       = kvp.GetBool("immobile", false);
     m_required       = kvp.GetBool("required", m_colour != "grey" && !m_immobile);
     m_turnPreference = kvp.GetEnum("turn_preference", TurnDirection.Left);
     if (kvp.ContainsKey("robot_model"))
     {
         m_robotModel = kvp.GetString("robot_model");
     }
     else
     {
         throw new IOException("robot_model not specified");
     }
     m_robotLightColour = kvp.GetColour("light_colour", Vector3.Zero);
     if (m_robotLightColour.Value.Length <= 0.0f)
     {
         m_robotLightColour = null;
     }
     m_robotLightRadius = kvp.GetFloat("light_radius", 15.0f);
     if (m_robotLightRadius.Value <= 0.0f)
     {
         m_robotLightRadius = null;
     }
     m_robotAnimSet  = kvp.GetString("robot_animset", "animation/entities/new_robot/new_robot.animset");
     m_robotSoundSet = kvp.GetString("robot_soundset", "sound/new_robot/new_robot.soundset");
     m_guiColour     = kvp.GetColour("gui_colour", Vector3.One);
 }
示例#6
0
        private Task ParseAsKeyValue(string line)
        {
            string[] splitLine = line.Split('=', 2);

            if (splitLine.Length != 2)
            {
                ThrowConfigException("Invalid key value pair");
            }

            string key   = splitLine[0];
            string value = splitLine[1];

            //ensures it wont fail on duplicate key value pairs
            //this will take the last key value pair
            if (KeyValuePairs.ContainsKey(key))
            {
                KeyValuePairs[key] = value;
                AddToCurrentGroup(key, value);
            }
            else
            {
                KeyValuePairs.Add(key, value);
                AddToCurrentGroup(key, value);
            }
            return(Task.CompletedTask);
        }
示例#7
0
 /// <summary>
 /// Removes the given key from the Ini. (if it exists)
 /// </summary>
 /// <param name="key">The key</param>
 public void RemoveKey(string key)
 {
     lock (KeyValuePairs)
         if (KeyValuePairs.ContainsKey(key))
         {
             KeyValuePairs.Remove(key);
         }
 }
示例#8
0
 internal void Add(string key, string value)
 {
     if (KeyValuePairs.ContainsKey(key))
     {
         KeyValuePairs[key] = value;
     }
     else
     {
         KeyValuePairs.Add(key, value);
     }
 }
示例#9
0
        /// <summary>
        /// 移除
        /// </summary>
        /// <param name="key"></param>
        public void Remove(Key key)
        {
            if (!KeyValuePairs.ContainsKey(key))
            {
                return;
            }

            var value = KeyValuePairs[key];

            KeyValuePairs.Remove(key);
            ValueKeyPairs.Remove(value);
        }
 public string this[string settingId, bool fromKeyValuePair]
 {
     get
     {
         if (KeyValuePairs.ContainsKey(settingId))
         {
             return(KeyValuePairs[settingId]);
         }
         return(String.Empty);
     }
     set
     {
         if (this[settingId, fromKeyValuePair] != value)
         {
             SetKeyValuePairs(settingId, value);
         }
     }
 }
示例#11
0
 public static bool GetEmbeddedGameInfo(out string o_gameTitle, out string o_gameVersion, out string o_gameURL, out string o_username, out string o_password)
 {
     try
     {
         var assembly = Assembly.GetExecutingAssembly();
         var stream   = assembly.GetManifestResourceStream("EmbeddedGame." + Program.Platform + ".txt");
         if (stream == null)
         {
             stream = assembly.GetManifestResourceStream("EmbeddedGame.txt");
         }
         if (stream != null)
         {
             var kvp = new KeyValuePairs();
             kvp.Load(stream);
             if (kvp.ContainsKey("game"))
             {
                 o_gameTitle   = kvp.GetString("game");
                 o_gameVersion = kvp.GetString("version");
                 o_gameURL     = kvp.GetString("url");
                 o_username    = kvp.GetString("username");
                 o_password    = kvp.GetString("password");
                 return(true);
             }
         }
         o_gameTitle   = default(string);
         o_gameVersion = default(string);
         o_gameURL     = default(string);
         o_username    = default(string);
         o_password    = default(string);
         return(false);
     }
     catch (Exception e)
     {
         Logger.Log("Caught Exception: {0}", e.ToString());
         o_gameTitle   = default(string);
         o_gameVersion = default(string);
         o_gameURL     = default(string);
         o_username    = default(string);
         o_password    = default(string);
         return(false);
     }
 }
示例#12
0
 /// <summary>
 /// 是否包含主键
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool ContainsKey(Key key)
 {
     return(KeyValuePairs.ContainsKey(key));
 }
示例#13
0
        /// <summary>
        /// Parses connection string
        /// </summary>
        /// <param name="connString">Semicolon delimented KeyValue pair(e.g. KeyName1=value1;KeyName2=value2;KeyName3=value3)</param>
        public void Parse(string connString)
        {
            string parseRegEx = @"(?<KeyName>[^=]+)=(?<KeyValue>.+)";

            if (_parseErrorSb != null)
            {
                _parseErrorSb.Clear();
            }

            if (string.IsNullOrEmpty(connString))
            {
                ParseErrors = "Empty connection string";
            }
            else
            {
                string[] pairs = connString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (pairs == null)
                {
                    ParseErrors = string.Format("'{0}' unable to parse string", connString);
                }

                //TODO: Shall we clear keyValue dictionary?
                //What if parsed gets called on the same instance multiple times
                //the connectionString is either malformed/invalid
                //For now clearing keyValue dictionary, we assume the caller wants to parse new connection string
                //and wants to discard old values (even if they are valid)

                KeyValuePairs.Clear(clearValuesOnly: true);
                foreach (string pair in pairs)
                {
                    Match m = Regex.Match(pair, parseRegEx);

                    if (m.Groups.Count > 2)
                    {
                        string keyName  = m.Groups["KeyName"].Value;
                        string newValue = m.Groups["KeyValue"].Value;

                        if (KeyValuePairs.ContainsKey(keyName))
                        {
                            string existingValue = KeyValuePairs[keyName];
                            // Replace if the existing value do not match.
                            // We allow existing key values to be overwritten (this is especially true for endpoints)
                            if (!existingValue.Equals(newValue, StringComparison.OrdinalIgnoreCase))
                            {
                                KeyValuePairs[keyName] = newValue;
                            }
                        }
                        else
                        {
                            KeyValuePairs[keyName] = newValue;
                        }
                    }
                    else
                    {
                        ParseErrors = string.Format("Incorrect '{0}' keyValue pair format", pair);
                    }
                }

                //Adjust key-value pairs and normalize values across multiple keys
                //We need to do this here because Connection string can be parsed multiple time within same instance
                NormalizeKeyValuePairs();
            }
        }
示例#14
0
        private void Load(IFileStore store)
        {
            // Load the file
            var kvp = new KeyValuePairs();

            using (var stream = store.OpenTextFile(m_path))
            {
                kvp.Load(stream);
            }

            // Load the ID
            m_id = kvp.GetInteger("id", MathUtils.SimpleStableHash(m_path));

            // Load the dimensions
            Width   = kvp.GetInteger("tiles.width", 0);
            Height  = kvp.GetInteger("tiles.height", 0);
            Depth   = kvp.GetInteger("tiles.depth", 0);
            XOrigin = kvp.GetInteger("tiles.x_origin", 0);
            YOrigin = kvp.GetInteger("tiles.y_origin", 0);
            ZOrigin = kvp.GetInteger("tiles.z_origin", 0);

            // Load the tile lookup
            TileLookup = kvp.GetStringArray("tiles.lookup", new string[0]);

            // Load the tiles
            TileIDs        = new int[Width, Height, Depth];
            TileDirections = new FlatDirection[Width, Height, Depth];
            var tileData = kvp.GetString("tiles.data", "");

            for (int x = 0; x < Width; ++x)
            {
                for (int y = 0; y < Height; ++y)
                {
                    for (int z = 0; z < Depth; ++z)
                    {
                        int index     = (x * Height * Depth) + (y * Depth) + z;
                        var id        = 0;
                        var direction = FlatDirection.North;
                        if (((index * 3) + 3) <= tileData.Length)
                        {
                            id = Base64.ParseInt(tileData.Substring(index * 3, 2));
                            int directionNum = Base64.ParseInt(tileData.Substring((index * 3) + 2, 1));
                            if (directionNum >= 0 && directionNum < 4)
                            {
                                direction = (FlatDirection)directionNum;
                            }
                        }
                        TileIDs[x, y, z]        = id;
                        TileDirections[x, y, z] = direction;
                    }
                }
            }

            // Load the level info
            Title  = kvp.GetString("title", "Untitled");
            Music  = kvp.GetString("music", "music/lightless_dawn.ogg");
            Sky    = kvp.GetString("sky", "skies/starfield.sky");
            Script = kvp.GetString("script", null);

            if (kvp.ContainsKey("items.grey_cube.count"))
            {
                Item      = "tiles/new/cone_spawn.tile";
                ItemCount = kvp.GetInteger("items.grey_cube.count", 0);
            }
            else
            {
                Item      = kvp.GetString("item", "tiles/new/cone_spawn.tile");
                ItemCount = kvp.GetInteger("item_count", 0);
            }
            EverCompleted = kvp.GetBool("ever_completed", false);

            CameraPitch    = kvp.GetFloat("camera.pitch", 60.0f);
            CameraYaw      = kvp.GetFloat("camera.yaw", 270.0f - 22.5f);
            CameraDistance = kvp.GetFloat("camera.distance", 18.0f);

            Intro = kvp.GetString("intro", null);
            Outro = kvp.GetString("outro", null);

            RandomSeed = kvp.GetInteger("random.seed", Path.GetHashCode());
            RobotCount = kvp.GetInteger("robot_count", 0);
        }
示例#15
0
 public bool HasKey(string key)
 => KeyValuePairs.ContainsKey(key);