/** * Game initialization script * * 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 . */ ( function() { var load_ltg = ltjs.FileLoader( document.getElementById( 'ltg' ) ), load_lvl = ltjs.FileLoader( document.getElementById( 'lvl' ) ), menu_bar = ltjs.ui.MenuBar( document.getElementById( 'menubar' ) ), game = document.getElementById( 'game' ), ctx = document.getElementById( 'render' ).getContext( '2d' ), ltg_loader = ltjs.LtgLoader(), masker = ltjs.TileMasker( ltjs.ClassicTileDfn() ), tile_set = null, map_set = null, render = null; load_ltg.onLoad( function( e, data ) { if ( e ) throw e; // get tile metadata var meta = ltg_loader.fromString( data ); masker.getMaskedTiles( meta.tiles, meta.mask, function( tdata ) { tile_set = tdata; gamechk(); } ); } ); load_lvl.onLoad( function( e, data ) { if ( e ) throw e; map_set = ltjs.MapSet( data, ltjs.ClassicMap ); gamechk(); } ); function gamechk() { if ( !( tile_set && map_set ) ) return; // temporary if ( game.className.search( 'opening' ) > -1 ) return; // clear any existing locks before rendering (allowing the user to change // tile sets and map sets) render && render.freeCanvas(); render = ltjs.MapRender( ctx, tile_set ); render.render( map_set.getMapByNumber( 1 ) ); } // temporary document.getElementById( 'new' ).onclick = function() { game.className = game.className.replace( ' opening', '' ); gamechk(); }; } )();