Inheritance: IGame
Exemplo n.º 1
0
        public CompileMessages NumberSpeechLines(Game game, bool includeNarrator, bool combineIdenticalLines, bool removeNumbering, int? characterID)
        {
            _speechableFunctionCalls = GetFunctionCallsToProcessForSpeech(includeNarrator);

            _errors = new CompileMessages();
            _game = game;
            _includeNarrator = includeNarrator;
            _combineIdenticalLines = combineIdenticalLines;
            _removeNumbering = removeNumbering;
            _characterID = characterID;

            if (Factory.AGSEditor.AttemptToGetWriteAccess(SPEECH_REFERENCE_FILE_NAME))
            {
                using (_referenceFile = new StreamWriter(SPEECH_REFERENCE_FILE_NAME, false))
                {
                    _referenceFile.WriteLine("// AGS auto-numbered speech lines output. This file was automatically generated.");
                    PerformNumbering(game);
                }
            }
            else
            {
                _errors.Add(new CompileError("unable to create file " + SPEECH_REFERENCE_FILE_NAME));
            }

            return _errors;
        }
Exemplo n.º 2
0
        private void PerformNumbering(Game game)
        {
            SpeechLineProcessor processor = new SpeechLineProcessor(game, _includeNarrator,
                _combineIdenticalLines, _removeNumbering, _characterID, _speechableFunctionCalls, _errors, _referenceFile);

            foreach (Dialog dialog in game.Dialogs)
            {
                foreach (DialogOption option in dialog.Options)
                {
                    if (option.Say)
                    {
                        option.Text = processor.ProcessText(option.Text, GameTextType.DialogOption, game.PlayerCharacter.ID);
                    }
                }

                dialog.Script = processor.ProcessText(dialog.Script, GameTextType.DialogScript);
            }

            foreach (Script script in game.Scripts)
            {
                if (!script.IsHeader)
                {
                    script.Text = processor.ProcessText(script.Text, GameTextType.Script);
                }
            }

            for (int i = 0; i < game.GlobalMessages.Length; i++)
            {
                game.GlobalMessages[i] = processor.ProcessText(game.GlobalMessages[i], GameTextType.Message, Character.NARRATOR_CHARACTER_ID);
            }

            Factory.AGSEditor.RunProcessAllGameTextsEvent(processor, _errors);
        }
Exemplo n.º 3
0
 public VoiceActorScriptProcessor(Game game, CompileMessages errors,
     Dictionary<string, FunctionCallType> speechableFunctionCalls)
     : base(game, errors, false, false, speechableFunctionCalls)
 {
     _linesByCharacter = new Dictionary<int, Dictionary<string, string>>();
     _linesInOrder = new List<GameTextLine>();
 }
Exemplo n.º 4
0
 public GameSpeechProcessor(Game game, CompileMessages errors, bool makesChanges, bool processHotspotAndObjectDescriptions)
 {
     _game = game;
     _errors = errors;
     _makesChanges = makesChanges;
     _processHotspotAndObjectDescriptions = processHotspotAndObjectDescriptions;
 }
Exemplo n.º 5
0
        public string ConvertGameDialogScripts(Game game, CompileMessages errors, bool rebuildAll)
        {
            int stringBuilderCapacity = 1000 * game.RootDialogFolder.GetAllItemsCount() + _DefaultDialogScriptsScript.Length;
            StringBuilder sb = new StringBuilder(_DefaultDialogScriptsScript, stringBuilderCapacity);

            foreach (Dialog dialog in game.RootDialogFolder.AllItemsFlat)
            {
                sb.AppendLine(AGS.CScript.Compiler.Constants.NEW_SCRIPT_MARKER + "Dialog " + dialog.ID + "\"");

                if ((dialog.CachedConvertedScript == null) ||
                    (dialog.ScriptChangedSinceLastConverted) ||
                    (rebuildAll))
                {
                    int errorCountBefore = errors.Count;
                    this.ConvertDialogScriptToRealScript(dialog, game, errors);

                    if (errors.Count > errorCountBefore)
                    {
                        dialog.ScriptChangedSinceLastConverted = true;
                    }
                    else
                    {
                        dialog.ScriptChangedSinceLastConverted = false;
                    }
                }

                sb.Append(dialog.CachedConvertedScript);
            }

            return sb.ToString();
        }
Exemplo n.º 6
0
 public static DialogResult Show(GlobalVariable variable, Game game)
 {
     GlobalVariableDialog dialog = new GlobalVariableDialog(variable, game);
     DialogResult result = dialog.ShowDialog();
     dialog.Dispose();
     return result;
 }
Exemplo n.º 7
0
 public static void ForEachViewFolder(IViewFolder parentFolder, Game game, ViewFolderProcessing proc)
 {
     foreach (ViewFolder subFolder in parentFolder.SubFolders)
     {
         proc(subFolder, game);
     }
 }
Exemplo n.º 8
0
        public void ConvertDialogScriptToRealScript(Dialog dialog, Game game, CompileMessages errors)
        {
            string thisLine;
            _currentlyInsideCodeArea = false;
            _hadFirstEntryPoint = false;
            _game = game;
            _currentDialog = dialog;
            _existingEntryPoints.Clear();
            _currentLineNumber = 0;

            StringReader sr = new StringReader(dialog.Script);
            StringWriter sw = new StringWriter();
            sw.Write(string.Format("function _run_dialog{0}(int entryPoint) {1} ", dialog.ID, "{"));
            while ((thisLine = sr.ReadLine()) != null)
            {
                _currentLineNumber++;
                try
                {
                    ConvertDialogScriptLine(thisLine, sw, errors);
                }
                catch (CompileMessage ex)
                {
                    errors.Add(ex);
                }
            }
            if (_currentlyInsideCodeArea)
            {
                sw.WriteLine("}");
            }
            sw.WriteLine("return RUN_DIALOG_RETURN; }"); // end the function
            dialog.CachedConvertedScript = sw.ToString();
            sw.Close();
            sr.Close();
        }
Exemplo n.º 9
0
 public CharactersEditorFilter(Panel displayPanel, Room room, Game game)
 {
     _room = room;
     _panel = displayPanel;
     _game = game;
     _propertyObjectChangedDelegate = new GUIController.PropertyObjectChangedHandler(GUIController_OnPropertyObjectChanged);
 }
Exemplo n.º 10
0
 internal NewRoomDialog(Game game, List<RoomTemplate> templates)
 {
     InitializeComponent();
     _templates = templates;
     _imageList.ImageSize = new Size(32, 32);
     _imageList.Images.Add("_default", Resources.ResourceManager.GetIcon("template_noicon.ico"));
     foreach (RoomTemplate template in templates)
     {
         ListViewItem newItem = lstRoomTemplates.Items.Add(template.FriendlyName);
         if (template.Icon != null)
         {
             _imageList.Images.Add(template.FileName, template.Icon);
             newItem.ImageKey = template.FileName;
         }
         else
         {
             newItem.ImageKey = "_default";
         }
     }
     lstRoomTemplates.LargeImageList = _imageList;
     lstRoomTemplates.Items[0].Selected = true;
     lstRoomTemplates.Items[0].Focused = true;
     _game = game;
     _chosenRoomNumber = -1;
     PickFirstAvailableRoomNumber();
 }
Exemplo n.º 11
0
        public static void ProcessAllGameText(IGameTextProcessor processor, Game game, CompileMessages errors)
        {
            foreach (Dialog dialog in game.RootDialogFolder.AllItemsFlat)
            {
                foreach (DialogOption option in dialog.Options)
                {
                    option.Text = processor.ProcessText(option.Text, GameTextType.DialogOption, game.PlayerCharacter.ID);
                }

                dialog.Script = processor.ProcessText(dialog.Script, GameTextType.DialogScript);
            }

            foreach (ScriptAndHeader script in game.RootScriptFolder.AllItemsFlat)
            {                                
                string newScript = processor.ProcessText(script.Script.Text, GameTextType.Script);
                if (newScript != script.Script.Text)
                {
                    // Only cause it to flag Modified if we changed it
                    script.Script.Text = newScript;
                }                
            }

            foreach (GUI gui in game.RootGUIFolder.AllItemsFlat)
            {
                foreach (GUIControl control in gui.Controls)
                {
                    GUILabel label = control as GUILabel;
                    if (label != null)
                    {
                        label.Text = processor.ProcessText(label.Text, GameTextType.ItemDescription);
                    }
                    else
                    {
                        GUIButton button = control as GUIButton;
                        if (button != null)
                        {
                            button.Text = processor.ProcessText(button.Text, GameTextType.ItemDescription);
                        }
                    }
                }
            }

            foreach (Character character in game.RootCharacterFolder.AllItemsFlat)
            {
                character.RealName = processor.ProcessText(character.RealName, GameTextType.ItemDescription);
            }

            foreach (InventoryItem item in game.RootInventoryItemFolder.AllItemsFlat)
            {
                item.Description = processor.ProcessText(item.Description, GameTextType.ItemDescription);
            }

			for (int i = 0; i < game.GlobalMessages.Length; i++)
			{
				game.GlobalMessages[i] = processor.ProcessText(game.GlobalMessages[i], GameTextType.Message);
			}

            Factory.AGSEditor.RunProcessAllGameTextsEvent(processor, errors);
        }
Exemplo n.º 12
0
 public static void SetRootViewFolder(Game game, IViewFolder folder)
 {
     ViewFolder default_folder = (ViewFolder)folder;
     if (default_folder != null)
     {
         game.RootViewFolder = default_folder;
     }
 }
Exemplo n.º 13
0
        public static void ProcessAllGameText(IGameTextProcessor processor, Game game, CompileMessages errors)
        {
            foreach (Dialog dialog in game.Dialogs)
            {
                foreach (DialogOption option in dialog.Options)
                {
                    option.Text = processor.ProcessText(option.Text, GameTextType.DialogOption, game.PlayerCharacter.ID);
                }

                dialog.Script = processor.ProcessText(dialog.Script, GameTextType.DialogScript);
            }

            foreach (Script script in game.Scripts)
            {
                if (!script.IsHeader)
                {
                    string newScript = processor.ProcessText(script.Text, GameTextType.Script);
                    if (newScript != script.Text)
                    {
                        // Only cause it to flag Modified if we changed it
                        script.Text = newScript;
                    }
                }
            }

            foreach (GUI gui in game.GUIs)
            {
                foreach (GUIControl control in gui.Controls)
                {
                    if (control is GUILabel)
                    {
                        ((GUILabel)control).Text = processor.ProcessText(((GUILabel)control).Text, GameTextType.ItemDescription);
                    }
                    else if (control is GUIButton)
                    {
                        ((GUIButton)control).Text = processor.ProcessText(((GUIButton)control).Text, GameTextType.ItemDescription);
                    }
                }
            }

            foreach (Character character in game.Characters)
            {
                character.RealName = processor.ProcessText(character.RealName, GameTextType.ItemDescription);
            }

            foreach (InventoryItem item in game.InventoryItems)
            {
                item.Description = processor.ProcessText(item.Description, GameTextType.ItemDescription);
            }

            for (int i = 0; i < game.GlobalMessages.Length; i++)
            {
                game.GlobalMessages[i] = processor.ProcessText(game.GlobalMessages[i], GameTextType.Message);
            }

            Factory.AGSEditor.RunProcessAllGameTextsEvent(processor, errors);
        }
Exemplo n.º 14
0
        public static CompileMessages ReplaceAllGameText(Game game, Translation withTranslation)
        {
            CompileMessages errors = new CompileMessages();

            TextImportProcessor processor = new TextImportProcessor(game, errors, withTranslation.TranslatedLines);

            TextProcessingHelper.ProcessAllGameText(processor, game, errors);

            return errors;
        }
Exemplo n.º 15
0
        public CompileMessages CreateTranslationList(Game game)
        {
            CompileMessages errors = new CompileMessages();

            TranslationSourceProcessor processor = new TranslationSourceProcessor(game, errors);

            TextProcessingHelper.ProcessAllGameText(processor, game, errors);

            _linesForTranslation = processor.LinesForTranslation;

            return errors;
        }
Exemplo n.º 16
0
		public CompileMessages CreateVoiceActingScript(Game game)
		{
			CompileMessages errors = new CompileMessages();

			VoiceActorScriptProcessor processor = new VoiceActorScriptProcessor(game, errors, GetFunctionCallsToProcessForSpeech(true));

			TextProcessingHelper.ProcessAllGameText(processor, game, errors);

			_linesByCharacter = processor.LinesByCharacter;
			_linesInOrder = processor.LinesInOrder;

			return errors;
		}
Exemplo n.º 17
0
        public GlobalVariablesEditor(Game game)
        {
            InitializeComponent();
            lvwWords.ListViewItemSorter = new GlobalVariableComparer();
            _game = game;
            _variables = game.GlobalVariables;

            lvwWords.Sorting = SortOrder.Ascending;
            foreach (GlobalVariable variable in _variables.ToList())
            {
                lvwWords.Items.Add(CreateListItemFromVariable(variable));
            }
            lvwWords.Sort();
        }
Exemplo n.º 18
0
        public void InitializeEngine(Game game, IntPtr editorHwnd)
        {
            _communicator.NewClient();
            _communicator.SendMessage("<Engine Command=\"START\" EditorWindow=\"" + editorHwnd + "\" />");
            ChangeDebugState(DebugState.Running);

            foreach (Script script in game.GetAllGameAndLoadedRoomScripts())
            {
                foreach (int line in script.BreakpointedLines)
                {
                    SetBreakpoint(script, line);
                }
            }

            _communicator.SendMessage("<Engine Command=\"READY\" EditorWindow=\"" + editorHwnd + "\" />");
        }
Exemplo n.º 19
0
        public SpeechLineProcessor(Game game, bool includeNarrator, bool combineIdenticalLines, 
            bool removeNumbering, int? characterID,
            Dictionary<string, FunctionCallType> speechableFunctionCalls, 
            CompileMessages errors, StreamWriter referenceFile)
            : base(game, errors, true, false, speechableFunctionCalls)
        {
            _speechLineCount = new Dictionary<int, int>();
            _combineIdenticalLines = combineIdenticalLines;
            _includeNarrator = includeNarrator;
            _referenceFile = referenceFile;
            _removeNumbering = removeNumbering;
            _characterID = characterID;

            if (combineIdenticalLines)
            {
                _existingLines = new Dictionary<int, Dictionary<string, string>>();
            }
        }
Exemplo n.º 20
0
 public static void CreateInteractionScripts(Game game, CompileMessages errors)
 {
     Script theScript = game.Scripts.GetScriptByFilename(Script.GLOBAL_SCRIPT_FILE_NAME);
     foreach (InventoryItem item in game.InventoryItems)
     {
         if (item.Name.Length < 1)
         {
             item.Name = "iInventory" + item.ID;
         }
         CreateScriptsForInteraction(item.Name, theScript, item.Interactions, errors);
     }
     foreach (Character character in game.Characters)
     {
         if (character.ScriptName.Length < 1)
         {
             character.ScriptName = "cCharacter" + character.ID;
         }
         CreateScriptsForInteraction(character.ScriptName, theScript, character.Interactions, errors);
     }
 }
Exemplo n.º 21
0
        public GlobalVariableDialog(GlobalVariable variable, Game game)
        {
            InitializeComponent();
            _variable = variable;
            _game = game;
            PopulateTypeList();
            txtName.Text = variable.Name ?? string.Empty;
            txtDefaultValue.Text = variable.DefaultValue ?? string.Empty;

            foreach (GlobalVariableType varType in cmbType.Items)
            {
                if (varType.TypeName == variable.Type)
                {
                    cmbType.SelectedItem = varType;
                    break;
                }
            }

            Utilities.CheckLabelWidthsOnForm(this);
        }
Exemplo n.º 22
0
        private static void ImportRoomList(Game game, BinaryReader reader, string fullPathToGameFiles, CompileMessages importErrors)
        {
            Dictionary<int, UnloadedRoom> rooms = new Dictionary<int, UnloadedRoom>();
            foreach (string roomFileFullPath in Utilities.GetDirectoryFileList(Path.GetDirectoryName(fullPathToGameFiles), "room*.crm"))
            {
                int roomNumber = GetRoomNumberFromFileName(Path.GetFileName(roomFileFullPath));

                if (roomNumber >= 0)
                {
                    try
                    {
                        string roomScript = Factory.NativeProxy.LoadRoomScript(roomFileFullPath);
                        if (roomScript != null)
                        {
                            StreamWriter sw = new StreamWriter(roomFileFullPath.Substring(0, roomFileFullPath.Length - 4) + ".asc", false, Encoding.Default);
                            sw.Write(roomScript);
                            sw.Close();
                        }
                    }
                    catch (AGSEditorException ex)
                    {
                        importErrors.Add(new CompileError("There was an error saving the script for room " + roomNumber + ": " + ex.Message));
                    }

                    UnloadedRoom newUnloadedRoom = new UnloadedRoom(roomNumber);
                    rooms.Add(roomNumber, newUnloadedRoom);
                    game.Rooms.Add(newUnloadedRoom);
                }
                else
                {
                    importErrors.Add(new CompileWarning("The room file '" + roomFileFullPath + "' does not have a recognised name and will not be part of the game."));
                }
            }

            ((List<IRoom>)game.Rooms).Sort();

            int roomCount = reader.ReadInt32();
            for (int i = 0; i < roomCount; i++)
            {
                string roomDescription = ReadNullTerminatedString(reader);
                if (rooms.ContainsKey(i))
                {
                    rooms[i].Description = roomDescription;
                }
            }
        }
Exemplo n.º 23
0
 private static void EnsureViewNameIsUnique(View view, Game game)
 {
     string scriptNameBase = view.Name;
     int suffix = 0;
     while (game.IsScriptNameAlreadyUsed(view.Name.ToUpper(), view))
     {
         suffix++;
         view.Name = scriptNameBase + suffix;
     }
 }
Exemplo n.º 24
0
 private static void EnsureCharacterScriptNameIsUnique(Character character, Game game)
 {
     string scriptNameBase = character.ScriptName;
     int suffix = 0;
     while (game.IsScriptNameAlreadyUsed(character.ScriptName, character))
     {
         suffix++;
         character.ScriptName = scriptNameBase + suffix;
     }
 }
Exemplo n.º 25
0
 private static void AdjustScriptNamesToEnsureEverythingIsUnique(GUI gui, Game game)
 {
     while (game.IsScriptNameAlreadyUsed(gui.Name, gui))
     {
         gui.Name += "2";
     }
     foreach (GUIControl control in gui.Controls)
     {
         while (game.IsScriptNameAlreadyUsed(control.Name, control))
         {
             control.Name += "2";
         }
     }
 }
Exemplo n.º 26
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.Scripts.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();

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

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

            game.Scripts.Add(scriptHeader);
            game.Scripts.Add(globalScript);

            // Ensure that all .asc/.ash files are saved
            foreach (Script script in game.Scripts)
            {
                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;
        }
Exemplo n.º 27
0
        public static GUI ImportGUIFromFile(string fileName, Game game)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);

            if (doc.DocumentElement.Name != GUI_XML_ROOT_NODE)
            {
                throw new AGS.Types.InvalidDataException("Not a valid AGS GUI file.");
            }
            if (SerializeUtils.GetAttributeString(doc.DocumentElement, GUI_XML_VERSION_ATTRIBUTE) != GUI_XML_CURRENT_VERSION)
            {
                throw new AGS.Types.InvalidDataException("This file requires a newer version of AGS to import it.");
            }

            GUI newGui;
            if (doc.DocumentElement.FirstChild.FirstChild.Name == NormalGUI.XML_ELEMENT_NAME)
            {
                newGui = new NormalGUI(doc.DocumentElement.FirstChild);
            }
            else
            {
                newGui = new TextWindowGUI(doc.DocumentElement.FirstChild);
            }

            PaletteEntry[] palette = game.ReadPaletteFromXML(doc.DocumentElement);

            SpriteFolder newFolder = new SpriteFolder(newGui.Name + "Import");
            game.RootSpriteFolder.SubFolders.Add(newFolder);

            Dictionary<int, int> spriteMapping = ImportSpritesFromXML(doc.DocumentElement.SelectSingleNode(GUI_XML_SPRITES_NODE), palette, newFolder);
            if (newGui.BackgroundImage > 0)
            {
                newGui.BackgroundImage = spriteMapping[newGui.BackgroundImage];
            }

            if (newGui.BackgroundImage < 0)
                newGui.BackgroundImage = 0;

            foreach (GUIControl control in newGui.Controls)
            {
                control.UpdateSpritesWithMapping(spriteMapping);
            }
            AdjustScriptNamesToEnsureEverythingIsUnique(newGui, game);

            game.RootSpriteFolder.NotifyClientsOfUpdate();
            return newGui;
        }
Exemplo n.º 28
0
        public static Character ImportCharacterNew(string fileName, Game game)
        {
            XmlDocument doc = new XmlDocument();
            try
            {
                doc.Load(fileName);
            }
            catch (XmlException ex)
            {
                throw new AGS.Types.InvalidDataException("This does not appear to be a valid AGS Character file." + Environment.NewLine + Environment.NewLine + ex.Message, ex);
            }

            if (doc.DocumentElement.Name != CHARACTER_XML_ROOT_NODE)
            {
                throw new AGS.Types.InvalidDataException("Not a valid AGS Character file.");
            }
            if (SerializeUtils.GetAttributeString(doc.DocumentElement, CHARACTER_XML_VERSION_ATTRIBUTE) != CHARACTER_XML_CURRENT_VERSION)
            {
                throw new AGS.Types.InvalidDataException("This file requires a newer version of AGS to import it.");
            }

            Character newChar = new Character(doc.DocumentElement.FirstChild);
            PaletteEntry[] palette = game.ReadPaletteFromXML(doc.DocumentElement);

            // Clear any existing event handler function names
            for (int i = 0; i < newChar.Interactions.ScriptFunctionNames.Length; i++)
            {
                newChar.Interactions.ScriptFunctionNames[i] = string.Empty;
            }

            SpriteFolder newFolder = new SpriteFolder(newChar.ScriptName + "Import");
            game.RootSpriteFolder.SubFolders.Add(newFolder);

            Dictionary<int, int> spriteMapping = new Dictionary<int, int>();
            XmlNode viewsNode = doc.DocumentElement.SelectSingleNode("Views");

            newChar.NormalView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("NormalView"), game, spriteMapping, palette, newFolder);

            if (newChar.SpeechView > 0)
            {
                newChar.SpeechView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("SpeechView"), game, spriteMapping, palette, newFolder);
            }
            if (newChar.IdleView > 0)
            {
                newChar.IdleView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("IdleView"), game, spriteMapping, palette, newFolder);
            }
            if (newChar.ThinkingView > 0)
            {
                newChar.ThinkingView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("ThinkingView"), game, spriteMapping, palette, newFolder);
            }
            if (newChar.BlinkingView > 0)
            {
                newChar.BlinkingView = ReadAndAddNewStyleView(viewsNode.SelectSingleNode("BlinkingView"), game, spriteMapping, palette, newFolder);
            }

            EnsureCharacterScriptNameIsUnique(newChar, game);

            game.RootSpriteFolder.NotifyClientsOfUpdate();
            game.NotifyClientsViewsUpdated();
            return newChar;
        }
Exemplo n.º 29
0
        /// <summary>
        /// Import a 2.72-compatible CHA file. This code is horrid, but it's
        /// backwards compatible!!
        /// </summary>
        public static Character ImportCharacter272(string fileName, Game game)
        {
            BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open, FileAccess.Read));
            string fileSig = Encoding.ASCII.GetString(reader.ReadBytes(12));
            if (fileSig != CHARACTER_FILE_SIGNATURE)
            {
                reader.Close();
                throw new AGS.Types.InvalidDataException("This is not a valid AGS character file.");
            }
            int fileVersion = reader.ReadInt32();
            if ((fileVersion < 5) || (fileVersion > 6))
            {
                reader.Close();
                throw new AGS.Types.InvalidDataException("This character file is not supported by this version of AGS.");
            }

            Color []palette = new Color[256];
            for (int i = 0; i < 256; i++)
            {
                int r = reader.ReadByte();
                int g = reader.ReadByte();
                int b = reader.ReadByte();
                reader.ReadByte();
                palette[i] = Color.FromArgb(r * 4, g * 4, b * 4);
            }

            Character character = new Character();
            reader.ReadInt32();
            character.SpeechView = reader.ReadInt32();
            reader.ReadInt32();
            character.StartingRoom = reader.ReadInt32();
            reader.ReadInt32();
            character.StartX = reader.ReadInt32();
            character.StartY = reader.ReadInt32();
            reader.ReadInt32();
            reader.ReadInt32();
            reader.ReadInt32();
            character.IdleView = reader.ReadInt32();
            reader.ReadInt32();
            reader.ReadInt32();
            reader.ReadInt32();
            character.SpeechColor = reader.ReadInt32();
            character.ThinkingView = reader.ReadInt32();
            character.BlinkingView = reader.ReadInt16();
            reader.ReadInt16();
            reader.ReadBytes(40);
            character.MovementSpeed = reader.ReadInt16();
            character.AnimationDelay = reader.ReadInt16();
            reader.ReadBytes(606);
            character.RealName = ReadNullTerminatedString(reader, 40);
            character.ScriptName = ReadNullTerminatedString(reader, 20);
            if (character.ScriptName.Length > 0)
            {
                character.ScriptName = "c" + Char.ToUpper(character.ScriptName[0]) + character.ScriptName.Substring(1).ToLower();

                EnsureCharacterScriptNameIsUnique(character, game);
            }
            reader.ReadInt16();

            string viewNamePrefix = character.ScriptName;
            if (viewNamePrefix.StartsWith("c")) viewNamePrefix = viewNamePrefix.Substring(1);

            SpriteFolder folder = new SpriteFolder(character.ScriptName + "Sprites");
            character.NormalView = ReadAndAddView(viewNamePrefix + "Walk", reader, game, folder, palette);
            if (character.SpeechView > 0)
            {
                character.SpeechView = ReadAndAddView(viewNamePrefix + "Talk", reader, game, folder, palette);
            }
            else
            {
                character.SpeechView = 0;
            }

            if (character.IdleView > 0)
            {
                character.IdleView = ReadAndAddView(viewNamePrefix + "Idle", reader, game, folder, palette);
            }
            else
            {
                character.IdleView = 0;
            }

            if ((character.ThinkingView > 0) && (fileVersion >= 6))
            {
                character.ThinkingView = ReadAndAddView(viewNamePrefix + "Think", reader, game, folder, palette);
            }
            else
            {
                character.ThinkingView = 0;
            }

            if ((character.BlinkingView > 0) && (fileVersion >= 6))
            {
                character.BlinkingView = ReadAndAddView(viewNamePrefix + "Blink", reader, game, folder, palette);
            }
            else
            {
                character.BlinkingView = 0;
            }

            reader.Close();

            game.RootSpriteFolder.SubFolders.Add(folder);
            game.RootSpriteFolder.NotifyClientsOfUpdate();
            game.NotifyClientsViewsUpdated();

            return character;
        }
Exemplo n.º 30
0
        public static void ExportGUIToFile(GUI gui, string fileName, Game game)
        {
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.Default);
            writer.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"" + Encoding.Default.WebName + "\"");
            writer.WriteComment("AGS Exported GUI file. DO NOT EDIT THIS FILE BY HAND, IT IS GENERATED AUTOMATICALLY BY THE AGS EDITOR.");
            writer.WriteStartElement(GUI_XML_ROOT_NODE);
            writer.WriteAttributeString(GUI_XML_VERSION_ATTRIBUTE, GUI_XML_CURRENT_VERSION);

            gui.ToXml(writer);

            writer.WriteStartElement(GUI_XML_SPRITES_NODE);
            ExportAllSpritesOnGUI(gui, writer);
            writer.WriteEndElement();

            game.WritePaletteToXML(writer);

            writer.WriteEndElement();
            writer.Close();
        }