Skip to content

Commit e13085e

Browse files
committed
Ability to choose game and hopefully offline mode
1 parent 4ead563 commit e13085e

File tree

7 files changed

+76
-19
lines changed

7 files changed

+76
-19
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ list.c
55
tags
66
wingames.lst
77
Puzzles.js
8+
cache.manifest

emscripten.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,17 @@ static void pick_preset(void)
250250
}
251251
*/
252252

253+
void c_callback(const char *name,int id,int sel);
254+
void populate_game_menu()
255+
{
256+
int i;
257+
for(i=0;i<gamecount;i++) {
258+
c_callback(gamelist[i]->name, i, 0);
259+
}
260+
}
261+
253262
void populate_type_menu()
254263
{
255-
void c_callback(char *name,int id,int sel);
256264
int num = midend_num_presets(fe->me);
257265
int i;
258266
int sel = midend_which_preset(fe->me);
@@ -319,6 +327,15 @@ void em_puzzle_init(void)
319327
em_new_game();
320328
}
321329

330+
void change_game(int id)
331+
{
332+
midend_free(fe->me);
333+
fe->game = gamelist[id];
334+
fe->me = midend_new(fe, fe->game, &drapi, fe);
335+
snaffle_colours(fe);
336+
em_new_game();
337+
}
338+
322339
void get_random_seed(void **randseed, int *randseedsize)
323340
{
324341
float *r = snew(float);

emscripten.js

+50-15
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function mouseup(e) {
3030
return false;
3131
}
3232

33-
function choose_type() {
33+
function do_menu(callback, populate) {
3434
var menu = document.createElement("div");
3535
menu.className = "ontopmenu";
3636
var list = document.createElement("div");
@@ -44,7 +44,48 @@ function choose_type() {
4444
}
4545
}
4646

47-
set_callback(function(name, i, sel) {
47+
var o = {list: list, hide_menu: hide_menu};
48+
49+
set_callback(callback.bind(o));
50+
populate();
51+
52+
document.body.appendChild(menu);
53+
menu.tabIndex = 100;
54+
menu.focus();
55+
menu.onblur = function() {
56+
/* setTimeout needed so clicking the radio buttons works
57+
* as the click will cause a loss of focus */
58+
setTimeout(hide_menu, 100);
59+
}
60+
}
61+
62+
function choose_game() {
63+
do_menu(function(name, i) {
64+
var hide_menu = this.hide_menu;
65+
name = Pointer_stringify(name);
66+
var div = document.createElement("div");
67+
var radio = document.createElement("input");
68+
radio.type = "radio";
69+
radio.name = 'game';
70+
var label = document.createElement("label");
71+
var img = document.createElement("img");
72+
img.src = "web-icons/"+name+".png";
73+
label.appendChild(img);
74+
label.appendChild(radio);
75+
label.appendChild(document.createTextNode(name));
76+
div.appendChild(label);
77+
this.list.appendChild(div);
78+
label.onclick = function() {
79+
hide_menu();
80+
location.hash = name;
81+
_change_game(i);
82+
};
83+
}, _populate_game_menu);
84+
}
85+
86+
function choose_type() {
87+
do_menu(function(name, i, sel) {
88+
var hide_menu = this.hide_menu;
4889
name = Pointer_stringify(name);
4990
var div = document.createElement("div");
5091
var radio = document.createElement("input");
@@ -55,29 +96,23 @@ function choose_type() {
5596
label.appendChild(radio);
5697
label.appendChild(document.createTextNode(name));
5798
div.appendChild(label);
58-
list.appendChild(div);
99+
this.list.appendChild(div);
59100
label.onclick = function() {
60101
hide_menu();
61102
_set_preset(i);
62-
}
63-
});
64-
_populate_type_menu();
65-
66-
document.body.appendChild(menu);
67-
menu.tabIndex = 100;
68-
menu.focus();
69-
menu.onblur = function() {
70-
/* setTimeout needed so clicking the radio buttons works
71-
* as the click will cause a loss of focus */
72-
setTimeout(hide_menu, 100);
73-
}
103+
};
104+
}, _populate_type_menu);
74105
}
75106

76107
function setup_menu() {
77108
var menu = document.getElementById("menu");
109+
var gamemenu = document.createElement("button");
78110
var typemenu = document.createElement("button");
111+
gamemenu.appendChild(document.createTextNode("Game"));
79112
typemenu.appendChild(document.createTextNode("Type"));
113+
menu.appendChild(gamemenu);
80114
menu.appendChild(typemenu);
115+
gamemenu.onclick = choose_game;
81116
typemenu.onclick = choose_type;
82117
}
83118

mkfiles.pl

+6-2
Original file line numberDiff line numberDiff line change
@@ -1671,8 +1671,8 @@ sub manpages {
16711671
(join " ", map {"-I$dirpfx$_"} @srcdirs) .
16721672
" \$(CFLAGS)")."\n".
16731673
"\n";
1674-
print &splitline("all:" . join "", map { " \$(BINPREFIX)$_.js" }
1675-
&progrealnames("MX"));
1674+
print &splitline("all:" . (join "", map { " \$(BINPREFIX)$_.js" }
1675+
&progrealnames("MX")) . " cache.manifest");
16761676
print "\n\n";
16771677
foreach $p (&prognames("MX")) {
16781678
($prog, $type) = split ",", $p;
@@ -1695,6 +1695,10 @@ sub manpages {
16951695
" -c \$< -o \$\@\n";
16961696
}
16971697

1698+
print "cache.manifest: puzzle.html Puzzles.js web-icons/*.png\n";
1699+
print "\techo CACHE MANIFEST > cache.new\n";
1700+
print "\t".'md5sum $+ | sed "s/\(.*\) \(.*\)/\2 # \1/" >> cache.new'."\n";
1701+
print "\tmv cache.new cache.manifest\n";
16981702
print "\n";
16991703
print $makefile_extra{'emscripten'} || "";
17001704
print "\nclean:\n".

puzzle.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<html>
1+
<html manifest="cache.manifest">
22
<head>
33
<style>
44
body {margin: 0px;}

web-icons/Bridges.png

23.7 KB
Loading

web-icons/Map.png

11.4 KB
Loading

0 commit comments

Comments
 (0)