ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/html5client/main.js
(Generate patch)

Comparing deliantra/html5client/main.js (file contents):
Revision 1.15 by sf-demisephi, Wed Nov 7 19:54:04 2012 UTC vs.
Revision 1.16 by sf-demisephi, Wed Nov 7 21:15:28 2012 UTC

311 311
312 for (var i = 0;i<255;++i){ 312 for (var i = 0;i<255;++i){
313 keys.states[i]=0; 313 keys.states[i]=0;
314 }; 314 };
315 315
316
317
318
316 if (isMainCalled==true){ 319 if (isMainCalled==true){
317 return; 320 return;
318 } 321 }
319 isMainCalled = true; 322 isMainCalled = true;
320 323
1380 doSend('exti ["resource",'+exti.getNextId()+',"exp_table"]'); 1383 doSend('exti ["resource",'+exti.getNextId()+',"exp_table"]');
1381 1384
1382 1385
1383 }else if (replyID==101){ 1386 }else if (replyID==101){
1384 expTableFacenum = parseInt(o[1]); 1387 expTableFacenum = parseInt(o[1]);
1388
1389 Faces.request(expTableFacenum,"json",function (tileInfo){expTable=(tileInfo.resource);});
1390
1391
1385 doSend ('exti ["resource",'+exti.getNextId() + ',"exp_table", "skill_info", "spell_paths"]'); 1392 doSend ('exti ["resource",'+exti.getNextId() + ', "skill_info", "spell_paths","command_help"]');
1386 }else if (replyID==102){ 1393 }else if (replyID==102){
1394
1395 Faces.request(parseInt(o[1]),"json",function (faceInfo){skillNames=(faceInfo.resource);});
1396 Faces.request(parseInt(o[2]),"json",function (faceInfo){spellPaths=(faceInfo.resource);});
1397 Faces.request(parseInt(o[3]),"json",function (faceInfo){commandsAll=(faceInfo.resource);});
1387 doSend("addme"); 1398 doSend("addme");
1399
1388 } 1400 }
1389 else{ 1401 else{
1390 1402
1391 } 1403 }
1392 1404
1800 this.isPending = false; 1812 this.isPending = false;
1801 this.isRequested = false; 1813 this.isRequested = false;
1802 this.requestedBy = ""; 1814 this.requestedBy = "";
1803 this.resource = null; 1815 this.resource = null;
1804 this.json = "{}"; 1816 this.json = "{}";
1817 this.afterLoad = [];
1805} 1818}
1806 1819
1807FaceInfo.prototype.request = function (rby){ 1820FaceInfo.prototype.request = function (rby){
1808 this.isRequested = true; 1821 this.isRequested = true;
1809 this.requestedBy = rby; 1822 this.requestedBy = rby;
1823
1824
1810 if ((this.name=="")) 1825 if ((this.name==""))
1811 return this; 1826 return this;
1812 1827
1813 if ((!this.isPending) && (!this.isLoading)){ 1828 if ((!this.isPending) && (!this.isLoading)){
1814
1815
1816 this.load(); 1829 this.load();
1817 } 1830 }
1818 1831
1832 return this;
1833};
1834
1835FaceInfo.prototype.appendOnLoad = function (f){
1836
1837 if (typeof(f) == typeof(function(){})){
1838 this.afterLoad.push (f);
1839 }
1819 return this; 1840 return this;
1820}; 1841};
1821 1842
1822FaceInfo.prototype.setName = function (name){ 1843FaceInfo.prototype.setName = function (name){
1823 this.name = name; 1844 this.name = name;
1828 this.type = parseInt(type); 1849 this.type = parseInt(type);
1829 return this; 1850 return this;
1830}; 1851};
1831 1852
1832FaceInfo.prototype.load = function (){ 1853FaceInfo.prototype.load = function (){
1854
1833 this.isPending = true; 1855 this.isPending = true;
1856
1834 Faces.load (this); 1857 Faces.load (this);
1835 1858
1836} 1859}
1837FaceInfo.prototype.onload = function (){ 1860FaceInfo.prototype.onload = function (){
1838 this.isPending = false; 1861 this.isPending = false;
1839 this.isLoading = false; 1862 this.isLoading = false;
1840 1863
1864 var o = this;
1865 this.afterLoad.each (function (e,i){
1866 e(o);
1867 });
1841 Faces.onload(this); 1868 Faces.onload(this);
1842} 1869}
1843FaceInfo.prototype.loadStart = function (){ 1870FaceInfo.prototype.loadStart = function (){
1844 1871
1845 this.isPending = false; 1872 this.isPending = false;
1877 getByNum : function (id,createIfNotExist){ 1904 getByNum : function (id,createIfNotExist){
1878 if (createIfNotExist) 1905 if (createIfNotExist)
1879 return Faces.byNum[id] ? Faces.byNum[id] : Faces.add(id); 1906 return Faces.byNum[id] ? Faces.byNum[id] : Faces.add(id);
1880 return Faces.byNum[id] ? Faces.byNum[id] : null; 1907 return Faces.byNum[id] ? Faces.byNum[id] : null;
1881 }, 1908 },
1882 request : function (id,by){ 1909 request : function (id,by,f){
1883 return this.getByNum(id,true).request(by); 1910 return this.getByNum(id,true).appendOnLoad(f).request(by);
1884 }, 1911 },
1885 1912
1886 load : function (faceInfo){ 1913 load : function (faceInfo){
1887 if (this.nDownloads<this.MAXDOWNLOADS){ 1914 if (this.nDownloads<this.MAXDOWNLOADS){
1888 this.nDownloads++ 1915 this.nDownloads++
2054 dy += parseInt(data.shift()); 2081 dy += parseInt(data.shift());
2055 2082
2056 2083
2057} 2084}
2058 2085
2059function $_(p){ 2086function $_(p,o){
2060 if (document.getElementById(p)!=null){ 2087 if (document.getElementById(p)!=null){
2061 return document.getElementById(p); 2088 return document.getElementById(p);
2062 }else{ 2089 }else{
2063 var ret = document.createElement(p); 2090 var ret = document.createElement(p);
2064 unselectable(ret); 2091 unselectable(ret);
2092 if (o&&o.css){
2093 var s="";
2094 for (var s in o.css){
2095 if (typeof(o.css[s])==typeof("")||typeof(o.css[s])==typeof(1)){
2096 ret.style[s] = o.css[s];
2097 }
2098 }
2099 }
2065 return ret; 2100 return ret;
2066 } 2101 }
2067} 2102}
2068var tiles = []; 2103var tiles = [];
2069 2104
2089 websocket.send( 2124 websocket.send(
2090 String.fromCharCode (message.length >> 8) 2125 String.fromCharCode (message.length >> 8)
2091 + String.fromCharCode (message.length & 255) 2126 + String.fromCharCode (message.length & 255)
2092 + message 2127 + message
2093 ); 2128 );
2129}
2130
2131/**
2132 * Command console
2133 */
2134
2135var xCommandContainer = null;
2136var xCommandLine = null;
2137var xCommandLines = null;
2138var command = "";
2139var lastCommand = "";
2140var firstOption = null;
2141var commandsAll = [];
2142
2143function commandLineOnKeyDown (e){
2144 if (e.keyCode==13){
2145 skipKeyTest = false;
2146
2147 doSend("command " + this.value);
2148 command = "";
2149 lastCommand = this.value;
2150
2151
2152 document.getElementsByTagName("body")[0].removeChild(xCommandContainer);
2153
2154 } else if (e.keyCode==27){
2155 command = "";
2156 skipKeyTest = false;
2157
2158 document.getElementsByTagName("body")[0].removeChild(xCommandContainer);
2159
2160 } else {
2161 //messageBox(JSON.stringify(commandsAll));
2162 }
2163}
2164
2165function autoComplete (keyCode){
2166 if (xCommandContainer==null){
2167 xCommandContainer =$_("div",{css:{position:"absolute",left:(stage.stageWidth/2)+"px",top:(stage.stageHeight/2)+"px"}});
2168
2169 xCommandLine = $_("input");
2170
2171 xCommandLine.addEventListener("keydown",commandLineOnKeyDown);
2172
2173 xCommandContainer.appendChild(xCommandLine);
2174 xCommandContainer.appendChild($_("br"));
2175
2176 xCommandLines = $_("select");
2177 xCommandLines.height = 5;
2178
2179 xCommandContainer.appendChild(xCommandLines);
2180
2181
2182 }
2183 if (command == ""){
2184 skipKeyTest = true;
2185 appendToBody(xCommandContainer);
2186 try {
2187 xCommandLine.focus();
2188 }catch (e){
2189
2190 }
2191 }
2192 command+=String.fromCharCode(keyCode).toLowerCase();
2193 xCommandLine.value = command;
2094} 2194}
2095 2195
2096 2196
2097/** 2197/**
2098 * Key up/down handlers 2198 * Key up/down handlers
2259 break; 2359 break;
2260 default: 2360 default:
2261 //messageBox(e.keyCode); 2361 //messageBox(e.keyCode);
2262 break; 2362 break;
2263 } 2363 }
2264 2364 if ((keyCode>="A".charCodeAt(0))&&(keyCode<="Z".charCodeAt(0))){
2365 autoComplete(keyCode); //launch command console
2366 }
2265} 2367}
2266 2368
2267/* 2369/*
2268 * UTILS 2370 * UTILS
2269 */ 2371 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines