Exemplo n.º 1
0
    private void Start()
    {
        string spellsText  = HandleTextFile.ReadString(spellBookLocation1);
        string spellsText2 = HandleTextFile.ReadString(spellBookLocation2);

        spell1Settings = JsonUtility.FromJson <SpellJson>(spellsText);

        if (creature != null)
        {
            creature.spell1Settings = spell1Settings;
        }
        if (spell1 != null && spell1.isOn)
        {
            codeSetter.text = (spell1Settings.code);
        }
        spell2Settings = JsonUtility.FromJson <SpellJson>(spellsText2);

        if (creature != null)
        {
            creature.spell2Settings = spell2Settings;
        }
        if (spell1 != null && spell2 != null)
        {
            spell1.onValueChanged.AddListener(delegate {
                OnToggleChangedSpell1();
            });
            spell2.onValueChanged.AddListener(delegate {
                OnToggleChangedSpell1();
            });
        }
    }
Exemplo n.º 2
0
 public void saveCode()
 {
     if (currentSpellJson == null)
     {
         ReadCode();
     }
     if (spell1.isOn)
     {
         spell1Settings = currentSpellJson;
         HandleTextFile.WriteString(spellBookLocation1, JsonUtility.ToJson(currentSpellJson, true));
         spellInterpreter.LogToConsole("Spell saved to slot 1");
     }
     if (spell2.isOn)
     {
         spell2Settings = currentSpellJson;
         HandleTextFile.WriteString(spellBookLocation2, JsonUtility.ToJson(currentSpellJson, true));
         spellInterpreter.LogToConsole("Spell saved to slot 2");
     }
 }
Exemplo n.º 3
0
    public void ReadCode()
    {
        foreach (Transform t in spellParent)
        {
            if (!t.CompareTag("Environment"))
            {
                Destroy(t.gameObject, 0.1f);
            }
        }
        //Interpret the code written by the player
        currentSpellJson = spellInterpreter.InterpretScript(code.text);
        //Turn the json into an actaul spell
        GameObject spellObj = Instantiate <GameObject>(creature.spellGenerator, Vector3.zero, Quaternion.identity);

        spellObj.transform.parent = spellParent;
        currentSpell = spellObj.GetComponent <SpellGenerator>();
        currentSpell.spellSettings = currentSpellJson;
        currentSpell.GenerateSpell(spellObj.transform);
        //HandleTextFile.WriteString(spellBookLocation, JsonUtility.ToJson(spell, true));
    }
Exemplo n.º 4
0
    public SpellJson InterpretScript(string code)
    {
        SpellJson spellJson = new SpellJson();

        string[] sepCode = null;
        spellJson.code = code;
        code           = code.Replace("\n", "");
        sepCode        = code.Split(';');
        PhaseJson currentPhase = new PhaseJson();

        for (int j = 0; j < sepCode.Length - 1; j++)  //-1 because the line after the ; is counted with
        {
            string   tillParan     = sepCode[j].Split('(')[0].ToLower();
            string   paramsValues  = sepCode[j].Split('(')[1].Replace(")", "");
            string[] paramsFunc    = paramsValues.Split(',');
            bool     foundFunction = false;
            for (int i = 0; i < functions.Length; i++)
            {
                if (tillParan.Length == functions[i].Length)
                {
                    if (tillParan.Equals(delayName))
                    {
                        currentPhase.phaseDuration = (float)Convert.ToDouble(paramsFunc[0]);
                        currentPhase.FinishShapeAdding();
                        spellJson.AddPhase(currentPhase);
                        currentPhase  = new PhaseJson();
                        foundFunction = true;
                    }
                    else if (tillParan.Equals(functions[i]))
                    {
                        try
                        {
                            ShapeType shapeType;
                            shapeDict.TryGetValue(tillParan, out shapeType);

                            currentPhase.AddShape(CreateShape(shapeType, paramsFunc));
                            foundFunction = true;
                        }
                        catch (ArgumentException)
                        {
                            LogToConsole(tillParan + " doesn't exist");
                            Debug.Log("Doesn't exist");
                            throw;
                        }
                    }
                }
            }
            if (!foundFunction)
            {
                LogToConsole("The " + tillParan + " function doesn't exist");
                Debug.Log("The " + tillParan + " function doesn't exist");
            }
        }
        if (currentPhase.shapes.Count > 0)
        {
            currentPhase.phaseDuration = (float)Convert.ToDouble(0);
            currentPhase.FinishShapeAdding();
            spellJson.AddPhase(currentPhase);
        }
        spellJson.finishPhaseAdding();
        foreach (PhaseJson phase in spellJson.phasesArray)
        {
            spellJson.manaCost += phase.GetManaCost();
        }
        return(spellJson);
    }