/// <summary>
    /// Select the image and process the request
    /// </summary>
    /// <param name="campaignName">name of the campaign</param>
    private void PickImage(string campaignName)
    {
        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path != null)
            {
                // Create Texture from selected image
                Texture2D tex = NativeGallery.LoadImageAtPath(path, 4096);
                if (tex == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }

                tex.Apply();
                var v = new Texture2D(2, 2);
                v.LoadImage(tex.EncodeToPNG(), false);
                v.Apply();


                ///map.sprite = Sprite.Create(v, new Rect(0.0f, 0.0f, v.width, v.height), new Vector2(0.5f, 0.5f), 100.0f);

                SharedImageData sid = new SharedImageData();
                sid.bytes           = v.EncodeToPNG();
                sid.info            = null;
                string finalPath    = SerializationManager.CreatePath(campaignName + "/NewMap.map");
                SerializationManager.SaveObject(finalPath, sid);
            }
        }, "Select a PNG image", "image/png", 4096);

        Debug.Log("Permission result: " + permission);
    }
Exemple #2
0
    /// <summary>
    /// Event listener, change the name of the campaign when the users modifies the input field
    /// Chnages the underlaying directory name and reloads all the files under the new directory
    /// </summary>
    /// <param name="name">New name of the campaign</param>
    public void ChangeCampaignName(string name)
    {
        var oldPath = SerializationManager.CreatePath(campaignName);
        var newPath = SerializationManager.CreatePath(name);

        if (oldPath.Equals(newPath) || Directory.Exists(newPath))
        {
            //Rebuild in order to reset text back to original name
            FileManager.instance.ReloadCampaignTabs();
            return;
        }

        Debug.LogFormat("Folder: {0}\nRenaming to: {1}", oldPath, newPath);
        try
        {
            Directory.Move(oldPath, newPath);

            campaignName = name; //Will get destroyed and recreated anyway
            FileManager.instance.ReloadCampaignTabs();
        }
        catch (IOException ex)
        {
            Debug.LogException(ex);
        }
    }
Exemple #3
0
    void PopulateUsers()
    {
        string usersPath = SerializationManager.CreatePath(UserFolder + "/", PathType);

        string[] directories = Directory.GetDirectories(usersPath);

        for (int i = 0; i < directories.Length; i++)
        {
            string   folderPath   = directories[i];
            string   filePath     = folderPath + "/user.json";
            string   userDataText = File.ReadAllText(filePath);
            UserData userData     = JsonUtility.FromJson <UserData>(userDataText);

            GameObject go = GameObject.Instantiate(UserPrefab, UserLayout);
            go.transform.position = Vector3.zero;
            CanvasGroup cg = go.GetComponent <CanvasGroup>();
            cg.interactable   = true;
            cg.blocksRaycasts = true;
            go.GetComponentInChildren <TextMeshProUGUI>().text = userData.Name;

            //Add trigger
            //Name is set to the folderpath
            go.name = folderPath + "/Languages";
            EventTrigger       trigger = go.AddComponent <EventTrigger>();
            EventTrigger.Entry entry   = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerClick;
            entry.callback.AddListener((data) => { TappedUser((PointerEventData)data); });
            trigger.triggers.Add(entry);

            //Add userdata to object for later retrieval
            UserButton buttonData = go.AddComponent <UserButton>();
            buttonData.userData = userData;
        }
        LayoutRebuilder.MarkLayoutForRebuild((RectTransform)transform);
    }
Exemple #4
0
    public void SavePage(string fileName)
    {
        UpdatePageData();
        //Currently using JsonSaving
        string location = SerializationManager.CreatePath(SAVE_PATH + fileName);

        SerializationManager.SaveJsonObject(location, pageData);
    }
Exemple #5
0
    public void SetupPage(string stickerPageName)
    {
        //Currently JsonLoading
        string          location = SerializationManager.CreatePath(SAVE_PATH + stickerPageName);
        StickerPageData data     = SerializationManager.LoadJsonObject <StickerPageData>(location);

        SetupPage(data);
    }
Exemple #6
0
    /// <summary>
    /// Get array of save folder names in SaveData path in campaign folder
    /// </summary>
    /// <param name="campaign">Name of folder e.g. "MyCampaign"</param>
    /// <returns>string[] of File names in campaign folder</returns>
    public string[] GetSavedFilesFromCampaign(string campaign)
    {
        string        folderPath = SerializationManager.CreatePath(campaign + "/");
        DirectoryInfo d          = new DirectoryInfo(folderPath);
        //Sort files by date created and then convert to a list of strings
        var stringList = d.GetFiles().ToList().OrderByDescending(x => x.CreationTime).Select(x => x.Name).ToList();

        return(stringList.ToArray());
    }
Exemple #7
0
    /// <summary>
    /// Called at creation, earlier than start
    /// </summary>
    void Awake()
    {
        instance = this;
        string savePath = SerializationManager.CreatePath("");

        if (!Directory.Exists(savePath))
        {
            SerializationManager.CreateFolder(savePath);
        }
    }
    // Use this for initialization
    void Start()
    {
        string path = SerializationManager.CreatePath("Cards/" + cardPath, SerializationManager.SavePathType.Persistent);

        //Test Save
        if (SaveOnStart)
        {
            SerializationManager.SaveJsonObject(path, data, true);
        }
        else
        {
            //Test Load
            data = SerializationManager.LoadJsonObject <CardData>(path);
        }
    }
    void OnGUI()
    {
        GUILayout.Label("Card Editor", EditorStyles.boldLabel);

        pathType = (SerializationManager.SavePathType)EditorGUILayout.EnumPopup("Save path:", pathType);
        filename = EditorGUILayout.TextField("File Name", filename);

        string filePath = SerializationManager.CreatePath(filename, pathType);

        GUILayout.Label($"Path:\n{filePath}");
        bool fileExists = File.Exists(filePath);

        if (!fileExists)
        {
            EditorGUILayout.HelpBox("File does not exist at path!", MessageType.Error, true);
        }
        EditorGUI.BeginDisabledGroup(!fileExists);
        if (GUILayout.Button("Load Card", new GUILayoutOption[] { GUILayout.Width(300), GUILayout.Height(32) }))
        {
            cardData = SerializationManager.LoadJsonObject <CardData>(filePath);
        }
        EditorGUI.EndDisabledGroup();

        //Card Data editing here
        GUILayout.FlexibleSpace();

        GUILayout.Label("CardData", EditorStyles.boldLabel);
        cardData.From = EditorGUILayout.TextField("From", cardData.From);
        cardData.To   = EditorGUILayout.TextField("To", cardData.To);

        GUILayout.FlexibleSpace();

        if (fileExists)
        {
            EditorGUILayout.HelpBox("File already exists at path.\nAre you sure you want to overrite?", MessageType.Warning, true);
        }
        if (GUILayout.Button("Save Card", new GUILayoutOption[] { GUILayout.Width(300), GUILayout.Height(32) }))
        {
            if (fileExists)
            {
                if (!EditorUtility.DisplayDialog("Overrite card?", "Card will be replaced:\n" + filePath + "\nThis cannot be undone.", "Yes", "Cancel"))
                {
                    return;
                }
            }
            SerializationManager.SaveJsonObject(filePath, cardData, true);
        }
    }
Exemple #10
0
    /// <summary>
    /// Get all files related to a specific campaign, used to display all related files
    /// </summary>
    void PullAssetNames()
    {
        string        assetPath = SerializationManager.CreatePath("");
        DirectoryInfo d         = new DirectoryInfo(assetPath);
        Dictionary <string, string> assetFiles = new Dictionary <string, string>();

        foreach (var file in d.GetFiles())
        {
            assetFiles.Add(file.Name, file.FullName);
        }

        //Here, the user selects the name of the file they want displayed on the page
        string chosenFile = GameObject.Find("StatBlockInputField").GetComponent <Text>().text;

        SerializationManager.LoadObject(assetFiles[chosenFile]);
    }
Exemple #11
0
    /// <summary>
    /// Propmt user to save a template based on the campaign
    /// </summary>
    /// <param name="template">Name of the selected template</param>
    /// <param name="campaignName">Name of the current campain</param>
    public void SaveTemplate(string template, string campaignName)
    {
        TextAsset[] templateAssets = Resources.LoadAll <TextAsset>("Templates");
        Dictionary <string, string> templateAssetNames = new Dictionary <string, string>();

        for (int i = 0; i < templateAssets.Length; i++)
        {
            templateAssetNames.Add(templateAssets[i].name, templateAssets[i].text);
        }

        string          path = SerializationManager.CreatePath(campaignName + "/" + template + "-mod.sbd");
        StatBlockUIData data = new StatBlockUIData();

        data.text = templateAssetNames[template];
        SerializationManager.SaveObject(path, data);
    }
Exemple #12
0
    void OnGUI()
    {
        GUILayout.Label("Story Parser", EditorStyles.boldLabel);

        pathType   = (SerializationManager.SavePathType)EditorGUILayout.EnumPopup("Save path:", pathType);
        userFolder = EditorGUILayout.TextField("User Path", userFolder);
        folderPath = EditorGUILayout.TextField("Folder Path", folderPath);

        string path = SerializationManager.CreatePath(folderPath, pathType);

        GUILayout.Label($"Path:\n{path}");
        bool dirExists = Directory.Exists(path);

        if (!dirExists)
        {
            EditorGUILayout.HelpBox("Directory does not exist at path.", MessageType.Warning, true);
        }
        else
        {
            EditorGUILayout.HelpBox("Directory already exists at path!", MessageType.Warning, true);
        }

        GUILayout.Label("Story Raw Text", EditorStyles.boldLabel);
        scroll  = EditorGUILayout.BeginScrollView(scroll);
        rawText = EditorGUILayout.TextArea(rawText);
        EditorGUILayout.EndScrollView();

        GUILayout.FlexibleSpace();

        if (GUILayout.Button("Parse/Save Cards", new GUILayoutOption[] { GUILayout.Width(300), GUILayout.Height(32) }))
        {
            if (!EditorUtility.DisplayDialog("Parse text into current path?", "Cards will be added to path:\n" + path + "\nThis cannot be undone.", "Yes", "Cancel"))
            {
                return;
            }
            //Load user cards first
            CardManager.UnloadAll();
            CardManager.LoadFolder(userFolder);

            RawStoryParser parser = new RawStoryParser();
            parser.folderPath = folderPath;
            parser.SavePath   = pathType;
            parser.ParseData(rawText);

            CardManager.UnloadAll();
        }
    }
Exemple #13
0
    /// <summary>
    /// Load a page, called by a campaign file
    /// </summary>
    /// <param name="file">File to load a page for</param>
    public void SwitchPage(CampaignFile file)
    {
        DeletePage();
        Debug.Log("Switching to page: " + file.GetFileName());

        string fullPath = file.GetCampaign().GetCampaignName() + "/" + file.GetFileName() + "." + file.GetExtension();

        fullPath = SerializationManager.CreatePath(fullPath);

        //Get the file extension to determine what file type to display
        switch (file.GetExtension())
        {
        case "sbd":
        {
            pinManager.SetActive(false);
            currrentPage = Instantiate(prefabs[0], viewport.transform);
            StatBlockUIData uiData = (StatBlockUIData)SerializationManager.LoadObject(fullPath);

            currrentPage.GetComponent <StatBlockForm>().BuildPage(uiData);
            currrentPage.GetComponent <StatBlockForm>().fullPath = fullPath;
            currrentPage.GetComponent <StatBlockForm>().campaign = file.GetCampaign().GetCampaignName();
            break;
        }

        case "map":
        {
            pinManager.SetActive(true);
            currrentPage = Instantiate(prefabs[1], viewport.transform);
            SharedImageData uiData = (SharedImageData)SerializationManager.LoadObject(fullPath);
            currrentPage.GetComponent <MapForm>().campaign = file.GetCampaign().GetCampaignName();
            currrentPage.GetComponent <MapForm>().BuildPage(uiData);
            break;
        }

        default:
        {
            Debug.Log(file.GetExtension() + " is not a proper extension!");
            return;
        }
        }

        scrollRect.enabled = true;
        scrollRect.content = currrentPage.GetComponent <RectTransform>();

        SetActiveCampaignView(false);
    }
    public void SavePage(string fileName, bool prettyPrint = false)
    {
        UpdatePageData();

        string path = SerializationManager.CreatePath(SAVE_PATH + fileName + ".json");

        if (BinaryFile)
        {
            path += ".bytes";
            SerializationManager.SaveObject(path, pageData);
        }
        else
        {
            path += ".json";
            SerializationManager.SaveJsonObject(path, pageData, prettyPrint);
        }
    }
    public void LoadPage(string stickerPageName)
    {
        string          path = SerializationManager.CreatePath(SAVE_PATH + stickerPageName);
        StickerPageData data;

        if (BinaryFile)
        {
            //BinaryFormmater implementation
            path += ".bytes";
            data  = (StickerPageData)SerializationManager.LoadObject(path);
        }
        else
        {
            path += ".json";
            //Json implementation
            data = SerializationManager.LoadJsonObject <StickerPageData>(path);
        }
        LoadPage(data);
    }
Exemple #16
0
    List <CardData> loadFolder(string folderName, bool placeInDictionary = true, SerializationManager.SavePathType PathType = SerializationManager.SavePathType.Streaming, SearchOption searchOption = SearchOption.AllDirectories)
    {
        string folderPath = SerializationManager.CreatePath(folderName, PathType);

        folderPath = folderPath.TrimEnd(new char[] { '\\', '/' }) + "/";
        var info = new DirectoryInfo(folderPath);

        if (!info.Exists)
        {
            Debug.LogWarning($"Folder {folderPath} doesn't exist!");
            return(new List <CardData>());
        }
        var             fileInfo    = info.GetFiles("*.json", searchOption);
        List <CardData> cardsLoaded = new List <CardData>();

        foreach (FileInfo file in fileInfo)
        {
            cardsLoaded.Add(LoadCard(file.FullName, placeInDictionary));
        }
        return(cardsLoaded);
    }
Exemple #17
0
    /// <summary>
    /// Create a new campaign with a distinct
    /// </summary>
    public void CreateCampaign()
    {
        const string newName = "NewCampaign";

        //Create hashset of campaign names to check against in order to make incremental campaign names
        HashSet <string> names = new HashSet <string>(GetSavedCampaigns());

        int count = 0;

        //Increment number as long as folder of that name and number already exist
        while (names.Contains(newName + (count > 0 ? count.ToString() : "")))
        {
            count++;
        }

        string folderPath = SerializationManager.CreatePath(newName + (count > 0 ? count.ToString(): ""));

        if (SerializationManager.CreateFolder(folderPath))
        {
            //Reload Campaigns
            ReloadCampaignTabs();
        }
    }
Exemple #18
0
    /// <summary>
    /// Event Listener, change the file name based on the changes the user made into the input field
    /// </summary>
    public void ChangeFileName()
    {
        string cname   = GetComponentInChildren <InputField>().text;
        var    oldPath = SerializationManager.CreatePath(campaign.GetCampaignName() + "/" + fileName + "." + extension);
        var    newPath = SerializationManager.CreatePath(campaign.GetCampaignName() + "/" + cname + "." + extension);

        if (oldPath.Equals(newPath) || Directory.Exists(newPath))
        {
            campaign.LoadFiles();
            return;
        }

        Debug.LogFormat("File: {0}\nRenaming to: {1}", oldPath, newPath);
        try
        {
            Directory.Move(oldPath, newPath);
            fileName = cname;
            campaign.LoadFiles();
        }
        catch (IOException ex)
        {
            Debug.LogException(ex);
        }
    }
Exemple #19
0
 public void Awake()
 {
     path = SerializationManager.CreatePath("test" + ".tst");
 }
Exemple #20
0
 /// <summary>
 /// Delete the file from the campaign folder
 /// </summary>
 public void DeleteFile()
 {
     SerializationManager.DeleteFile(SerializationManager.CreatePath(campaign.GetCampaignName() + "/" + fileName + "." + extension));
     campaign.LoadFiles();
 }
    public void ParseData(string s)
    {
        EditType  editType  = EditType.None;
        ParseType parseType = ParseType.From;


        StoryData   story   = null;
        SectionData section = null;
        LineData    line    = null;

        CardData current = null; //Can be story, section, line, or card. All inherit from carddata
        Dictionary <string, CardData> generatedCards = new Dictionary <string, CardData>();
        List <CardData> generatedWordCards           = new List <CardData>();

        foreach (string word in s.Trim().Split())
        {
            if (string.IsNullOrWhiteSpace(word))
            {
                continue;
            }
            switch (word)
            {
            case "#story":
                editType = EditType.Story;
                story    = new StoryData();
                current  = story;
                break;

            case "#section":
                editType = EditType.Section;
                section  = new SectionData();
                story.SectionsUID.Add(section.UID);
                current = section;
                break;

            case "*":
                //Trim all whitespace
                current.From         = current.From.TrimEnd();
                current.To           = current.To.TrimEnd();
                current.PhoneticFrom = current.PhoneticFrom.TrimEnd();
                current.BrokenUpTo   = current.BrokenUpTo.TrimEnd();

                //Create individual word cards for all stories/sections/lines
                current.DataFinalize();
                List <CardData> lineCards = current.GenerateWordCards();
                lineCards.ForEach(x => { generatedWordCards.Add(x); generatedCards.Add(x.UID, x); });

                //Finish parsing line
                if (editType == EditType.Section)
                {
                    editType = EditType.Line;
                }
                else if (editType == EditType.Line)
                {
                    current.AddCardReferences(lineCards);
                }


                parseType = ParseType.From;
                generatedCards.Add(current.UID, current);
                current = null;
                break;

            case "$":
                parseType = ParseType.BrokenUpFrom;
                break;

            case "/":
                parseType = ParseType.BrokenUpTo;
                break;

            case "=":
                parseType = ParseType.To;
                break;

            default:
                //If there is no defined current card this is a new line
                if (current == null)
                {
                    line    = new LineData();
                    current = line;
                    section.LinesUID.Add(line.UID);
                }
                switch (parseType)
                {
                case ParseType.From:
                    current.From += word + " ";
                    break;

                case ParseType.BrokenUpFrom:
                    current.PhoneticFrom += word + " ";
                    break;

                case ParseType.BrokenUpTo:
                    current.BrokenUpTo += word + " ";
                    break;

                case ParseType.To:
                    current.To += word + " ";
                    break;
                }
                break;
            }
        }
        string path = SerializationManager.CreatePath(folderPath, SavePath);

        //Finalize cards and repair their references to refer to cards that already exist

        //Save word cards before checking for references because CheckDefinitionRepair checks CardManager dictionary
        generatedWordCards.ForEach(x => x.DataFinalize());
        foreach (CardData c in generatedWordCards)
        {
            if (!CardManager.ContainsMatchingDefinition(c))
            {
                CardManager.SaveCard(c, path);
                CardManager.PlaceInDictionaries(c);
            }
        }
        //References fixed, add new cards to dictionary/save as well
        foreach (CardData c in generatedCards.Values)
        {
            //Don't resave this card, it is only in the dictionary to be used with CheckDefinitionRepair
            if (c.CardType == "CardData")
            {
                continue;
            }

            c.CheckDefinitionRepair(generatedCards);
            if (!CardManager.ContainsMatchingDefinition(c))
            {
                CardManager.SaveCard(c, path);
            }
        }
    }
Exemple #22
0
 /// <summary>
 /// Event Listener, Delete the current campaign
 /// </summary>
 public void DeleteCampaign()
 {
     SerializationManager.DeleteFolder(SerializationManager.CreatePath(campaignName), true);
     FileManager.instance.ReloadCampaignTabs();
 }