Correct JS function order.

main
Roy 2 years ago
parent a965706a35
commit b24a94352b
  1. 11
      chess_gui/lib/chess_gui.pm
  2. 24
      chess_gui/public/js/dand.js
  3. 10
      chess_gui/public/js/head.js

@ -715,7 +715,6 @@ my ($pval, $called_player, $reason) = @_; # Arguments: (Value of all pieces of $
} }
sub PROGRAM { sub PROGRAM {
my $sessid = $_[2]{'id'};
$user_mode = 0; $user_mode = 0;
# if (!defined($user_mode)) { # if (!defined($user_mode)) {
# print 'Please input your side:', "\n"; # print 'Please input your side:', "\n";
@ -757,12 +756,12 @@ $user_mode = 0;
($xrc, $yrc) = split //, $_[1]; ($xrc, $yrc) = split //, $_[1];
$_[1] = join '.', $pxr{$xrc}, ($yrc-1); $_[1] = join '.', $pxr{$xrc}, ($yrc-1);
print $_[0], ' ', $_[1], "\n"; print $_[0], ' ', $_[1], "\n";
($prio, @id[0, 1], $selection, $ice, $n_o_selections) = &MOVEMENT_TREE($player, $depth, undef, undef, undef, undef, undef, $_[0], $_[1], $sessid); ($prio, @id[0, 1], $selection, $ice, $n_o_selections) = &MOVEMENT_TREE($player, $depth, undef, undef, undef, undef, undef, $_[0], $_[1], $_[2]);
print 'w ', $id[0], ' ', $id[1], "\n"; print 'w ', $id[0], ' ', $id[1], "\n";
} else { } else {
$depth = 2; # Usually about 20^$depth possibilities (but ten times as much iterates for including no movement). $depth = 2; # Usually about 20^$depth possibilities (but ten times as much iterates for including no movement).
($prio, @id[0, 1], $selection, $ice, $n_o_selections) = &MOVEMENT_TREE($player, $depth, undef, undef, undef, undef, undef, undef, undef, $sessid); ($prio, @id[0, 1], $selection, $ice, $n_o_selections) = &MOVEMENT_TREE($player, $depth, undef, undef, undef, undef, undef, undef, undef, $_[2]);
$sth10->execute($sessid, @id[0, 1]); $sth10->execute($_[2], @id[0, 1]);
print 'b ', $id[0], ' ', $id[1], "\n"; print 'b ', $id[0], ' ', $id[1], "\n";
} }
# print 'keys: ', scalar keys %key_list_by_value, "\n"; # print 'keys: ', scalar keys %key_list_by_value, "\n";
@ -934,7 +933,7 @@ get '/board/init' => sub {
get '/move/:src/:dst' => sub { get '/move/:src/:dst' => sub {
#if (session('init')) { #if (session('init')) {
my %diff = &PROGRAM(route_parameters->get('src'), route_parameters->get('dst'), session); # Includes player input. my %diff = &PROGRAM(route_parameters->get('src'), route_parameters->get('dst'), session->id); # Includes player input.
encode_json(\%diff); encode_json(\%diff);
#} #}
}; };
@ -945,8 +944,6 @@ get '/' => sub {
#any ['get', 'post'] => '/' => sub { #any ['get', 'post'] => '/' => sub {
# my $session = session; # TODO: I only want %{session}{'id'}.
# $session = %{$session}{'id'};
# $sth11->execute($session); # $sth11->execute($session);
#print $session, "\n"; #print $session, "\n";
# my @sth11 = $sth11->fetchrow_array(); # my @sth11 = $sth11->fetchrow_array();

@ -1,6 +1,3 @@
var d;
var drag;
var drop;
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
//var e = document.createElement('li'); //var e = document.createElement('li');
//var f = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']; //var f = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
@ -44,17 +41,7 @@ i++;
} }
} }
onload = function () { function dragAndDrop(drag, drop) {
for (var b=0; C('coord').length > b; b++) {C('coord')[b].onmousedown = function () {
event.preventDefault();
drag = this.id;
}}
}
for (var c=0; C('coord').length > c; c++) {C('coord')[c].onmouseup = function () {
drop = this.id;
//console.log(this.id);
if (drag.length === 2 && drop.length === 2) { // Shouldn't rely on legal input here.
xhr.open('GET', 'move/' + drag + '/' + drop , true); xhr.open('GET', 'move/' + drag + '/' + drop , true);
xhr.send(null); xhr.send(null);
xhr.onload = function () { xhr.onload = function () {
@ -171,11 +158,16 @@ d.appendChild(li);
//I('description').innerHTML = responseObject.Black.status[1]; //I('description').innerHTML = responseObject.Black.status[1];
} }
} }
};
}
} }
//for (b=0; C('coord').length > b; b++) {C('coord')[b].onmousemove = function () { //for (b=0; C('coord').length > b; b++) {C('coord')[b].onmousemove = function () {
//if (drag !== null && drag !== undefined) {console.log(this.x + '.' + this.y)} //if (drag !== null && drag !== undefined) {console.log(this.x + '.' + this.y)}
//if (drag !== null && drag !== undefined) {I(this.id).style.position = 'absolute'; I(this.id).style.left = this.x + 'px'; I(this.id).style.up = this.y + 'px'} //if (drag !== null && drag !== undefined) {I(this.id).style.position = 'absolute'; I(this.id).style.left = this.x + 'px'; I(this.id).style.up = this.y + 'px'}
//}} //}}
//window.onload = function () {
//for (var b=0; C('coord').length > b; b++) {C('coord')[b].onmousedown = function () {
//event.preventDefault();
//drag = this.id;
//}}
//}

@ -52,4 +52,14 @@ li.innerHTML = srci; // Add.
} }
} }
} }
postG();
}
function postG () {
var drag;
var drop;
for (var b=0; C('coord').length > b; b++) {
C('coord')[b].onmousedown = function () {event.preventDefault(); drag = this.id}
C('coord')[b].onmouseup = function () {drop = this.id; if (drag.length === 2 && drop.length === 2) {dragAndDrop(drag, drop)}} // Shouldn't rely on legal input here.
}
} }

Loading…
Cancel
Save