Пример #1
0
        private static EntityComponent DeserializeComponent(ReloadedComponentEntryLive reloadedComponent)
        {
            var eventReader = new EventReader(new MemoryParser(reloadedComponent.YamlEvents));
            var components  = new EntityComponentCollection();

            // Use the newly created component during second pass for proper cycle deserialization
            var newComponent = reloadedComponent.NewComponent;

            if (newComponent is not null)
            {
                components.Add(newComponent);
            }

            // Try to create component first
            AssetYamlSerializer.Default.Deserialize(eventReader, components, typeof(EntityComponentCollection), out _);
            var component = components.Count == 1 ? components[0] : null;

            return(component);
        }
        private static void ReplaceComponent(Game game, ReloadedComponentEntryLive reloadedComponent)
        {
            // Create new component instance
            var newComponent = DeserializeComponent(reloadedComponent);

            // Dispose and unregister old component (and their MicroThread, if any)
            var oldComponent = reloadedComponent.Entity.Components[reloadedComponent.ComponentIndex];

            // Flag scripts as being live reloaded
            if (game != null && oldComponent is ScriptComponent)
            {
                game.Script.LiveReload((ScriptComponent)oldComponent, (ScriptComponent)newComponent);
            }

            // Replace with new component
            // TODO: Remove component before serializing it, so cancellation code can run
            reloadedComponent.Entity.Components[reloadedComponent.ComponentIndex] = newComponent;

            // TODO: Dispose or Cancel on script?
            (oldComponent as ScriptComponent)?.Cancel();
        }
Пример #3
0
        private static void ReplaceComponent(Game game, ReloadedComponentEntryLive reloadedComponent)
        {
            // Create new component instance
            var newComponent = DeserializeComponent(reloadedComponent);

            // Dispose and unregister old component (and their MicroThread, if any)
            var oldComponent = reloadedComponent.Entity.Components[reloadedComponent.ComponentIndex];

            // Flag scripts as being live reloaded
            if (game != null && oldComponent is ScriptComponent)
            {
                game.Script.LiveReload((ScriptComponent)oldComponent, (ScriptComponent)newComponent);
            }

            // Replace with new component
            // TODO: Remove component before serializing it, so cancellation code can run
            reloadedComponent.Entity.Components[reloadedComponent.ComponentIndex] = newComponent;

            // TODO: Dispose or Cancel on script?
            (oldComponent as ScriptComponent)?.Cancel();
        }
Пример #4
0
        private static EntityComponent DeserializeComponent(ReloadedComponentEntryLive reloadedComponent)
        {
            var eventReader = new EventReader(new MemoryParser(reloadedComponent.YamlEvents));
            var components = new EntityComponentCollection();

            // Use the newly created component during second pass for proper cycle deserialization
            var newComponent = reloadedComponent.NewComponent;
            if (newComponent != null)
                components.Add(newComponent);

            // Try to create component first
            YamlSerializer.Deserialize(eventReader, components, typeof(EntityComponentCollection));
            var component = components.Count == 1 ? components[0] : null;
            return component;
        }