コード例 #1
0
    private WidgetButtonBase CreateMainMenuButton(JsonElement definition)
    {
        var button = new MainMenuButton();

        WidgetDocLoader.LoadWidgetBase(definition, button);

        if (definition.TryGetProperty("text", out var textProp))
        {
            button.Text = textProp.GetString() ?? throw new NullReferenceException("text is null");
        }

        return(button);
    }
コード例 #2
0
    public static WidgetDoc Load(string path, CustomWidgetFactory customFactory = null)
    {
        var json = Tig.FS.ReadBinaryFile(path);

        using var root = JsonDocument.Parse(json);

        try
        {
            var loader = new WidgetDocLoader(path);
            if (customFactory != null)
            {
                loader.CustomFactory = customFactory;
            }

            var rootWidget = loader.LoadWidgetTree(root.RootElement);

            return(new WidgetDoc(path, rootWidget, loader.Registry, loader.ContentRegistry));
        }
        catch (Exception e)
        {
            throw new Exception($"Unable to load widget doc '{path}'.", e);
        }
    }