2012-03-21 00:48:31 -04:00
|
|
|
/**
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2015-12-21 00:41:34 -05:00
|
|
|
"use strict";
|
|
|
|
|
2012-03-21 00:48:31 -04:00
|
|
|
( function()
|
|
|
|
{
|
2015-12-21 00:41:34 -05:00
|
|
|
/* jshint browser:true */
|
|
|
|
/* global lasertank */
|
2012-03-21 00:48:31 -04:00
|
|
|
|
2015-12-21 00:47:39 -05:00
|
|
|
const ltg_input = document.getElementById( 'ltg' ),
|
|
|
|
lvl_input = document.getElementById( 'lvl' ),
|
|
|
|
|
|
|
|
load_ltg = lasertank.FileLoader( ltg_input, new window.FileReader() ),
|
|
|
|
load_lvl = lasertank.FileLoader( lvl_input, new window.FileReader() ),
|
2012-03-24 23:09:20 -04:00
|
|
|
|
2015-12-21 00:41:34 -05:00
|
|
|
ele_game = document.getElementById( 'game' ),
|
|
|
|
ctx = document.getElementById( 'render' ).getContext( '2d' );
|
2012-03-27 21:34:33 -04:00
|
|
|
|
2015-12-21 00:41:34 -05:00
|
|
|
let ltg_data = '',
|
2012-03-27 21:34:33 -04:00
|
|
|
lvl_data = '';
|
2012-03-21 00:48:31 -04:00
|
|
|
|
|
|
|
|
2015-12-21 00:41:34 -05:00
|
|
|
// XXX: relies on side-effects of ctor
|
|
|
|
lasertank.ui.MenuBar( document.getElementById( 'menubar' ) );
|
|
|
|
|
|
|
|
|
2012-03-21 00:48:31 -04:00
|
|
|
load_ltg.onLoad( function( e, data )
|
|
|
|
{
|
|
|
|
if ( e ) throw e;
|
|
|
|
|
2012-03-27 21:34:33 -04:00
|
|
|
ltg_data = data;
|
|
|
|
gamechk();
|
2012-03-21 00:48:31 -04:00
|
|
|
} );
|
|
|
|
|
2015-12-21 00:41:34 -05:00
|
|
|
|
2012-03-21 00:48:31 -04:00
|
|
|
load_lvl.onLoad( function( e, data )
|
|
|
|
{
|
|
|
|
if ( e ) throw e;
|
|
|
|
|
2012-03-27 21:34:33 -04:00
|
|
|
lvl_data = data;
|
2012-03-21 00:48:31 -04:00
|
|
|
gamechk();
|
|
|
|
} );
|
|
|
|
|
2015-12-21 00:41:34 -05:00
|
|
|
|
2012-03-21 00:48:31 -04:00
|
|
|
function gamechk()
|
|
|
|
{
|
2012-03-27 21:34:33 -04:00
|
|
|
if ( !( ltg_data && lvl_data ) ) return;
|
2012-03-21 00:48:31 -04:00
|
|
|
|
2012-03-21 22:44:44 -04:00
|
|
|
// temporary
|
2012-03-27 21:34:33 -04:00
|
|
|
if ( ele_game.className.search( 'opening' ) > -1 ) return;
|
2012-03-21 00:48:31 -04:00
|
|
|
|
2015-12-20 00:32:41 -05:00
|
|
|
lasertank.ClassicGame( ltg_data, lvl_data )
|
2012-03-27 21:34:33 -04:00
|
|
|
.on( 'ready', function()
|
|
|
|
{
|
2015-12-21 00:20:36 -05:00
|
|
|
this.renderTo( ctx, window );
|
2012-03-27 21:34:33 -04:00
|
|
|
} );
|
2012-03-21 00:48:31 -04:00
|
|
|
}
|
|
|
|
|
2015-12-21 00:41:34 -05:00
|
|
|
|
2012-03-21 22:44:44 -04:00
|
|
|
// temporary
|
2012-03-21 23:22:53 -04:00
|
|
|
document.getElementById( 'new' ).onclick = function()
|
2012-03-21 22:44:44 -04:00
|
|
|
{
|
2012-03-27 21:34:33 -04:00
|
|
|
ele_game.className = ele_game.className.replace( ' opening', '' );
|
2012-03-21 22:44:44 -04:00
|
|
|
gamechk();
|
|
|
|
};
|
|
|
|
|
2012-03-21 00:48:31 -04:00
|
|
|
} )();
|