Beispiel #1
0
 public static IDictionary <string, object> Use()
 {
     lock (Locker)
     {
         return(HookComponentRegistration.GetOrRegisterHook(_prepopulated).Value);
     }
 }
        public static void Prepopulate()
        {
            lock (Locker)
            {
                if (_prepopulated == null)
                {
                    _prepopulated = new BaseHook(nameof(ScreenSizeHook), new Dictionary <string, object>()
                    {
                        { "width", Screen.safeArea.width },
                        { "height", Screen.safeArea.height }
                    });
                }
                else
                {
                    if (_prepopulated.Value["width"].Equals(Screen.safeArea.width) &&
                        _prepopulated.Value["height"].Equals(Screen.safeArea.height))
                    {
                        return;
                    }

                    _prepopulated.Value["width"]  = Screen.safeArea.width;
                    _prepopulated.Value["height"] = Screen.safeArea.height;

                    HookComponentRegistration.InvalidateHooks(hook => hook.Name == nameof(ScreenSizeHook));
                }
            }
        }
Beispiel #3
0
        public static void Prepopulate()
        {
            lock (Locker)
            {
                if (_prepopulated == null)
                {
                    _prepopulated = new BaseHook(nameof(MousePositionHook), new Dictionary <string, object>()
                    {
                        { "x", Input.mousePosition.x },
                        { "y", Input.mousePosition.y }
                    });
                }
                else
                {
                    if (_prepopulated.Value["x"].Equals(Input.mousePosition.x) &&
                        _prepopulated.Value["y"].Equals(Input.mousePosition.y))
                    {
                        return;
                    }

                    _prepopulated.Value["x"] = Input.mousePosition.x;
                    _prepopulated.Value["y"] = Input.mousePosition.y;

                    HookComponentRegistration.InvalidateHooks(hook => hook.Name == nameof(MousePositionHook));
                }
            }
        }
Beispiel #4
0
        public (List <Element> children, GameObjectElementBuilder builder) Render(Element container, PropCollection props, List <Element> children)
        {
            HookComponentRegistration.CurrentComponent = this;
            HookComponentRegistration.CurrentContainer = container;
            HookComponentRegistration.ResetHookCounter();

            var elementId = state.Call(state.Globals[$"{Name}_render"], props).CastToString();

            HookComponentRegistration.CurrentComponent = null;
            HookComponentRegistration.CurrentContainer = null;

            var element = Element.GetById(elementId);

            if (element == null)
            {
                return(new List <Element>(), null);
            }

            element.Parent = container;

            return(new List <Element>()
            {
                element
            }, null);
        }
        public static void DestroyElement(Element existing, IObjectPool pool)
        {
            if (existing.Builder != null)
            {
                existing.Builder.Destroy(pool);
            }
            else
            {
                foreach (var child in existing.Children)
                {
                    DestroyElement(child, pool);
                }
            }

            HookComponentRegistration.RemoveHooksFor(existing);
        }
Beispiel #6
0
        public static void Prepopulate()
        {
            lock (Locker)
            {
                foreach (var used in _usedSystems)
                {
                    var system   = ConnectedSystemRegistry.Instance.Get(used.Key);
                    var newProps = system.Props;

                    if (HavePropsChanged(newProps, used.Value.Value))
                    {
                        used.Value.Value = newProps;
                        HookComponentRegistration.InvalidateHooks(hook => hook.Name == $"{nameof(ScreenSizeHook)}_{used.Key}");
                    }
                }
            }
        }
Beispiel #7
0
        public static IDictionary <string, object> Use(object initialValue)
        {
            var hook = new BaseHook(nameof(StateHook), new Dictionary <string, object> {
                { "value", initialValue }
            });

            var currentElement = HookComponentRegistration.CurrentContainer;

            hook.Value.Add("change", (Action <object>)((value) =>
            {
                hook.Value["value"] = value;

                currentElement.Invalidated = true;
                RenderQueue.Instance.Enqueue(new RenderQueueItem {
                    elementToUpdate = currentElement
                });
            }));

            return(HookComponentRegistration.GetOrRegisterHook(hook).Value);
        }
Beispiel #8
0
        public static IDictionary <string, object> Use(string systemName)
        {
            lock (Locker)
            {
                var system = ConnectedSystemRegistry.Instance.Get(systemName);

                if (system == null)
                {
                    return(null);
                }

                if (_usedSystems.ContainsKey(systemName))
                {
                    return(HookComponentRegistration.GetOrRegisterHook(_usedSystems[systemName]).Value);
                }

                var hook = new BaseHook($"{nameof(ScreenSizeHook)}_{systemName}", new Dictionary <string, object>(system.Props));
                _usedSystems.Add(systemName, hook);

                return(HookComponentRegistration.GetOrRegisterHook(_usedSystems[systemName]).Value);
            }
        }