Skip to content

Commit 58547ef

Browse files
committed
Improved texts in info box
Improved texts in info box
1 parent e0de821 commit 58547ef

File tree

6 files changed

+85
-6
lines changed

6 files changed

+85
-6
lines changed

bin/lcdgame.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,28 @@ LCDGame.Game.prototype = {
763763
xhr.send();
764764
},
765765

766+
tinyMarkDown: function(str) {
767+
// \n => <br/>
768+
str = str.replace(/\n/gi, "<br/>");
769+
770+
// *bold* => <b>bold</b>
771+
str = str.replace(/\*.*?\*/g, function(foo){
772+
return "<b>"+foo.slice(1, -1)+"</b>";
773+
});
774+
775+
// _italic_ => <i>italic</i>
776+
str = str.replace(/\_.*?\_/g, function(foo){
777+
return "<i>"+foo.slice(1, -1)+"</i>";
778+
});
779+
780+
// [button] => <btn>button</btn>
781+
str = str.replace(/\[.*?\]/g, function(foo){
782+
return "<btn>"+foo.slice(1, -1)+"</btn>";
783+
});
784+
785+
return str;
786+
},
787+
766788
// -------------------------------------
767789
// metadata load JSON file
768790
// -------------------------------------
@@ -771,7 +793,8 @@ LCDGame.Game.prototype = {
771793
this.metadata = data;
772794

773795
// infobox content
774-
this.infocontent.innerHTML = "<h1>" + data.gameinfo.device.title + "</h1><br/>" + data.gameinfo.instructions.en;
796+
var instr = this.tinyMarkDown(data.gameinfo.instructions.en);
797+
this.infocontent.innerHTML = "<h1>" + data.gameinfo.device.title + "</h1><br/>" + instr;
775798

776799
// get info from metadata
777800
var title = data.gameinfo.device.title
@@ -1240,7 +1263,7 @@ LCDGame.Game.prototype = {
12401263
//this.context2d.fillStyle = "#fff";
12411264
//this.context2d.fillText(index, this.gamedata.frames[index].xpos, this.gamedata.frames[index].ypos);
12421265
},
1243-
1266+
12441267
debugText: function(str, x, y) {
12451268
// set font
12461269
this.context2d.font = "bold 12px sans-serif";

css/lcdstyle.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ td:nth-child(3) {
2222
text-align: right;
2323
}
2424

25+
btn {
26+
display: inline-block;
27+
margin: 0 .1em;
28+
padding: .1em .6em;
29+
font-family: Arial,"Helvetica Neue",Helvetica,sans-serif;
30+
line-height: 1.4;
31+
color: #242729;
32+
text-shadow: 0 1px 0 #FFF;
33+
background-color: #e1e3e5;
34+
border: 1px solid #adb3b9;
35+
border-radius: 3px;
36+
box-shadow: 0 1px 0 rgba(12,13,14,0.2), 0 0 0 2px #FFF inset;
37+
white-space: nowrap;
38+
}
39+
2540
.container {
2641
}
2742

games/highway/metadata/gameinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"game 1", "game 2"
1717
],
1818
"instructions": {
19-
"en": "Avoid obstacles, pick up hitchhiker on the left and drop them off at sign on the right. Drop off 3 hitchhikers for a bonus game, get 3 identical numers for bonus."
19+
"en": "Avoid obstacles, pick up hitchhiker on the left and drop them off at sign on the right. Drop off 3 hitchhikers for a bonus game, get 3 identical numers for bonus.\n\nPress [Mode] to select game mode,\nthen [< Left] or [Right >] to start the game.\nYou can also press keyboard cursors left and right to move."
2020
}
2121
}
2222
}

games/mariobros/metadata/gameinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"game A", "game B"
1717
],
1818
"instructions": {
19-
"en": "Move Mario and Luigi up and down the bottling factory to safely get the crates into the truck. Fill the truck with 8 crates to complete the level."
19+
"en": "Move Mario and Luigi up and down the bottling factory to safely get the crates into the truck. Fill the truck with 8 crates to complete the level.\n\nPress [Game A] or [Game B] to start the game.\nPress [Q]/[A] to move Luigi and [P]/[L] to move Mario."
2020
}
2121
}
2222
}

games/searanger/metadata/gameinfo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"pro 1", "pro 2"
1717
],
1818
"instructions": {
19-
"en": "Move left and right to avoid coconuts, boats, sharks and birds. When lifesaver drops down, move to the right to escape on the boat."
19+
"en": "Move left and right to avoid coconuts, boats, sharks and birds. When lifesaver drops down, move to the right to escape on the boat.\n\nPress [Mode] and then [Game A/B] to select 'pro1' or 'pro2', then press [Start] to start the game. You can also press keyboard cursors left and right to move."
2020
}
2121
}
2222
}

src/Game.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,28 @@ LCDGame.Game.prototype = {
311311
xhr.send();
312312
},
313313

314+
tinyMarkDown: function(str) {
315+
// \n => <br/>
316+
str = str.replace(/\n/gi, "<br/>");
317+
318+
// *bold* => <b>bold</b>
319+
str = str.replace(/\*.*?\*/g, function(foo){
320+
return "<b>"+foo.slice(1, -1)+"</b>";
321+
});
322+
323+
// _italic_ => <i>italic</i>
324+
str = str.replace(/\_.*?\_/g, function(foo){
325+
return "<i>"+foo.slice(1, -1)+"</i>";
326+
});
327+
328+
// [button] => <btn>button</btn>
329+
str = str.replace(/\[.*?\]/g, function(foo){
330+
return "<btn>"+foo.slice(1, -1)+"</btn>";
331+
});
332+
333+
return str;
334+
},
335+
314336
// -------------------------------------
315337
// metadata load JSON file
316338
// -------------------------------------
@@ -319,7 +341,8 @@ LCDGame.Game.prototype = {
319341
this.metadata = data;
320342

321343
// infobox content
322-
this.infocontent.innerHTML = "<h1>" + data.gameinfo.device.title + "</h1><br/>" + data.gameinfo.instructions.en;
344+
var instr = this.tinyMarkDown(data.gameinfo.instructions.en);
345+
this.infocontent.innerHTML = "<h1>" + data.gameinfo.device.title + "</h1><br/>" + instr;
323346

324347
// get info from metadata
325348
var title = data.gameinfo.device.title
@@ -789,6 +812,24 @@ LCDGame.Game.prototype = {
789812
//this.context2d.fillText(index, this.gamedata.frames[index].xpos, this.gamedata.frames[index].ypos);
790813
},
791814

815+
debugText: function(str, x, y) {
816+
// set font
817+
this.context2d.font = "bold 12px sans-serif";
818+
819+
var lineheight = 15;
820+
var lines = str.split('\n');
821+
822+
for (var i = 0; i<lines.length; i++) {
823+
// shadow text
824+
this.context2d.fillStyle = "#000";
825+
this.context2d.fillText(lines[i], x+2, y+2);
826+
// white text
827+
this.context2d.fillStyle = "#fff";
828+
this.context2d.fillText(lines[i], x, y);
829+
y = y + lineheight;
830+
};
831+
},
832+
792833
// -------------------------------------
793834
// buttons input through keyboard
794835
// -------------------------------------

0 commit comments

Comments
 (0)