Skip to content

Commit 26265e8

Browse files
committed
Removes TBS which is overkill.
Implement autoinc text. Improves zh localisation. Implement SetCell undo.
1 parent cfe6bf7 commit 26265e8

19 files changed

+218
-8779
lines changed

html/change.log

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ TODO
66
* Chinese localisation
77

88
== 2012-08: Bug fix and usability enhancements ==
9-
2012-08-19: Add fixed palette
10-
2012-08-18: Export would left pad single ASCII characters in a cell
11-
2012-08-15: Move layer box to the right
12-
2012-08-08: Fix dropper bug preventing other tools from being selected
9+
2012-08-22: Add text auto-increment. Map data is trimmed before save/export. Amend Chinese Localisation.
10+
2012-08-19: Add fixed palette.
11+
2012-08-18: Export would left pad single ASCII characters in a cell.
12+
2012-08-15: Move layer box to the right.
13+
2012-08-08: Fix dropper bug preventing other tools from being selected.
1314

1415
== 2011-12: Server side implementation and usabiliy ==
1516
2011-12-08: Fix typo breaking client sync. Fix webkit export compatibility.

html/map_template.html

+50-51
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
77
<script>
88
if (!window.$) document.write('<script src="../html/res/jquery.js"></sc'+'ript>');
9+
window.arena = {};
910
</script>
1011
</head><body
1112
onmousedown='arena.event.documentMouseUpDown(event)'
@@ -18,15 +19,13 @@
1819
<table id='map'><tbody><tr><td style='width: auto; max-width: none; font-size:x-large; padding:2em 4em'>Please wait a few seconds.</td><tr></tbody></table>
1920

2021
<table id='statusbar' unselectable="on"><tr>
21-
<td id='hint' colspan='6'>
22-
<b>Requires <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">IE 8</a>, <a href="http://www.mozilla.com/firefox/">Firefox</a> 3, or <a href="http://www.opera.com/">Opera</a> 9</b>. <a href="http://www.apple.com/safari/">Safari</a> 4 and <a href="http://www.google.com/chrome/">Chrome</a> 1 works partially.
23-
</td>
22+
<td id='hint' colspan='6'></td>
2423
</tr><tr>
2524
<td id='current_foreground'></td>
2625
<td id='current_background'></td>
2726
<td id='coordinate_status'>X:-- Y:--</td>
2827
<!--td id='dimension_status'>[--x--]</td-->
29-
<td id='status'>[var.lang.welcome_status; htmlconv=no]</td>
28+
<td id='status'></td>
3029
<td id='debug' onclick='this.innerHTML=""'></td>
3130
</tr></table>
3231

@@ -68,54 +67,55 @@
6867
</div>
6968

7069
<div id='layer' class='floatbox'>
70+
<center><b>Layers</b></center>
7171
<div class='tool' onclick='arena.event.addLayerOnClick(event)' onmouseover='arena.ui.hint("tool|barhint_AddLayer")' >+</div>
7272
<div class='tool' onclick='arena.event.delLayerOnClick(event)' onmouseover='arena.ui.hint("tool|barhint_DelLayer")' >-</div>
7373
<div class='tool' onclick='arena.event.upLayerOnClick(event)' onmouseover='arena.ui.hint("tool|barhint_LayerUp")' >^</div>
7474
<div class='tool' onclick='arena.event.downLayerOnClick(event)' onmouseover='arena.ui.hint("tool|barhint_LayerDown")'>v</div>
7575
</div>
7676

77-
<!--script>
78-
(function(){ /* Can't make it load at beginning */
79-
var lang = 'en';
80-
try {
81-
var l = navigator.language;
82-
if ( l ) {
83-
var l = /(?:^|;)(en|zh)(?=-|$|;)/.exec( navigator.language );
84-
if ( l ) lang = l[0];
85-
}
86-
} catch (err) {
87-
}
88-
var e = document.createElement('script');
89-
e.src = '../html/res/lang/'+lang+'.js?ver=[var.out.app_version]';
90-
alert('pause');
91-
document.body.insertBefore( e, document.getElementById('firstScript') );
92-
window.arena = {};
93-
})()
94-
</script-->
9577
<script src='../html/res/lang/en.js?ver=[var.out.app_version]'></script>
96-
<script src='../html/res/lang/[var.out.language].js?ver=[var.out.app_version]'></script>
78+
<script src='../html/res/lang/zh.js?ver=[var.out.app_version]'></script>
79+
<script>(function(){ "strict mode";
80+
if ( arena.lang ) {
81+
/** Tried to dynamically insert but always loaded after existing scripts,
82+
* we need the error messages to load before them, so just load all languages first. */
83+
var lang = location.search.match( /[?&]lang=(\w+)($|&)/ );
84+
if ( lang ) {
85+
lang = lang[1];
86+
} else {
87+
lang = navigator.language || navigator.userLanguage;
88+
}
89+
if ( lang &&lang.match( /^zh(-.+)?$/ ) ) {
90+
arena.lang = arena.lang.zh;
91+
} else {
92+
arena.lang = arena.lang.en;
93+
}
94+
document.getElementById('hint').innerHTML = arena.lang.ui.initial;
95+
}
96+
})()</script>
9797
<script src='../html/res/model.js?ver=[var.out.app_version]'></script>
9898
<script src='../html/res/ui.js?ver=[var.out.app_version]'></script>
9999
<script src='../html/res/tools.js?ver=[var.out.app_version]'></script>
100100
<script src='../html/res/commands.js?ver=[var.out.app_version]'></script>
101101
<script src='../html/res/io.js?ver=[var.out.app_version]'></script>
102-
<script>
103-
(function(){ "strict mode";
104-
if (!window.arena || !arena.lang || !arena.ui || !arena.map || !arena.tools || !arena.commands || !arena.io || !arena.sharing ) {
105-
var str = "[var.lang.err_IncompleteLoad]";
106-
if (str.substring(0,1) == "[")
107-
str = "Cannot load. Check that browsers is up to date and refresh.";
108-
document.getElementById('hint').innerHTML = str;
109-
} else {
110-
arena.ui.createColourPalette();
111-
arena.ui.createGlyphs();
112-
arena.reset();
113-
arena.ui.updateButtons();
114-
}
115-
document.close();
116-
})();
117-
</script><noscript>
102+
<script>(function(){ "strict mode";
103+
if (!window.arena || !arena.lang || !arena.ui || !arena.map || !arena.tools || !arena.commands || !arena.io || !arena.sharing ) {
104+
document.getElementById('hint').innerHTML =
105+
arena && arena.lang && arena.lang && arena.lang.error && arena.lang.error.IncompleteLoad
106+
? arena.lang.error.IncompleteLoad
107+
: "Cannot load. Check that browsers is up to date and refresh.";
108+
} else {
109+
// All modules loaded, setup map.
110+
arena.ui.createColourPalette();
111+
arena.ui.createGlyphs();
112+
arena.reset();
113+
arena.ui.updateButtons();
114+
}
115+
document.close();
116+
})();</script><noscript>
118117
<p>Please enable JavaScript.</p>
118+
<p>請啓用 JavaScript.</p>
119119
</noscript>
120120

121121
<div id='mask'></div>
@@ -207,19 +207,18 @@ <h2 id='titleData'>Data</h2>
207207
<script src='../html/res/rawinflate.js'></script>
208208
<script src='../html/res/rawdeflate.js'></script>
209209
<script src='../html/res/base64.js'></script>
210-
<script>"strict mode";
211-
if ( arena && arena.io ) arena.io.autoLoad();
212-
</script>
213210
<!--script src='http://jsonip.appspot.com/?callback=getip'></script-->
214211
<script>"strict mode";
215-
if (location.host && location.host != "localhost") {
216-
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
217-
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'%3E%3C/script%3E"));
218-
}
219-
try {
220-
var pageTracker = _gat._getTracker("UA-9070778-1");
221-
pageTracker._trackPageview();
222-
} catch(err) {}
223-
document.close()</script>
212+
if ( arena && arena.io ) arena.io.autoLoad();
213+
if ( location.host && location.host != "localhost" ) {
214+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
215+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js'%3E%3C/script%3E"));
216+
}
217+
try {
218+
var pageTracker = _gat._getTracker("UA-9070778-1");
219+
pageTracker._trackPageview();
220+
} catch(err) {}
221+
document.close()
222+
</script>
224223

225224
</body></html>

html/res/commands.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,52 @@ arena.commands.SetMask.prototype = {
204204
}
205205

206206
arena.commands.SetCell.prototype = {
207+
text: undefined,
208+
foreground: undefined,
209+
background: undefined,
210+
lastText: undefined,
207211
redo : function() {
212+
var text = this.text, txt;
213+
if ( text && ( txt = text.match( /^.*?([a-zA-Z0-9]+).*?\+\+$/ ) ) ) {
214+
txt = txt[1];
215+
var overflow = false;
216+
function incChar( chr ) {
217+
overflow = true;
218+
if ( chr === '9' ) return '0';
219+
if ( chr === 'z' ) return 'a';
220+
if ( chr === 'Z' ) return 'A';
221+
overflow = false;
222+
return String.fromCharCode( chr.charCodeAt(0) + 1 );
223+
}
224+
var newTxt = txt.split("");
225+
var pos = txt.length-1;
226+
// Increase alpha from the end, cascading to front
227+
newTxt[pos] = incChar( newTxt[pos] );
228+
while ( overflow && pos > 0 ) {
229+
--pos;
230+
newTxt[pos] = incChar( newTxt[pos] );
231+
}
232+
// If overflowing from one character to two, allow it
233+
if ( overflow && text.length === 3 )
234+
newTxt.unshift( newTxt[0] === '0' ? '1' : ( newTxt[0] === 'A' ? 'A' : 'a' ) );
235+
// Update text
236+
arena.ui.setText( text.replace( txt, newTxt.join("") ) );
237+
this.lastText = text;
238+
text = text.replace( /\+\+$/, '' );
239+
}
240+
208241
var l = this.coList.length;
209242
var undoData = this.undoData ? null : [];
210243
for (var i = 0; i < l; i++) {
244+
// Get coordinate list and undo data
211245
var m = this.coList[i];
212246
var orig = this.layer.get(m[0], m[1]);
213247
if (undoData)
214248
undoData.push( orig ? orig.clone({}) : null );
249+
// Get and set cell
215250
var c = orig ? orig : this.layer.createCell(m[0], m[1]);
216-
c.setIf(this);
251+
c.setIf( text, this.foreground, this.background );
252+
// Process text
217253
}
218254
if (undoData) // Don't double set because consolidated coordinate list may overlap
219255
this.undoData = undoData;
@@ -232,6 +268,7 @@ arena.commands.SetCell.prototype = {
232268
}
233269
}
234270
arena.map.repaint(this.coList);
271+
if ( this.lastText ) arena.ui.setText( this.lastText );
235272
},
236273
consolidate : function(newCmd) {
237274
if (newCmd.className != this.className

html/res/io.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ arena.io = {
143143

144144
/** Get save data of this map */
145145
getSaveData : function(map) {
146+
for ( var i in map.layers ) map.layers[i].trim();
146147
return {
147148
id: 'sheepy.arena.20101025.', // data structure version, shouldn't change unless structure change.
148149
data: {
@@ -372,7 +373,7 @@ arena.io = {
372373

373374

374375
/************************** Export **********************************/
375-
376+
376377
normaliseSize : function ( txt ) {
377378
// Make sure txt takes up two character's space
378379
if ( txt.length === 1 ) {

html/res/lang/en.js

+31-23
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/********************** JavaScript Arena, english language resource *****************************/
22

3-
window.arena = {};
3+
if ( ! arena.lang ) arena.lang = {};
44

5-
arena.lang = {
5+
arena.lang.en = {
66

77
tool : {
88
usehint_text : '[Text] Drag: Draw text in colour. Shift: Draw text and background.',
@@ -14,35 +14,30 @@ arena.lang = {
1414
usehint_dropper : '[Dropper] Click: Get text and foreground colour. Shift: text and background.',
1515

1616
barhint_NewMap : 'Create a new map. Will discard existing map.',
17-
barhint_ImportExport : 'Export map in various text formats, or import from exported Json data.',
17+
barhint_ImportExport : 'Export/Import map. Long press Ctrl to export with last config.',
1818
barhint_SaveLoad: 'Save / load map locally in browser',
1919
barhint_rotateClock : 'Rotate whole map clockwise 90 degree. Ctrl: Anti-clockwise.',
2020
//barhint_Layer : 'Click to select layer to draw. Top layer show first.',
2121
//barhint_UsingLayer : 'You are drawing on this layer.',
2222
barhint_Foreground : 'Drawing in this foreground colour. Click to fill current mask.',
23-
//barhint_Background : 'Drawing in this background colour. Click to fill current mask.',
2423
barhint_Sync : 'Sync map to viewers. Double click to setup sharing.',
25-
barhint_MapInput : 'Brush text for text tool. Click or press Enter to set text.',
24+
barhint_MapInput : 'Brush text for text tool. Click or press Enter to set text. End text with \'++\' to auto increment text.',
2625
barhint_Colour : 'Click to set foreground, Ctrl/Shift+Click to fill foreground/background of selected area.',
27-
//barhint_NoColour : 'No colour : Use lower layer\'s colour.',
28-
//barhint_ReverseColour : 'Reverse colour : Reverse lower layer\'s colour.',
2926
barhint_Undo : 'Undo last command (Ctrl+Z)',
3027
barhint_Redo : 'Redo next command (Ctrl+Y)',
31-
barhint_Layer : 'Click to work with this layer. Double-click to toggle visibility.',
28+
barhint_Layer : 'Click to work with this layer. Double-click to toggle visibility. Shift+Minus/Plus to change layer.',
3229
barhint_toolText : 'Text tool, draw text on current layer. (T) Press Enter to set text before draw.',
3330
barhint_toolBrush : 'Brush tool, paint background on current layer. (B)',
3431
barhint_toolEraser : 'Eraser tool, erase stuff from curent layer. (E)',
3532
barhint_toolMask : 'Rectangle mask tool, limit paint area or move masked area of current layer. (R) Double click: Mask Layer / Reduce mask. (R)',
3633
barhint_toolMove : 'Move tool, move similiar area. (M)',
3734
barhint_toolDropper: 'Dropper tool, get colours and text of current cell. (O)',
3835
barhint_brushSize : 'Brush size. (+/-)',
39-
//barhint_viewLayer : 'View layer list. Shift+Minus/Plus to move between layers.',
40-
//barhint_viewGlyph : 'View glyph list.',
4136

42-
barhint_AddLayer : 'Add top layer',
43-
barhint_DelLayer : 'Delete currnet layer',
44-
barhint_LayerUp : 'Move currnet layer up',
45-
barhint_LayerDown : 'Move currnet layer down',
37+
barhint_AddLayer : 'Add new layer.',
38+
barhint_DelLayer : 'Delete currnet layer.',
39+
barhint_LayerUp : 'Move currnet layer up.',
40+
barhint_LayerDown : 'Move currnet layer down.',
4641
barhint_Glyph : 'Click to set brush text, Ctrl+Click to draw text in current mask.',
4742

4843
dlghint_TextPrompt : 'Enter text to draw:',
@@ -60,9 +55,13 @@ arena.lang = {
6055
dlghint_CopyJson : 'Export in JSON. Layers are preserved, suitable for long-term map storage.',
6156
},
6257

58+
ui: {
59+
initial: '<b>Requires <a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">IE 8+</a>, Latest <a href="http://www.mozilla.com/firefox/">Firefox</a>, or latest <a href="http://www.opera.com/">Opera</a></b>. <a href="http://www.apple.com/safari/">Safari</a> and <a href="http://www.google.com/chrome/">Chrome</a> may fails to save/load. <a href="http://goddessfantasy.net/sheepy/arena/archive/arena.2012-08-19.7z">Download Source</a>.',
60+
},
61+
6362
command : {
64-
undo : "Undo %s",
65-
redo : "Redo %s",
63+
undo : "Undo %s.",
64+
redo : "Redo %s.",
6665

6766
name_SetMask : 'Set Mask',
6867
name_SetCell : 'Set',
@@ -96,20 +95,23 @@ arena.lang = {
9695
},
9796

9897
error : {
98+
// Not all modules are loaded
99+
IncompleteLoad: 'Cannot load. Check that browsers is up to date, clear cache, and then refresh.',
100+
99101
// Drawing error
100102
NoMask : 'Where should I draw? Please select an area first.',
101103

102104
// Sync error
103-
TitleEmpty : 'Title must not be empty',
104-
AdminEmpty : 'Master password must not be empty',
105-
AdminViewerSame : 'Master password must not be same with viewer password',
106-
TitleExists : 'A shared map with same title already exists',
105+
TitleEmpty : 'Title must not be empty.',
106+
AdminEmpty : 'Master password must not be empty.',
107+
AdminViewerSame : 'Master password must not be same with viewer password.',
108+
TitleExists : 'A shared map with same title already exists.',
107109
MalformedData : 'Malformed data.',
108110

109111
// S/L error
110-
NoHost : 'Save/load unavailable (Host not found). Blame HTML5 spec.',
112+
NoHost : 'Save/load unavailable (Host not found).',
111113
NoLocalStorage : 'No LocalStorage facility. Please upgrade browser or enable offline storage.',
112-
SaveNotFound : 'Cannot find saved map',
114+
SaveNotFound : 'Cannot find saved map.',
113115

114116
// I/O error
115117
CannotRestore : 'Cannot restore map.',
@@ -118,7 +120,13 @@ arena.lang = {
118120
NoDeflate : 'Cannot load zip library. Please reload.',
119121
},
120122

121-
123+
layers : [
124+
'Terrain',
125+
'Effects',
126+
'Objects',
127+
'Creatures',
128+
'Overlay',
129+
],
122130

123131
palette : { /** Colour palettle. Same as mIRC. */
124132
/*

0 commit comments

Comments
 (0)