Пример #1
0
        public override bool Equals(object obj)
        {
            ScriptAndHeader scriptAndHeader = (obj as ScriptAndHeader);

            if (scriptAndHeader == null)
            {
                return(false);
            }
            return(object.Equals(Header, scriptAndHeader.Header) && object.Equals(Script, scriptAndHeader.Script));
        }
Пример #2
0
        /// <summary>
        /// Helper private function to add a script. The index is the internal data structure index
        /// to which we would like to add the script.
        /// The function automatically finds the ScriptAndHeader that matches the current script file name
        /// and adds the script to the pair, if it doesn't exist.
        /// If the pair is not found, a new item is added
        /// </summary>
        /// <param name="newScript">The script to add</param>
        /// <param name="index">The desired index where -1 indicates no specific location.</param>
        private void AddAt(Script newScript, int index)
        {
            int             indexExisting;
            ScriptAndHeader scriptAndHeaderExisting = _scripts.GetScriptAndHeaderByFilename(newScript.FileName, out indexExisting);

            if (scriptAndHeaderExisting == null)
            {
                // Script does not exist, add a new item
                if (newScript.IsHeader)
                {
                    _scripts.AddAt(new ScriptAndHeader(newScript, null), index);
                }
                else
                {
                    _scripts.AddAt(new ScriptAndHeader(null, newScript), index);
                }
            }
            else
            {
                // Update to the existing index if the requested index is -1
                // (default value), otherwise, add it to the requested index
                if (index != -1)
                {
                    indexExisting = index;
                }
                if (scriptAndHeaderExisting.Header != null &&
                    scriptAndHeaderExisting.Script == null &&
                    !newScript.IsHeader)
                {
                    // Header found, script does not exist and trying to add a script, so add it as its pair.
                    // Note that ScriptAndHeader is immutable so we remove the existing one and add a new one
                    _scripts.AddAt(new ScriptAndHeader(scriptAndHeaderExisting.Header, newScript), indexExisting);                    _scripts.Remove(scriptAndHeaderExisting);
                }
                else if (scriptAndHeaderExisting.Header == null &&
                         scriptAndHeaderExisting.Script != null &&
                         newScript.IsHeader)
                {
                    // Script found, header does not exist and trying to add a script, so add it as its pair
                    // Note that ScriptAndHeader is immutable so we remove the existing one and add a new one
                    _scripts.AddAt(new ScriptAndHeader(newScript, scriptAndHeaderExisting.Script), indexExisting);
                    _scripts.Remove(scriptAndHeaderExisting);
                }
            }

            // Will not add duplicate file name scripts, this is a change from previous behavior
            // for Add and AddAtTop, but it is not expected to be a real use case
        }
Пример #3
0
        public Game()
        {
            _guis                    = new GUIFolders(GUIFolder.MAIN_GUI_FOLDER_NAME);
            _inventoryItems          = new InventoryItemFolders(InventoryItemFolder.MAIN_INVENTORY_ITEM_FOLDER_NAME);
            _cursors                 = new List <MouseCursor>();
            _dialogs                 = new DialogFolders(DialogFolder.MAIN_DIALOG_FOLDER_NAME);
            _fonts                   = new List <Font>();
            _characters              = new CharacterFolders(CharacterFolder.MAIN_CHARACTER_FOLDER_NAME);
            _plugins                 = new List <Plugin>();
            _translations            = new List <Translation>();
            _rooms                   = new UnloadedRoomFolders(UnloadedRoomFolder.MAIN_UNLOADED_ROOM_FOLDER_NAME);
            _oldInteractionVariables = new List <OldInteractionVariable>();
            _settings                = new Settings();
            _defaultSetup            = new RuntimeSetup(_settings);
            _workspaceState          = new WorkspaceState();
            _palette                 = new PaletteEntry[PALETTE_SIZE];
            _sprites                 = new SpriteFolder("Main");
            _views                   = new ViewFolders("Main");
            _audioClips              = new AudioClipFolders("Main");
            _audioClipTypes          = new List <AudioClipType>();
            _textParser              = new TextParser();
            _lipSync                 = new LipSync();
            _propertySchema          = new CustomPropertySchema();
            _globalVariables         = new GlobalVariables();
            _globalMessages          = new string[NUMBER_OF_GLOBAL_MESSAGES];
            _deletedViewIDs          = new Dictionary <int, object>();
            _scripts                 = new ScriptFolders(ScriptFolder.MAIN_SCRIPT_FOLDER_NAME);
            _scriptsToCompile        = new ScriptsAndHeaders();
            ScriptAndHeader globalScript = new ScriptAndHeader(
                new Script(Script.GLOBAL_HEADER_FILE_NAME, "// script header\r\n", true),
                new Script(Script.GLOBAL_SCRIPT_FILE_NAME, "// global script\r\n", false));

            ((IList <ScriptAndHeader>)_scripts).Add(globalScript);
            _playerCharacter = null;

            for (int i = 0; i < _globalMessages.Length; i++)
            {
                _globalMessages[i] = string.Empty;
            }

            InitializeDefaultPalette();
        }
Пример #4
0
        public Script FindMatchingScriptOrHeader(Script scriptOrHeader)
        {
            ScriptAndHeader scriptAndHeader = _scripts.FindScriptAndHeader(scriptOrHeader);

            if (scriptAndHeader != null)
            {
                if (scriptOrHeader.Equals(scriptAndHeader.Header))
                {
                    return(scriptAndHeader.Script);
                }
                else
                {
                    return(scriptAndHeader.Header);
                }
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
        public void Remove(Script script)
        {
            int             index;
            ScriptAndHeader scriptAndHeader = _scripts.FindScriptAndHeader(script, out index);

            if (scriptAndHeader != null)
            {
                _scripts.Remove(scriptAndHeader);

                // Check if there is an existing item, if so add a ScriptAndHeader to keep it.
                if (script.IsHeader && scriptAndHeader.Script != null)
                {
                    _scripts.AddAt(new ScriptAndHeader(null, scriptAndHeader.Script), index);
                }
                else if (!script.IsHeader && scriptAndHeader.Header != null)
                {
                    _scripts.AddAt(new ScriptAndHeader(scriptAndHeader.Header, null), index);
                }
            }
        }
Пример #6
0
        public static CompileMessages ImportOldEditorDatFile(string fileName, Game game, Dictionary<int, Sprite> spriteList)
        {
            CompileMessages importErrors = new CompileMessages();
            string editorDatFilename = Path.Combine(Path.GetDirectoryName(fileName), "editor.dat");
            BinaryReader reader = new BinaryReader(new FileStream(editorDatFilename, FileMode.Open));
            string fileSig = Encoding.ASCII.GetString(reader.ReadBytes(14));
            if (fileSig != "AGSEditorInfo\0")
            {
                throw new AGS.Types.InvalidDataException("This is not a valid AGS game file.");
            }
            int version = reader.ReadInt32();
            if (version != EDITOR_DAT_LATEST_FILE_VERSION)
            {
                throw new AGS.Types.InvalidDataException("This game is from an unsupported version of AGS. This editor can only import games saved with AGS 2.72.");
            }
            game.RootScriptFolder.Clear();

            Script globalScript, scriptHeader;
            ReadGlobalScriptAndScriptHeader(reader, game, out globalScript, out scriptHeader);

            game.RootSpriteFolder = ImportSpriteFolders(reader, spriteList, importErrors);

            ImportRoomList(game, reader, fileName, importErrors);

            if (reader.ReadInt32() != 1)
            {
                throw new AGS.Types.InvalidDataException("Error in game files: invalid header for script modules");
            }

            int moduleCount = reader.ReadInt32();
            for (int i = 0; i < moduleCount; i++)
            {
                string author = ReadNullTerminatedString(reader);
                string description = ReadNullTerminatedString(reader);
                string name = ReadNullTerminatedString(reader);
                string moduleVersion = ReadNullTerminatedString(reader);

                int scriptLength = reader.ReadInt32();
                string moduleScript = Encoding.Default.GetString(reader.ReadBytes(scriptLength));
                reader.ReadByte();  // discard the null terminating byte

                scriptLength = reader.ReadInt32();
                string moduleHeader = Encoding.Default.GetString(reader.ReadBytes(scriptLength));
                reader.ReadByte();  // discard the null terminating byte

                int uniqueKey = reader.ReadInt32();

                ScriptAndHeader scripts = new ScriptAndHeader(
                        new Script("Module" + i + ".ash", moduleHeader, name, description, author, moduleVersion, uniqueKey, true),
                        new Script("Module" + i + ".asc", moduleScript, name, description, author, moduleVersion, uniqueKey, false));
                game.RootScriptFolder.Items.Add(scripts);

                int permissions = reader.ReadInt32();
                int weAreOwner = reader.ReadInt32();
            }

            game.RootScriptFolder.Items.Add(new ScriptAndHeader(scriptHeader, globalScript));            

            // Ensure that all .asc/.ash files are saved
            foreach (Script script in game.RootScriptFolder.AllScriptsFlat)
            {
                script.Modified = true;
            }

            int voxFilesListLength = reader.ReadInt32();
            reader.ReadBytes(voxFilesListLength); // skip over vox file list

            // The final portion of the file contains state data
            // for COM plugins, but since we no longer support these,
            // we can ignore it and finish here.

            reader.Close();
            return importErrors;
        }
Пример #7
0
        public Game()
        {
            _guis = new GUIFolder(GUIFolder.MAIN_GUI_FOLDER_NAME);
            _inventoryItems = new InventoryItemFolder(InventoryItemFolder.MAIN_INVENTORY_ITEM_FOLDER_NAME);
            _cursors = new List<MouseCursor>();
            _dialogs = new DialogFolder(DialogFolder.MAIN_DIALOG_FOLDER_NAME);
            _fonts = new List<Font>();
            _characters = new CharacterFolder(CharacterFolder.MAIN_CHARACTER_FOLDER_NAME);
            _plugins = new List<Plugin>();
            _translations = new List<Translation>();
            _rooms = new UnloadedRoomFolder(UnloadedRoomFolder.MAIN_UNLOADED_ROOM_FOLDER_NAME);
            _oldInteractionVariables = new List<OldInteractionVariable>();
            _settings = new Settings();
            _palette = new PaletteEntry[PALETTE_SIZE];
            _sprites = new SpriteFolder("Main");
            _views = new ViewFolder("Main");
            _audioClips = new AudioClipFolder("Main");
            _audioClipTypes = new List<AudioClipType>();
            _textParser = new TextParser();
            _lipSync = new LipSync();
            _propertySchema = new CustomPropertySchema();
            _globalVariables = new GlobalVariables();
            _globalMessages = new string[NUMBER_OF_GLOBAL_MESSAGES];
            _deletedViewIDs = new Dictionary<int, object>();
            _scripts = new ScriptFolder(ScriptFolder.MAIN_SCRIPT_FOLDER_NAME);
            _scriptsToCompile = new Scripts();
            ScriptAndHeader globalScript = new ScriptAndHeader(
                new Script(Script.GLOBAL_HEADER_FILE_NAME, "// script header\r\n", true),
                new Script(Script.GLOBAL_SCRIPT_FILE_NAME, "// global script\r\n", false));
            _scripts.Items.Add(globalScript);
            _playerCharacter = null;

            for (int i = 0; i < _globalMessages.Length; i++)
            {
                _globalMessages[i] = string.Empty;
            }

            InitializeDefaultPalette();
        }