コード例 #1
0
        public static void TestStringCollection()
        {
            var testCollection = new StringCollection();

            string testID        = "test_id";
            string testString    = "test_string";
            string testStringTwo = "test_string_two";

            testCollection.AddString(testID, testString);
            string testNewString = testCollection.GetString(testID);

            Debug.Assert(testString.Equals(testNewString), "Input/output replication test failed for StringCollection");

            bool exceptionCaught;

            try
            {
                // Adding same string with same ID
                testCollection.AddString(testID, testString);
                exceptionCaught = false;
            }
            catch (Exception e)
            {
                exceptionCaught = true;
            }

            Debug.Assert(exceptionCaught == false, "Same ID same string test failed for StringCollection");

            try
            {
                // Adding different string with same ID
                testCollection.AddString(testID, testStringTwo);
                exceptionCaught = false;
            }
            catch (Exception e)
            {
                exceptionCaught = true;
            }

            Debug.Assert(exceptionCaught == true, "Same ID different string test failed for StringCollection");

            try
            {
                // Trying to access non-existent string
                string nonExistentID     = "afesrgrt3qr\aefgsgggaftr3qr4q4";
                string nonExistentString = testCollection.GetString(nonExistentID);
                exceptionCaught = false;
            }
            catch (Exception e)
            {
                exceptionCaught = true;
            }

            Debug.Assert(exceptionCaught == true, "Non-existent ID test failed for StringCollection");

            var testCollectionWithID = new StringCollection("TEST");

            Debug.Assert(testCollectionWithID.GenerateNewID() == "$TEST_0", "ID generation test failed for StringCollection"); // this test does not account for variable idPrefix etc. which are technicallty not supported at the moment
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var col = new StringCollection();

            col.AddString("White");
            col.AddString("Red");
            col.AddString("Black");
            Console.WriteLine("string ouput : " + col.ToString());
            Console.ReadKey();
        }
コード例 #3
0
ファイル: LocationCard.cs プロジェクト: shindouj/KPT
        public void AddStrings(StringCollection collection)
        {
            string newID;

            newID = collection.GenerateNewID();
            collection.AddString(newID, time);
            time = newID;

            newID = collection.GenerateNewID();
            collection.AddString(newID, location);
            location = newID;
        }
コード例 #4
0
ファイル: DialogueBox.cs プロジェクト: shindouj/KPT
        public void AddStrings(StringCollection collection)
        {
            string newID = collection.GenerateNewID();

            collection.AddString(newID, dialogue);
            dialogue = newID;
        }
コード例 #5
0
        public void AddStrings(StringCollection collection)
        {
            string newID = collection.GenerateNewID();

            collection.AddString(newID, choiceText);
            choiceText = newID;
        }
コード例 #6
0
ファイル: CSVFileReader.cs プロジェクト: shindouj/KPT
        /// <summary>
        /// Read the contents of a CSV file following the CSVRecord format and place its strings into the provided string collection
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="collection"></param>
        public void ReadCSVFile(string fileName, StringCollection collection)
        {
            FileStream   fs = new FileStream(fileName, FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            var csvReader = new CsvHelper.CsvReader(sr);

            csvReader.Configuration.MissingFieldFound = null;
            csvReader.Configuration.RegisterClassMap <CSVRecordMap>();

            csvReader.Read();
            csvReader.ReadHeader(); // not checking correctness of header atm

            while (csvReader.Read())
            {
                var record         = csvReader.GetRecord <CSVRecord>();
                var id             = record.stringID;
                var translatedText = record.translatedText;
                if (translatedText == "")
                {
                    translatedText = record.originalText; // replace translated text with original text if it's blank
                }
                collection.AddString(id, translatedText);
            }

            sr.Close();
            fs.Close();
        }
コード例 #7
0
        public static bool DumpStrings()
        {
            string dialogueFileDir = Path.Combine(rootDir, unpackedGameFilesDir, @"PSP_GAME\USRDIR\St000"); // at the moment there's only one directory with files that have strings and only files with strings in that directory, so this is a quick way of processing. if any non-string files are added to this directory or any string files are found in other directories more advanced filtering will be necessary.

            string[] fileList = Directory.GetFiles(dialogueFileDir);

            if (!Directory.Exists(dialogueFileDir))
            {
                string errorMessage = string.Format("Could not find directory {0}.", dialogueFileDir);
                MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            var nameCollection = new StringCollection();
            Dictionary <string, StringCollection> stringFiles = new Dictionary <string, StringCollection>();

            foreach (string file in fileList)
            {
                string fileName    = Path.Combine(dialogueFileDir, file);
                var    fileStrings = new StringCollection(GetSubPath(file, Path.Combine(rootDir, unpackedGameFilesDir)));

                FileStream   fs = new FileStream(fileName, FileMode.Open);
                BinaryReader br = new BinaryReader(fs);

                var testParser = new FileParser();
                var parsedFile = testParser.ParseFile(br, Path.GetFileName(file), null);

                foreach (IElement element in parsedFile.instructions)
                {
                    if (element is IHasName)
                    {
                        var name = (element as IHasName).GetName();
                        nameCollection.AddString(name, name); // using name as ID and value since we want a single entry for each name - saves messing with IDs
                    }
                    if (element is IHasStrings)
                    {
                        var temp = element as IHasStrings;
                        temp.AddStrings(fileStrings);
                    }
                }

                br.Close();
                fs.Close();

                if (fileStrings.NumberOfKeys > 0)
                {
                    var    subPath             = GetSubPath(file, Path.Combine(rootDir, unpackedGameFilesDir));
                    string spreadsheetFileName = Path.Combine(rootDir, editableGameFiesDir, subPath);
                    var    spreadsheet         = new CSVFileWriter();
                    spreadsheet.WriteCSVFile(spreadsheetFileName, parsedFile.instructions, fileStrings);
                }
            }

            return(true);
        }
コード例 #8
0
        // under ideal circumstances a large portion of DumpStrings and LoadStrings code would be seperated out into ProcessStrings - but that's more of goal for future refactoring
        // yeah this is just getting done to provide a quick beta and will have to be refactored later
        public static void LoadStrings(object sender, EventArgs e)
        {
            BackgroundWorker worker    = null;
            DoWorkEventArgs  eventArgs = null;

            if (sender is BackgroundWorker)
            {
                worker    = sender as BackgroundWorker;
                eventArgs = e as DoWorkEventArgs;
            }
            else
            {
                worker = null;
            }

            string dialogueFileDir = Path.Combine(rootDir, unpackedGameFilesDir, @"PSP_GAME\USRDIR\St000"); // at the moment there's only one directory with files that have strings and only files with strings in that directory, so this is a quick way of processing. if any non-string files are added to this directory or any string files are found in other directories more advanced filtering will be necessary.

            string[]         fileList          = Directory.GetFiles(dialogueFileDir);
            StringCollection translatedStrings = LoadCSVStrings(Path.Combine(rootDir, editableGameFiesDir, @"PSP_GAME\USRDIR\St000"));

            if (!Directory.Exists(dialogueFileDir))
            {
                string errorMessage = string.Format("Could not find directory {0}.", dialogueFileDir);
                MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                eventArgs.Result = false;
            }

            var nameCollection = new StringCollection();
            Dictionary <string, StringCollection> stringFiles = new Dictionary <string, StringCollection>();

            FontHandler fontHandler = new FontHandler(); // we will sneak fixing the font size in here

            fontHandler.ChangeSpaceSize(FontHandler.DEFAULT_SPACE_SIZE);

            var textWrapper = new DynamicTextBoxes();
            var jumpTable   = new KPT.Parser.Jump_Label_Manager.JumpTableInterface();

            jumpTable.LoadJumpTable(); // changing the size of instructions with new dialogue will mess up file offsets so we will need to load the jump table and make sure it's updated as we go
            var jumpLabelManager = new JumpLabelManager(jumpTable.GetJumpTableEntries());

            int counter = 0;

            foreach (string file in fileList)
            {
                counter++;

                if (worker != null)
                {
                    double progress = ((double)counter / (double)fileList.Length) * 100;

                    worker.ReportProgress((int)progress);

                    Thread.Sleep(3); // these are aeshetic sleeps, there to make the progress bar grow steadily so the user doesn't think something might have went wrong
                }

                if (worker != null)
                {
                    if (worker.WorkerSupportsCancellation && worker.CancellationPending)
                    {
                        eventArgs.Result = false;
                        MessageBox.Show("Load strings cancelled");
                        return;
                    }
                }

                string fileName    = Path.Combine(dialogueFileDir, file);
                var    fileStrings = new StringCollection(GetSubPath(file, Path.Combine(rootDir, unpackedGameFilesDir)));

                FileStream   fs = new FileStream(fileName, FileMode.Open);
                BinaryReader br = new BinaryReader(fs);

                var parser     = new FileParser();
                var parsedFile = parser.ParseFile(br, Path.GetFileName(file), jumpLabelManager);

                foreach (IElement element in parsedFile.instructions)
                {
                    if (element is IHasName)
                    {
                        var name = (element as IHasName).GetName();
                        nameCollection.AddString(name, name); // using name as ID and value since we want a single entry for each name - saves messing with IDs
                    }
                    if (element is IHasStrings)
                    {
                        var temp = element as IHasStrings;
                        temp.AddStrings(fileStrings);
                        temp.GetStrings(translatedStrings);
                    }
                }

                textWrapper.CheckTextboxes(parsedFile);

                br.Close();
                fs.Close();

                if (fileStrings.NumberOfKeys > 0)
                {
                    string outputFileName = Path.Combine(rootDir, reassembledGameFilesDir, GetSubPath(file, Path.Combine(rootDir, unpackedGameFilesDir)));
                    parser.WriteFile(parsedFile, outputFileName);
                }
            }

            jumpTable.SaveJumpTable();

            Thread.Sleep(1000); // this is another aesthetic sleep, ensuring the the progress bar does not disappear before the user can see it completing
            eventArgs.Result = true;
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: ThaboPayi/Assessment
        static void Main(string[] args)
        {
            string stringInput;

            //Instatiation
            IStringCollection stringCollection = new StringCollection();
            CoinJar           jar = new CoinJar();

            Console.WriteLine("Strings");
            Console.WriteLine("//=======//");
            Console.WriteLine();
            //Just for demo purpose i will take only 5 strings, otherwise it can be set to any no you want
            stringInput = "Please enter five strings";
            Console.WriteLine(stringInput);
            Console.WriteLine("//==================================================//");
            //Catch input
            for (int i = 0; i <= 4; i++)
            {
                stringCollection.AddString(Console.ReadLine()?.ToString());
            }

            //Display String
            Console.WriteLine("Concatenated list of strings delimited with comma is:");
            Console.WriteLine(stringCollection.ToString());
            Console.WriteLine("....................................................");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Coinage");
            Console.WriteLine("//======//");
            Console.WriteLine();
            Console.WriteLine("Because there is a lot of countries using '$'other than U.S ....");
            Console.WriteLine("Please enter US coins, first enter coin amount with US currency code e.g '10USD' then enter its volume size");
            Console.WriteLine("//=========================================================================================================//");
            //Just for demo purpose i will take only 5 coins, otherwise it can be set to any no you want or to anything less than Jar Volume
            for (int i = 0; i <= 4; i++)
            {
                try
                {
                    string coinAmount = Console.ReadLine();
                    if (coinAmount != null)
                    {
                        string  coinAmountWithOutCurrencyCode = coinAmount.Remove(coinAmount.Length - 3);
                        decimal amount = decimal.Parse(coinAmountWithOutCurrencyCode);

                        decimal volume = decimal.Parse(Console.ReadLine());
                        Console.WriteLine();
                        Console.WriteLine();

                        Coin coin = new Coin(amount, volume);

                        ICoin enteredCoin = new CoinJar();
                        jar.TryParse(amount.ToString(), ref enteredCoin);
                    }

                    if (jar.Message != null)
                    {
                        Console.WriteLine(jar.Message);
                        Console.ReadKey();
                    }
                    else
                    {
                        //Display TotalAmount of Coins Collected
                        Console.WriteLine("Total Amount is:");
                        Console.WriteLine(jar.TotalAmount);
                        Console.WriteLine("//==================================================//");
                        Console.WriteLine("Now lets empty the jar before it gets full");
                        jar.Reset();
                        Console.WriteLine(jar.TotalAmount);
                        Console.WriteLine("//====================End===========================//");
                        Console.ReadKey();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("The Coin Amount or Coin Volume entered is in incorrect format, or null");
                }
            }
        }