Esempio n. 1
0
    public void Render(DrawingSurface ds, string name = null)
    {
        string      dsName   = name ?? ds.name;
        List <Node> nodeList = null;

        if (!this.renderNodes.TryGetValue(dsName, out nodeList))
        {
            ds.Text("No template found").Draw();
            return;
        }

        DsCallback callback = null;
        int        i        = 0;

        this.removeNodes.Clear();
        foreach (Node node in nodeList)
        {
            if (node.action == "newline")
            {
                ds.Newline();
                continue;
            }

            if (node.action == "text")
            {
                ds.AddTextSprite((MySprite)node.sprite);
                continue;
            }

            if (node.action == "config")
            {
                this.ConfigureScreen(ds, node.options);
                removeNodes.Add(i);
                continue;
            }

            if (this.methods.TryGetValue(node.action, out callback))
            {
                callback(ds, node.text, node.options);
            }
            else
            {
                ds.Text($"{{{node.action}}}");
            }
            i++;
        }
        ds.Draw();

        foreach (int removeNode in removeNodes)
        {
            nodeList.RemoveAt(removeNode);
        }
    }
Esempio n. 2
0
 public void Register(string key, DsCallback callback)
 {
     this.methods[key] = callback;
 }