From efbdd28c6f809a1a4e1a82463d6c9c599315b2b0 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 10 Feb 2018 18:51:03 +0900 Subject: [PATCH] =?UTF-8?q?json=EC=9C=BC=EB=A1=9C=20=EB=B0=9B=EC=95=84?= =?UTF-8?q?=EC=98=A8=20=EB=82=B4=EC=9A=A9=EC=9D=84=20=EC=B6=9C=EB=A0=A5?= =?UTF-8?q?=ED=95=98=EA=B8=B4=20=EC=9C=84=ED=95=9C=20template=20=EC=A4=80?= =?UTF-8?q?=EB=B9=84=20common.js=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EB=A9=94=EC=8B=9C=EC=A7=80=EB=A5=BC=20=EB=B3=80=ED=99=98?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20msg=5Ftemplate.html?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tmp_map/map.html | 1 + tmp_msg/msg.html | 1 + tmp_msg/msg.js | 65 +++++++++++++++++++++-- tmp_msg/tmp_template.html | 49 +++++++++++++++++ twe/a_status.php | 1 + twe/b_diplomacy.php | 1 + twe/index.php | 1 + twe/js/base_map.js | 36 ------------- twe/js/common.js | 109 ++++++++++++++++++++++++++++++++++++++ twe/processing.php | 1 + 10 files changed, 224 insertions(+), 41 deletions(-) create mode 100644 tmp_msg/tmp_template.html create mode 100644 twe/js/common.js diff --git a/tmp_map/map.html b/tmp_map/map.html index d4071195..37706b26 100644 --- a/tmp_map/map.html +++ b/tmp_map/map.html @@ -5,6 +5,7 @@ + diff --git a/tmp_msg/msg.html b/tmp_msg/msg.html index 961c2645..b3c1bb39 100644 --- a/tmp_msg/msg.html +++ b/tmp_msg/msg.html @@ -5,6 +5,7 @@ + diff --git a/tmp_msg/msg.js b/tmp_msg/msg.js index dac2d41c..9ea064cb 100644 --- a/tmp_msg/msg.js +++ b/tmp_msg/msg.js @@ -1,11 +1,66 @@ + + +//FIXME: ES6 template literal을 ES5에 맞게 변경 +var messageTemplate = ` + + bgcolor="#CC6600" + <%} else if(msgType == 'national') {%> + bgcolor="#336600" + <%} else /*$msgType == 'public'*/ {%> + bgcolor="#000055" + <%} %> + style="font-size:13px;table-layout:fixed;word-break:break-all;" + data-id="<%id%>" +> + + + + +
+ <%if(src.iconPath !== null) { %> + + <%} else {%> + /*NOTE: image 폴더는 어느 단에서 다뤄야하는가? */ + <%}%> + + <%if(msgType == 'private') {%> + [ + <%e(src.name)%>:<%e(src.nation)%> + ▶ + <%e(dest.name)%>:<%e(dest.nation)%> + ] + <%} else if(msgType == 'national') {%> + [ + <%e(src.name)%>:<%e(src.nation)%> + ▶ + <%e(dest.nation)%> + ] + <%} else {%> + [ + <%e(src.name)%>:<%e(src.nation)%> + ] + <%} %> + <<%e($datetime)%>> +
+ <%e(message)%> +
+`; + jQuery(function($){ var generalID=1; var sequence =null; -}); - - -function refreshMsg(){ + function refreshMsg(){ -} \ No newline at end of file + } + + refreshMsg(); +}); \ No newline at end of file diff --git a/tmp_msg/tmp_template.html b/tmp_msg/tmp_template.html new file mode 100644 index 00000000..dded576a --- /dev/null +++ b/tmp_msg/tmp_template.html @@ -0,0 +1,49 @@ + + bgcolor="#CC6600" + <%} else if(msgType == 'national') {%> + bgcolor="#336600" + <%} else /*$msgType == 'public'*/ {%> + bgcolor="#000055" + <%} %> + style="font-size:13px;table-layout:fixed;word-break:break-all;" + data-id="<%id%>" +> + + + + +
+ <%if(src.iconPath !== null) { %> + + <%} else {%> + /*NOTE: image 폴더는 어느 단에서 다뤄야하는가? */ + <%}%> + + <%if(msgType == 'private') {%> + [ + <%e(src.name)%>:<%e(src.nation)%> + ▶ + <%e(dest.name)%>:<%e(dest.nation)%> + ] + <%} else if(msgType == 'national') {%> + [ + <%e(src.name)%>:<%e(src.nation)%> + ▶ + <%e(dest.nation)%> + ] + <%} else {%> + [ + <%e(src.name)%>:<%e(src.nation)%> + ] + <%} %> + <<%e($datetime)%>> +
+ <%e(message)%> +
\ No newline at end of file diff --git a/twe/a_status.php b/twe/a_status.php index 71ef307e..cad3073a 100644 --- a/twe/a_status.php +++ b/twe/a_status.php @@ -25,6 +25,7 @@ if($con >= 2) { printLimitMsg($me['turntime']); exit(); } 세력도 + + + diff --git a/twe/js/base_map.js b/twe/js/base_map.js index 3acfb72b..a7e1bc49 100644 --- a/twe/js/base_map.js +++ b/twe/js/base_map.js @@ -1,40 +1,4 @@ -function convertDictById(arr){ - var result = {}; - arr.forEach(function(v, i){ - result[v.id] = v; - }); - return result; -} -function convertSet(arr){ - var result = {}; - arr.forEach(function(v){ - result[v] = v; - }); - return result; -} - -function convColorValue(color){ - if(color.charAt(0) == '#'){ - color = color.substr(1); - } - color = color.toUpperCase(); - - var colorBase = convertSet([ - '000080', '0000FF', '008000', '008080', '00BFFF', '00FF00', '00FFFF', '20B2AA', - '2E8B57', '483D8B', '6495ED', '7B68EE', '7CFC00', '7FFFD4', '800000', '800080', - '808000', '87CEEB', 'A0522D', 'A9A9A9', 'AFEEEE', 'BA55D3', 'E0FFFF', 'F5F5DC', - 'FF0000', 'FF00FF', 'FF6347', 'FFA500', 'FFC0CB', 'FFD700', 'FFDAB9', 'FFFF00', - 'FFFFFF' - ]); - - if(!colorBase.hasOwnProperty(color)){ - return '000000'; - } - - return color; - -} function getCityPosition(){ return { diff --git a/twe/js/common.js b/twe/js/common.js new file mode 100644 index 00000000..27b486bf --- /dev/null +++ b/twe/js/common.js @@ -0,0 +1,109 @@ +/** + * <>& 등을 html에서도 그대로 보이도록 escape주는 함수 + * @see https://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery + * @param {string} string escape하고자 하는 문자열 + * @returns {string} +*/ +var escapeHtml = (function (string) { + var entityMap = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''', + '/': '/', + '`': '`', + '=': '=' + }; + + return function(string) { + return String(string).replace(/[&<>"'`=\/]/g, function(s) { + return entityMap[s]; + }); + } +})(); + + +/** + * object의 array를 id를 key로 삼는 object로 재 변환 + * @param {Array.{id: Object}} arr id를 가진 object의 array + * @returns {Object} + */ +function convertDictById(arr) { + var result = {}; + arr.forEach(function (v, i) { + result[v.id] = v; + }); + return result; +} + +/** + * array를 set 형태의 object로 변환 + * @param {Array} arr 값을 가진 array + * @returns {Object} + */ +function convertSet(arr) { + var result = {}; + arr.forEach(function (v) { + result[v] = true; + }); + return result; +} + +/** + * 게임내에서 지원하는 color type만 선택할 수 있도록 해주는 함수 + * @param {string} color #AAAAAA 또는 AAAAAA 형태로 작성된 RGB hex color string + * @returns {string} + */ +function convColorValue(color) { + if (color.charAt(0) == '#') { + color = color.substr(1); + } + color = color.toUpperCase(); + + var colorBase = convertSet([ + '000080', '0000FF', '008000', '008080', '00BFFF', '00FF00', '00FFFF', '20B2AA', + '2E8B57', '483D8B', '6495ED', '7B68EE', '7CFC00', '7FFFD4', '800000', '800080', + '808000', '87CEEB', 'A0522D', 'A9A9A9', 'AFEEEE', 'BA55D3', 'E0FFFF', 'F5F5DC', + 'FF0000', 'FF00FF', 'FF6347', 'FFA500', 'FFC0CB', 'FFD700', 'FFDAB9', 'FFFF00', + 'FFFFFF' + ]); + + if (!colorBase.hasOwnProperty(color)) { + return '000000'; + } + + return color; + +} + +/** + * 단순한 Template 함수. <%변수명%>으로 template 가능 + * @see https://github.com/krasimir/absurd/blob/master/lib/processors/html/helpers/TemplateEngine.js + * @param {string} html + * @param {object} options + * @returns {string} + */ +var TemplateEngine = function (html, options) { + var re = /<%(.+?)%>/g, + reExp = /(^( )?(var|if|for|else|switch|case|break|{|}|;))(.*)?/g, + code = 'with(obj) { var r=[];\n', + cursor = 0, + result, + match; + var add = function (line, js) { + js ? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : + (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : ''); + return add; + } + options.e = escapeHtml; + while (match = re.exec(html)) { + add(html.slice(cursor, match.index))(match[1], true); + cursor = match.index + match[0].length; + } + add(html.substr(cursor, html.length - cursor)); + code = (code + 'return r.join(""); }').replace(/[\r\t\n]/g, ' '); + try { result = new Function('obj', code).apply(options, [options]); } + catch (err) { console.error("'" + err.message + "'", " in \n\nCode:\n", code, "\n"); } + return result; +} \ No newline at end of file diff --git a/twe/processing.php b/twe/processing.php index 5978a30d..362eea3e 100644 --- a/twe/processing.php +++ b/twe/processing.php @@ -118,6 +118,7 @@ function starter($name, $type=0) { +