Example #1
0
        public void UpdateSheetFromGameFile(string gameFileRootPath)
        {
            string gameFilePath = gameFileRootPath + Path.DirectorySeparatorChar + "Adjustment.bytes";

            //Getting all current entries
            Dictionary <string, AdjustmentEntry> adjustmentEntries = new Dictionary <string, AdjustmentEntry>();

            Console.WriteLine("Getting Adjustment Spreadsheet content");
            GoogleSheetConnector gsc = GoogleSheetConnector.GetInstance();
            string talkSpreadsheetId = gsc.SpreadsheetIDs["Adjustment"];

            SpreadsheetsResource.ValuesResource.GetRequest request = gsc.Service.Spreadsheets.Values.Get(talkSpreadsheetId, SheetRange);
            ValueRange             response = request.Execute();
            List <IList <object> > values   = (List <IList <object> >)response.Values;
            int rowC = 1;

            if (values != null && values.Count > 0)
            {
                foreach (var row in values)
                {
                    AdjustmentEntry ae = new AdjustmentEntry(row);
                    ae.row = rowC;
                    adjustmentEntries[ae.ID] = ae;
                    rowC++;
                }
            }

            //UpdatingRequests
            var updateRequests = new List <Request>();

            Console.WriteLine("Comparing with games version and calculating updates...");
            //Parse every line in the game file
            System.IO.StreamReader reader = new System.IO.StreamReader(gameFilePath);
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                //Splitting
                string[] data = line.Split('\t');
                //Parsing data
                string ID                  = data[0];
                string OriginalTitle       = data[1];
                string OriginalSecondTitle = data[2];
                string OriginalDescription = data[3];
                string Element1            = data[4];
                string Element2            = data[5];
                string J      = data[6];
                string H      = data[7];
                string NpcId1 = data[8];
                string NpcId2 = data[9];
                string NpcId3 = data[10];
                string StandardizedTermLocator_Title       = StandardizedTermManager.GetInstance().GetTermLocatorText(OriginalTitle);
                string StandardizedTermLocator_SecondTitle = StandardizedTermManager.GetInstance().GetTermLocatorText(OriginalSecondTitle);
                string StandardizedTermLocator_Description = StandardizedTermManager.GetInstance().GetTermLocatorText(OriginalDescription);

                if (adjustmentEntries.ContainsKey(ID))
                {
                    //Compare and update
                    AdjustmentEntry existingEntry = adjustmentEntries[ID];
                    bool            needsUpdate   = false;

                    if (!string.IsNullOrEmpty(OriginalTitle) && existingEntry.OriginalTitle != OriginalTitle)
                    {
                        existingEntry.OriginalTitle = OriginalTitle;
                        existingEntry.TitleChanged  = true;
                        needsUpdate = true;
                    }

                    if (!string.IsNullOrEmpty(OriginalSecondTitle) && existingEntry.OriginalSecondTitle != OriginalSecondTitle)
                    {
                        existingEntry.OriginalSecondTitle = OriginalSecondTitle;
                        existingEntry.SecondTitleChanged  = true;
                        needsUpdate = true;
                    }

                    if (!string.IsNullOrEmpty(OriginalDescription) && existingEntry.OriginalDescription != OriginalDescription)
                    {
                        existingEntry.OriginalDescription = OriginalDescription;
                        existingEntry.DescriptionChanged  = true;
                        needsUpdate = true;
                    }

                    if (existingEntry.Element1 != Element1)
                    {
                        existingEntry.Element1 = Element1;
                        needsUpdate            = true;
                    }

                    if (existingEntry.Element2 != Element2)
                    {
                        existingEntry.Element2 = Element2;
                        needsUpdate            = true;
                    }

                    if (existingEntry.J != J)
                    {
                        existingEntry.J = J;
                        needsUpdate     = true;
                    }

                    if (existingEntry.H != H)
                    {
                        existingEntry.H = H;
                        needsUpdate     = true;
                    }

                    if (existingEntry.NpcId1 != NpcId1)
                    {
                        existingEntry.NpcId1 = NpcId1;
                        needsUpdate          = true;
                    }

                    if (existingEntry.NpcId2 != NpcId2)
                    {
                        existingEntry.NpcId2 = NpcId2;
                        needsUpdate          = true;
                    }

                    if (existingEntry.NpcId3 != NpcId3)
                    {
                        existingEntry.NpcId3 = NpcId3;
                        needsUpdate          = true;
                    }

                    if (existingEntry.StandardizedTermLocator_Title != StandardizedTermLocator_Title)
                    {
                        existingEntry.StandardizedTermLocator_Title = StandardizedTermLocator_Title;
                        needsUpdate = true;
                    }

                    if (existingEntry.StandardizedTermLocator_SecondTitle != StandardizedTermLocator_SecondTitle)
                    {
                        existingEntry.StandardizedTermLocator_SecondTitle = StandardizedTermLocator_SecondTitle;
                        needsUpdate = true;
                    }

                    if (existingEntry.StandardizedTermLocator_Description != StandardizedTermLocator_Description)
                    {
                        existingEntry.StandardizedTermLocator_Description = StandardizedTermLocator_Description;
                        needsUpdate = true;
                    }

                    if (needsUpdate)
                    {
                        updateRequests.Add(existingEntry.ToGoogleSheetUpdateRequest());
                    }
                }
                else
                {
                    //New one
                    AdjustmentEntry newEntry = new AdjustmentEntry();
                    newEntry.ID                  = ID;
                    newEntry.TitleText           = TranslationManager.GetInstance().Translate(StandardizedTermLocator_Title);
                    newEntry.OriginalTitle       = OriginalTitle;
                    newEntry.SecondTitle         = TranslationManager.GetInstance().Translate(StandardizedTermLocator_SecondTitle);
                    newEntry.OriginalSecondTitle = OriginalSecondTitle;
                    newEntry.Description         = TranslationManager.GetInstance().Translate(StandardizedTermLocator_Description);
                    newEntry.OriginalDescription = OriginalDescription;
                    newEntry.Element1            = Element1;
                    newEntry.Element2            = Element2;
                    newEntry.J      = J;
                    newEntry.H      = H;
                    newEntry.NpcId1 = NpcId1;
                    newEntry.NpcId2 = NpcId2;
                    newEntry.NpcId3 = NpcId3;
                    newEntry.StandardizedTermLocator_Title       = StandardizedTermLocator_Title;
                    newEntry.StandardizedTermLocator_SecondTitle = StandardizedTermLocator_SecondTitle;
                    newEntry.StandardizedTermLocator_Description = StandardizedTermLocator_Description;

                    newEntry.TitleChanged       = true;
                    newEntry.SecondTitleChanged = true;
                    newEntry.DescriptionChanged = true;
                    newEntry.MLTranslated       = true;

                    updateRequests.Add(newEntry.ToGoogleSheetUpdateRequest());
                }
            }

            Console.WriteLine("Updating spreadsheet...");
            BatchUpdateSpreadsheetRequest batchUpdate = new BatchUpdateSpreadsheetRequest();

            batchUpdate.Requests = new List <Request>();
            int reqHandled = 0;

            //updateRequests.RemoveRange(2, updateRequests.Count - 2);
            foreach (var req in updateRequests)
            {
                batchUpdate.Requests.Add(req);
                reqHandled++;
                if (batchUpdate.Requests.Count >= 500 || reqHandled >= updateRequests.Count)
                {
                    var updateRequest = gsc.Service.Spreadsheets.BatchUpdate(batchUpdate, talkSpreadsheetId);
                    updateRequest.Execute();
                    //Resetting batch update
                    batchUpdate          = new BatchUpdateSpreadsheetRequest();
                    batchUpdate.Requests = new List <Request>();
                }
            }

            Console.WriteLine("Done!");
        }
Example #2
0
        public void UpdateSheetFromGameFile(string gameFileRootPath)
        {
            string gameFilePath = gameFileRootPath + Path.DirectorySeparatorChar + "Achievement.bytes";

            //Getting all current entries
            Dictionary <string, AchievementEntry> achievementEntries = new Dictionary <string, AchievementEntry>();

            Console.WriteLine("Getting Achievement Spreadsheet content");
            GoogleSheetConnector gsc = GoogleSheetConnector.GetInstance();
            string talkSpreadsheetId = gsc.SpreadsheetIDs["Achievement"];

            SpreadsheetsResource.ValuesResource.GetRequest request = gsc.Service.Spreadsheets.Values.Get(talkSpreadsheetId, SheetRange);
            ValueRange             response = request.Execute();
            List <IList <object> > values   = (List <IList <object> >)response.Values;
            int rowC = 1;

            if (values != null && values.Count > 0)
            {
                foreach (var row in values)
                {
                    AchievementEntry ae = new AchievementEntry(row);
                    ae.row = rowC;
                    achievementEntries[ae.ID] = ae;
                    rowC++;
                }
            }

            //UpdatingRequests
            var updateRequests = new List <Request>();

            Console.WriteLine("Comparing with games version and calculating updates...");
            //Parse every line in the game file
            System.IO.StreamReader reader = new System.IO.StreamReader(gameFilePath);
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                //Splitting
                string[] data = line.Split('\t');

                //Parsing data
                string ID = data[0];
                string ShortOriginalText = data[1];
                string LongOriginalText  = data[2];
                string D = data[3];

                string StandardizedTerm_Short = StandardizedTermManager.GetInstance().GetTermLocatorText(ShortOriginalText);
                string StandardizedTerm_Long  = StandardizedTermManager.GetInstance().GetTermLocatorText(LongOriginalText);

                if (achievementEntries.ContainsKey(ID))
                {
                    //Compare and update
                    AchievementEntry existingEntry = achievementEntries[ID];
                    bool             needsUpdate   = false;

                    if (!string.IsNullOrEmpty(ShortOriginalText) && existingEntry.ShortOriginalText != ShortOriginalText)
                    {
                        existingEntry.ShortOriginalText = ShortOriginalText;
                        existingEntry.ShortTextChanged  = true;
                        needsUpdate = true;
                    }

                    if (!string.IsNullOrEmpty(LongOriginalText) && existingEntry.LongOriginalText != LongOriginalText)
                    {
                        existingEntry.LongOriginalText = LongOriginalText;
                        existingEntry.LongTextChanged  = true;
                        needsUpdate = true;
                    }

                    if (!string.IsNullOrEmpty(StandardizedTerm_Short) && existingEntry.StandardizedTerm_Short != StandardizedTerm_Short)
                    {
                        existingEntry.StandardizedTerm_Short = StandardizedTerm_Short;
                        needsUpdate = true;
                    }

                    if (!string.IsNullOrEmpty(StandardizedTerm_Long) && existingEntry.StandardizedTerm_Long != StandardizedTerm_Long)
                    {
                        existingEntry.StandardizedTerm_Long = StandardizedTerm_Long;
                        needsUpdate = true;
                    }

                    if (existingEntry.D != D)
                    {
                        existingEntry.D = D;
                        needsUpdate     = true;
                    }

                    if (needsUpdate)
                    {
                        updateRequests.Add(existingEntry.ToGoogleSheetUpdateRequest());
                    }
                }
                else
                {
                    //New one
                    AchievementEntry newEntry = new AchievementEntry();
                    newEntry.ID = ID;
                    newEntry.ShortOriginalText = ShortOriginalText;
                    newEntry.ShortText         = TranslationManager.GetInstance().Translate(StandardizedTerm_Short);
                    newEntry.ShortTextChanged  = true;
                    newEntry.LongOriginalText  = LongOriginalText;
                    newEntry.LongText          = TranslationManager.GetInstance().Translate(StandardizedTerm_Long);
                    newEntry.D = D;
                    newEntry.LongTextChanged        = true;
                    newEntry.MLTranslated           = true;
                    newEntry.StandardizedTerm_Short = StandardizedTerm_Short;
                    newEntry.StandardizedTerm_Long  = StandardizedTerm_Long;

                    updateRequests.Add(newEntry.ToGoogleSheetUpdateRequest());
                }
            }

            Console.WriteLine("Updating spreadsheet...");
            BatchUpdateSpreadsheetRequest batchUpdate = new BatchUpdateSpreadsheetRequest();

            batchUpdate.Requests = new List <Request>();
            int reqHandled = 0;

            //updateRequests.RemoveRange(2, updateRequests.Count - 2);
            foreach (var req in updateRequests)
            {
                batchUpdate.Requests.Add(req);
                reqHandled++;
                if (batchUpdate.Requests.Count >= 500 || reqHandled >= updateRequests.Count)
                {
                    var updateRequest = gsc.Service.Spreadsheets.BatchUpdate(batchUpdate, talkSpreadsheetId);
                    updateRequest.Execute();
                    //Resetting batch update
                    batchUpdate          = new BatchUpdateSpreadsheetRequest();
                    batchUpdate.Requests = new List <Request>();
                }
            }

            Console.WriteLine("Done!");
        }
Example #3
0
        public void UpdateSheetFromGameFile(string gameFileRootPath)
        {
            string gameFilePath      = gameFileRootPath + Path.DirectorySeparatorChar + "Talk.bytes";
            GoogleSheetConnector gsc = GoogleSheetConnector.GetInstance();
            string talkSpreadsheetId = gsc.SpreadsheetIDs["Talk"];

            Console.WriteLine("Getting Talk Spreadsheet content");

            //Getting all current entries
            Dictionary <string, TalkEntry> talkEntries = new Dictionary <string, TalkEntry>();

            SpreadsheetsResource.ValuesResource.GetRequest request = gsc.Service.Spreadsheets.Values.Get(talkSpreadsheetId, SheetRange);
            ValueRange             response = request.Execute();
            List <IList <object> > values   = (List <IList <object> >)response.Values;
            int rowC = 1;

            if (values != null && values.Count > 0)
            {
                foreach (var row in values)
                {
                    TalkEntry te = new TalkEntry((string)row[0]);
                    te.TalkerID                = (string)row[1];
                    te.C                       = (string)row[2];
                    te.D                       = (string)row[3];
                    te.Text                    = (string)row[4];
                    te.OriginalText            = (string)row[5];
                    te.PreviousOriginalText    = (string)row[6];
                    te.NextDialogID            = (string)row[7];
                    te.I                       = (string)row[8];
                    te.AlternativeNextDialogID = (string)row[9];
                    te.K                       = (string)row[10];
                    te.Script                  = (string)row[11];
                    te.SecondScript            = (string)row[12];
                    if (row.Count > 13)
                    {
                        te.TranslatorNotes = (string)row[13];
                    }
                    if (row.Count > 14)
                    {
                        te.StandardizedTermLocator = (string)row[14];
                    }

                    te.row = rowC;

                    talkEntries[te.DialogID] = te;
                    rowC++;
                }
            }
            //UpdatingRequests
            var updateRequests          = new List <Request>();
            var standardizedTermLocator = StandardizedTermManager.GetInstance();

            Console.WriteLine("Comparing with games version and calculating updates...");
            //Parse every line in the game file
            System.IO.StreamReader reader = new System.IO.StreamReader(gameFilePath);
            string line;

            while ((line = reader.ReadLine()) != null)
            {
                //We first splite the line into the parts
                string[] data = line.Split('\t');

                string dialogID                = data[0];
                string talkerID                = data[1];
                string valueC                  = data[2];
                string valueD                  = data[3];
                string originalText            = data[4];
                string nextDialogId            = data[5];
                string valueI                  = data[6];
                string alternativeNextDialogID = data[7];
                string valueK                  = data[8];
                string script                  = data[9];
                string secondScript            = data[10];
                string standardizedTermText    = standardizedTermLocator.GetTermLocatorText(originalText);

                if (talkEntries.ContainsKey(dialogID))
                {
                    //Compare and update
                    TalkEntry existingEntry = talkEntries[dialogID];
                    bool      needsUpdate   = false;

                    //First we take care of originalText, previousOriginalText and Text
                    if (!string.IsNullOrEmpty(originalText) && existingEntry.OriginalText != originalText)
                    {
                        existingEntry.TextChanged = true;

                        //Update the original Text and previous Text

                        existingEntry.PreviousOriginalText    = existingEntry.OriginalText;
                        existingEntry.OriginalText            = originalText;
                        existingEntry.StandardizedTermLocator = standardizedTermText;
                        needsUpdate = true;
                    }

                    if (string.IsNullOrEmpty(existingEntry.StandardizedTermLocator) && !string.IsNullOrEmpty(standardizedTermText))
                    {
                        existingEntry.StandardizedTermLocator = standardizedTermText;
                        needsUpdate = true;
                    }

                    //Updating TalkerID
                    if (existingEntry.TalkerID != talkerID)
                    {
                        existingEntry.TalkerID = talkerID;
                        needsUpdate            = true;
                    }
                    //Updating NextDialogID
                    if (existingEntry.TalkerID != talkerID)
                    {
                        existingEntry.TalkerID = talkerID;
                        needsUpdate            = true;
                    }

                    //Updating NextDialogID
                    if (existingEntry.NextDialogID != nextDialogId)
                    {
                        existingEntry.NextDialogID = nextDialogId;
                        needsUpdate = true;
                    }

                    //Updating AlternativeNextDialogID
                    if (existingEntry.AlternativeNextDialogID != alternativeNextDialogID)
                    {
                        existingEntry.AlternativeNextDialogID = alternativeNextDialogID;
                        needsUpdate = true;
                    }

                    //Updating C, D, I and K
                    if (existingEntry.C != valueC)
                    {
                        existingEntry.C = valueC;
                        needsUpdate     = true;
                    }

                    if (existingEntry.D != valueD)
                    {
                        existingEntry.D = valueD;
                        needsUpdate     = true;
                    }

                    if (existingEntry.I != valueI)
                    {
                        existingEntry.I = valueI;
                        needsUpdate     = true;
                    }

                    if (existingEntry.K != valueK)
                    {
                        existingEntry.K = valueK;
                        needsUpdate     = true;
                    }

                    //Updating Script and SecondScript

                    if (existingEntry.Script != script)
                    {
                        existingEntry.Script = script;
                        needsUpdate          = true;
                    }

                    if (existingEntry.SecondScript != secondScript)
                    {
                        existingEntry.SecondScript = secondScript;
                        needsUpdate = true;
                    }

                    if (needsUpdate)
                    {
                        updateRequests.Add(existingEntry.ToGoogleSheetUpdateRequest());
                    }
                }
                else
                {
                    //TalkEntry is unknown, add a new one
                    TalkEntry newEntry = new TalkEntry(dialogID);
                    newEntry.TalkerID                = talkerID;
                    newEntry.C                       = valueC;
                    newEntry.D                       = valueD;
                    newEntry.OriginalText            = originalText;
                    newEntry.NextDialogID            = nextDialogId;
                    newEntry.K                       = valueK;
                    newEntry.AlternativeNextDialogID = alternativeNextDialogID;
                    newEntry.I                       = valueI;
                    newEntry.Script                  = script;
                    newEntry.SecondScript            = secondScript;
                    newEntry.StandardizedTermLocator = standardizedTermText;

                    newEntry.TextChanged = true;

                    //Doing intial ML Translation
                    var translatedText = TranslationManager.GetInstance().Translate(standardizedTermText);
                    newEntry.Text             = translatedText;
                    newEntry.TextMLTranslated = true;

                    rowC++;
                    updateRequests.Add(newEntry.ToGoogleSheetUpdateRequest());
                }
            }

            Console.WriteLine("Updating spreadsheet...");
            BatchUpdateSpreadsheetRequest batchUpdate = new BatchUpdateSpreadsheetRequest();

            batchUpdate.Requests = new List <Request>();
            int reqHandled = 0;

            //updateRequests.RemoveRange(2, updateRequests.Count - 2);
            foreach (var req in updateRequests)
            {
                batchUpdate.Requests.Add(req);
                reqHandled++;
                if (batchUpdate.Requests.Count >= 500 || reqHandled >= updateRequests.Count)
                {
                    var updateRequest = gsc.Service.Spreadsheets.BatchUpdate(batchUpdate, talkSpreadsheetId);
                    updateRequest.Execute();
                    //Resetting batch update
                    batchUpdate          = new BatchUpdateSpreadsheetRequest();
                    batchUpdate.Requests = new List <Request>();
                }
            }

            Console.WriteLine("Done!");
        }