Source

namethatanime / templates / gamenew.html

Full commit
{% extends "base.html" %}
{% block headmore %}
<script type="text/javascript" src="/static/swfobject.js"></script>
<script type="text/javascript" src="/static/web_socket.js"></script>
<script type="text/javascript" src="/static/soundmanager2/soundmanager2-nodebug-jsmin.js"></script>
<!--<script type="text/javascript" src="/static/soundmanager2/soundmanager2.js"></script>-->
<script type="text/javascript" src="/static/js/ntt.js"></script>
<script type="text/javascript" src="/static/js/jquery.hotkeys.js"></script>
<style>
.container
{
	width:960px;
}
</style>
{% end %}
    
{% block nav %}
            <li class="active"><a href="/">Home</a></li>
            <li><a href="/about">About</a></li>
            <li><a href="/contact">Contact</a></li>
            {% if user %}
				<li><a href="/donate">Donate</a></li>
			{% end %}
{% end %}

{% block container %}
<div class="content">
        <div class="page-header">
         <h1>Single Player Game</h1>
        </div>
        <div class="row">
          <div class="span16">			   
			<div id="ready"><a href="#" id="plready" class="btn primary large">Ready</a><span id="rstatus">Turn off music players or other audio sources and click ready to start the game!</span></div>
			
			<div id="question">
				
			</div>
			<br/><br/>
			<div class="row">
				<div id="points" class="span5">
					
				</div>
				<div id="lastsong" class="offset1 span10">

				</div>
			</div>					
          </div>          
        </div>
        <div id="soundmanager-debug"></div>
      </div>

{% end %}

{% block scripts %}
<script>
	
window.switchFade = function () {
	if ($('#ready').is(":visible")) {
		if ($('#plready').css('opacity') < 1) {
			$('#plready').fadeTo("fast", 1, function() {
				setTimeout("switchFade();",500);
			});
		} else {
			$('#plready').fadeTo("fast", 0.5, function() {
				setTimeout("switchFade();",500);
			});
		}
	}
};
	
$(document).ready(function() {

	//ws = new WebSocket('ws://' + location.hostname + ':' + location.port + '/ws{{ player.name }}/get');
	ws = new WebSocket('ws://namethatanime.net:7777/ws{{ player.name }}/get');

    
    update('points');    
    update('debug');

    ws.onmessage = function(msg) {
		console.log("jest msg=" + msg.data)
		if (msg.data == '!gs') {
			clearInterval(counter);
			delay = false;
			count = 30;
			points = 10;
			soundManager.setPosition('song', 0);
			soundManager.play('song');		
			update('question');		
			counter=setInterval("timer()",1000);		
		}
		else if (msg.data.startsWith("!rl")) {
			update(msg.data.substr(3, msg.data.length));
		}
		else if (msg.data.startsWith("!ge")) {
			update('lastsong');
			$('#timeandpoints').html('Game ends in 3 sec...');
		}
		else if (msg.data.startsWith("!rb")) {
			update('lastsong');
			update('question');	
			clearInterval(counter);		
			$("#ptssec").text('Round Break');		
			$("#plready").removeAttr("disabled");
			$('#rstatus').text('Click ready to start next round');
			$('#ready').show('slow');
			$('#plready').fadeTo('slow', 0.5, function() {
			  switchFade();
			});
		}
		else if (msg.data.startsWith("!de")) {
			update('lastsong');
			update('question');
			delay = true;
			clearInterval(counter);
			count = 4;
			counter=setInterval("timer()",1000);	
			$("#ptssec").text('Break');
		}
		else if (msg.data == '!st') {		
			soundManager.destroySound('song');		
		}
		else if (msg.data.startsWith("!l")) {
			loadsong(msg.data.substr(2, msg.data.length));
		}
		else {
				$('#chat').prepend(msg.data + '<br/>');
		}
    };
    
    /*
    soundManager.onready(function() {
		// SM2 is ready to go!
	   soundManager.createSound({
		  id: 'song',
		  url: 'http://www.multiworldproject.com/media/uploads/songs/66d9827f-86e2-4445-b33c-99795853ae84.mp4',
		  autoLoad: false,
		  autoPlay: false,
		  onload: function() {
			  alert('ok!');
			ws.send("!rdy");
		  },
		  volume: 30,
		  multiShot: false,
		  stream: false
		});
		soundManager.load('song');	
	});
	*/
	$('#plready').fadeTo('slow', 0.5, function() {
		  switchFade();
	});
		
	$("#quitgame").click(function() {
				window.location.href = "{{ player.game.url }}/end";						
			});
	$("#plready").click(function() {					
				$(this).attr('disabled', 'disabled');
				$('#rstatus').text('You are ready!');				
				setTimeout("$('#ready').hide('slow');",1250);
				setTimeout("ws.send('!plrdy');",1250); // Just to be safe
				setTimeout("ws.send('!plrdy');",2250); // Just to be safe
				if ($("#ptssec").text() == 'Round Break') {
					$('#timeandpoints').html("<img src='/static/images/ajax-loader.gif' width='32px' height='32px' />");
				}
				ws.send("!plrdy");				
			});
			
	$(document).bind('keypress', '1', function(){
	  $('#a0').click();
	});
	$(document).bind('keypress', '2', function(){
	  $('#a1').click();
	});
	$(document).bind('keypress', '3', function(){
	  $('#a2').click();
	});
	$(document).bind('keypress', '4', function(){
	  $('#a3').click();
	});
	$(document).bind('keypress', '5', function(){
	  $('#a4').click();
	});

});
</script>
{% end %}