public PEERbotPalette newPalette(bool streamingAsset = false) { //Game Object Vars GameObject newPaletteObject = Instantiate(paletteCopy, Vector3.zero, Quaternion.identity); newPaletteObject.transform.SetParent(paletteCopy.transform.parent, true); newPaletteObject.transform.localScale = new Vector3(1, 1, 1); newPaletteObject.SetActive(true); //Change color to denote default streaming asset if (streamingAsset) { newPaletteObject.transform.Find("TitleText").GetComponent <Text>().color = new Color32(150, 80, 220, 255); } //Palette vars PEERbotPalette newPalette = newPaletteObject.GetComponent <PEERbotPalette>(); if (newPalette == null) { Debug.LogError("Palette script on PaletteCopy not found. PaletteCopy must have Palette script attached!"); return(null); } newPalette.title = "Palette " + (int)Random.Range(0, 100); selectPalette(newPalette); palettes.Add(newPalette); return(newPalette); }
public void SaveCSVPalette(PEERbotPalette palette, string path) { //Check and make sure path and path are not null. if (palette == null) { Debug.LogWarning("Palette is null! Cannot save palette."); return; } if (string.IsNullOrEmpty(path)) { Debug.LogWarning("Path is null! Cannot save palette."); return; } //Change Palette Name to Path Name (if different) //editorUI.setPaletteTitle(getPaletteNameFromFilePath(path)); //Convert button list to button data list, List <PEERbotButtonDataFull> buttonDataListFull = palette.buttons.ConvertAll(x => x.data); //And then crimp from full data to simplified data List <PEERbotButtonData> buttonDataList = buttonDataListFull.ConvertAll(x => JsonUtility.FromJson <PEERbotButtonData>(JsonUtility.ToJson(x))); try { //Save using sinban CSV auto json parser Sinbad.CsvUtil.SaveObjects(buttonDataList, path); //If successfully saved, set the new path setHomePath(getPalettePathFolder(path)); } catch (Exception e) { Debug.LogWarning(e); } }
public void selectPalette(PEERbotPalette palette) { if (palette == null) { Debug.LogWarning("Null palette! Cannot select palette."); return; } //Hide all unselected palette buttons. if (currentPalette != null) { foreach (PEERbotButton button in currentPalette.buttons) { button.gameObject.SetActive(false); } currentPalette.gameObject.transform.Find("SelectedOutline").gameObject.SetActive(false); } //Show/hide outlines palette.gameObject.transform.Find("SelectedOutline").gameObject.SetActive(true); //Show all selected palette buttons. foreach (PEERbotButton button in palette.buttons) { button.gameObject.SetActive(true); } //Select nothing selectButton(null); //Set currentPalette currentPalette = palette; //Change Title Text editorUI.setPaletteTitle(palette.title); //Debug.Log("Selected Palette!"); }
public void SaveJSONPalette(PEERbotPalette palette, string path) { //Check and make sure path and path are not null. if (palette == null) { Debug.LogWarning("Palette is null! Cannot save palette."); return; } if (string.IsNullOrEmpty(path)) { Debug.LogWarning("Path is null! Cannot save palette."); return; } //Change Palette Name to Path Name (if different) editorUI.setPaletteTitle(Path.GetFileNameWithoutExtension(path)); //Convert Waseda Palette to Waseda Palette Data (for JSON serialization) PEERbotPaletteData paletteData = new PEERbotPaletteData(); paletteData.title = palette.title; paletteData.buttons = palette.buttons.ConvertAll(x => JsonUtility.FromJson <PEERbotButtonData>(JsonUtility.ToJson(x.data))); // Create a file to write to. string json = JsonUtility.ToJson(paletteData); File.WriteAllText(path, json); Debug.Log(json); }
public PEERbotPalette LoadJSONPalette(PEERbotPalette palette, string path) { //Try to load the CSV first string encodedString = ""; try{ StreamReader reader = new StreamReader(path); encodedString = reader.ReadToEnd();//.ToLower(); reader.Close(); } catch (Exception e) { Debug.LogWarning("Failed to load JSON: " + path); return(palette); } //overwrite the palette if it exists PEERbotPaletteData paletteData = JsonUtility.FromJson <PEERbotPaletteData>(encodedString); palette.title = paletteData.title; //Create new buttons from newPalette template foreach (PEERbotButtonData buttonData in paletteData.buttons) { PEERbotButton buttonClone = pc.newButton(); buttonClone.data = JsonUtility.FromJson <PEERbotButtonDataFull>(JsonUtility.ToJson(buttonData)); pc.selectButton(buttonClone); } //Select the newly creatde palette pc.selectPalette(palette); //If successfully loaded, set the new path setHomePath(getPalettePathFolder(path)); //Return the result return(palette); }
IEnumerator MobileFileBrowserSaveCoroutinePalette(PEERbotPalette palette) { SimpleFileBrowser.FileBrowser.SetDefaultFilter(".csv"); yield return(SimpleFileBrowser.FileBrowser.WaitForSaveDialog(FileBrowser.PickMode.Files, false, getPalettePathFolder(), palette.title, "Save CSV Palette File", "Save")); androidSaveLoadBackground.SetActive(false); if (SimpleFileBrowser.FileBrowser.Success) { SaveCSVPalette(palette, SimpleFileBrowser.FileBrowser.Result[0]); } }
public void AddToPaletteLog(PEERbotPalette palette) { if (palette == null) { Debug.LogWarning("Palette is null! Cannot add to PaletteLog!"); return; } PEERbotPaletteLogData data = new PEERbotPaletteLogData(); data.title = palette.title; data.date = System.DateTime.Now.ToString("yyyy-MM-dd"); data.time = System.DateTime.Now.ToString("hh:mm:sstt ") + timezone; paletteLog.Add(data); }
public void AddToLog(PEERbotPalette palette, PEERbotButtonDataFull data) { if (!isLogging) { return; } data.palette = palette.title; data.date = System.DateTime.Now.ToString("yyyy-MM-dd"); data.time = System.DateTime.Now.ToString("hh:mm:sstt ") + timezone; log.Add(data); //Add to master log file List <PEERbotButtonDataFull> single = new List <PEERbotButtonDataFull>(); single.Add(data); Sinbad.CsvUtil.SaveObjects(single, logPath + SLASH + "[LOG] MasterLog.csv", true); }
public void deletePalette(PEERbotPalette palette) { if (palette == null) { Debug.LogWarning("No palette selected! Cannot delete palette."); return; } //Delete all current buttons foreach (PEERbotButton button in palette.buttons) { Destroy(button.gameObject); } //Remove the palette from the list palettes.Remove(palette); //Destroy the palette Destroy(palette.gameObject); palette = null; }
IEnumerator MobileFileBrowserLoadCoroutinePalette(PEERbotPalette palette) { SimpleFileBrowser.FileBrowser.SetDefaultFilter(".csv"); yield return(SimpleFileBrowser.FileBrowser.WaitForLoadDialog(FileBrowser.PickMode.Files, false, getPalettePathFolder(), null, "Load CSV Palette File", "Load")); androidSaveLoadBackground.SetActive(false); if (FileBrowser.Success) //Try to load if successful //Because F%^$ing Android refuses to keep file IO simple, with their F!@# stupid SAF system { string filepath = FileBrowserHelpers.GetDirectoryName(FileBrowser.Result[0]); string filename = FileBrowserHelpers.GetFilename(FileBrowser.Result[0]); string realpath = Path.Combine(filepath, filename); Debug.Log("Realpath: " + realpath); LoadCSVPalette(palette, realpath); } else { pc.deletePalette(palette); } }
public PEERbotPalette LoadCSVPalette(PEERbotPalette palette, string path) { try{ //Try to load the file (raw) StreamReader reader = new StreamReader(path); string encodedString = reader.ReadToEnd();//.ToLower(); reader.Close(); //Try to parse the read encodedString string filename = getPaletteNameFromFilePath(path); PEERbotPalette newPalette = LoadCSVPaletteFromEncodedString(palette, encodedString, filename); //If successfully loaded, set the new path if (newPalette != null) { setHomePath(getPalettePathFolder(path)); } //Return the result return(newPalette); } catch (Exception e) { Debug.LogWarning("Failed to load CSV: " + path); return(palette); } }
public void LoadAllJSONPalettes() { string[] filePaths = System.IO.Directory.GetFiles(defaultJSONPath, "*.json"); foreach (string filePath in filePaths) { Debug.Log(filePath); //Delete the palette if it already exists string name = getPaletteNameFromFilePath(filePath); PEERbotPalette deleteMe = null; foreach (PEERbotPalette palette in pc.palettes) { if (palette.name == name) { deleteMe = palette; } } pc.deletePalette(deleteMe); //Load the palette LoadJSONPalette(pc.newPalette(), filePath); } }
public PEERbotPalette LoadCSVPaletteFromEncodedString(PEERbotPalette palette, string encodedString, string filename) { //Try to load the CSV first string[][] table; try{ table = CsvParser2.Parse(encodedString); } catch (Exception e) { Debug.LogWarning("Failed to load malformed CSV: " + filename); return(palette); } //check and make sure there is content if parsed correctly if (table.Length == 0) { Debug.LogWarning("No rows, empty file: " + filename); return(palette); } else if (table[0].Length == 0) { Debug.LogWarning("No cols, empty file: " + filename); return(palette); } //Get rows/cols of table int rows = table.Length; int cols = table[0].Length; //Get a list of all the fields in the CSV List <string> fields = new List <string>(); for (int j = 0; j < cols; j++) { //try to automap to known palette format(s) for backwards compatibility //Debug.Log("Before: " + table[0][j]); if (table[0][j] == "TITLE(text)") { table[0][j] = "title"; } if (table[0][j] == "COLOR(0-7)") { table[0][j] = "color"; } if (table[0][j] == "EMOTION(0-7)") { table[0][j] = "emotion"; } if (table[0][j] == "SPEECH(text)") { table[0][j] = "speech"; } if (table[0][j] == "RATE(0.0-3.0)") { table[0][j] = "rate"; } if (table[0][j] == "PITCH(0.0-2.0)") { table[0][j] = "pitch"; } if (table[0][j] == "GOAL(text)") { table[0][j] = "goal"; } if (table[0][j] == "SUBGOAL(text)") { table[0][j] = "subgoal"; } if (table[0][j] == "PROFICIENCY(text)") { table[0][j] = "proficiency"; } //Debug.Log("After: " + table[0][j]); //Add to the list of fields fields.Add("\"" + table[0][j] + "\""); } //Load every button from every row in CSV for (int i = 1; i < rows; i++) { string json = "{ "; for (int j = 0; j < cols; j++) { json += fields[j] + ":" + "\"" + table[i][j] + "\""; json += (j != cols - 1) ? ", " : "}"; } //Debug.Log(json); PEERbotButton newButton = pc.newButton(); JsonUtility.FromJsonOverwrite(json, newButton.data); pc.selectButton(newButton); } //Fill the title and path palette.title = filename; //Select the newly created palette pc.selectPalette(palette); //Convert to JSON //SaveCurrentJSONPalette(); //Return the result return(palette); }