Exemple #1
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);
    }
Exemple #2
0
 public void AddPhase(PhaseJson p)
 {
     phases.Add(p);
 }