66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
/**
|
|
* Handles the loading of LVL files
|
|
*
|
|
* Copyright (C) 2012 Mike Gerwitz
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*
|
|
* Maps (the term "level" is used in the game) are stored in a fixed-width LVL
|
|
* file.
|
|
*/
|
|
|
|
|
|
/**
|
|
* Handles delegation of LVL data
|
|
*
|
|
* This acts as a Map factory, leaving all processing responsibilities to the
|
|
* Map instance. Consequently, any custom map format would be supported,
|
|
* provided that the appropriate Map is handling it.
|
|
*/
|
|
ltjs.MapSet = Class( 'MapSet',
|
|
{
|
|
/**
|
|
* Raw level set data (binary)
|
|
* @type {string}
|
|
*/
|
|
'private _data': '',
|
|
|
|
|
|
/**
|
|
* Initialize map set with LVL data and a Map constructor
|
|
*
|
|
* The Map constructor is used in place of a separate Map factory.
|
|
*
|
|
* @param {string} data binary LVL data
|
|
* @param {ltjs.Map} map_ctor Map constructor
|
|
*/
|
|
__construct: function( data, map_ctor )
|
|
{
|
|
this._data = ''+( data );
|
|
this._mapCtor = map_ctor;
|
|
},
|
|
|
|
|
|
/**
|
|
* Load a level by the given number (e.g. level 1)
|
|
*
|
|
* @param {number} id number of level to load, 1-indexed
|
|
*/
|
|
'public getMapByNumber': function( id )
|
|
{
|
|
return this._mapCtor( this._data, id );
|
|
}
|
|
} );
|