Esempio n. 1
0
        public static bool LoadLevel(string levelName)
        {
            // Start loading the level.

            // First, make sure the file is open.
            Filesystem.OpenFile(levelName, Filesystem.AccessType.AccessType_ReadOnly);

            // Next start reading the file one line at a time.
            string currentLine = "";

            Filesystem.ReadLine(ref currentLine);

            while (Filesystem.IsFileOpen)
            {
                // Skip any line with a #. It's a comment.
                if (currentLine.StartsWith("#"))
                {
                    continue;
                }

                if (currentLine.Substring(0, Math.Min(currentLine.Length, 14)).CompareTo("BeginObjectDef") == 0)
                {
                    // This is an object definition. Start loading it.
                    ObjectDefinition newObjectDefinition = Filesystem.LoadObjectDescription();
                    if (newObjectDefinition.ObjectClassType.Length != 0)
                    {
                        Firecracker.engineInstance.CreateObjectByDefinition(newObjectDefinition);
                    }
                }
                //else if ( ... Add other loadable types here for example, a cutscene def or a set of physics edges... )


                Filesystem.ReadLine(ref currentLine);
            }


            // The file will close itself when it hits the EOF so we don't need to worry about cleanup.
            return(true);
        }
        public static bool LoadDefinitions(string sDefinitionFolder)
        {
            // Load all the definitions.

            // First, make sure the file is open.
            Filesystem.OpenFolder(sDefinitionFolder, "*.DEF");

            // Next start reading the file one line at a time.
            string currentLine = "";

            Filesystem.ReadLine(ref currentLine);

            while (Filesystem.IsFileOpen)
            {
                // Skip any line with a #. It's a comment.
                if (currentLine.StartsWith("#"))
                {
                    continue;
                }

                if (currentLine.Substring(0, Math.Min(currentLine.Length, 14)).CompareTo("BeginObjectDef") == 0)
                {
                    // This is an object definition. Start loading it.
                    ObjectDefinition newObjectDefinition = Filesystem.LoadObjectDefinition();
                    if (newObjectDefinition.ObjectClassType.Length != 0)
                    {
                        m_lObjectDefinitionList.Add(newObjectDefinition);
                        newObjectDefinition = new ObjectDefinition();
                    }
                }
                //else if ( ... Add other loadable types here for example, a cutscene def or a set of physics edges... )


                Filesystem.ReadLine(ref currentLine);
            }

            // The file will close itself when it hits the EOF so we don't need to worry about cleanup.
            return(true);
        }
Esempio n. 3
0
        public static ObjectDefinition LoadObjectDescription()
        {
            CurrentState     eCurrentState = CurrentState.State_ObjectProperties;
            ObjectDefinition NewObjectDef  = new ObjectDefinition(false);
            PluginDef        NewPluginDef  = new PluginDef(false);
            string           sCurrentLine  = "";

            char[] trimString = " \t\"\'".ToCharArray();

            while (Filesystem.ReadLine(ref sCurrentLine))
            {
                if (sCurrentLine.Trim(" \t\"\'".ToCharArray()).Length == 0)
                {
                    continue;
                }
                // Skip any line with a #. It's a comment.
                if (sCurrentLine.StartsWith("#"))
                {
                    continue;
                }

                switch (eCurrentState)
                {
                case CurrentState.State_ObjectProperties:
                {
                    if (sCurrentLine.Substring(0, Math.Min(sCurrentLine.Length, 10)).CompareTo("ObjectName") == 0)
                    {
                        NewObjectDef.ObjectName = sCurrentLine.Substring(10).Trim(trimString);
                    }
                    else if (sCurrentLine.Substring(0, Math.Min(sCurrentLine.Length, 9)).CompareTo("ObjectDef") == 0)
                    {
                        NewObjectDef.ObjectClassType = sCurrentLine.Substring(9).Trim(trimString);
                    }
                    else if (sCurrentLine.CompareTo("EndObjectDef") == 0)
                    {
                        // this is the end of this object definition.
                        return(NewObjectDef);
                    }
                    else
                    {
                        string param      = sCurrentLine.Substring(0, sCurrentLine.IndexOfAny(trimString));
                        string value      = sCurrentLine.Substring(sCurrentLine.IndexOfAny(trimString)).Trim(trimString);
                        int    leftCount  = Helpers.CountStringOccurrences(value, "{");
                        int    rightCount = Helpers.CountStringOccurrences(value, "}");
                        if (leftCount > rightCount)
                        {
                            while (Filesystem.ReadLine(ref sCurrentLine))
                            {
                                value      = string.Concat(value, sCurrentLine);
                                leftCount  = Helpers.CountStringOccurrences(value, "{");
                                rightCount = Helpers.CountStringOccurrences(value, "}");
                                if (leftCount == rightCount)
                                {
                                    break;
                                }
                            }
                        }
                        // If it is none of the above then it is a class property.
                        NewObjectDef.ClassProperties.Add(
                            param,
                            value
                            );
                    }
                }
                break;
                }
            }
            return(NewObjectDef);
        }