Exemplo n.º 1
0
        public void Load2DProject(GameScreen screen, string filename, Assembly assembly)
        {
            CatalystProject2D project = screen.Content.Load <CatalystProject2D>(filename);

            if (project == null)
            {
                throw new Exception("Error: Failed to load the Catalyst3D 2D Project!");
            }

            if (project.Paths != null)
            {
                Paths.AddRange(project.Paths);
            }

            foreach (var v in project.SceneObjects)
            {
                if (!string.IsNullOrEmpty(v.ObjectTypeName))
                {
                    // load as this type
                    var type = assembly.GetType(v.ObjectTypeName);

                    var obj = (VisualObject)Activator.CreateInstance(type, new object[] { Game, ContentManager });

                    if (obj is Actor)
                    {
                        Actor n = obj as Actor;
                        Actor o = v as Actor;

                        if (o != null)
                        {
                            // Dig out the sprite sheet on these
                            n.SpriteSheetFileName      = o.SpriteSheetFileName;
                            n.ClipPlayer.Sequences     = o.ClipPlayer.Sequences;
                            n.IsCentered               = o.IsCentered;
                            n.StartPathingLerpPosition = o.StartPathingLerpPosition;
                            n.StartPathNodeIndex       = o.StartPathNodeIndex;
                            n.Direction = o.Direction;
                            n.StartPathingLerpPosition = o.StartPathingLerpPosition;
                            n.StartPathNodeIndex       = o.StartPathNodeIndex;
                            n.SpriteEffects            = o.SpriteEffects;
                            n.CurrentPathLerpPosition  = o.CurrentPathLerpPosition;
                            n.CurrentPathNodeIndex     = o.CurrentPathNodeIndex;
                        }
                    }

                    if (obj is Sprite)
                    {
                        Sprite n = obj as Sprite;
                        Sprite o = v as Sprite;

                        if (o != null)
                        {
                            n.SpriteSortMode           = o.SpriteSortMode;
                            n.StartPathNodeIndex       = o.StartPathNodeIndex;
                            n.StartPosition            = o.StartPosition;
                            n.Effects                  = o.Effects;
                            n.IsCentered               = o.IsCentered;
                            n.IsLerpingBackToFirstNode = o.IsLerpingBackToFirstNode;
                            n.LayerDepth               = o.LayerDepth;
                            n.BlendMode                = o.BlendMode;
                            n.Color                   = o.Color;
                            n.ScrollSpeed             = o.ScrollSpeed;
                            n.CurrentPathLerpPosition = o.CurrentPathLerpPosition;
                            n.CurrentPathNodeIndex    = o.CurrentPathNodeIndex;
                        }
                    }

                    if (obj is ParticleEmitter)
                    {
                        ParticleEmitter n = obj as ParticleEmitter;
                        ParticleEmitter o = v as ParticleEmitter;

                        if (o != null)
                        {
                            n.StartPathNodeIndex       = o.StartPathNodeIndex;
                            n.StartPathingLerpPosition = o.StartPathingLerpPosition;
                            n.RespawnParticles         = o.RespawnParticles;
                            n.ParticleColor            = o.ParticleColor;
                            n.MaxAcceleration          = o.MaxAcceleration;
                            n.MinAcceleration          = o.MinAcceleration;
                            n.MaxInitialSpeed          = o.MaxInitialSpeed;
                            n.MinInitialSpeed          = o.MinInitialSpeed;
                            n.MaxLifeSpan      = o.MaxLifeSpan;
                            n.MinLifeSpan      = o.MinLifeSpan;
                            n.MinParticles     = o.MinParticles;
                            n.MaxParticles     = o.MaxParticles;
                            n.MaxRotationSpeed = o.MaxRotationSpeed;
                            n.MinRotationSpeed = o.MinRotationSpeed;
                            n.MinScale         = o.MinScale;
                            n.MaxScale         = o.MaxScale;
                            n.DelayedStartTime = o.DelayedStartTime;

                            n.StartPathNodeIndex       = o.StartPathNodeIndex;
                            n.StartPathingLerpPosition = o.StartPathingLerpPosition;
                            n.CurrentPathLerpPosition  = o.CurrentPathLerpPosition;
                            n.CurrentPathNodeIndex     = o.CurrentPathNodeIndex;
                        }
                    }

                    obj.GameScreen              = this;
                    obj.AssetName               = v.AssetName;
                    obj.ObjectType              = type;
                    obj.ObjectTypeName          = v.ObjectTypeName;
                    obj.Position                = v.Position;
                    obj.Scale                   = v.Scale;
                    obj.AttachedPathingNode     = (project.Paths.Where(p => p.Name == v.AttachedPathingNodeName)).FirstOrDefault();
                    obj.AttachedPathingNodeName = v.AttachedPathingNodeName;
                    obj.Enabled                 = v.Enabled;
                    obj.Visible                 = v.Visible;
                    obj.Rotation                = v.Rotation;
                    obj.Name                 = v.Name;
                    obj.SpriteBatch          = SpriteBatch;
                    obj.DrawOrder            = v.DrawOrder;
                    obj.SpriteSortMode       = v.SpriteSortMode;
                    obj.IsLocked             = v.IsLocked;
                    obj.CurrentPathNodeIndex = v.CurrentPathNodeIndex;
                    obj.IsCentered           = v.IsCentered;
                    AddVisualObject(obj);
                }
            }
        }
Exemplo n.º 2
0
 public T Get <T>(GameScreen screen, string name) where T : class
 {
     return((from vo in screen.VisualObjects where vo.Name == name select vo as T).FirstOrDefault());
 }
Exemplo n.º 3
0
        private void LoadProject(GameScreen screen, CatalystProject2D project)
        {
            // First load any pathing ledges
            if (project.Paths.Count > 0)
            {
                Paths.AddRange(project.Paths);
            }

            // Loop thru our objects and reload them
            foreach (VisualObject vo in project.SceneObjects)
            {
                if (vo is VisualObjectGroup)
                {
                    VisualObjectGroup group = vo as VisualObjectGroup;

                    foreach (VisualObject o in group.Objects)
                    {
                        if (o is Sprite && o.GetType() != typeof(SpriteBox))
                        {
                            Sprite sprite = o as Sprite;
                            sprite.AssetFolder = AssetFolder;
                            sprite.Game        = Game;

                            sprite.Texture = screen.Content.Load <Texture2D>(Path.GetFileNameWithoutExtension(o.AssetName));

                            sprite.GameScreen = this;

                            // Re-attach any nodes
                            if (!string.IsNullOrEmpty(sprite.AttachedPathingNodeName))
                            {
                                sprite.AttachedPathingNode = GetPath(sprite.AttachedPathingNodeName);
                            }
                        }

                        if (o is SpriteBox)
                        {
                            SpriteBox sprite = o as SpriteBox;
                            sprite.AssetFolder = AssetFolder;
                            sprite.Game        = Game;
                            sprite.GameScreen  = this;

                            // Re-attach any nodes
                            if (!string.IsNullOrEmpty(sprite.AttachedPathingNodeName))
                            {
                                sprite.AttachedPathingNode = GetPath(sprite.AttachedPathingNodeName);
                            }
                        }

                        if (o is ParticleEmitter)
                        {
                            ParticleEmitter emitter = o as ParticleEmitter;
                            emitter.AssetFolder = AssetFolder;
                            emitter.Game        = Game;

                            emitter.Texture = screen.Content.Load <Texture2D>(Path.GetFileNameWithoutExtension(o.AssetName));

                            emitter.GameScreen = this;
                        }
                    }

                    group.Game = Game;

                    AddVisualObject(group);
                }

                if (vo is Actor)
                {
                    Actor a = vo as Actor;

                    a.Game            = Game;
                    a.GameScreen      = this;
                    a.ClipPlayer.Game = Game;
                    a.AssetFolder     = AssetFolder;

                    a.ClipPlayer.Texture = screen.Content.Load <Texture2D>(Path.GetFileNameWithoutExtension(a.SpriteSheetFileName));

                    AddVisualObject(a);

                    continue;
                }

                if (vo is Button)
                {
                    Button button = vo as Button;
                    button.Game        = Game;
                    button.GameScreen  = this;
                    button.AssetFolder = AssetFolder;

                    button.Texture = screen.Content.Load <Texture2D>(Path.GetFileNameWithoutExtension(button.AssetName));

                    AddVisualObject(button);

                    continue;
                }

                // Make sure its a sprite and not the spritebox
                if (vo is Sprite && vo.GetType() != typeof(SpriteBox))
                {
                    Sprite sprite = vo as Sprite;
                    sprite.Game        = Game;
                    sprite.GameScreen  = this;
                    sprite.AssetFolder = AssetFolder;

                    sprite.Texture = screen.Content.Load <Texture2D>(Path.GetFileNameWithoutExtension(sprite.AssetName));

                    // Re-attach any nodes
                    if (!string.IsNullOrEmpty(sprite.AttachedPathingNodeName))
                    {
                        sprite.AttachedPathingNode = GetPath(sprite.AttachedPathingNodeName);
                    }

                    AddVisualObject(sprite);
                }

                if (vo is SpriteBox)
                {
                    SpriteBox sprite = vo as SpriteBox;
                    sprite.AssetFolder = AssetFolder;
                    sprite.Game        = Game;
                    sprite.GameScreen  = this;

                    // Re-attach any nodes
                    if (!string.IsNullOrEmpty(sprite.AttachedPathingNodeName))
                    {
                        sprite.AttachedPathingNode = GetPath(sprite.AttachedPathingNodeName);
                    }

                    AddVisualObject(sprite);
                }

                if (vo is ParticleEmitter)
                {
                    ParticleEmitter emitter = vo as ParticleEmitter;
                    emitter.Game        = Game;
                    emitter.GameScreen  = this;
                    emitter.AssetFolder = AssetFolder;

                    emitter.Texture = screen.Content.Load <Texture2D>(Path.GetFileNameWithoutExtension(emitter.AssetName));

                    AddVisualObject(emitter);
                }
            }
        }