Exemplo n.º 1
0
    public AbilityDataSubclass[] RelinkSubclass()
    {
        int[] globalAddress     = new int[subclasses.l.Count];
        int[] active            = subclasses.ReturnActiveElementIndex();
        int[] activeConnections = linkAddresses.ReturnActiveElementIndex();

        AbilityDataSubclass[] relinkedClasses = new AbilityDataSubclass[active.Length];

        //Floods global address with negative values first.
        for (int i = 0; i < globalAddress.Length; i++)
        {
            globalAddress[i] = -1;
        }

        //Fills global address up with valid classes.
        for (int i = 0; i < active.Length; i++)
        {
            globalAddress[active[i]] = i;
        }

        List <int[]>[][] vLinks = new List <int[]> [active.Length][];

        for (int i = 0; i < active.Length; i++)
        {
            relinkedClasses[i] = subclasses.l[active[i]];
            int varLength = relinkedClasses[i].var.Length;
            vLinks[i] = new List <int[]> [varLength];

            for (int j = 0; j < varLength; j++)
            {
                vLinks[i][j] = new List <int[]>();
            }
        }

        // Replaces the values correctly.
        for (int i = 0; i < activeConnections.Length; i++)
        {
            //Debug.LogFormat("Start node id changed from {0} to {1}", linkAddresses.l[activeConnections[i]][0], globalAddress[linkAddresses.l[activeConnections[i]][0]]);
            //Debug.LogFormat("End node id changed from {0} to {1}", linkAddresses.l[activeConnections[i]][2], globalAddress[linkAddresses.l[activeConnections[i]][2]]);
            int modS = globalAddress[linkAddresses.l[activeConnections[i]][0]];
            int modR = globalAddress[linkAddresses.l[activeConnections[i]][2]];

            int[] linkTarget = new int[] { modR, linkAddresses.l[activeConnections[i]][3], linkAddresses.l[activeConnections[i]][4] };

            vLinks[modS][linkAddresses.l[activeConnections[i]][1]].Add(linkTarget);
        }

        for (int i = 0; i < vLinks.Length; i++)
        {
            for (int j = 0; j < vLinks[i].Length; j++)
            {
                relinkedClasses[i].var[j].links = vLinks[i][j].ToArray();
            }
        }

        return(relinkedClasses);
    }
        public void BuildGlobalVariables()
        {
            AbilityDataSubclass[] globalVariableNodes = new AbilityDataSubclass[globalVariables.Count];
            string[] keys = globalVariables.Keys.ToArray();


            for (int i = 0; i < keys.Length; i++)
            {
                int[] instanceAddress = new int[2];
                globalVariableNodes[i] = new AbilityDataSubclass(typeof(GlobalVariables));
                (globalVariableNodes[i].var[LoadedData.loadedParamInstances[typeof(GlobalVariables)].variableAddresses["Variable Name"]].field as RuntimeParameters <string>).v = keys[i];

                globalVariables[keys[i]] = Tuple.Create(playerId,0,i);

                //Debug.LogWarning("Create Node ID: " + keys[i] + " " + globalVariables[keys[i]]);
            }

            AbilityData globalVarInst = new AbilityData(globalVariableNodes,new AbilityInfo(),playerId,"");

            abilties.Add("",globalVarInst);
        }
    void Start()
    {
        string cData = FileSaver.sFT[FileSaverTypes.PLAYER_GENERATED_DATA].GenericLoadTrigger(new string[] { AbilityPageScript.selectedAbility }, 0);
        string wData = FileSaver.sFT[FileSaverTypes.PLAYER_GENERATED_DATA].GenericLoadTrigger(new string[] { AbilityPageScript.selectedAbility }, 2);

        if (cData != "")
        {
            abilityData = new UIAbilityData(LoadedData.GetSingleton <JSONFileConvertor>().ConvertToData(JsonConvert.DeserializeObject <StandardJSONFileFormat[]>(cData)), JsonConvert.DeserializeObject <float[][]>(wData));
        }
        else
        {
            abilityData = new UIAbilityData();
        }


        abilityWindows = new AutoPopulationList <EditableWindow>();
        lineData       = new AutoPopulationList <LineData>();

        SpawnUIFromData();

        mainClassSelection = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(LinearLayout));

        SpawnerOutput name = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(InputFieldWrapper));

        name.script.transform.position = UIDrawer.UINormalisedPosition(new Vector3(0.5f, 0.9f));

        InputField castedName = LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <InputField>(name);

        string data = FileSaver.sFT[FileSaverTypes.PLAYER_GENERATED_DATA].GenericLoadTrigger(new string[] { AbilityPageScript.selectedAbility }, 1);

        abilityDescription = JsonConvert.DeserializeObject <AbilityInfo>(data);
        castedName.text    = abilityDescription.n;

        castedName.onValueChanged.AddListener((s) => {
            abilityDescription.n = s;
        });

        SpawnerOutput[] buttons = new SpawnerOutput[LoadedData.loadedNodeInstance.Count];


        foreach (KeyValuePair <Type, AbilityTreeNode> entry in LoadedData.loadedNodeInstance)
        {
            SpawnerOutput button = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(ButtonWrapper));

            Button butInst = LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Button>(button);

            // Need another way to get elements within spawner output...
            LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Text>(button, "Text").text = entry.Key.Name;

            butInst.onClick.AddListener(() => {
                selectedType = entry.Key;
                windowSpawner.script.gameObject.SetActive(true);
                mMode = MouseMode.CREATE_NODE;
            });

            (mainClassSelection.script as LinearLayout).Add(butInst.transform as RectTransform);
        }

        classSelectionScrollRect = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(ScrollRectWrapper));
        (classSelectionScrollRect.script as ScrollRectWrapper).ChangeScrollRectSize(new Vector2(100, 600));


        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <UIMule>(classSelectionScrollRect, "Content").GetRectTransform().sizeDelta = (mainClassSelection.script.transform as RectTransform).sizeDelta;
        classSelectionScrollRect.script.transform.position = UIDrawer.UINormalisedPosition(new Vector3(0.1f, 0.6f));

        mainClassSelection.script.transform.SetParent(LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <UIMule>(classSelectionScrollRect, "Content").transform);
        mainClassSelection.script.transform.localPosition = new Vector2(-(mainClassSelection.script.transform as RectTransform).sizeDelta.x / 2, 0);


        windowSpawner = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(Image));
        windowSpawner.script.gameObject.SetActive(false);

        SpawnerOutput optLL = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(LinearLayout));

        SpawnerOutput normConnButt = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(ButtonWrapper));

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Text>(normConnButt, "Text").text    = "Normal Conection";
        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Image>(normConnButt, "Image").color = Color.green;

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Button>(normConnButt).onClick.AddListener(() => {
            mMode = MouseMode.EDIT_CONN;
            lMode = LinkMode.NORMAL;
        });

        SpawnerOutput sigConnButt = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(ButtonWrapper));

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Text>(sigConnButt, "Text").text    = "Signal Conection";
        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Image>(sigConnButt, "Image").color = Color.red;

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Button>(sigConnButt).onClick.AddListener(() => {
            mMode = MouseMode.EDIT_CONN;
            lMode = LinkMode.SIGNAL;
        });

        SpawnerOutput rmConnButt = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(ButtonWrapper));

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Text>(rmConnButt,"Text").text = "Remove Conection";

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Button>(rmConnButt).onClick.AddListener(() => {
            mMode = MouseMode.REMOVE_CONN;
        });

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <LinearLayout>(optLL).Add(normConnButt.script.transform as RectTransform);
        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <LinearLayout>(optLL).Add(sigConnButt.script.transform as RectTransform);
        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <LinearLayout>(optLL).Add(rmConnButt.script.transform as RectTransform);

        optLL.script.transform.position = UIDrawer.UINormalisedPosition(new Vector3(0.9f,0.9f));

        SpawnerOutput saveButton = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(ButtonWrapper));

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Button>(saveButton).onClick.AddListener(() => {
            int[] aEle = abilityData.subclasses.ReturnActiveElementIndex();

            AbilityDataSubclass[] cAD = abilityData.RelinkSubclass();

            string[] imgDependencies = AbilityDataSubclass.GetImageDependencies(cAD);

            // Gets all window locations.
            float[][] windowLocations = new float[cAD.Length][];

            for (int i = 0; i < windowLocations.Length; i++)
            {
                windowLocations[i] = new float[2];

                windowLocations[i][0] = abilityWindows.l[aEle[i]].transform.position.x;
                windowLocations[i][1] = abilityWindows.l[aEle[i]].transform.position.y;
            }

            FileSaver.sFT[FileSaverTypes.PLAYER_GENERATED_DATA].GenericSaveTrigger(new string[] { AbilityPageScript.selectedAbility },0,JsonConvert.SerializeObject(LoadedData.GetSingleton <JSONFileConvertor>().ConvertToStandard(cAD)));
            FileSaver.sFT[FileSaverTypes.PLAYER_GENERATED_DATA].GenericSaveTrigger(new string[] { AbilityPageScript.selectedAbility }, 1, JsonConvert.SerializeObject(abilityDescription));
            FileSaver.sFT[FileSaverTypes.PLAYER_GENERATED_DATA].GenericSaveTrigger(new string[] { AbilityPageScript.selectedAbility }, 2, JsonConvert.SerializeObject(windowLocations));
            FileSaver.sFT[FileSaverTypes.PLAYER_GENERATED_DATA].GenericSaveTrigger(new string[] { AbilityPageScript.selectedAbility }, 3, JsonConvert.SerializeObject(imgDependencies));
        });

        LoadedData.GetSingleton <UIDrawer>().GetTypeInElement <Text>(saveButton, "Text").text = "Save JSON";
        saveButton.script.transform.position = UIDrawer.UINormalisedPosition(new Vector3(0.5f, 0.1f));


        // Creates dropdown for input.
        kcDdL = new KeyCodeDropdownList(abilityDescription.kC);
        kcDdL.ReturnDropdownWrapper().transform.position = UIDrawer.UINormalisedPosition(new Vector3(0.75f, 0.9f));

        kcDdL.ReturnDropdownWrapper().dropdown.onValueChanged.AddListener((v) => {
            abilityDescription.kC = KeyCodeDropdownList.inputValues[v];
        });

        // Creates dropdown for startnode.
        //DropdownWrapper sNDW = LoadedData.GetSingleton<UIDrawer>().CreateScriptedObject(typeof(DropdownWrapper)).script as DropdownWrapper;



        ButtonWrapper addOptionsButton = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(ButtonWrapper)).script as ButtonWrapper;

        addOptionsButton.button.onClick.AddListener(() => CreateWindowForAdditionalOptions());

        addOptionsButton.text.text          = "Additional Options";
        addOptionsButton.transform.position = UIDrawer.UINormalisedPosition(new Vector3(0.1f, 0.2f));

        ButtonWrapper exitBlueprintMaker = LoadedData.GetSingleton <UIDrawer>().CreateScriptedObject(typeof(ButtonWrapper)).script as ButtonWrapper;

        exitBlueprintMaker.button.onClick.AddListener(() => SceneTransitionData.LoadScene("AbilityPage"));
        exitBlueprintMaker.text.text          = "Exit";
        exitBlueprintMaker.transform.position = UIDrawer.UINormalisedPosition(new Vector3(0.1f, 0.1f));
    }
    public AbilityDataSubclass[] ConvertToData(StandardJSONFileFormat[] sFs)
    {
        convertedFormat = null;
        standardFiles   = sFs;

        if (sFs != null)
        {
            convertedFormat = new AbilityDataSubclass[sFs.Length];
            Dictionary <Tuple <int, int>, int> relinkRequired = new Dictionary <Tuple <int, int>, int>();

            for (int i = 0; i < convertedFormat.Length; i++)
            {
                convertedFormat[i] = new AbilityDataSubclass();

                convertedFormat[i].classType = sFs[i].cT;
                convertedFormat[i].var       = new Variable[LoadedData.loadedParamInstances[convertedFormat[i].classType].runtimeParameters.Length];

                for (int j = 0; j < standardFiles[i].rP.Length; j++)
                {
                    int varId = -1;

                    if (LoadedData.loadedParamInstances[convertedFormat[i].classType].variableAddresses.ContainsKey(sFs[i].vN[j]))
                    {
                        varId = LoadedData.loadedParamInstances[convertedFormat[i].classType].variableAddresses[sFs[i].vN[j]];
                        LoadedData.loadedParamInstances[convertedFormat[i].classType].runtimeParameters[varId].rP.RunGenericBasedOnRP(this, new int[] { i, j, varId });
                    }
                    else
                    {
                        Debug.Log("Variable has been removed.");
                    }

                    if (varId != j)
                    {
                        relinkRequired.Add(Tuple.Create(i, j), varId);
                        Debug.Log(sFs[i].vN[j] + " has been shifted.");
                    }
                }

                for (int j = 0; j < convertedFormat[i].var.Length; j++)
                {
                    if (convertedFormat[i].var[j] == null)
                    {
                        convertedFormat[i].var[j] = new Variable(LoadedData.loadedParamInstances[convertedFormat[i].classType].runtimeParameters[j].rP);
                    }
                }
            }

            for (int i = 0; i < convertedFormat.Length; i++)
            {
                for (int j = 0; j < convertedFormat[i].var.Length; j++)
                {
                    List <int[]> links = new List <int[]>(convertedFormat[i].var[j].links);

                    for (int k = links.Count - 1; k >= 0; k--)
                    {
                        Tuple <int, int> id = Tuple.Create(links[k][0], links[k][1]);

                        if (relinkRequired.ContainsKey(id))
                        {
                            if (relinkRequired[id] > -1)
                            {
                                Debug.Log(links[k][1] + " id variable of " + convertedFormat[i].var[j].field.n + " has been moved to " + relinkRequired[id]);
                                links[k][1] = relinkRequired[id];
                            }
                            else
                            {
                                links.RemoveAt(k);
                            }
                        }
                    }

                    convertedFormat[i].var[j].links = links.ToArray();
                }
            }
        }

        return(convertedFormat);
    }