Пример #1
0
    public void LoadMechanicGraph(int inputSeed = -1)
    {
        List <NodeGrammar> grammars = new List <NodeGrammar>();

        foreach (var grammar in _nodeGrammars)
        {
            grammars.AddRange(NodeGrammar.ImportGrammars(Application.streamingAssetsPath + "/Grammar/Node/" + grammar + ".json"));
        }

        // generate a simple left hand side for now
        var inputGraph = new NodeGraph();

        inputGraph.AddNode(new Node()
        {
            Node_text = "S"
        });

        var seed = _randomString ? UnityEngine.Random.Range(0, 1000) : _seed;

        if (inputSeed != -1)
        {
            seed = inputSeed;
        }

        var stringgrams = GrammarUtils.ImportGrammars(Application.streamingAssetsPath + "/Grammar/String/" + _stringGrammar + ".json");
        var inputString = GrammarUtils.ApplyGrammars(ref stringgrams, _inputString, seed);

        Debug.Log("mechanic generated with input string " + inputString);
        Debug.Log("Seed: " + seed);
        FindObjectOfType <SeedDisplay>()?.DisplaySeed(seed);
        _mechanicGraph = GrammarUtils.ApplyNodeGrammars(inputString, ref grammars, inputGraph, seed);
        AnalyseMechanicNodes();


        AdjustBalance();
        AnalyseMechanicNodes();
        ApplySignifiers();

        NodeBehaviour.Callbacks      = new Stack <NodeActivationCallBack>();
        NodeBehaviour.PlayerAttacks  = GetComponent <PlayerAttackControl>();
        NodeBehaviour.PlayerMovement = GetComponent <PlayerMovement>();
    }
 private void GrammarSaveAndLoad()
 {
     _exportName = EditorGUILayout.TextField("File Name : ", _exportName);
     EditorGUILayout.BeginHorizontal();
     if (GUILayout.Button("import"))
     {
         _grammars = NodeGrammar.ImportGrammars(_directory + _exportName + ".json");
         if (_grammars == default)
         {
             Reset();
         }
         LoadGrammar(_grammarSelectedIndex);
     }
     if (GUILayout.Button("export"))
     {
         SaveGrammar(_grammarSelectedIndex);
         StreamWriter writer     = new StreamWriter(_directory + _exportName + ".json");
         var          jsonString = SerializableNodeGrammars_Converter.ToJson(_grammars);
         writer.Write(jsonString);
         writer.Close();
         writer.Dispose();
     }
     EditorGUILayout.EndHorizontal();
 }