示例#1
0
文件: Tileset.cs 项目: Gayo/XNAVERGE
        protected bool reversed; // Used only for the BackAndForth animation mode. When true, animation is going backwards.

        #endregion Fields

        #region Constructors

        public TileAnimation(string name, TilesetAnimationMode mode, int start, int end, int delay, Tileset tileset)
        {
            this.name = name;
            this.mode = mode;
            this.start = start;
            this.end = end;
            this.delay = delay;
            frame_coord = new Point[end - start + 1];

            for (int i = 0; i < frame_coord.Length; i++)
                frame_coord[i] = tileset.tile_frame[start + i].Location;

            reset();
        }
示例#2
0
        // Attempts to load the map's tileset. If there is a manual tileset override specified, it looks for
        // that and errors if it's not found. Otherwise, it first checks for any content with a name matching
        // the map's vsp filename, then tries to match the filename without the .vsp part, then loads the
        // game's default tileset, erroring out if there isn't one.
        public Tileset load_tileset(String filename)
        {
            int pos;
            Tileset ts = null;
            filename = Utility.strip_path(filename);
            if (!String.IsNullOrEmpty(tileset_override)) {
                ts = VERGEGame.game.MapContent.Load<Tileset>(tileset_override);
            }
            else {
                try { // there doesn't seem to be a way to check if content exists without trying to load it, so let's do that
                    ts = VERGEGame.game.MapContent.Load<Tileset>(filename);
                }
                catch (Microsoft.Xna.Framework.Content.ContentLoadException e) {
                    // OK, the filename doesn't correspond to an asset name. Let's try it without the extension
                    try {
                        pos = filename.LastIndexOf(".");
                        if (pos < 0) throw e;
                        ts = VERGEGame.game.MapContent.Load<Tileset>(filename.Substring(0, pos));
                    }
                    catch (Microsoft.Xna.Framework.Content.ContentLoadException) { // That didn't work either. Check for a default tileset to use.
                        if (VERGEMap._default_tileset != null) {
                            System.Diagnostics.Debug.WriteLine("Couldn't match legacy vsp name to an asset; using the default tileset.");
                            ts = VERGEMap._default_tileset;
                        }
                        else {

                            /// this is dirty and bad and I am ashamed.  But whatever.
                            try {
                                filename = "maps/" + filename;
                                pos = filename.LastIndexOf( "." );
                                if( pos < 0 ) throw e;
                                ts = VERGEGame.game.MapContent.Load<Tileset>( (filename).Substring( 0, pos ) );
                            } catch( Microsoft.Xna.Framework.Content.ContentLoadException ) {
                                throw new ArgumentException( "Couldn't find a tileset asset named " + filename +
                                                                ", with or without extension, and there was no default tileset or override given." );
                            }
                        }
                    }
                }
            }
            tileset = ts;
            return ts;
        }
示例#3
0
 public static Tileset set_default_tileset(String asset_name)
 {
     try {
         _default_tileset = VERGEGame.game.MapContent.Load<Tileset>("asset_name");
     }
     catch (Microsoft.Xna.Framework.Content.ContentLoadException e) { // not found
         _default_tileset = null;
         throw e;
     }
     return _default_tileset;
 }
示例#4
0
文件: VERGEMap.cs 项目: Gayo/XNAVERGE
        // Attempts to load the map's tileset. If there is a manual tileset override specified, it looks for
        // that and errors if it's not found. Otherwise, it first checks for any content with a name matching
        // the map's vsp filename, then tries to match the filename without the .vsp part, then loads the
        // game's default tileset, erroring out if there isn't one.
        public Tileset load_tileset(String filename)
        {
            Tileset ts = null;
            string cur, naked_name = System.IO.Path.GetFileNameWithoutExtension(filename);
            int has_extension;
            if (naked_name == filename) has_extension = 0;
            else has_extension = 1;

            for (int i = 0; i < 2; i++) {
                for (int j = 0; j <= has_extension; j++) {
                    cur = (i == 0 ? MAP_LOCATION : "") + (j == 0 ? filename : naked_name);
                    if (System.IO.File.Exists(@"content\" + cur + ".xnb")) {
                        ts = VERGEGame.game.MapContent.Load<Tileset>(cur);
                        i = 999;
                        j = 999;
                    }
                }
            }
            if (ts == null) {
                if (VERGEMap._default_tileset != null) {
                    System.Diagnostics.Debug.WriteLine("DEBUG: Couldn't match legacy vsp name to an asset; using the default tileset.");
                    ts = VERGEMap._default_tileset;
                }
                else throw new ArgumentException("Couldn't find a tileset asset named " + filename + ", with or without extension, either in or not in content\\"
                                             + MAP_LOCATION + ", and there was no default tileset or override given.");

            }
            tileset = ts;
            return ts;
        }