예제 #1
0
    public JSONObject Save(JSONObject jsonObject)
    {
        //save the data
        var isLastDialogueFinished = false;

        if (_currentDialogueMessages.Count != 0)
        {
            WrapAndSavePlotDialogues();
        }
        else
        {
            isLastDialogueFinished = true;
        }

        var dialogueLengthInfo = new List <int>();
        var dialogueMessages   = new List <MessageContent>();

        SerializeManager.Serialize2DArray(_dialogueMessages.ToArray(), out dialogueLengthInfo, out dialogueMessages);

        if (currentStory != null)
        {
            File.WriteAllText(Services.saveManager.inkjsonPath, Services.textManager.currentStory.state.ToJson(), Encoding.UTF8);
        }
        else
        {
            File.WriteAllText(Services.saveManager.inkjsonPath, "");
        }

        //write them in the json file
        var textJsonObj = new JSONObject();

        textJsonObj.Add("isLastDialogueFinished", isLastDialogueFinished);
        var jsonDialogueLengthInfo = new JSONArray();

        foreach (var lengthInfo in dialogueLengthInfo)
        {
            jsonDialogueLengthInfo.Add(lengthInfo);
        }
        textJsonObj.Add("dialogueLengthInfo", jsonDialogueLengthInfo);
        var jsonDialogueContent = new JSONArray();

        foreach (var msg in dialogueMessages)
        {
            var msgObj = new JSONObject();
            msgObj.Add("messageType", msg.messageType.ToString());
            msgObj.Add("content", msg.content);
            var shootTimeString = (SerializeManager.JsonDateTime)msg.shootTime;
            msgObj.Add("shootTime", shootTimeString.value.ToString());
            if (!ReferenceEquals(msg.fileBubbleName, null))
            {
                msgObj.Add("fileBubbleName", msg.fileBubbleName);
            }
            if (!ReferenceEquals(msg.fileContentName, null))
            {
                msgObj.Add("fileBubbleName", msg.fileContentName);
            }
            jsonDialogueContent.Add(msgObj);
        }
        textJsonObj.Add("dialogueMessages", jsonDialogueContent);
        if (_lastTimeStamp != DateTime.MinValue)
        {
            var stringTimeStamp = (SerializeManager.JsonDateTime)_lastTimeStamp;
            textJsonObj.Add("lastTimeStamp", stringTimeStamp.value.ToString());
        }


        jsonObject.Add("text", textJsonObj);
        return(jsonObject);
    }