Ejemplo n.º 1
0
    public void DeserializeJson(string JsonPath)
    {
        UIComplexCommand newCommand = Instantiate(commandBuilder.ComplexCommandPrefab.gameObject, GameObject.Find("AvailableCommandsField").transform).GetComponent <UIComplexCommand>();
        string           str        = File.ReadAllText(JsonPath);

        //Debug.Log(str);
        JsonUtility.FromJsonOverwrite(str, newCommand);
        string name = JsonPath.Substring(Application.persistentDataPath.Length + 1);

        name = name.Remove(name.Length - 5, 5);
        newCommand.GetComponentInChildren <Text>().text = name;
        string[] SubFiles = Directory.GetFiles(Application.persistentDataPath + "/" + name, "*.json");

        Debug.Log("    " + "Saveindex: " + newCommand.localSaveIndex);
        Regex lastNum = new Regex(@"[0-9]{1,}", RegexOptions.RightToLeft);//, RegexOptions.RightToLeft);

        for (int i = 0; i < SubFiles.Length; ++i)
        {
            //Read from json string which prefab will be used
            string CommandInJson = File.ReadAllText(SubFiles[i]);
            int    SerialNumber  = int.Parse(lastNum.Match(SubFiles[i]).Value);
            //Debug.Log("i: " + i + " match: "+lastNum.Match(SubFiles[i]).Value+" in subfiles "+SubFiles[i]);
            //Debug.Log(SerialNumber);

            if (CommandInJson.Substring(CommandInJson.IndexOf("isComplex") + 11, 4) == "true")
            {
                newCommand.UICommandElements[SerialNumber] = Instantiate(commandBuilder.ComplexCommandPrefab.gameObject, newCommand.transform).GetComponent <UIComplexCommand>();
            }
            else
            {
                newCommand.UICommandElements[SerialNumber] = Instantiate(commandBuilder.CommandPrefab.gameObject, newCommand.transform).GetComponent <UICommand>();
            }


            JsonUtility.FromJsonOverwrite(File.ReadAllText(SubFiles[i]), newCommand.UICommandElements[SerialNumber]);
            newCommand.UICommandElements[SerialNumber].gameObject.name = newCommand.UICommandElements[SerialNumber].CommandName;
            newCommand.UICommandElements[SerialNumber].GetComponentInChildren <Text>().text = newCommand.UICommandElements[SerialNumber].CommandName;
            newCommand.UICommandElements[SerialNumber].gameObject.SetActive(false);
        }
        SceneManager.avalaibleCommands.Names.Add(newCommand.CommandName);
        int count = SceneManager.avalaibleCommands.AvailableCommandsSet.Count;

        for (int i = 0; i < SceneManager.avalaibleCommands.AvailableCommandsSet.Count; ++i)
        {
            if (SceneManager.avalaibleCommands.AvailableCommandsSet[i].localSaveIndex >= newCommand.localSaveIndex)
            {
                SceneManager.avalaibleCommands.AvailableCommandsSet.Insert(i, newCommand);
                SceneManager.avalaibleCommands.SetSavedOrderIndex(newCommand);
                break;
            }
        }

        if (SceneManager.avalaibleCommands.AvailableCommandsSet.Count == count)
        {
            SceneManager.avalaibleCommands.AvailableCommandsSet.Add(newCommand);
            SceneManager.avalaibleCommands.SetSavedOrderIndex(newCommand);
        }
    }
Ejemplo n.º 2
0
    public void SaveNewComplexCommand()
    {
        if (!CheckName(commandBuilder.CommandName, true))//&&!rewriteButton.IsActive())
        {
            Debug.Log("NOOO SAVE");
            return;
        }

        UIComplexCommand newCommand = Instantiate(commandBuilder.ComplexCommandPrefab, SceneManager.avalaibleCommands.transform).GetComponent <UIComplexCommand>();

        for (int i = 0; i < commandBuilder.UICommandElements.Count; ++i)
        {
            newCommand.UICommandElements.Add(Instantiate <UICommand>(commandBuilder.UICommandElements[i], newCommand.transform) as UICommand);
            if (newCommand.UICommandElements[i].isComplex)
            {
                newCommand.UICommandElements[i].GetComponent <UIComplexCommand>().UICommandElements = commandBuilder.UICommandElements[i].GetComponent <UIComplexCommand>().UICommandElements;
                newCommand.UICommandElements[i].GetComponent <UIComplexCommand>().CommandsSet       = commandBuilder.UICommandElements[i].GetComponent <UIComplexCommand>().CommandsSet;
            }
            else
            {
                newCommand.UICommandElements[i].command = commandBuilder.UICommandElements[i].command;
            }
            newCommand.UICommandElements[i].name        = commandBuilder.UICommandElements[i].name;
            newCommand.UICommandElements[i].CommandName = commandBuilder.UICommandElements[i].CommandName;
            newCommand.UICommandElements[i].gameObject.SetActive(false);
        }
        for (int i = 0; i < newCommand.UICommandElements.Count; ++i)
        {
            if ((newCommand.UICommandElements[i].isComplex))
            {
                for (int j = 0; j < newCommand.UICommandElements[i].GetComponent <UIComplexCommand>().CommandsSet.Count; ++j)
                {
                    newCommand.CommandsSet.Add(newCommand.UICommandElements[i].GetComponent <UIComplexCommand>().CommandsSet[j]);
                }
            }
            else
            {
                newCommand.CommandsSet.Add(newCommand.UICommandElements[i].command);
            }
        }
        newCommand.GetComponentInChildren <Text>().text = commandBuilder.CommandName.text;
        newCommand.CommandName = commandBuilder.CommandName.text;
        foreach (UICommand com in newCommand.UICommandElements)
        {
            if (newCommand.localSaveIndex <= com.localSaveIndex)
            {
                newCommand.localSaveIndex = com.localSaveIndex + 1;
            }
        }
        savedCommand = newCommand;
        SerializeToJson(savedCommand);
        cancelRewriting();
        SceneManager.avalaibleCommands.AvailableCommandsSet.Add(savedCommand);
        SceneManager.avalaibleCommands.Names.Add(savedCommand.CommandName);
    }
Ejemplo n.º 3
0
    public void SerializeToJson(UIComplexCommand com)
    {
        System.IO.Directory.CreateDirectory(Application.persistentDataPath + "/" + com.GetComponentInChildren <Text>().text);
        Debug.Log("ss-s-s-s-s-SAVED");
        File.WriteAllText(Application.persistentDataPath + "/" + com.GetComponentInChildren <Text>().text + ".json", JsonUtility.ToJson(com));

        for (int i = 0; i < com.transform.childCount - DefaulChilds; ++i)
        {
            File.WriteAllText(Application.persistentDataPath + "/" + com.GetComponentInChildren <Text>().text + "/" + i + ".json", JsonUtility.ToJson(com.transform.GetChild(i + DefaulChilds).GetComponent <UICommand>()));
        }
    }
Ejemplo n.º 4
0
    public override void Add()
    {
        UIComplexCommand NewCommand = Instantiate(CommandBuilder.ComplexCommandPrefab, CommandBuilder.transform).GetComponent <UIComplexCommand>();

        NewCommand.CommandsSet = new List <Command>(this.CommandsSet);
        NewCommand.transform.SetParent(CommandBuilder.transform);
        NewCommand.transform.localScale = new Vector3(UIScale, UIScale);
        CommandBuilder.AddUIElementToGroup(NewCommand.GetComponent <UICommand>());
        NewCommand.gameObject.AddComponent <DragDrop>();
        NewCommand.isOriginal = false;
        NewCommand.SettingsButton.interactable          = false;
        NewCommand.GetComponentInChildren <Text>().text = this.GetComponentInChildren <Text>().text;
        NewCommand.CommandName    = this.CommandName;
        NewCommand.localSaveIndex = this.localSaveIndex;
    }
Ejemplo n.º 5
0
    //public void RewriteAllrefs(UIComplexCommand RWCommand, UIComplexCommand NewCommand)
    //{
    //    List<UIComplexCommand> ComToRW=new List<UIComplexCommand>();
    //    ComToRW.Add(RWCommand);
    //    Debug.Log("in rewrite");
    //    int Index = -1;
    //    Debug.Log(AvaibleCommandsSet.Count);
    //    foreach(UIComplexCommand CommandToRewrite in ComToRW )
    //    {
    //        for (int i = AvaibleCommandsSet.IndexOf(CommandToRewrite) + 1; i < AvaibleCommandsSet.Count - 1; ++i)
    //        {
    //            if (AvaibleCommandsSet[i].GetNumberofCommands() < CommandToRewrite.GetNumberofCommands())
    //                return;
    //            int deletedcommandsoffset = 0;
    //            for (int k = 0, l = 0; AvaibleCommandsSet[i].GetNumberofCommands() - k >= CommandToRewrite.GetNumberofCommands(); ++k)
    //            {

    //                Debug.Log("Fast check " + k + " " + l);
    //                if (Command.IsEQ(AvaibleCommandsSet[i].CommandsSet[k], CommandToRewrite.CommandsSet[l]))
    //                {

    //                    Index = k;
    //                    ++k; ++l;
    //                    for (; l < CommandToRewrite.GetNumberofCommands();)
    //                    {
    //                        Debug.Log("now checking " + k + " " + l);
    //                        if (!Command.IsEQ(AvaibleCommandsSet[i].CommandsSet[k], CommandToRewrite.CommandsSet[l]))
    //                        {
    //                            l = 0;
    //                            Index = -1;
    //                            break;
    //                        }
    //                        ++k; ++l;
    //                    }
    //                    l = 0;
    //                    Debug.Log("K= " + k);
    //                    k -= 1;
    //                    Debug.Log("Index= " + Index);
    //                    if (Index != -1)
    //                    {
    //                        //-_-----------------------
    //                        int sum = 0;
    //                        for (int s = 0; s < AvaibleCommandsSet[i].UICommandElements.Count; ++s)
    //                        {
    //                            sum += AvaibleCommandsSet[i].UICommandElements[s].GetNumberofCommands();

    //                            if ((sum > Index) && (AvaibleCommandsSet[i].UICommandElements[s].GetNumberofCommands() == CommandToRewrite.GetNumberofCommands()))
    //                            {
    //                                AvaibleCommandsSet[i].UICommandElements[s] = NewCommand;
    //                                Debug.Log("Deleted" + " " + (Index) + " " + CommandToRewrite.GetNumberofCommands() + " of " + AvaibleCommandsSet[i].CommandsSet.Count);
    //                                AvaibleCommandsSet[i].CommandsSet.RemoveRange(Index, CommandToRewrite.GetNumberofCommands());
    //                                AvaibleCommandsSet[i].CommandsSet.InsertRange(Index, NewCommand.CommandsSet);
    //                                break;
    //                            }
    //                        }
    //                        //-_-----------------------

    //                        deletedcommandsoffset += CommandToRewrite.GetNumberofCommands() - NewCommand.GetNumberofCommands();
    //                        Debug.Log("k--" + deletedcommandsoffset);
    //                        k -= CommandToRewrite.GetNumberofCommands() - NewCommand.GetNumberofCommands();
    //                    }
    //                }
    //            }
    //        }
    //    }
    // NewCommand.transform.SetSiblingIndex(CommandToRewrite.transform.GetSiblingIndex());
    // AvaibleCommandsSet[AvaibleCommandsSet.IndexOf(CommandToRewrite)] = AvaibleCommandsSet[AvaibleCommandsSet.Count - 1];
    //AvaibleCommandsSet.RemoveAt(AvaibleCommandsSet.Count - 1);
    // Destroy(CommandToRewrite.gameObject);
    //   }

    public void RewriteAllrefs(UIComplexCommand RWCommand, UIComplexCommand NewCom)
    {
        List <UIComplexCommand> ComToRW = new List <UIComplexCommand>();

        UIComplexCommand[] comsArray = new UIComplexCommand[AvailableCommandsSet.Count + 1];

        int IndComNew = 0;

        //ComToRW.Add(RWCommand);
        comsArray[0] = NewCom;


        //AvaibleCommandsSet[AvaibleCommandsSet.IndexOf(RWCommand)] = AvaibleCommandsSet[AvaibleCommandsSet.Count - 1];
        //AvaibleCommandsSet.RemoveAt(AvaibleCommandsSet.Count - 1);
        NewCom.transform.SetSiblingIndex(RWCommand.transform.GetSiblingIndex());
        NewCom.localSaveIndex = RWCommand.localSaveIndex;
        Debug.Log(AvailableCommandsSet.Count);
        for (int i = 0; i < AvailableCommandsSet.Count - 1; ++i)
        {
            ComToRW.Add(Instantiate <UIComplexCommand>(AvailableCommandsSet[i]));
        }
        Debug.Log(ComToRW.IndexOf(RWCommand));
        for (int i = AvailableCommandsSet.IndexOf(RWCommand), j = 0; i < ComToRW.Count - 1; ++i, ++j)
        {
            UIComplexCommand CommandToRewrite = ComToRW[i];
            UIComplexCommand NewCommand       = comsArray[j];
            ++IndComNew;
            Debug.Log(CommandToRewrite.CommandName + " in rewrite");
            if (comsArray[j] != null)
            {
                for (int Rw = i + 1; Rw < AvailableCommandsSet.Count - 1; ++Rw)
                {
                    bool needToRewrite = false;
                    Debug.Log("Cheking " + (Rw + 1) + " of " + AvailableCommandsSet.Count);

                    for (int subRW = 0; subRW < AvailableCommandsSet[Rw].UICommandElements.Count; ++subRW)
                    {
                        Debug.Log(AvailableCommandsSet[Rw].UICommandElements[subRW].CommandName + " == " + CommandToRewrite.CommandName);
                        if (AvailableCommandsSet[Rw].UICommandElements[subRW].CommandName == CommandToRewrite.CommandName)
                        {
                            Debug.Log("isEQ");
                            int sum = 0;
                            for (int index = 0; index < subRW; ++index)
                            {
                                sum += AvailableCommandsSet[Rw].UICommandElements[index].GetNumberofCommands();
                                Debug.Log("Number of commands " + index + "subcommand of  command " + Rw + " is " + AvailableCommandsSet[Rw].UICommandElements[index].GetNumberofCommands());
                            }
                            // if (ComToRW.Count == i+1)
                            Debug.Log("deleted " + sum + " to " + (sum + CommandToRewrite.GetNumberofCommands() - 1) + " of " + AvailableCommandsSet[Rw].GetNumberofCommands());
                            //trouble is here
                            AvailableCommandsSet[Rw].CommandsSet.RemoveRange(sum, CommandToRewrite.GetNumberofCommands());

                            AvailableCommandsSet[Rw].UICommandElements[subRW].Copy(NewCommand);
                            Debug.Log("inserted " + sum + " to " + (sum + AvailableCommandsSet[Rw].UICommandElements[subRW].GetComponent <UIComplexCommand>().GetNumberofCommands() - 1) + " of " + AvailableCommandsSet[Rw].GetNumberofCommands());
                            AvailableCommandsSet[Rw].CommandsSet.InsertRange(sum, AvailableCommandsSet[Rw].UICommandElements[subRW].GetComponent <UIComplexCommand>().CommandsSet);
                            comsArray[Rw] = AvailableCommandsSet[Rw];
                            needToRewrite = true;
                        }
                    }

                    if (needToRewrite)
                    {
                        SceneManager.builderInterface.RewritetoJson(AvailableCommandsSet[Rw]);
                    }
                }
            }
        }
        AvailableCommandsSet[AvailableCommandsSet.IndexOf(RWCommand)] = AvailableCommandsSet[AvailableCommandsSet.Count - 1];
        Names[Names.IndexOf(RWCommand.CommandName)] = NewCom.CommandName;

        if (RWCommand.CommandName != NewCom.CommandName)
        {
            RWCommand.Destroy();
        }

        else
        {
            Destroy(RWCommand.gameObject);
            AvailableCommandsSet.RemoveAt(AvailableCommandsSet.Count - 1);
            Names.RemoveAt(Names.Count - 1);
        }


        // Names.RemoveAt(Names.Count - 1);
        for (int i = 0; i < ComToRW.Count; ++i)
        {
            Destroy(ComToRW[i].gameObject);
        }
    }
Ejemplo n.º 6
0
 public void SetSavedOrderIndex(UIComplexCommand comp)
 {
     Debug.Log("added to " + (BasicCommandsNumber + AvailableCommandsSet.IndexOf(comp)) + " " + AvailableCommandsSet.IndexOf(comp));
     comp.transform.SetSiblingIndex(BasicCommandsNumber + AvailableCommandsSet.IndexOf(comp));
 }
Ejemplo n.º 7
0
 public void Remove(UIComplexCommand com)
 {
     AvailableCommandsSet.Remove(com);
     Names.Remove(com.CommandName);
 }
Ejemplo n.º 8
0
 public override void Copy(UIComplexCommand com)
 {
     this.CommandsSet = new List <Command>(com.CommandsSet);
     this.CommandName = com.CommandName;
     this.GetComponentInChildren <Text>().text = com.CommandName;
 }
Ejemplo n.º 9
0
 public UIComplexCommand(UIComplexCommand com)
 {
     this.UICommandElements = new List <UICommand>(com.UICommandElements);
     this.CommandsSet       = new List <Command>(com.CommandsSet);
 }
Ejemplo n.º 10
0
 public virtual void Copy(UIComplexCommand com)
 {
     Debug.Log("there is NO copy");
 }