Exemplo n.º 1
0
        private static bool BBCBasicLines(XElement xm, DataItems gameData, BBCBasicLine.LineType lt)
        {
            //remove < and > escape characters
            string text = xm.Value;

            text = text.Replace("&lt;", "<");
            text = text.Replace("&gt;", ">");
            string lineText = "";

            //breaks the variou user code chunks into separate lines and saves as BBC Basic lines
            //string[] lines = xm.Value.Trim().Split(new[] { "\n" }, StringSplitOptions.None);
            string[] lines = text.Trim().Split(new[] { "\n" }, StringSplitOptions.None);
            foreach (string line in lines)
            {
                lineText = line.Trim();

                if (lineText != null && lineText.Length >= 2 && lineText.Substring(0, 1) != "'")
                {
                    gameData.UserBBCBasicProgram.Add(new BBCBasicLine(0, lineText.Trim(), lt));
                    if (!BBCBasicFunctions.ParseLine(gameData.UserBBCBasicProgram[gameData.UserBBCBasicProgram.Count - 1], gameData))
                    {
                        return(false);
                    }
                    ;
                    gameData.eventList.Add(new EventLog(gameData.UserBBCBasicProgram[gameData.UserBBCBasicProgram.Count - 1].LineText()));
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public static bool ReadBasicFile(DataItems gameData)
        {
            string line;
            string fd = gameData.folderDivider;

            try
            {
                // Read the file and display it line by line.
                System.IO.StreamReader file = new System.IO.StreamReader(gameData.folderLocation + fd + "Source" + fd + gameData.sourceFile);
                while ((line = file.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (line != null && line.Length >= 2 && line.Trim().Substring(0, 1) != "'")
                    {
                        if (line.Trim().Substring(0, 1) == "-")
                        {
                            if (gameData.debugMode)
                            {
                                line = line.Right(1, line.Length - 1);
                                gameData.SourceBBCBasicProgram.Add(new BBCBasicLine(0, line, BBCBasicLine.LineType.SourceLine));
                                BBCBasicFunctions.GetLineNumber(gameData.SourceBBCBasicProgram[gameData.SourceBBCBasicProgram.Count - 1]);
                            }
                        }
                        else
                        {
                            gameData.SourceBBCBasicProgram.Add(new BBCBasicLine(0, line, BBCBasicLine.LineType.SourceLine));
                            BBCBasicFunctions.GetLineNumber(gameData.SourceBBCBasicProgram[gameData.SourceBBCBasicProgram.Count - 1]);
                        }
                    }
                }

                file.Close();
                return(true);
            }
            catch (Exception e)
            {
                gameData.eventList.Add(new EventLog("Error processing file : " + gameData.sourceFile + ". " + e.Message));
                return(false);
            }
        }
Exemplo n.º 3
0
        public static bool CreateOutputProgram(DataItems gameData)
        {
            try
            {
                int iNumLines     = gameData.SourceBBCBasicProgram.Count;
                int iNumUserLines = gameData.UserBBCBasicProgram.Count;

                for (int i = 0; i < iNumLines; i++)
                {
                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@NumObjects@") > -1)
                    {
                        //replace the room index size with the actual number used
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@NumObjects@", gameData.objectList.Count.ToString()));
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@SizeOfObject@") > -1)
                    {
                        //replace the room index size with the actual number used
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@SizeOfObject@", 11.ToString()));
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@ObjectData@") > -1)
                    {
                        //replace the room index size with the actual number used
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@ObjectData@", (gameData.objectList.Count * 11).ToString()));
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@RMIndex@") > -1)
                    {
                        //replace the room index size with the actual number used
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@RMIndex@", gameData.roomIndexLength.ToString()));
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@Room@") > -1)
                    {
                        //replace the room index size with the actual number used
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@Room@", gameData.roomDataLength.ToString()));
                    }


                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@NumVar@") > -1)
                    {
                        //replace the 256 with the actual number used
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@NumVar@", gameData.varList.Count.ToString()));
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@ScreenMode@") > -1)
                    {
                        //replace the screen mode
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@ScreenMode@", gameData.screenMode.ToString()));
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@Title@") > -1)
                    {
                        //replace the game title
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@Title@", gameData.gameTitle));
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@NumMssages@") > -1)
                    {
                        //replace the number of messages with the actual number used
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@NumMssages@", gameData.messageList.Count.ToString()));
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().IndexOf("@ScreenWidth@") > -1)
                    {
                        //replace the screen width
                        string tmp = gameData.SourceBBCBasicProgram[i].LineText();
                        gameData.SourceBBCBasicProgram[i].SetLineText(tmp.Replace("@ScreenWidth@", gameData.screenWidth.ToString()));
                    }

                    if (!BBCBasicFunctions.ParseLine(gameData.SourceBBCBasicProgram[i], gameData))
                    {
                        return(false);
                    }

                    if (gameData.debugMode)
                    {
                        switch (gameData.SourceBBCBasicProgram[i].LineText().Left(2))
                        {
                        case "#R":
                            break;

                        case "#D":
                            string txt = gameData.SourceBBCBasicProgram[i].LineText().Right(2, gameData.SourceBBCBasicProgram[i].LineText().Length - 2);
                            gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.SourceBBCBasicProgram[i].OriginalLineNumber(), txt, BBCBasicLine.LineType.SourceLine));
                            break;

                        default:
                            gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.SourceBBCBasicProgram[i].OriginalLineNumber(), gameData.SourceBBCBasicProgram[i].LineText(), BBCBasicLine.LineType.SourceLine));
                            break;
                        }
                    }
                    else
                    {
                        //any lines starting with #R
                        switch (gameData.SourceBBCBasicProgram[i].LineText().Left(2))
                        {
                        case "#D":
                            break;

                        case "#R":
                            string txt = gameData.SourceBBCBasicProgram[i].LineText().Right(2, gameData.SourceBBCBasicProgram[i].LineText().Length - 2);
                            gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.SourceBBCBasicProgram[i].OriginalLineNumber(), txt, BBCBasicLine.LineType.SourceLine));
                            break;

                        default:
                            gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.SourceBBCBasicProgram[i].OriginalLineNumber(), gameData.SourceBBCBasicProgram[i].LineText(), BBCBasicLine.LineType.SourceLine));
                            break;
                        }
                    }



                    //loop through each line of the following items:
                    //gameData.SourceBBCBasicProgram
                    //gameData.UserBBCBasicProgram.PreRoom
                    //gameData.UserBBCBasicProgram.Init
                    //gameData.UserBBCBasicProgram.HighPriority
                    //gameData.UserBBCBasicProgram.LowPriority

                    if (gameData.SourceBBCBasicProgram[i].LineText().ToUpper() == "DEFPROCPREROOM")
                    {
                        //merge in the preroom stuff, if any
                        for (int line = 0; line < iNumUserLines; line++)
                        {
                            if (gameData.UserBBCBasicProgram[line].GetLineType() == (int)BBCBasicLine.LineType.PreRoom)
                            {
                                gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.UserBBCBasicProgram[line].OriginalLineNumber(), gameData.UserBBCBasicProgram[line].LineText(), BBCBasicLine.LineType.PreRoom));
                            }
                        }
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().ToUpper() == "DEFPROCINIT")
                    {
                        //merge in the preroom stuff, if any
                        for (int line = 0; line < iNumUserLines; line++)
                        {
                            if (gameData.UserBBCBasicProgram[line].GetLineType() == (int)BBCBasicLine.LineType.Init)
                            {
                                gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.UserBBCBasicProgram[line].OriginalLineNumber(), gameData.UserBBCBasicProgram[line].LineText(), BBCBasicLine.LineType.Init));
                            }
                        }
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().ToUpper() == "DEFPROCRMMSG")
                    {
                        //merge in the preroom stuff, if any
                        for (int line = 0; line < iNumUserLines; line++)
                        {
                            if (gameData.UserBBCBasicProgram[line].GetLineType() == (int)BBCBasicLine.LineType.RoomMsg)
                            {
                                gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.UserBBCBasicProgram[line].OriginalLineNumber(), gameData.UserBBCBasicProgram[line].LineText(), BBCBasicLine.LineType.RoomMsg));
                            }
                        }
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().ToUpper() == "DEFFNHIGHPTY")
                    {
                        //merge in the preroom stuff, if any
                        for (int line = 0; line < iNumUserLines; line++)
                        {
                            if (gameData.UserBBCBasicProgram[line].GetLineType() == (int)BBCBasicLine.LineType.HighPriority)
                            {
                                gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.UserBBCBasicProgram[line].OriginalLineNumber(), gameData.UserBBCBasicProgram[line].LineText(), BBCBasicLine.LineType.PreRoom));
                            }
                        }
                    }

                    if (gameData.SourceBBCBasicProgram[i].LineText().ToUpper() == "DEFFNLOWPTY")
                    {
                        //merge in the preroom stuff, if any
                        for (int line = 0; line < iNumUserLines; line++)
                        {
                            if (gameData.UserBBCBasicProgram[line].GetLineType() == (int)BBCBasicLine.LineType.LowPriority)
                            {
                                gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.UserBBCBasicProgram[line].OriginalLineNumber(), gameData.UserBBCBasicProgram[line].LineText(), BBCBasicLine.LineType.PreRoom));
                            }
                        }
                    }
                }

                //add in the user code section
                for (int line = 0; line < iNumUserLines; line++)
                {
                    if (gameData.UserBBCBasicProgram[line].GetLineType() == (int)BBCBasicLine.LineType.UserCode)
                    {
                        gameData.TargetBBCBasicProgram.Add(new BBCBasicLine(gameData.UserBBCBasicProgram[line].OriginalLineNumber(), gameData.UserBBCBasicProgram[line].LineText(), BBCBasicLine.LineType.UserCode));
                    }
                }
                //renumber the lines
                BBCBasicFunctions.RenumberLines(gameData);

                //tokenise (has to be done after renumbering as line number is stored)
                //BBCBasicFunctions.TokeniseLines(gameData);

                return(true);
            }
            catch (Exception e)
            {
                gameData.eventList.Add(new EventLog(e.Message));
                return(false);
            }
        }