var zg = zg || {}; var G = G || {}; var Game = Game || {}; zg.Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", ekey: "s912edgh9187272dg1297127ddfiuhzvclkzxkcvj1-09djh20eu0=pw[]l,2e12;", decode:function(input) { var output = [], chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0, l=input.length, keyStr=zg.Base64._keyStr; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < l) { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output.push(String.fromCharCode(chr1)); if (enc3 !== 64) { output.push(String.fromCharCode(chr2)); } if (enc4 !== 64) { output.push(String.fromCharCode(chr3)); } } output = output.join(''); return output; }, my64decode:function(input) { var output = [], chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0, epos = 0, l=input.length, ekey=zg.Base64.ekey, keyStr=zg.Base64._keyStr; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < l) { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output.push(String.fromCharCode(chr1 ^ ekey.charCodeAt(epos++))); if(ekey[epos] == ';') epos = 0; if (enc3 !== 64) { output.push(String.fromCharCode(chr2 ^ ekey.charCodeAt(epos++))); if(ekey[epos] == ';') epos = 0; } if (enc4 !== 64) { output.push(String.fromCharCode(chr3 ^ ekey.charCodeAt(epos++))); if(ekey[epos] == ';') epos = 0; } } output = output.join(''); return output; } } zg.base64decode = zg.Base64.decode; zg.my64decode = zg.Base64.my64decode; const TEXT_LEFT = 0; const TEXT_CENTER = 1; const TEXT_RIGHT = 2; const ALIGN_LEFT = 0; const ALIGN_CENTER = 1; const ALIGN_RIGHT = 2; const M_PI = 3.14159; const M_DEG = 0.01745327; const M_ROTATE = 57.2958279; const NOTI_BOOL=0; const NOTI_INT=1; const NOTI_DOUBLE=2; const NOTI_STRING=3; const NOTI_OBJECT=4; const FADE_OUT =0xff; const FADE_DARK =0xdc; const FADE_IN =0; const IS_WIN = 1; const IS_ANDROID = 0; const IS_IOS = 0; const OS_WIN=0; const OS_ANDROID=1; const OS_IOS=2; function encode_utf8(s) { return unescape(encodeURIComponent(s)); } function decode_utf8(s) { return decodeURIComponent(escape(s)); } function js_urlencode(s) { return encodeURIComponent(decodeURIComponent(escape(s))); } cc.associateWithNative = function(rec, rec2) {} cc.RED = {r:255, g:0, b:0}; cc.GREEN = {r:0, g:255, b:0}; cc.BLUE = {r:0, g:0, b:255}; cc.BLACK = {r:0, g:0, b:0}; cc.WHITE = {r:255, g:255, b:255}; cc.YELLOW = {r:255, g:255, b:0}; cc.easeSineIn = cc.EaseSineIn.create; cc.easeElasticIn = cc.EaseElasticIn.create; cc.easeElasticOut = cc.EaseElasticOut.create; cc.easeIn = cc.EaseIn.create; cc.easeOut = cc.EaseOut.create; _proto = cc.Node.prototype; cc.defineGetterSetter(_proto, "pos", _proto.getPosition, _proto.setPosition); strlen = function(str) { if(!str) return 0; return str.length; } G.getLang = function() { return cc.sys.language; } G.jellyTouchScale = 0.85; G.setJellyTouchScale = function(fScale) { G.jellyTouchScale = fScale; } G.getLanguage = function() { switch(cc.sys.language) { case cc.sys.LANGUAGE_ENGLISH : return "english"; case cc.sys.LANGUAGE_CHINESE : return "chinese"; case cc.sys.LANGUAGE_FRENCH : return "french"; case cc.sys.LANGUAGE_ITALIAN : return "italian"; case cc.sys.LANGUAGE_GERMAN : return "german"; case cc.sys.LANGUAGE_SPANISH : return "spanish"; case cc.sys.LANGUAGE_DUTCH : return "dutch"; case cc.sys.LANGUAGE_RUSSIAN : return "russian"; case cc.sys.LANGUAGE_KOREAN : return "korean"; case cc.sys.LANGUAGE_JAPANESE : return "japanese"; case cc.sys.LANGUAGE_HUNGARIAN : return "hungarian"; case cc.sys.LANGUAGE_PORTUGUESE : return "portuguese"; case cc.sys.LANGUAGE_ARABIC : return "arabic"; case cc.sys.LANGUAGE_NORWEGIAN : return "norwegian"; case cc.sys.LANGUAGE_POLISH : return "polish"; case cc.sys.LANGUAGE_UNKNOWN : return "polish"; default : return "english"; } } Game.lang = G.getLang(); Game.language = G.getLanguage(); Game.getScore = function(id) { return 0; } Game.sendEvent = function(id) { return 0; } Game.submitScore = function(name, score) { return 0; } // 네이티브 게임 호환성 위해 정의 function EmptyFunc() {}; Game.openInterstitial = EmptyFunc; Game.callJni = EmptyFunc; Game.callNative = EmptyFunc; Game.logoutGoogle = EmptyFunc Game.loginGoogle = EmptyFunc var AdMob = {}; AdMob.showSmartBanner = EmptyFunc; AdMob.hideSmartBanner = EmptyFunc; Game.os = OS_WIN; Game.onBackKeyClicked = function() { BackKey.apply(); } Game.run = function(main) { Game.main = main; Main = main; var statusLabel = new cc.LabelTTF("No keyboard event received!", "", 20); statusLabel.setPosition(200, 600); main.addChild(statusLabel); statusLabel.hide(); cc.eventManager.addListener({ event: cc.EventListener.KEYBOARD, onKeyPressed : Game.onKeyPressed.bind(Game) }, statusLabel); Noti.addS("BACKKEY_CLICKED", Game, Game.onBackKeyClicked); main.onMain.call(main); } Game.onKeyPressed = function(keyCode, event) { if(keyCode == 27) Noti.push("BACKKEY_CLICKED"); } zg.time = function() { return 0; } G.TFS = 1; G.TF = 1; G.RX = 0; G.RY = 0; G.isSound = function() { return true; } G.isMusic = function() { return true; } G.init = function(w, h, p) { G.W = w; G.H = h; G.RW = w; G.RH = h; G.X = 0; G.Y = 0; G.X2 = w-1; G.Y2 = h-1; G.RX = 0; G.RY = 0; G.TF = 1; G.TFS = 1.0; G.CX = w/2; G.CY = h/2; cc.view.setDesignResolutionSize(w, h, p); } cc.Node.prototype.hide = function () { this.setVisible(false); } cc.Node.prototype.show = function () { this.setVisible(true); } cc.Node.prototype.setHexColor = function (c) { this.setColor(hex2col(c)); } cc.Node.prototype.setColorHex = function (c) { this.setColor(hex2col(c)); } G.WHITE = cc.color(cc.color.WHITE); G.BLACK = cc.color(cc.color.BLACK); var EchoBuff = Array(); var EchoTxt = null; var cLayer = null; var TRACE_COLOR = G.WHITE; var TRACE_Y = 0; var TRACE_MAX = 30; var TRACE_FSIZE = 15; function trace(str) { if(str == null) str = "null"; else if(typeof str == "object") { try { // str = JSON.stringify(str); trace(""); return; } catch(e) { str = e } } // if(str.length > 50) // return; if(EchoTxt == null) { EchoTxt = cc.LabelTTF.create("", "Fixedsys", TRACE_FSIZE*G.TF); EchoTxt.setPosition( cc.p(10, G.Y2-30-TRACE_Y)); EchoTxt.setColor( TRACE_COLOR ); EchoTxt.setAnchorPoint(cc.p(0.0, 1.0)); EchoTxt.setHorizontalAlignment(cc.TEXT_ALIGNMENT_LEFT); EchoTxt.setVerticalAlignment(cc.VERTICAL_TEXT_ALIGNMENT_TOP); EchoTxt.setScale(G.TFS); // EchoTxt.setMaxLength(300, 0); cLayer.addChild(EchoTxt, 1024); } EchoBuff.push(str); var l = TRACE_MAX - EchoBuff.length; if(l < 0) { EchoBuff.shift(); } EchoTxt.setString(EchoBuff.join("\n")); } message = alert; function message_r(str) { alert(JSON.stringify(str)); } function dirname(path) { if(path.lastIndexOf("/")==-1) return "./"; return path.replace(/\\/g,'/').replace(/\/[^\/]*\/?$/, '') + "/"; } function int(str) { return parseInt(str||0); } function zContainsPoint(rect, point, nExtend) { var left = cc.rectGetMinX(rect); var top = cc.rectGetMaxY(rect); var right = cc.rectGetMaxX(rect); var bottom = cc.rectGetMinY(rect); if (point.x < left-nExtend) return false; if(point.x > right+nExtend) return false; if(point.y < bottom-nExtend) return false; if(point.y > top+nExtend) return false; left = null; top = null; right = null; bottom = null; rect = null; point = null; nExtend = null; return true; } zg.containsPoint = zContainsPoint; zg.isProbability = function(rate) { return (zg.rand(1, 1000)/10)<=rate; } /* cc.rectContainsPoint = function (rect, point) { return (point.x >= cc.rectGetMinX(rect) && point.x <= cc.rectGetMaxX(rect) && point.y >= cc.rectGetMinY(rect) && point.y <= cc.rectGetMaxY(rect)) ; };*/ function parse_str(str, array) { // discuss at: http://phpjs.org/functions/parse_str/ // original by: Cagri Ekin // improved by: Michael White (http://getsprink.com) // improved by: Jack // improved by: Brett Zamir (http://brett-zamir.me) // bugfixed by: Onno Marsman // bugfixed by: Brett Zamir (http://brett-zamir.me) // bugfixed by: stag019 // bugfixed by: Brett Zamir (http://brett-zamir.me) // bugfixed by: MIO_KODUKI (http://mio-koduki.blogspot.com/) // reimplemented by: stag019 // input by: Dreamer // input by: Zaide (http://zaidesthings.com/) // input by: David Pesta (http://davidpesta.com/) // input by: jeicquest // note: When no argument is specified, will put variables in global scope. // note: When a particular argument has been passed, and the returned value is different parse_str of PHP. For example, a=b=c&d====c // test: skip // example 1: var arr = {}; // example 1: parse_str('first=foo&second=bar', arr); // example 1: $result = arr // returns 1: { first: 'foo', second: 'bar' } // example 2: var arr = {}; // example 2: parse_str('str_a=Jack+and+Jill+didn%27t+see+the+well.', arr); // example 2: $result = arr // returns 2: { str_a: "Jack and Jill didn't see the well." } // example 3: var abc = {3:'a'}; // example 3: parse_str('abc[a][b]["c"]=def&abc[q]=t+5'); // returns 3: {"3":"a","a":{"b":{"c":"def"}},"q":"t 5"} var strArr = String(str) .replace(/^&/, '') .replace(/&$/, '') .split('&'), sal = strArr.length, i, j, ct, p, lastObj, obj, lastIter, undef, chr, tmp, key, value, postLeftBracketPos, keys, keysLen, fixStr = function(str) { return decodeURIComponent(str.replace(/\+/g, '%20')); }; if (!array) { array = this.window; } for (i = 0; i < sal; i++) { tmp = strArr[i].split('='); key = fixStr(tmp[0]); value = (tmp.length < 2) ? '' : fixStr(tmp[1]); while (key.charAt(0) === ' ') { key = key.slice(1); } if (key.indexOf('\x00') > -1) { key = key.slice(0, key.indexOf('\x00')); } if (key && key.charAt(0) !== '[') { keys = []; postLeftBracketPos = 0; for (j = 0; j < key.length; j++) { if (key.charAt(j) === '[' && !postLeftBracketPos) { postLeftBracketPos = j + 1; } else if (key.charAt(j) === ']') { if (postLeftBracketPos) { if (!keys.length) { keys.push(key.slice(0, postLeftBracketPos - 1)); } keys.push(key.substr(postLeftBracketPos, j - postLeftBracketPos)); postLeftBracketPos = 0; if (key.charAt(j + 1) !== '[') { break; } } } } if (!keys.length) { keys = [key]; } for (j = 0; j < keys[0].length; j++) { chr = keys[0].charAt(j); if (chr === ' ' || chr === '.' || chr === '[') { keys[0] = keys[0].substr(0, j) + '_' + keys[0].substr(j + 1); } if (chr === '[') { break; } } obj = array; for (j = 0, keysLen = keys.length; j < keysLen; j++) { key = keys[j].replace(/^['"]/, '') .replace(/['"]$/, ''); lastIter = j !== keys.length - 1; lastObj = obj; if ((key !== '' && key !== ' ') || j === 0) { if (obj[key] === undef) { obj[key] = {}; } obj = obj[key]; } else { // To insert new dimension ct = -1; for (p in obj) { if (obj.hasOwnProperty(p)) { if (+p > ct && p.match(/^\d+$/g)) { ct = +p; } } } key = ct + 1; } } lastObj[key] = value; } } } /*! sprintf.js | Copyright (c) 2007-2013 Alexandru Marasteanu | 3 clause BSD license */ var sprintf = function() { if (!sprintf.cache.hasOwnProperty(arguments[0])) { sprintf.cache[arguments[0]] = sprintf.parse(arguments[0]); } return sprintf.format.call(null, sprintf.cache[arguments[0]], arguments); }; sprintf.format = function(parse_tree, argv) { var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; for (i = 0; i < tree_length; i++) { node_type = get_type(parse_tree[i]); if (node_type === 'string') { output.push(parse_tree[i]); } else if (node_type === 'array') { match = parse_tree[i]; // convenience purposes only if (match[2]) { // keyword argument arg = argv[cursor]; for (k = 0; k < match[2].length; k++) { if (!arg.hasOwnProperty(match[2][k])) { throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); } arg = arg[match[2][k]]; } } else if (match[1]) { // positional argument (explicit) arg = argv[match[1]]; } else { // positional argument (implicit) arg = argv[cursor++]; } if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); } switch (match[8]) { case 'b': arg = arg.toString(2); break; case 'c': arg = String.fromCharCode(arg); break; case 'd': arg = parseInt(arg, 10); break; case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; case 'o': arg = arg.toString(8); break; case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; case 'u': arg = arg >>> 0; break; case 'x': arg = arg.toString(16); break; case 'X': arg = arg.toString(16).toUpperCase(); break; } arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; pad_length = match[6] - String(arg).length; pad = match[6] ? str_repeat(pad_character, pad_length) : ''; output.push(match[5] ? arg + pad : pad + arg); } } return output.join(''); }; sprintf.cache = {}; sprintf.parse = function(fmt) { var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; while (_fmt) { if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { parse_tree.push(match[0]); } else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { parse_tree.push('%'); } else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { if (match[2]) { arg_names |= 1; var field_list = [], replacement_field = match[2], field_match = []; if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { field_list.push(field_match[1]); while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { field_list.push(field_match[1]); } else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { field_list.push(field_match[1]); } else { throw('[sprintf] huh?'); } } } else { throw('[sprintf] huh?'); } match[2] = field_list; } else { arg_names |= 2; } if (arg_names === 3) { throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); } parse_tree.push(match); } else { throw('[sprintf] huh?'); } _fmt = _fmt.substring(match[0].length); } return parse_tree; }; var vsprintf = function(fmt, argv, _argv) { _argv = argv.slice(0); _argv.splice(0, 0, fmt); return sprintf.apply(null, _argv); }; var strfmt = sprintf; /** * helpers */ function get_type(variable) { return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); } function str_repeat(input, multiplier) { for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} return output.join(''); } function cstr(str) { return str ? str : ""; } zg.getDistance = function(x, y, tx, ty) { var diffX = tx - x; var diffY = ty - y; return Math.sqrt(diffX*diffX+diffY*diffY); } zg.pn = function(v, n) { return v * Math.abs(n)/n; } zg.getRotate = function(x, y, tx, ty) { var diffX = tx - x; var diffY = ty - y; return -(Math.atan2(diffY, diffX) * M_ROTATE); } zg.getRotate360 = function(x, y, tx, ty) { var diffX = tx - x; var diffY = ty - y; return Math.abs((-(Math.atan2(diffY, diffX) * M_ROTATE)+360)%360); } zg.wrand = function(s, e) { if(!e) return Math.floor(Math.random()*s); return Math.floor(Math.random()*(e-s+1)) + s; } zg.rand = function(s, e) { if(!e) return Math.floor(Math.random()*s); return Math.floor(Math.random()*(e-s+1)) + s; } function RandNo(objs, rnd, remove) { if(objs == null) return null; var obj; var totalRate = 0; var num = objs.length; var i; for(i=0; i= rndRate) { if(remove == true) objs.splice(i, 1); break; } } objs = null; rnd = null; remove = null; rndRate = null; rate = null; totalRate = null; num = null; i = null; return obj; } const TOUCH_INIT = 1; const TOUCH_BEGAN = 2; const TOUCH_ENDED = 4; const TOUCH_ROLLOVER = 8; const TOUCH_ROLLOUT = 16; const TOUCH_RELEASE = 32; const TOUCH_MOVED = 64; const TOUCH_CANCELED = 128; zg.Texture = cc.Class.extend({ pTexture:null, rect:null, anchor:null, frame:0, getWidth:function() { }, getHeight:function() { }, }); zg._Sprite = cc.Class.extend({ arrTexture:null, totalFrame:0, totalScene:0, db:null, ctor:function() { this.arrTexture = []; }, addTex:function(pTex) { this.arrTexture.push(pTex); this.totalScene++; this.totalFrame += pTex.frame; }, optimize:function(db) { this.db = db; /* return; this.totalScene = 0; this.totalFrame = 0; for(var i=0; this.arrTexture.length; i++) { // this.arrTexture[this.totalScene++] = this.arrTexture[i]; this.totalFrame += this.arrTexture[i].frame; } */ // this.arrTexture = null; }, getTexture:function() { return this.arrTexture[0].pTexture; }, setTexture:function(pTex) { this.arrTexture[0].pTexture = pTex; }, }); zg.Sprite = cc.Sprite.extend({ currentFrame:0, _currentFrame:0, currentScene:0, _currentScene:0, playIdx:0, pSprite:null, isPlay:false, ctor:function(pSpr) { this._super(); this.init_(); this.setSprite(pSpr); }, init_:function() { this.currentFrame = 1; this._currentFrame = 1; this.currentScene = 1; this._currentScene = 1; this.playIdx = 0; this.pSprite = null; this.isPlay = false; }, setSprite:function(pSpr) { if(pSpr == null) return; if(this.pSprite == null) { this.initWithTexture(pSpr.arrTexture[0].pTexture, pSpr.arrTexture[0].rect); } this.pSprite = pSpr; this.id = pSpr.id; this._currentScene = -1; this._currentFrame = -1; this.syncFrame(); }, setClip:function(fX, fY, fWidth, fHeight) { var texture = this.pSprite.arrTexture[this.currentScene-1]; var rect = cc.rect(cc.rectGetMinX(texture.rect)+fX, cc.rectGetMinY(texture.rect)+fY, fWidth, fHeight); this.setTextureRect(rect); texture = null; rect = null; }, frame2scene:function(frame) { var i; var addFrame = 0; for(i=0; i=0; i--) { this._arrSingleTouch[i].clearTouch(); } } cc.Layer.prototype.lockTouch = function() { this._listener1 = cc.EventListener.create({ event: cc.EventListener.TOUCH_ONE_BY_ONE, swallowTouches: true, onTouchBegan:function(touch, event) { var layer = event.getCurrentTarget(); if(layer.visible == false) { touch = null; event = null; return layer._lockEvent; } // onTouchOutSide 이벤트가 존재하면 처리하기... if(layer.onTouchOutSide) { if(layer._outsideSize) { var hw = layer._outsideSize.width>>1; var hh = layer._outsideSize.height>>1; var bl = layer.convertToWorldSpaceAR(cc.p(-hw, -hh)); layer._outsideRect = cc.rect(bl.x, bl.y, layer._outsideSize.width, layer._outsideSize.height); layer._outsideSize = null; } if(layer._outsideRect) { var pt = touch.getLocation(); layer._outsizeTouch = zg.containsPoint(layer._outsideRect, pt) ? null : pt; pt = null; } } if(layer.onTouchBegan_) return layer.onTouchBegan_.call(layer, touch, event); touch = null; event = null; return layer._lockEvent; }, onTouchEnded:function(touch, event) { var layer = event.getCurrentTarget(); if(layer.onTouchOutSide) { var pt = touch.getLocation(); if(layer._outsizeTouch && zg.containsPoint(layer._outsideRect, pt) == false) { if(zg.getDistance(layer._outsizeTouch, touch.getLocation()) < 30) { layer.onTouchOutSide.call(layer); } } } if(layer.onTouchEnded_) return layer.onTouchEnded_.call(layer, touch, event); return layer._lockEvent; }, }); cc.eventManager.addListener(this._listener1, this); this._lockEvent = true; } cc.Layer.prototype.unlockTouch = function() { if(this._lockEvent == false) return; cc.eventManager.removeListener(this._listener1); this._lockEvent = false; } cc.LabelTTF.prototype.setWidthScale = function (w) { this.scaleX = ((this.width/G.TF <= w) ? G.TFS : (w / this.width*G.TF) * G.TFS); } cc.intToCol = function (hex) { var r = hex >> 16; var g = (hex >> 8) % 256; var b = hex % 256; return cc.color(r, g, b); }; var hex2col = cc.intToCol; zg.col = function(c) { return hex2col(c); } zg.FontTTF = cc.Class.extend({ m_fScale:1.0, m_font:null, ctor:function() { }, setFont:function(font, fScale) { this.m_font = font; this.m_fScale = fScale; }, create:function(x, y, align, text, size, color) { var labelTTF; var fAlign = 0; var hAlignment = cc.TEXT_ALIGNMENT_LEFT; size *= this.m_fScale * G.TF; switch(align) { case TEXT_CENTER : fAlign = 0.5; hAlignment = cc.TEXT_ALIGNMENT_CENTER; break; case TEXT_RIGHT : fAlign = 1.0; hAlignment = cc.TEXT_ALIGNMENT_RIGHT; break; } labelTTF = cc.LabelTTF.create(text, "", size*G.TF); labelTTF.setPosition(x, y); labelTTF.setColor( hex2col(color||0xffffff)); labelTTF.setAnchorPoint(cc.p(fAlign, 0.5)); labelTTF.setScale(1.0/G.TF); return labelTTF; }, }); var BFont = new zg.FontTTF(); zg.base64decode = function(str) { return cc.Codec.Base64.decode(str); } zg.parseStr = function(str) { var ret = {}; var regex = /([\w \t]+)=\s*{!([^!]+[^}]+[^\n]+)/gi; var match; while((match = regex.exec(str))) { //파이어폭스 같은 브라우저가 무한 루프에 빠지는 것을 방지. if ( match.index == regex.lastIndex) regex.lastIndex++; ret[match[1].trim()] = match[2].trim().replace("!}", ""); } // 긴데이타 제거하기 NAME={! !} 이런 형태의 문자열 str = str.replace(/\n[\w \t]*#[^\n]+/g, ""); str = str.replace(/[\w \t]+=\s*{![^!]*[^}]+[^\n]+/g, ""); regex = /([\w \t]+)=([^\r\n]+)/gi; while((match = regex.exec(str))) { //파이어폭스 같은 브라우저가 무한 루프에 빠지는 것을 방지. if ( match.index == regex.lastIndex) regex.lastIndex++; ret[match[1].trim()] = match[2].trim(); } return ret; } /* zg.parseStr2("XXX={!10!}\nLEE=1\nLEE2={!xxx\nxx!}"); zg.parseStr = function(str) { var ret = {}; var parts = str.split("\n"); var list; for(var i=parts.length; i--; ) { list = parts[i].split("=", 2); if(list.length < 2) continue; ret[list[0]] = list[1].trim(); } return ret; } */ zg.mydecode = function(str) { if(str == null) return null; if(str.charAt(0) != "@") return zg.my64decode(str); return zg.my64decode((str.substring(1, str.length))); }, zg.ImageBox = cc.Layer.extend({ m_pSpr:null, m_fW:0, m_fH:0, m_fRound:0, m_anchorPoint:null, m_arrChild:null, ctor:function() { this._super(); this.m_anchorPoint = cc.p(0.5, 0.5); }, add:function(fX, fY, fAx, fAy, fClipX, fClipY, fClipWidth, fClipHeight) { var pBSpr; pBSpr = new zg.Sprite(); pBSpr.setSprite(this.m_pSpr); pBSpr.setClip(fClipX, fClipY, fClipWidth, fClipHeight); pBSpr.setAnchorPoint(fAx, fAy); pBSpr.targetX = fX; pBSpr.targetY = fY; this.addChild(pBSpr); return pBSpr; }, setAnchorPoint:function(fX, fY) { if(!this.m_arrChild) return; this.m_anchorPoint = cc.p(fX, fY); fX = -this.m_fW * fX; fY = -this.m_fH * fY; var pSpr; for(var i=this.m_arrChild.length; i--; ) { pSpr = this.m_arrChild[i]; pSpr.setPosition(fX+pSpr.targetX, fY+pSpr.targetY); } // this.Layer.setAnchorPoint(this.m_anchorPoint); }, init:function(pSpr, fW, fH, fRound) { this.m_pSpr = pSpr; var fTexWidth = pSpr.arrTexture[0].rect.width; var fTexHeight = pSpr.arrTexture[0].rect.height; this.m_fW = fW; this.m_fH = fH; this.m_fRound = fRound; // 중앙 m_spr22 = this.add(fRound, fH-fRound, 0.0, 1.0, fRound, fRound, fTexWidth-fRound-fRound, fTexHeight-fRound-fRound); m_spr22.width = fW-fRound-fRound; m_spr22.height = fH-fRound-fRound; // 왼쪽 m_spr12 = this.add(0.0, fH-fRound, 0.0, 1.0, 0.0, fRound, fRound, fTexHeight-fRound-fRound); m_spr12.height = fH-fRound-fRound; // 우측 m_spr32 = this.add(fW-fRound, fH-fRound, 0.0, 1.0, fTexWidth-fRound, fRound, fRound, fTexHeight-fRound-fRound); // 우측상단 m_spr32.height = fH-fRound-fRound; // 상단 m_spr21 = this.add(fRound, fH, 0.0, 1.0, fRound, 0.0, fTexWidth-fRound-fRound, fRound); m_spr21.width = fW-fRound-fRound; // 하단 m_spr23 = this.add(fRound, fRound, 0.0, 1.0, fRound, fTexHeight-fRound, fTexWidth-fRound-fRound, fRound); m_spr23.width = fW-fRound-fRound; m_spr11 = this.add(0.0, fH, 0.0, 1.0, 0.0, 0.0, fRound, fRound); // 왼쪽상단 m_spr31 = this.add(fW-fRound, fH, 0.0, 1.0, fTexWidth-fRound, 0.0, fRound, fRound); // 우측상단 m_spr13 = this.add(0.0, fRound, 0.0, 1.0, 0.0, fTexHeight-fRound, fRound, fRound); // 왼쪽하단 m_spr33 = this.add(fW-fRound, fRound, 0.0, 1.0, fTexWidth-fRound, fTexHeight-fRound, fRound, fRound); // 우측하단 this.m_arrChild = this.getChildren(); this.setAnchorPoint(this.m_anchorPoint); } }); /* ZImageBox::ZImageBox() { m_anchorPoint = Point(0.5f, 0.5f); } void ZImageBox::setAnchorPoint(float fX, float fY) { auto &array = getChildren(); ZSprite *pSpr; m_anchorPoint = Point(fX, fY); fX = -m_fW * fX; fY = -m_fH * fY; for(const auto& obj:array) { pSpr = (ZSprite*)obj; pSpr->setPosition(fX + pSpr->targetX, fY + pSpr->targetY); } SpriteBatchNode::setAnchorPoint(Point(fX, fY)); } void ZImageBox::setAnchorPointX(float fX) { auto &array = getChildren(); ZSprite *pSpr; float fY = m_anchorPoint.y; m_anchorPoint = Point(fX, fY); fX = -m_fW * fX; fY = -m_fH * fY; for(const auto& obj:array) { pSpr = (ZSprite*)obj; pSpr->setPosition(fX + pSpr->targetX, fY + pSpr->targetY); } SpriteBatchNode::setAnchorPoint(Point(fX, fY)); } void ZImageBox::setAnchorPointY(float fY) { auto &array = getChildren(); ZSprite *pSpr; float fX = m_anchorPoint.x; m_anchorPoint = Point(fX, fY); fX = -m_fW * fX; fY = -m_fH * fY; for(const auto& obj:array) { pSpr = (ZSprite*)obj; pSpr->setPosition(fX + pSpr->targetX, fY + pSpr->targetY); } SpriteBatchNode::setAnchorPoint(Point(fX, fY)); } ZSprite * ZImageBox::add(float fX, float fY, float fAx, float fAy, float fClipX, float fClipY, float fClipWidth, float fClipHeight) { ZSprite *pBSpr; pBSpr = new ZSprite(); pBSpr->setSprite(m_pSpr); pBSpr->setClip(fClipX, fClipY, fClipWidth, fClipHeight); pBSpr->setAnchorPoint(Point(fAx, fAy)); //pBSpr->setPosition(Point(fX, fY)); pBSpr->targetX = fX; pBSpr->targetY = fY; addChild(pBSpr); return pBSpr; } void ZImageBox::init(_ZSprite *pSpr, float fW, float fH, int fRound) { initWithTexture(pSpr->getTexture(), 0); m_pSpr = pSpr; float fTexWidth = pSpr->arrTexture[0]->getWidth(); float fTexHeight = pSpr->arrTexture[0]->getHeight(); m_fW = fW; m_fH = fH; m_fRound = fRound; // 중앙 m_spr22 = add(fRound, fH-fRound, 0.0f, 1.0f, fRound, fRound, fTexWidth-fRound-fRound, fTexHeight-fRound-fRound); m_spr22->setWidth(fW-fRound-fRound); m_spr22->setHeight(fH-fRound-fRound); // 왼쪽 m_spr12 = add(0.0f, fH-fRound, 0.0f, 1.0f, 0.0f, fRound, fRound, fTexHeight-fRound-fRound); m_spr12->setHeight(fH-fRound-fRound); // 우측 m_spr32 = add(fW-fRound, fH-fRound, 0.0f, 1.0f, fTexWidth-fRound, fRound, fRound, fTexHeight-fRound-fRound); // 우측상단 m_spr32->setHeight(fH-fRound-fRound); // 상단 m_spr21 = add(fRound, fH, 0.0f, 1.0f, fRound, 0.0f, fTexWidth-fRound-fRound, fRound); m_spr21->setWidth(fW-fRound-fRound); // 하단 m_spr23 = add(fRound, fRound, 0.0f, 1.0f, fRound, fTexHeight-fRound, fTexWidth-fRound-fRound, fRound); m_spr23->setWidth(fW-fRound-fRound); m_spr11 = add(0.0f, fH, 0.0f, 1.0f, 0.0f, 0.0f, fRound, fRound); // 왼쪽상단 m_spr31 = add(fW-fRound, fH, 0.0f, 1.0f, fTexWidth-fRound, 0.0f, fRound, fRound); // 우측상단 m_spr13 = add(0.0f, fRound, 0.0f, 1.0f, 0.0f, fTexHeight-fRound, fRound, fRound); // 왼쪽하단 m_spr33 = add(fW-fRound, fRound, 0.0f, 1.0f, fTexWidth-fRound, fTexHeight-fRound, fRound, fRound); // 우측하단 setAnchorPoint(m_anchorPoint.x, m_anchorPoint.y); m_nType = IMAGEBOX; } void ZImageBox::initHorizon(_ZSprite *pSpr, float fW, int fRound) { initWithTexture(pSpr->getTexture(), 0); m_pSpr = pSpr; float fTexWidth = pSpr->arrTexture[0]->getWidth(); float fTexHeight = pSpr->arrTexture[0]->getHeight(); m_fW = fW; m_fH = fTexHeight; m_spr12 = add(0.0f, m_fH, 0.0f, 1.0f, 0.0f, 0.0f, fRound, fTexHeight); // 왼쪽 m_spr32 = add(fW-fRound, m_fH, 0.0f, 1.0f, fTexWidth-fRound, 0.0f, fRound, fTexHeight); // 오른쪽 m_spr22 = add(fRound, m_fH, 0.0f, 1.0f, fRound, 0.0f, fTexWidth-fRound-fRound, fTexHeight); // 오른쪽 m_spr22->setWidth(fW-fRound-fRound); m_fRound = fRound; setAnchorPoint(m_anchorPoint.x, m_anchorPoint.y); m_nType = IMAGEBOX_HORIZEN; } void ZImageBox::setWidth(float fSize) { m_fW = fSize; if(m_nType == IMAGEBOX_HORIZEN) { m_spr32->targetX = m_fW-m_fRound; m_spr22->setWidth(m_fW-m_fRound-m_fRound); } else { // 중앙 m_spr22->setWidth(m_fW-m_fRound-m_fRound); m_spr32->targetX = m_fW-m_fRound; m_spr31->targetX = m_fW-m_fRound; m_spr33->targetX = m_fW-m_fRound; m_spr21->setWidth(m_fW-m_fRound-m_fRound); m_spr23->setWidth(m_fW-m_fRound-m_fRound); } setAnchorPoint(m_anchorPoint.x, m_anchorPoint.y); } void ZImageBox::setHeight(float fSize) { m_fH = fSize; if(m_nType == IMAGEBOX_VETICAL) { // m_sprRight->targetY = m_fW-m_fRound; //m_sprCenter->setHeight(m_fW-m_fRound-m_fRound); } else { // 중앙 m_spr22->setHeight(m_fH-m_fRound-m_fRound); m_spr22->targetY = m_fH-m_fRound; m_spr11->targetY = m_fH; m_spr21->targetY = m_fH; m_spr31->targetY = m_fH; m_spr12->targetY = m_fH-m_fRound; m_spr12->setHeight(m_fH-m_fRound-m_fRound); m_spr32->targetY = m_fH-m_fRound; m_spr32->setHeight(m_fH-m_fRound-m_fRound); } setAnchorPoint(m_anchorPoint.x, m_anchorPoint.y); } void ZImageBox::setSize(Size Size) { setWidth(Size.width); setHeight(Size.height); } void ZImageBox::initVetical(_ZSprite *pSpr, float fH, int fRound) { initWithTexture(pSpr->getTexture(), 0); m_pSpr = pSpr; float fTexWidth = pSpr->arrTexture[0]->getWidth(); float fTexHeight = pSpr->arrTexture[0]->getHeight(); m_fW = fTexWidth; m_fH = fH; ZSprite *pBSpr; add(0.0f, m_fH, 0.0f, 1.0f, 0.0f, 0.0f, fTexWidth, fRound); // 상단 add(0.0f, fRound, 0.0f, 1.0f, 0.0f, fTexHeight-fRound, fTexWidth, fRound); // 하단 pBSpr = add(0, m_fH-fRound, 0.0f, 1.0f, 0.0f, fRound, fTexWidth, fTexHeight-fRound-fRound); // 중앙 pBSpr->setHeight(fH-fRound-fRound); setAnchorPoint(m_anchorPoint.x, m_anchorPoint.y); m_nType = IMAGEBOX_VETICAL; } void ZImageBox::syncAlpha() { auto &array = getChildren(); // Ref* obj = NULL; for(const auto& obj:array) { ((ZSprite*)obj)->setOpacity(alpha); } Array *array = getChildren(); Ref* obj = NULL; CCARRAY_FOREACH(array, obj) { ((ZSprite*)obj)->setOpacity(alpha); } } void ZImageBox::setColorInt(uint uColor) { auto &array = getChildren(); for(const auto& obj:array) { ((ZSprite*)obj)->setColorInt(uColor); } } void ZImageBox::setSprite(_ZSprite *pSpr) { auto &array = getChildren(); ZSprite *spr; Vec2 ap; for (const auto& obj : array) { spr = (ZSprite*)obj; ap = spr->getAnchorPoint(); spr->setSprite(pSpr); spr->setAnchorPoint(ap); } } */ zg.LinkedList = cc.Class.extend({ m_fScale:1.0, m_font:null, m_arrList:null, ctor:function() { this.m_arrList = {}; }, load:function(file, mode) { var cfg = zg.mydecode(cc.loader._loadTxtSync(file)); if(cfg == null) return false; cfg = zg.parseStr(decode_utf8(cfg)); for(var i in cfg) { this.m_arrList[i] = cfg[i]; } return true; }, update:function(name, value) { this.m_arrList[name] = value; }, val:function(name) { return this.m_arrList[name] || ""; }, ival:function(name) { return int(this.val(name)); }, parse:function(val) { var that = this; // ($KEY) 형태의 문자열을 찾아서 LnkLang연관배열에서 값을찾아 치환하기 return val.replace(/\(\$[\w]+\)/g, function(str) { return that.val(str.match(/[\$\w]+/g)); }); } }); zg.SQLite3 = cc.Class.extend({ m_fScale:1.0, m_font:null, m_grp:null, ctor:function(grp) { this.m_grp = grp; }, setFont:function(font, fScale) { this.m_font = font; this.m_fScale = fScale; }, val:function(name) { return cc.sys.localStorage.getItem(this.m_grp+name); }, ival:function(name, keys) { if(typeof name == "object") { keys = keys.split(","); for(var i=keys.length; i--;) { if(keys.length < 2) continue; name[keys[i].trim()] = int(cc.sys.localStorage.getItem(this.m_grp+keys[i].trim())); } return; } return int(cc.sys.localStorage.getItem(this.m_grp+name)); }, update:function(name, value) { cc.sys.localStorage.setItem(this.m_grp+name, value); }, uadd:function(name, value) { this.update(name, this.ival(this.m_grp+name)+ value); }, del:function(name) { cc.sys.localStorage.removeItem(this.m_grp+name); }, }); zg.SoundDB = cc.Class.extend({ m_path:null, m_ext:null, m_nDelay:0, ctor:function() { }, init:function(hash, delay) { this.m_nDelay = delay; }, setPathExt:function(path, ext) { this.m_path = path; this.m_ext = ext; }, setFont:function(font, fScale) { this.m_font = font; this.m_fScale = fScale; }, getFullName:function(name) { return (name.indexOf("/")==-1 ? this.m_path : "") + name + (name.indexOf(".")==-1 ? this.m_ext : ""); }, stop:function(name) { }, play:function(name, bDef) { cc.audioEngine.playEffect(this.getFullName(name)); }, stopMusic:function(name) { }, playMusic:function(name) { }, resumeAll:function() { }, pauseAll:function() { }, }); var LnkLang = new zg.LinkedList(); cc.LabelTTF.prototype.setHexColor = function (c) { this.setColor(zg.col(c)); } cc.LabelTTF.prototype.setColorHex = function (c) { this.setColor(zg.col(c)); } cc.LabelTTF.prototype.setLang = function (str) { this.setString(LnkLang.val(str)); } cc.LabelTTF.prototype.setLangFmt = function (str) { this.setString(LnkLang.dval(str)); } cc.LabelTTF.prototype.setBold = function (thickness) { if(thickness == 0 || thickness == false) this.disableStroke(); else this.enableStroke(this.getColor(), thickness-1, true); thickness = null; } zg.NotificationCenter = cc.Class.extend({ m_path:null, m_ext:null, m_nDelay:0, m_arrNoti:null, ctor:function() { this.m_arrNoti = {}; }, add:function(name, rec, func) { var node = this.m_arrNoti[name]; var noti; if(node == null) { node = []; this.m_arrNoti[name] = node; } for(var i=node.length; i--; ) { noti = node[i]; // 이미 등록된 함수면 빠져나가기 if(noti.rec == rec && noti.func) return; } node.push({"rec":rec, "func":func}); }, addS:function(name, ref, func) { this.add(name, ref, func); }, addI:function(name, ref, func) { this.add(name, ref, func); }, push:function(name, v) { var node = this.m_arrNoti[name]; if(!node) return; var i; for(i=node.length; i--; ) { noti = node[i]; noti.func.call(noti.rec); } node = null; i = null; }, }); zg.Fade = cc.LayerColor.extend({ ctor:function(x, y, w, h, color) { this._super(); this.init(x, y, w, h, color); }, init:function(x, y, w, h, color) { this.setColor(hex2col(color)); this.width = w; this.height = h; this.setPosition(x, y); this.setOpacity(0); this.hide(); }, fade:function(sec, opacity) { this.show(); var hide = opacity == 0 ? cc.hide() : cc.delayTime(0); this.runAction( cc.sequence( cc.fadeTo(sec, opacity), hide ) ) }, setFade:function(opacity) { this.setOpacity(opacity); } }); var Noti = new zg.NotificationCenter(); zg.BackKey = cc.Class.extend({ m_arrObj:null, ctor:function() { this.m_arrObj = []; }, push:function(cls) { this.m_arrObj.push(cls); }, pop:function(cls) { var len = this.m_arrObj.length; for(var i=0; i=this.m_row || j>=this.m_col) this.m_arrBlock[i][j].no = 0; else this.m_arrBlock[i][j].no = no; } } i = null; j = null; }, checkEdge:function(block, x, y) { var cblock = this.m_arrBlock[block.by+y][block.bx+x]; if(cblock.no != 0) return; // 방향 반대로 변경하기 x *= -1; y *= -1; var i; if(y) { for(i=-1; i<=1; i++) { cblock.m_arrEdge[y][i]++; cblock.m_arrDir[y][i] = 1; // 세로방향 } } if(x) { for(i=-1; i<=1; i++) { cblock.m_arrEdge[i][x]++; cblock.m_arrDir[i][x] = 0; // 가로방향 } } i = 0; }, checkEdgeCross:function(block) { // 빈칸이면 패스 (블록이 있는 칸만 조사하기) if(block.no == 0) return; // 동서남북 체크하기 this.checkEdge(block, 0, 1); // 12시 방향 this.checkEdge(block, 1, 0); // 3시 방향 this.checkEdge(block, 0, -1); // 6시 방향 this.checkEdge(block, -1, 0); // 9시 방향 }, getEdge:function(x1, y1, x2, y2) { if(x1 < -1) return 0; if(y1 < -1) return 0; if(x1 > this.m_col) return 0; if(y1 > this.m_row) return 0; var block = this.m_arrBlock[y1][x1]; if(block == null) return 0; if(block.no != 0) return; return -block.m_arrEdge[y2][x2]; }, checkEdgeRound:function(block) { // 빈칸이면 패스 (블록이 있는 칸만 조사하기) if(block.no != 0) return; // 10시 방향 if(block.m_arrEdge[1][-1] == 0) { block.m_arrEdge[1][-1] = this.getEdge(block.bx, block.by+1, -1, -1) + this.getEdge(block.bx-1, block.by, 1, 1); } // 1시 방향 if(block.m_arrEdge[1][1] == 0) { block.m_arrEdge[1][1] = this.getEdge(block.bx, block.by+1, 1, -1) + this.getEdge(block.bx+1, block.by, -1, 1); } // 4시방향 if(block.m_arrEdge[-1][1] == 0) { block.m_arrEdge[-1][1] = this.getEdge(block.bx+1, block.by, -1, -1) + this.getEdge(block.bx, block.by-1, 1, 1); } // 7시 방향 if(block.m_arrEdge[-1][-1] == 0) { block.m_arrEdge[-1][-1] = this.getEdge(block.bx-1, block.by, 1, -1) + this.getEdge(block.bx, block.by-1, -1, 1); } }, // this.m_parent.addChild(Main.newSprite(frame, this.x+j*27, this.y+i*27), Math.abs(edge)+1); onDrawEdge:function(x, y, name, zOrder) { this.m_func.call(this.m_rec, x, y, name, zOrder); }, showBlock:function() { var i, j; var edge; for(i=-1; i<=this.m_row; i++) { for(j=-1; j<=this.m_col; j++) { edge = this.m_arrBlock[i][j]; if(edge.no == 0) { edge.showEdge(); continue; } this.onDrawEdge(edge.x, edge.y, "back", 0); // this.addChild(Main.newSprite("b"+ edge.no, edge.x, edge.y)); // this.addChild(Main.newSprite("eg_back", edge.x, edge.y)); } } }, }); zg.EdgeTexture = cc.RenderTexture.extend({ m_col:0, m_row:0, m_xsize:0, m_ysize:0, m_xsize:0, m_ysize:0, m_rtEdge:null, m_arrBack:null, m_cEdgeCenter:null, m_sprDB:null, m_arrBlock:null, ctor:function(col, row, xsize, ysize, sprDB) { this._super((col+2)*xsize, (row+2)*ysize, cc.Texture2D.PIXEL_FORMAT_RGBA8888); cc.associateWithNative( this, cc.RenderTexture ); this.getSprite().texture.setAntiAliasTexParameters(); this.m_cEdgeCenter = new zg.EdgeCenter(col, row, xsize, ysize, this, this.onDrawEdge); this.m_arrBack = []; this.m_arrBlock = this.m_cEdgeCenter.m_arrBlock; /* for(var i=0; i= this.m_col) return; if(row >= this.m_row) return; // this.m_cEdgeCenter.m_arrBlock[row][col].no = !this.m_cEdgeCenter.m_arrBlock[row][col].no; this.redraw(); return false; }, redraw:function() { this.beginWithClear(0, 0, 0, 0); this.m_cEdgeCenter.open(); var edge; for(var i=0; i