Exemplo n.º 1
0
        public override void BuildGameDataFromSheet(string outRootPath)
        {
            string mergeFilePath = outRootPath + Path.DirectorySeparatorChar + FilePathWithoutExtension + OutputExtension;

            Console.WriteLine("Getting " + AssetName + " Spreadsheet content");

            SpreadsheetsResource.ValuesResource.GetRequest request = GoogleSheetConnector.GetInstance().Service.Spreadsheets.Values.Get(SheetId, SheetRange);
            ValueRange             response = request.Execute();
            List <IList <object> > values   = (List <IList <object> >)response.Values;

            //Clearing Asset File
            string outDirectory = Path.GetDirectoryName(mergeFilePath);

            if (!Directory.Exists(outDirectory))
            {
                Directory.CreateDirectory(outDirectory);
            }
            //Resetting file
            File.WriteAllText(mergeFilePath, "");

            string scheduleRelativeFolderPath = Path.DirectorySeparatorChar + "chs" + Path.DirectorySeparatorChar + "battle" + Path.DirectorySeparatorChar + "buffer";
            string bufferFolderPath           = outRootPath + Path.DirectorySeparatorChar + scheduleRelativeFolderPath;

            //Getting all Sheet entries and dumping them into Talk.txt in right format
            Console.WriteLine("Extracting to " + FilePathWithoutExtension + OutputExtension + " and the schedules folder");
            StreamWriter mergeFileWriter = File.AppendText(mergeFilePath);

            if (values != null && values.Count > 0)
            {
                foreach (var row in values)
                {
                    BufferAsset thisEntry = new BufferAsset(VariableDefinitions);
                    thisEntry.PopulateBySheetRow(row);

                    //Writing to merge file
                    thisEntry.AppendToFile(mergeFileWriter, thisEntry);

                    //Writting to .json file
                    string fileName = thisEntry.Variables[0].OriginalValue;
                    string filePath = bufferFolderPath + Path.DirectorySeparatorChar + fileName;
                    outDirectory = Path.GetDirectoryName(filePath);
                    if (!Directory.Exists(outDirectory))
                    {
                        Directory.CreateDirectory(outDirectory);
                    }

                    File.WriteAllText(filePath, "");
                    StreamWriter scheduleFileWriter = File.AppendText(filePath);
                    thisEntry.AppendToFile(scheduleFileWriter, thisEntry);
                    scheduleFileWriter.Close();
                }
            }

            mergeFileWriter.Close();
        }
Exemplo n.º 2
0
        public override void UpdateSheetFromGameFile(string inputFolder)
        {
            string bufferFolderPath = inputFolder + Path.DirectorySeparatorChar + "chs" + Path.DirectorySeparatorChar + "battle" + Path.DirectorySeparatorChar + "buffer";

            //Getting all current entries
            Dictionary <string, BufferAsset> entries = new Dictionary <string, BufferAsset>();
            GoogleSheetConnector             gsc     = GoogleSheetConnector.GetInstance();

            Console.WriteLine("Getting " + AssetName + " Spreadsheet content");

            SpreadsheetsResource.ValuesResource.GetRequest request = gsc.Service.Spreadsheets.Values.Get(SheetId, 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)
                {
                    BufferAsset ae = new BufferAsset(VariableDefinitions);
                    ae.PopulateBySheetRow(row);
                    ae.Row = rowC;

                    entries[(string)row[0]] = ae;
                    rowC++;
                }
            }

            var updateRequests = new List <Request>();

            Console.WriteLine("Comparing with games version and calculating updates...");
            //Parse every battle schedule file
            string[] files = Directory.GetFiles(bufferFolderPath, "*.bytes");
            for (int i = 0; i < files.Length; i++)
            {
                Console.Title = "[" + AssetName + "] Processing " + i + "/" + files.Length;

                //Reading file
                string bufferFilePathTmp      = files[i];
                System.IO.StreamReader reader = new System.IO.StreamReader(bufferFilePathTmp);
                string line = reader.ReadLine();

                //Construction relative .json path
                int    lastSplitterIndex = bufferFilePathTmp.LastIndexOf(Path.DirectorySeparatorChar);
                string scheduleFilePath  = bufferFilePathTmp.Substring(lastSplitterIndex + 1, bufferFilePathTmp.Length - lastSplitterIndex - 1);
                scheduleFilePath = scheduleFilePath.Replace(".bytes", ".json");

                //Parsing
                string[]    data = line.Split('\t');
                BufferAsset entry;
                if (entries.ContainsKey(scheduleFilePath))
                {
                    //Compare and update
                    entry = entries[scheduleFilePath];
                }
                else
                {
                    //New entry
                    entry = new BufferAsset(VariableDefinitions);
                }

                entry.PopulateByGameAssetRow(scheduleFilePath, data);
                List <Request> updateReqs = entry.GetUpdateRequests();
                foreach (Request req in updateReqs)
                {
                    updateRequests.Add(req);
                }

                if (updateRequests.Count >= 2500)
                {
                    HandleUpdateRequests(ref updateRequests);
                }
            }

            HandleUpdateRequests(ref updateRequests);
        }