Esempio n. 1
0
    public void UpdateSelected(string name)
    {
        //Searches for node with selected name
        LawNode selectedNode = GetNode(Country.laws[currentBranch], currentNode);

        //Updates the TMPro text elements
        actionName.text        = selectedNode.law.name;
        actionDescription.text = selectedNode.law.description;
        actionCost.text        = string.Format("Kosten: {0}€", selectedNode.law.cost);
        statsText.text         = string.Format("Befriedigung: {0}\nIsolierung: {1}\nInfektion: {2}\nMitgation: {3}", selectedNode.law.satisfaction, selectedNode.law.isolationDampener, selectedNode.law.r0Dampener, selectedNode.law.mtDampener);

        //If enforced button should be disabled
        if (Enforces(selectedNode.law.name) != -1)
        {
            enforceButton.interactable = false;
        }
        //If previous is not enforced it should be disabled
        else if (Enforces(selectedNode.prev.law.name) == -1 && selectedNode.prev.law.name != "")
        {
            enforceButton.interactable = false;
        }
        else
        {
            enforceButton.interactable = true;
        }

        //Disables if not enought money or currently enforcing
        if (country.enforcingLaw || country.currentBudget < GetNode(Country.laws[currentBranch], currentNode).law.cost)
        {
            enforceButton.interactable = false;
        }
    }
Esempio n. 2
0
    public LawNode AddTree(LawNode law)
    {
        law.SetPrev(this);
        law.SetChildIndex(subNode.Count);
        subNode.Add(law);

        return(this);
    }
Esempio n. 3
0
    //Recursive function that creates the node gameobject from a LawNode
    private void CreateNode(LawNode node, Vector2 position, Transform parent)
    {
        //Debug.Log(string.Format("Name: {0}, ChildIndex: {1}, Previous: {2}", node.law.name, node.childIndex, node.prev.law.name));

        //Offset to left, right or top
        Vector2[] offsets = new Vector2[3] {
            (Mathf.Cos(150f * Mathf.Deg2Rad) * Vector2.left + Mathf.Sin(150f * Mathf.Deg2Rad) * Vector2.up) * spriteDim.y,
            (Mathf.Cos(150f * Mathf.Deg2Rad) * Vector2.left - Mathf.Sin(150f * Mathf.Deg2Rad) * Vector2.up) * spriteDim.y,
            -Vector2.left * spriteDim.x
        };

        GameObject nodeG = Instantiate(hexagon, position, Quaternion.identity);         //Create Hexagon object

        nodeG.name = node.law.name;
        nodeG.SetActive(true);
        nodeG.layer = 8;
        nodeG.transform.SetParent(parent, false);

        //Check if previous Node is unlocked, otherwise lock
        if (Enforces(node.law.name) == -1 && node.prev.law.name != "")//(!country.enforcedLaws.Contains(node.law) && node.prev.law.name != "")
        {
            nodeG.GetComponent <Image>().color = lockedColor;
        }

        if (Enforces(node.law.name) == -1 && node.prev.law.name == "")
        {
            nodeG.GetComponent <Image>().color = enforcableColor;
        }

        //Previous is unlocked -> set to white
        if (Enforces(node.prev.law.name) != -1)//(country.enforcedLaws.Contains(node.prev.law))
        {
            nodeG.GetComponent <Image>().color = enforcableColor;
        }


        //If active law
        if (Enforces(node.law.name) != -1)//(country.enforcedLaws.Contains(node.law))
        {
            nodeG.GetComponent <Image>().color = enforcedColor;
        }


        foreach (LawNode subNode in node.subNode)                                        //Call function for each subnode
        {
            //Different cases, check notebook (Progyo)

            Vector2 newPos = position + offsets[subNode.childIndex];

            CreateNode(subNode, newPos, parent);
        }
    }
Esempio n. 4
0
    //Import Laws from json files
    public virtual void ReadLaws()
    {
        Debug.LogWarning("Please implement proper directory when reading JSON Files!!!");
        string dir = ".\\Assets\\Laws";

        laws = new Dictionary <string, LawNode>();

        string[] paths = Directory.GetFiles(dir);   //Get Files in path
        foreach (string path in paths)
        {
            //If JSON File
            if (path.Split(".".ToCharArray())[path.Split(".".ToCharArray()).Length - 1] == "json")
            {
                StreamReader file = File.OpenText(path);
                string       text = file.ReadToEnd();                 //Get file contents as string
                file.Close();


                //Clean up json
                text = text.Replace("\r\n", "");
                text = text.Replace("            ", "");
                text = text.Replace("    ", "");


                //File Name
                string  name = path.Split("\\".ToCharArray())[path.Split("\\".ToCharArray()).Length - 1].Split(".".ToCharArray())[0]; //Get file name <name>.json by splitting at .
                LawNode node = JsonUtility.FromJson <LawNode>(text);                                                                  //Convert json to LawNode object
                node.UpdatePrev();                                                                                                    //Adds missing previous attribute to nodes
                node.UpdateChildIndex();
                laws.Add(name, node);                                                                                                 //Add law tree into dictionary
            }
        }
        //Debug.Log(laws["Hygiene"].subNode[0].law.name);
        /// DEBUG ZONE  ///
        //Debug.Log(laws);
        //LawNode test = new LawNode(new Law("Washing Hands", 10, 0.1f),true).AddTree(new LawNode(new Law("Washing Hands", 10, 0.1f))).subNode[0].AddTree(new LawNode(new Law("Verteilen von Taschentüchern",1,0.01f))).AddTree(new LawNode(new Law("Verteilen von Disinfektionmittel", 1, 0.01f))).prev;
        //List<LawNode> test = new List<LawNode>() { new LawNode(new Law("Washing Hands", 10, 0.1f)), new LawNode(new Law("Verteilen von Taschentüchern", 10, 0.1f)).AddTree(new LawNode(new Law("Verteilen von Disinfektionmittel", 1, 0.01f))).AddTree(new LawNode(new Law("Oiiiii", 1, 0.01f))) };

        /*string temp = JsonUtility.ToJson(test);
         * Debug.Log(temp);
         * LawNode tmp = JsonUtility.FromJson<LawNode>(temp);
         * Debug.Log(tmp.subNode[0].law.name);*/
        //Debug.Log(test.subNode[0].subNode[0].law.name);
        //LawNode temp = JsonUtility.FromJson<LawNode>();
    }
Esempio n. 5
0
    //Recursive function that locates a child LawNode from a parent LawNode
    private LawNode GetNode(LawNode parent, string name)
    {
        //Break out of recursion
        if (parent.law.name == name)
        {
            return(parent);
        }
        LawNode toReturn = null;

        foreach (LawNode node in parent.subNode)
        {
            LawNode temp = GetNode(node, name);
            if (temp != null && temp.law.name == name)
            {
                toReturn = temp;
            }
        }
        return(toReturn);
    }
Esempio n. 6
0
 public void SetPrev(LawNode previous)
 {
     prev = previous;
 }