12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190 |
- if (cc.sys._supportWebAudio) {
- var _ctx = cc.webAudioContext = new(window.AudioContext || window.webkitAudioContext || window.mozAudioContext);
- cc.WebAudio = cc.Class.extend({
- _events: null,
- _buffer: null,
- _sourceNode: null,
- _volumeNode: null,
- src: null,
- preload: null,
- autoplay: null,
- controls: null,
- mediagroup: null,
- currentTime: 0,
- startTime: 0,
- duration: 0,
- _loop: null,
- _volume: 1,
- _pauseTime: 0,
- _paused: !1,
- _stopped: !0,
- _loadState: -1,
- ctor: function(b) {
- this._events = {};
- this.src = b;
- this._volumeNode = _ctx.createGain ? _ctx.createGain() : _ctx.createGainNode();
- this._onSuccess1 = this._onSuccess.bind(this);
- this._onError1 = this._onError.bind(this)
- },
- _play: function(e) {
- var d = this._sourceNode = _ctx.createBufferSource(),
- f = this._volumeNode;
- e = e || 0;
- d.buffer = this._buffer;
- f.gain.value = this._volume;
- d.connect(f);
- f.connect(_ctx.destination);
- d.loop = this._loop;
- this._stopped = this._paused = !1;
- d.start ? d.start(0, e) : d.noteGrainOn ? (f = d.buffer.duration, this.loop ? d.noteGrainOn(0, e, f) : d.noteGrainOn(0, e, f - e)) : d.noteOn(0);
- this._pauseTime = 0
- },
- _stop: function() {
- var b = this._sourceNode;
- this._stopped || (b.stop ? b.stop(0) : b.noteOff(0), this._stopped = !0)
- },
- play: function() {
- if ( - 1 == this._loadState) {
- this._loadState = 0
- } else {
- if (1 == this._loadState) {
- var b = this._sourceNode;
- if (this._stopped || !(b && 2 == b.playbackState)) {
- this.startTime = _ctx.currentTime,
- this._play(0)
- }
- }
- }
- },
- pause: function() {
- this._pauseTime = _ctx.currentTime;
- this._paused = !0;
- this._stop()
- },
- resume: function() {
- this._paused && this._play(this._buffer ? (this._pauseTime - this.startTime) % this._buffer.duration: 0)
- },
- stop: function() {
- this._pauseTime = 0;
- this._paused = !1;
- this._stop()
- },
- load: function() {
- var d = this;
- if (1 != d._loadState) {
- d._loadState = -1;
- d.played = !1;
- d.ended = !0;
- var c = new XMLHttpRequest;
- c.open("GET", d.src, !0);
- c.responseType = "arraybuffer";
- c.onload = function() {
- _ctx.decodeAudioData(c.response, d._onSuccess1, d._onError1)
- };
- c.send()
- }
- },
- addEventListener: function(d, c) {
- this._events[d] = c.bind(this)
- },
- removeEventListener: function(b) {
- delete this._events[b]
- },
- canplay: function() {
- return cc.sys._supportWebAudio
- },
- _onSuccess: function(d) {
- this._buffer = d;
- d = this._events.success;
- var c = this._events.canplaythrough;
- d && d();
- c && c(); (0 == this._loadState || "autoplay" == this.autoplay || !0 == this.autoplay) && this._play();
- this._loadState = 1
- },
- _onError: function() {
- var b = this._events.error;
- b && b();
- this._loadState = -2
- },
- cloneNode: function() {
- var b = new cc.WebAudio(this.src);
- b.volume = this.volume;
- b._loadState = this._loadState;
- b._buffer = this._buffer; (0 == b._loadState || -1 == b._loadState) && b.load();
- return b
- }
- });
- var _p = cc.WebAudio.prototype;
- cc.defineGetterSetter(_p, "loop",
- function() {
- return this._loop
- },
- function(b) {
- this._loop = b;
- this._sourceNode && (this._sourceNode.loop = b)
- });
- cc.defineGetterSetter(_p, "volume",
- function() {
- return this._volume
- },
- function(b) {
- this._volume = b;
- this._volumeNode.gain.value = b
- });
- cc.defineGetterSetter(_p, "paused",
- function() {
- return this._paused
- });
- cc.defineGetterSetter(_p, "ended",
- function() {
- var b = this._sourceNode;
- return ! this._paused && (this._stopped || !b || 3 == b.playbackState)
- });
- cc.defineGetterSetter(_p, "played",
- function() {
- var b = this._sourceNode;
- return b && 2 == b.playbackState
- })
- }
- cc.AudioEngine = cc.Class.extend({
- _soundSupported: !1,
- _currMusic: null,
- _currMusicPath: null,
- _musicPlayState: 0,
- _audioID: 0,
- _effects: {},
- _audioPool: {},
- _effectsVolume: 1,
- _maxAudioInstance: 5,
- _effectPauseCb: null,
- _playings: [],
- ctor: function() {
- this._soundSupported = 0 < cc._audioLoader._supportedAudioTypes.length;
- this._effectPauseCb && (this._effectPauseCb = this._effectPauseCb.bind(this))
- },
- willPlayMusic: function() {
- return ! 1
- },
- getEffectsVolume: function() {
- return this._effectsVolume
- },
- playMusic: function(e, d) {
- if (this._soundSupported) {
- var f = this._currMusic;
- f && this._stopAudio(f);
- e != this._currMusicPath && (this._currMusic = f = this._getAudioByUrl(e), this._currMusicPath = e);
- f && (f.loop = d || !1, this._playMusic(f))
- }
- },
- _getAudioByUrl: function(e) {
- var d = cc.loader,
- f = d.getRes(e);
- f || (d.load(e), f = d.getRes(e));
- return f
- },
- _playMusic: function(b) {
- b.ended || (b.stop ? b.stop() : (b.pause(), b.currentTime = 0));
- this._musicPlayState = 2;
- b.play()
- },
- stopMusic: function(d) {
- if (0 < this._musicPlayState) {
- var c = this._currMusic;
- c && this._stopAudio(c) && (d && cc.loader.release(this._currMusicPath), this._currMusicPath = this._currMusic = null, this._musicPlayState = 0)
- }
- },
- _stopAudio: function(b) {
- return b && !b.ended ? (b.stop ? b.stop() : b.duration && Infinity != b.duration ? b.currentTime = b.duration: b.pause(), !0) : !1
- },
- pauseMusic: function() {
- 2 == this._musicPlayState && (this._currMusic.pause(), this._musicPlayState = 1)
- },
- resumeMusic: function() {
- 1 == this._musicPlayState && (this._resumeAudio(this._currMusic), this._musicPlayState = 2)
- },
- _resumeAudio: function(b) {
- b && !b.ended && (b.resume ? b.resume() : b.play())
- },
- rewindMusic: function() {
- this._currMusic && this._playMusic(this._currMusic)
- },
- getMusicVolume: function() {
- return 0 == this._musicPlayState ? 0 : this._currMusic.volume
- },
- setMusicVolume: function(b) {
- 0 < this._musicPlayState && (this._currMusic.volume = Math.min(Math.max(b, 0), 1))
- },
- isMusicPlaying: function() {
- return 2 == this._musicPlayState && this._currMusic && !this._currMusic.ended
- },
- _getEffectList: function(d) {
- var c = this._audioPool[d];
- c || (c = this._audioPool[d] = []);
- return c
- },
- _getEffect: function(g) {
- var e;
- if (!this._soundSupported) {
- return null
- }
- for (var l = this._getEffectList(g), j = 0, i = l.length; j < i; j++) {
- var h = l[j];
- if (h.ended) {
- e = h;
- e.currentTime = 0;
- window.chrome && e.load();
- break
- }
- }
- if (!e) {
- if (l.length >= this._maxAudioInstance) {
- return cc.log("Error: " + g + " greater than " + this._maxAudioInstance),
- null
- }
- e = this._getAudioByUrl(g);
- if (!e) {
- return null
- }
- e = e.cloneNode(!0);
- this._effectPauseCb && cc._addEventListener(e, "pause", this._effectPauseCb);
- e.volume = this._effectsVolume;
- l.push(e)
- }
- return e
- },
- playEffect: function(f, e) {
- var h = this._getEffect(f);
- if (!h) {
- return null
- }
- h.loop = e || !1;
- h.play();
- var g = this._audioID++;
- this._effects[g] = h;
- return g
- },
- setEffectsVolume: function(e) {
- e = this._effectsVolume = Math.min(Math.max(e, 0), 1);
- var d = this._effects,
- f;
- for (f in d) {
- d[f].volume = e
- }
- },
- pauseEffect: function(b) { (b = this._effects[b]) && !b.ended && b.pause()
- },
- pauseAllEffects: function() {
- var e = this._effects,
- d;
- for (d in e) {
- var f = e[d];
- f.ended || f.pause()
- }
- },
- resumeEffect: function(b) {
- this._resumeAudio(this._effects[b])
- },
- resumeAllEffects: function() {
- var d = this._effects,
- c;
- for (c in d) {
- this._resumeAudio(d[c])
- }
- },
- stopEffect: function(b) {
- this._stopAudio(this._effects[b]);
- delete this._effects[b]
- },
- stopAllEffects: function() {
- var d = this._effects,
- c;
- for (c in d) {
- this._stopAudio(d[c]),
- delete d[c]
- }
- },
- unloadEffect: function(g) {
- var e = cc.loader,
- j = this._effects,
- i = this._getEffectList(g);
- e.release(g);
- if (0 != i.length) {
- e = i[0].src;
- delete this._audioPool[g];
- for (var h in j) {
- j[h].src == e && (this._stopAudio(j[h]), delete j[h])
- }
- }
- },
- end: function() {
- this.stopMusic();
- this.stopAllEffects()
- },
- _pausePlaying: function() {
- var e = this._effects,
- d, f;
- for (f in e) {
- if ((d = e[f]) && !d.ended && !d.paused) {
- this._playings.push(d),
- d.pause()
- }
- }
- this.isMusicPlaying() && (this._playings.push(this._currMusic), this._currMusic.pause())
- },
- _resumePlaying: function() {
- for (var e = this._playings,
- d = 0,
- f = e.length; d < f; d++) {
- this._resumeAudio(e[d])
- }
- e.length = 0
- }
- }); ! cc.sys._supportWebAudio && 0 > cc.sys._supportMultipleAudio && (cc.AudioEngineForSingle = cc.AudioEngine.extend({
- _waitingEffIds: [],
- _pausedEffIds: [],
- _currEffect: null,
- _maxAudioInstance: 2,
- _effectCache4Single: {},
- _needToResumeMusic: !1,
- _expendTime4Music: 0,
- _isHiddenMode: !1,
- _playMusic: function(b) {
- this._stopAllEffects();
- this._super(b)
- },
- resumeMusic: function() {
- 1 == this._musicPlayState && (this._stopAllEffects(), this._needToResumeMusic = !1, this._expendTime4Music = 0, this._super())
- },
- playEffect: function(g, e) {
- var j = this._currEffect,
- i = e ? this._getEffect(g) : this._getSingleEffect(g);
- if (!i) {
- return null
- }
- i.loop = e || !1;
- var h = this._audioID++;
- this._effects[h] = i;
- this.isMusicPlaying() && (this.pauseMusic(), this._needToResumeMusic = !0);
- j ? (j != i && this._waitingEffIds.push(this._currEffectId), this._waitingEffIds.push(h), j.pause()) : (this._currEffect = i, this._currEffectId = h, i.play());
- return h
- },
- pauseEffect: function(b) {
- cc.log("pauseEffect not supported in single audio mode!")
- },
- pauseAllEffects: function() {
- var g = this._waitingEffIds,
- e = this._pausedEffIds,
- j = this._currEffect;
- if (j) {
- for (var i = 0,
- h = g.length; i < h; i++) {
- e.push(g[i])
- }
- g.length = 0;
- e.push(this._currEffectId);
- j.pause()
- }
- },
- resumeEffect: function(b) {
- cc.log("resumeEffect not supported in single audio mode!")
- },
- resumeAllEffects: function() {
- var f = this._waitingEffIds,
- e = this._pausedEffIds;
- this.isMusicPlaying() && (this.pauseMusic(), this._needToResumeMusic = !0);
- for (var h = 0,
- g = e.length; h < g; h++) {
- f.push(e[h])
- }
- e.length = 0;
- if (!this._currEffect && 0 <= f.length && (f = f.pop(), e = this._effects[f])) {
- this._currEffectId = f,
- this._currEffect = e,
- this._resumeAudio(e)
- }
- },
- stopEffect: function(f) {
- var e = this._currEffect,
- h = this._waitingEffIds,
- g = this._pausedEffIds;
- e && this._currEffectId == f ? this._stopAudio(e) : (e = h.indexOf(f), 0 <= e ? h.splice(e, 1) : (e = g.indexOf(f), 0 <= e && g.splice(e, 1)))
- },
- stopAllEffects: function() {
- this._stopAllEffects(); ! this._currEffect && this._needToResumeMusic && (this._resumeAudio(this._currMusic), this._musicPlayState = 2, this._needToResumeMusic = !1, this._expendTime4Music = 0)
- },
- unloadEffect: function(h) {
- var e = cc.loader,
- n = this._effects,
- m = this._effectCache4Single,
- l = this._getEffectList(h),
- i = this._currEffect;
- e.release(h);
- if (0 != l.length || m[h]) {
- e = 0 < l.length ? l[0].src: m[h].src;
- delete this._audioPool[h];
- delete m[h];
- for (var j in n) {
- n[j].src == e && delete n[j]
- }
- i && i.src == e && this._stopAudio(i)
- }
- },
- _getSingleEffect: function(g) {
- var e = this._effectCache4Single[g],
- l = this._waitingEffIds,
- j = this._pausedEffIds,
- i = this._effects;
- if (e) {
- e.currentTime = 0
- } else {
- e = this._getAudioByUrl(g);
- if (!e) {
- return null
- }
- e = e.cloneNode(!0);
- this._effectPauseCb && cc._addEventListener(e, "pause", this._effectPauseCb);
- e.volume = this._effectsVolume;
- this._effectCache4Single[g] = e
- }
- g = 0;
- for (var h = l.length; g < h;) {
- i[l[g]] == e ? l.splice(g, 1) : g++
- }
- g = 0;
- for (h = j.length; g < h;) {
- i[j[g]] == e ? j.splice(g, 1) : g++
- }
- e._isToPlay = !0;
- return e
- },
- _stopAllEffects: function() {
- var h = this._currEffect,
- e = this._audioPool,
- n = this._effectCache4Single,
- m = this._waitingEffIds,
- l = this._pausedEffIds;
- if (h || !(0 == m.length && 0 == l.length)) {
- for (var i in n) {
- var j = n[i];
- j.duration && Infinity != j.duration && (j.currentTime = j.duration)
- }
- m.length = 0;
- l.length = 0;
- for (i in e) {
- n = e[i];
- m = 0;
- for (l = n.length; m < l; m++) {
- j = n[m],
- j.loop = !1,
- j.duration && Infinity != j.duration && (j.currentTime = j.duration)
- }
- }
- h && this._stopAudio(h)
- }
- },
- _effectPauseCb: function() {
- if (!this._isHiddenMode) {
- var d = this._getWaitingEffToPlay();
- if (d) {
- d._isToPlay ? (delete d._isToPlay, d.play()) : this._resumeAudio(d)
- } else {
- if (this._needToResumeMusic) {
- d = this._currMusic;
- if (d.duration && Infinity != d.duration) {
- var c = d.currentTime + this._expendTime4Music,
- c = c - d.duration * (c / d.duration | 0);
- d.currentTime = c
- }
- this._expendTime4Music = 0;
- this._resumeAudio(d);
- this._musicPlayState = 2;
- this._needToResumeMusic = !1
- }
- }
- }
- },
- _getWaitingEffToPlay: function() {
- var g = this._waitingEffIds,
- e = this._effects,
- j = this._currEffect,
- i = j ? j.currentTime - (j.startTime || 0) : 0;
- for (this._expendTime4Music += i; 0 != g.length;) {
- var h = g.pop();
- if (j = e[h]) {
- if (j._isToPlay || j.loop || j.duration && j.currentTime + i < j.duration) {
- return this._currEffectId = h,
- this._currEffect = j,
- !j._isToPlay && (j.duration && Infinity != j.duration) && (g = j.currentTime + i, g -= j.duration * (g / j.duration | 0), j.currentTime = g),
- j._isToPlay = !1,
- j
- }
- j.duration && Infinity != j.duration && (j.currentTime = j.duration)
- }
- }
- return this._currEffect = this._currEffectId = null
- },
- _pausePlaying: function() {
- var b = this._currEffect;
- this._isHiddenMode = !0;
- if (b = 2 == this._musicPlayState ? this._currMusic: b) {
- this._playings.push(b),
- b.pause()
- }
- },
- _resumePlaying: function() {
- var b = this._playings;
- this._isHiddenMode = !1;
- 0 < b.length && (this._resumeAudio(b[0]), b.length = 0)
- }
- }));
- cc._audioLoader = {
- _supportedAudioTypes: null,
- getBasePath: function() {
- return cc.loader.audioPath
- },
- _load: function(q, o, n, m, l, i, j) {
- var h = this,
- e = cc.loader,
- s = cc.path,
- x = this._supportedAudioTypes,
- t = "";
- if (0 == x.length) {
- return j("can not support audio!")
- }
- if ( - 1 == m) {
- t = (s.extname(q) || "").toLowerCase(),
- h.audioTypeSupported(t) || (t = x[0], m = 0)
- } else {
- if (m < x.length) {
- t = x[m]
- } else {
- return j("can not found the resource of audio! Last match url is : " + q)
- }
- }
- if (0 <= l.indexOf(t)) {
- return h._load(q, o, n, m + 1, l, i, j)
- }
- q = s.changeExtname(q, t);
- l.push(t);
- i = h._loadAudio(q, i,
- function(a) {
- if (a) {
- return h._load(q, o, n, m + 1, l, i, j)
- }
- j(null, i)
- },
- m == x.length - 1);
- e.cache[o] = i
- },
- audioTypeSupported: function(b) {
- return ! b ? !1 : 0 <= this._supportedAudioTypes.indexOf(b.toLowerCase())
- },
- _loadAudio: function(g, e, j, i) {
- var h = "file://" == location.origin ? Audio: cc.WebAudio || Audio;
- 2 == arguments.length ? (j = e, e = new h) : 3 < arguments.length && !e && (e = new h);
- e.src = g;
- e.preload = "auto";
- h = navigator.userAgent;
- /Mobile/.test(h) && (/iPhone OS/.test(h) || /iPad/.test(h) || /Firefox/.test(h)) || /MSIE/.test(h) ? (e.load(), j(null, e)) : (cc._addEventListener(e, "canplaythrough",
- function() {
- j(null, e);
- this.removeEventListener("canplaythrough", arguments.callee, !1);
- this.removeEventListener("error", arguments.callee, !1)
- },
- !1), cc._addEventListener(e, "error",
- function() {
- j("load " + g + " failed");
- i && (this.removeEventListener("canplaythrough", arguments.callee, !1), this.removeEventListener("error", arguments.callee, !1))
- },
- !1), e.load());
- return e
- },
- load: function(f, e, h, g) {
- this._load(f, e, h, -1, [], null, g)
- }
- };
- cc._audioLoader._supportedAudioTypes = function() {
- var e = cc.newElement("audio"),
- d = [];
- if (e.canPlayType) {
- var f = function(a) {
- a = e.canPlayType(a);
- return "no" != a && "" != a
- };
- f('audio/ogg; codecs\x3d"vorbis"') && d.push(".ogg");
- f("audio/mpeg") && d.push(".mp3");
- f('audio/wav; codecs\x3d"1"') && d.push(".wav");
- f("audio/mp4") && d.push(".mp4"); (f("audio/x-m4a") || f("audio/aac")) && d.push(".m4a")
- }
- return d
- } ();
- cc.loader.register(["mp3", "ogg", "wav", "mp4", "m4a"], cc._audioLoader);
- cc.audioEngine = cc.AudioEngineForSingle ? new cc.AudioEngineForSingle: new cc.AudioEngine;
- cc.eventManager.addCustomListener(cc.game.EVENT_HIDE,
- function() {
- cc.audioEngine._pausePlaying()
- });
- cc.eventManager.addCustomListener(cc.game.EVENT_SHOW,
- function() {
- cc.audioEngine._resumePlaying()
- });
- var bs = bs || {};
- bs.System = {
- messageBox: function() {},
- measureStringWidth: function() {
- return this
- },
- openUrl: function() {},
- countStringCanDisplayInWidth: function() {
- return this
- },
- setRateAppDelegate: function() {},
- getDeviceIdfa: function() {
- return this
- },
- UTFStringBytes: function() {
- return this
- },
- getDeviceID: function() {
- return this
- },
- rateApp: function() {},
- copyToClipboard: function() {},
- getTimeOfDay: function() {
- return this
- },
- getSystemUpTime: function() {
- return this
- },
- isRetina: function() {
- return this
- },
- urlEncode: function() {
- return this
- },
- generateOrderID: function() {
- return this
- },
- getPackageName: function() {
- return this
- },
- calcStringLength: function() {
- return this
- },
- md5: function() {
- return this
- },
- getCurrentVersion: function() {
- return this
- },
- logMemoryUsage: function() {},
- compareVersion: function() {
- return this
- },
- isUsingWifi: function() {
- return this
- },
- showRateAppAlert: function() {},
- getDeviceMac: function() {
- return this
- }
- };
- bs.Notification = {
- destroy: function() {},
- init: function() {
- return this
- },
- cancelAllNotification: function() {},
- scheduleNotification: function() {},
- shared: function() {
- return this
- },
- BSNotification: function() {}
- };
- bs.Umeng = {
- feedback: function() {},
- getConfigParam: function() {
- return this
- },
- checkUpdate: function() {},
- failLevel: function() {},
- logEvent: function() {},
- getChannel: function() {
- return this
- },
- setIsUpdated: function() {},
- init: function() {
- return this
- },
- setVersionKey: function() {},
- startWithAppKey: function() {},
- getIsUpdated: function() {
- return this
- },
- logPurchase: function() {},
- destroy: function() {},
- getAppKey: function() {
- return this
- },
- startLevel: function() {},
- finishLevel: function() {},
- logRecharge: function() {},
- isInReview: function() {
- return this
- },
- shared: function() {
- return this
- },
- BSUmeng: function() {}
- };
- bs.TencentMTA = {
- setPlayerLevel: function() {},
- trackRecharge: function() {},
- trackLevelUp: function() {},
- trackEvent: function() {},
- trackRaid: function() {},
- startWithAppKey: function() {},
- trackLogout: function() {},
- setDebugEnable: function() {},
- isInReview: function() {
- return this
- },
- trackRegister: function() {},
- getConfigParam: function() {
- return this
- },
- setPlayerId: function() {},
- init: function() {
- return this
- },
- destroy: function() {},
- trackConsumeItem: function() {},
- trackPurchaseItem: function() {},
- getChannel: function() {
- return this
- },
- setExchangeRate: function() {},
- trackLogin: function() {},
- trackTask: function() {},
- getAppKey: function() {
- return this
- },
- trackPurchaseOther: function() {},
- shared: function() {
- return this
- },
- BSTencentMTA: function() {}
- };
- bs.Share = {
- registerApp: function() {},
- shareVideo: function() {},
- shareImage: function() {},
- shareURL: function() {},
- init: function() {
- return this
- },
- onShareSuccess: function() {},
- destroy: function() {},
- shared: function() {
- return this
- },
- BSShare: function() {}
- };
- bs.ShareQQ = {
- destroy: function() {},
- init: function() {
- return this
- },
- registerApp: function() {},
- shared: function() {
- return this
- },
- BSShareQQ: function() {}
- };
- bs.AsyncRemoteSprite = {
- textureLoaded: function() {},
- create: function() {
- return this
- },
- BSAsyncRemoteSprite: function() {}
- };
- bs.Social = {
- invite: function() {},
- getType: function() {
- return this
- },
- initWithAppId: function() {},
- isLogin: function() {
- return this
- },
- login: function() {},
- queryUserInfo: function() {},
- BSSocial: function() {}
- };
- bs.SocialQQ = {
- getType: function() {
- return this
- },
- shared: function() {
- return this
- }
- };
- bs.SocialWechat = {
- setCode: function() {},
- getType: function() {
- return this
- },
- getCode: function() {
- return this
- },
- shared: function() {
- return this
- }
- };
- bs.SocialWeibo = {
- getType: function() {
- return this
- },
- shared: function() {
- return this
- }
- };
- bs.Config = {
- decrypt: function() {
- return this
- },
- init: function() {
- return this
- },
- setKey: function() {},
- loadConf: function() {
- return this
- },
- destroy: function() {},
- shared: function() {
- return this
- },
- BSConfig: function() {}
- };
- bs.PlatformImpl = {
- feedback: function() {},
- setPlatformDelegate: function() {},
- getPlatformName: function() {
- return this
- },
- setLoginStateToTrue: function() {},
- restorePurchase: function() {},
- getProductID: function() {
- return this
- },
- quitGame: function() {},
- getUserBalance: function() {
- return this
- },
- setIsInited: function() {},
- setAppIdAndKey: function() {},
- accountManagement: function() {},
- init: function() {
- return this
- },
- getUserNickName: function() {
- return this
- },
- setPlatformType: function() {},
- setProductID: function() {},
- getPlatformDelegate: function() {
- return this
- },
- getisVersionChecked: function() {
- return this
- },
- setRechargeAddr: function() {},
- getisFirstLogin: function() {
- return this
- },
- social: function() {},
- setisVersionChecked: function() {},
- getRechargeAddr: function() {
- return this
- },
- setOrderID: function() {},
- updateVersion: function() {},
- enterAppBBS: function() {},
- getIsInited: function() {
- return this
- },
- buyGoodConfirm: function() {},
- onEnterForeground: function() {},
- setisFirstLogin: function() {},
- setPlatformName: function() {},
- buyGood: function() {},
- setIsDebugMode: function() {},
- getLoginState: function() {
- return this
- },
- isLogined: function() {
- return this
- },
- getUserID: function() {
- return this
- },
- getPlatformType: function() {
- return this
- },
- getOrderID: function() {
- return this
- },
- login: function() {},
- BSPlatformImpl: function() {}
- };
- bs.Platform = {
- setPlatformImpl: function() {},
- shared: function() {
- return this
- }
- };
- bs.Sound = {
- stopAllEffects: function() {},
- switchMusicMute: function() {},
- setEffectVolume: function() {},
- setMusicVolume: function() {},
- setIsMusicMute: function() {},
- stopEffect: function() {},
- getEffectVolume: function() {
- return this
- },
- pushMusic: function() {
- return this
- },
- getMusicVolume: function() {
- return this
- },
- stopMusic: function() {},
- dump: function() {},
- getIsMute: function() {
- return this
- },
- setIsEffectMute: function() {},
- playMusic: function() {},
- setIsMute: function() {},
- popMusic: function() {},
- destroy: function() {},
- getIsMusicMute: function() {
- return this
- },
- configure: function() {},
- playEffect: function() {
- return this
- },
- active: function() {},
- switchEffectMute: function() {},
- init: function() {
- return this
- },
- getIsEffectMute: function() {
- return this
- },
- shared: function() {
- return this
- },
- BSSound: function() {}
- };
- bs.Ad = {
- destroy: function() {},
- init: function() {
- return this
- },
- showAd: function() {},
- setID: function() {},
- shared: function() {
- return this
- },
- BSAd: function() {}
- };
- bs.OfferWall = {
- setID: function() {},
- showWall: function() {},
- consumeAllPoints: function() {}
- };
- bs.OfferWallAdwo = {
- consumeAllPoints: function() {},
- init: function() {
- return this
- },
- showWall: function() {},
- destroy: function() {},
- setID: function() {},
- shared: function() {
- return this
- },
- BSOfferWallAdwo: function() {}
- };
- bs.OfferWallDM = {
- consumeAllPoints: function() {},
- init: function() {
- return this
- },
- showWall: function() {},
- destroy: function() {},
- setID: function() {},
- shared: function() {
- return this
- },
- BSOfferWallDM: function() {}
- };
- bs.OfferWallYjf = {
- consumeAllPoints: function() {},
- init: function() {
- return this
- },
- showWall: function() {},
- destroy: function() {},
- setID: function() {},
- shared: function() {
- return this
- },
- BSOfferWallYjf: function() {}
- };
- bs.OfferWallDianRu = {
- consumeAllPoints: function() {},
- init: function() {
- return this
- },
- showWall: function() {},
- destroy: function() {},
- setID: function() {},
- shared: function() {
- return this
- },
- BSOfferWallDianRu: function() {}
- };
- bs.Coupon = {
- setServer: function() {},
- useCoupon: function() {},
- setProduct: function() {},
- init: function() {
- return this
- },
- destroy: function() {},
- shared: function() {
- return this
- },
- BSCoupon: function() {}
- };
- bs.Pay = {
- getPlayerId: function() {
- return this
- },
- setPayCode: function() {},
- getIsSandbox: function() {
- return this
- },
- setIsSandbox: function() {},
- recordOrder: function() {},
- getPayMethod: function() {
- return this
- },
- setServerId: function() {},
- getPayCode: function() {
- return this
- },
- setPrice: function() {},
- setPlayerId: function() {},
- init: function() {
- return this
- },
- getProductId: function() {
- return this
- },
- destroy: function() {},
- getPrice: function() {
- return this
- },
- setPayData: function() {},
- onRecordOrder: function() {},
- getServerId: function() {
- return this
- },
- setPayMethod: function() {},
- restoreProduct: function() {},
- getOrderId: function() {
- return this
- },
- setProductId: function() {},
- getPayData: function() {
- return this
- },
- setOrderId: function() {},
- setPaySecret: function() {},
- buyProduct: function() {},
- shared: function() {
- return this
- },
- BSPay: function() {}
- };
- bs.Resource = {
- unuseResource: function() {},
- setThreadCount: function() {},
- getThreadCount: function() {
- return this
- },
- checkUpdate: function() {},
- setMaxThreadCount: function() {},
- getStatus: function() {
- return this
- },
- setRemoteHost: function() {},
- setStatus: function() {},
- getRemoteHost: function() {
- return this
- },
- init: function() {
- return this
- },
- startUpdate: function() {},
- getMaxThreadCount: function() {
- return this
- },
- destroy: function() {},
- getUpdateDurationMS: function() {
- return this
- },
- getCacheFilePath: function() {
- return this
- },
- useResource: function() {},
- shared: function() {
- return this
- },
- BSResource: function() {}
- };
- bs.Promotion = {
- setServer: function() {},
- sendInfo: function() {},
- init: function() {
- return this
- },
- destroy: function() {},
- shared: function() {
- return this
- },
- BSPromotion: function() {}
- };
- bs.KTPlay = {
- handleOpenURL: function() {},
- setAppKeyAndSecret: function() {},
- show: function() {},
- isEnabled: function() {
- return this
- },
- dismiss: function() {},
- isShowing: function() {
- return this
- },
- init: function() {
- return this
- },
- destroy: function() {},
- shared: function() {
- return this
- },
- BSKTPlay: function() {}
- };
- bs.AsyncRemoteSprite = cc.Sprite.extend({
- _preferredSize: null,
- initWithUrlAndSize: function(d, c) {
- this.initWithFile(d);
- this._preferredSize = c
- },
- onEnter: function() {
- this._super();
- this._preferredSize && (0 !== this.getContentSize().width ? bs.scaleToSize(this, this._preferredSize) : this.schedule(function() {
- 0 !== this.getContentSize().width && (bs.scaleToSize(this, this._preferredSize), this.unscheduleAllCallbacks())
- }.bind(this), 0.01))
- }
- });
- bs.AsyncRemoteSprite.create = function(e, d, f) {
- f = new bs.AsyncRemoteSprite;
- f.initWithUrlAndSize(e, d);
- return f
- };
- bs.System.getDeviceID = function() {
- var b = cc.sys.localStorage.getItem("device_id");
- if (b) {
- return b
- }
- b = bs.guid();
- cc.sys.localStorage.setItem("device_id", b);
- return b
- };
- bs.System.getSystemUpTime = function() {
- return Math.ceil((new Date).getTime() / 1000)
- };
- bs.System.currentTimeMillis = function() {
- return (new Date).getTime()
- };
- bs.System.getServerTime = function(b) {
- bs.Http.get("http://week.pictoword.hortorgame.com/week/serverTime",
- function(a, f) {
- if (a) {
- b(a, null)
- } else {
- var e = parseInt(f);
- isNaN(e) || 0 > e ? (cc.log("[BSHTTP] server time request error:" + JSON.stringify(f)), b("", null)) : b(null, e)
- }
- })
- };
- bs.platform = "html5";
- bs.platformpay = "appstore";
- bs._ResourceClass = cc.Class.extend({
- _resUsed: null,
- init: function() {
- this._resUsed = {}
- },
- useResource: function(b) {
- this._resUsed[b] || (this._resUsed[b] = 0, cc.spriteFrameCache.addSpriteFrames(b));
- this._resUsed[b]++
- },
- unuseResource: function(b) {
- this._resUsed[b]--;
- 0 == this._resUsed[b] && cc.spriteFrameCache.removeSpriteFramesFromFile(b)
- }
- });
- bs.Resource = {
- _instance: null,
- shared: function() {
- this._instance || (this._instance = new bs._ResourceClass, this._instance.init());
- return this._instance
- }
- }; (function() {
- var ar = this,
- aq = ar._,
- ap = {},
- ao = Array.prototype,
- am = Object.prototype,
- aj = ao.push,
- al = ao.slice,
- ag = ao.concat,
- ac = am.toString,
- S = am.hasOwnProperty,
- W = ao.forEach,
- U = ao.map,
- ai = ao.reduce,
- ak = ao.reduceRight,
- ah = ao.filter,
- aa = ao.every,
- T = ao.some,
- o = ao.indexOf,
- R = ao.lastIndexOf,
- am = Array.isArray,
- Q = Object.keys,
- af = Function.prototype.bind,
- an = function(b) {
- if (b instanceof an) {
- return b
- }
- if (! (this instanceof an)) {
- return new an(b)
- }
- this._wrapped = b
- };
- "undefined" !== typeof exports ? ("undefined" !== typeof module && module.exports && (exports = module.exports = an), exports._ = an) : ar._ = an;
- an.VERSION = "1.6.0";
- var Y = an.each = an.forEach = function(g, e, p) {
- if (null == g) {
- return g
- }
- if (W && g.forEach === W) {
- g.forEach(e, p)
- } else {
- if (g.length === +g.length) {
- for (var k = 0,
- c = g.length; k < c; k++) {
- if (e.call(p, g[k], k, g) === ap) {
- return
- }
- }
- } else {
- for (var l = an.keys(g), k = 0, c = l.length; k < c; k++) {
- if (e.call(p, g[l[k]], l[k], g) === ap) {
- return
- }
- }
- }
- }
- return g
- };
- an.map = an.collect = function(f, d, h) {
- var g = [];
- if (null == f) {
- return g
- }
- if (U && f.map === U) {
- return f.map(d, h)
- }
- Y(f,
- function(b, e, c) {
- g.push(d.call(h, b, e, c))
- });
- return g
- };
- an.reduce = an.foldl = an.inject = function(f, e, l, k) {
- var g = 2 < arguments.length;
- null == f && (f = []);
- if (ai && f.reduce === ai) {
- return k && (e = an.bind(e, k)),
- g ? f.reduce(e, l) : f.reduce(e)
- }
- Y(f,
- function(b, d, c) {
- g ? l = e.call(k, l, b, d, c) : (l = b, g = !0)
- });
- if (!g) {
- throw new TypeError("Reduce of empty array with no initial value")
- }
- return l
- };
- an.reduceRight = an.foldr = function(h, g, q, p) {
- var e = 2 < arguments.length;
- null == h && (h = []);
- if (ak && h.reduceRight === ak) {
- return p && (g = an.bind(g, p)),
- e ? h.reduceRight(g, q) : h.reduceRight(g)
- }
- var l = h.length;
- if (l !== +l) {
- var k = an.keys(h),
- l = k.length
- }
- Y(h,
- function(c, b, a) {
- b = k ? k[--l] : --l;
- e ? q = g.call(p, q, h[b], b, a) : (q = h[b], e = !0)
- });
- if (!e) {
- throw new TypeError("Reduce of empty array with no initial value")
- }
- return q
- };
- an.find = an.detect = function(f, e, h) {
- var g;
- ae(f,
- function(b, d, c) {
- if (e.call(h, b, d, c)) {
- return g = b,
- !0
- }
- });
- return g
- };
- an.filter = an.select = function(f, e, h) {
- var g = [];
- if (null == f) {
- return g
- }
- if (ah && f.filter === ah) {
- return f.filter(e, h)
- }
- Y(f,
- function(b, d, c) {
- e.call(h, b, d, c) && g.push(b)
- });
- return g
- };
- an.reject = function(e, d, f) {
- return an.filter(e,
- function(b, g, c) {
- return ! d.call(f, b, g, c)
- },
- f)
- };
- an.every = an.all = function(e, c, g) {
- c || (c = an.identity);
- var f = !0;
- if (null == e) {
- return f
- }
- if (aa && e.every === aa) {
- return e.every(c, g)
- }
- Y(e,
- function(b, h, d) {
- if (! (f = f && c.call(g, b, h, d))) {
- return ap
- }
- });
- return !! f
- };
- var ae = an.some = an.any = function(e, c, g) {
- c || (c = an.identity);
- var f = !1;
- if (null == e) {
- return f
- }
- if (T && e.some === T) {
- return e.some(c, g)
- }
- Y(e,
- function(b, h, d) {
- if (f || (f = c.call(g, b, h, d))) {
- return ap
- }
- });
- return !! f
- };
- an.contains = an.include = function(d, c) {
- return null == d ? !1 : o && d.indexOf === o ? -1 != d.indexOf(c) : ae(d,
- function(b) {
- return b === c
- })
- };
- an.invoke = function(f, e) {
- var h = al.call(arguments, 2),
- g = an.isFunction(e);
- return an.map(f,
- function(b) {
- return (g ? e: b[e]).apply(b, h)
- })
- };
- an.pluck = function(d, c) {
- return an.map(d, an.property(c))
- };
- an.where = function(d, c) {
- return an.filter(d, an.matches(c))
- };
- an.findWhere = function(d, c) {
- return an.find(d, an.matches(c))
- };
- an.max = function(f, e, l) {
- if (!e && an.isArray(f) && f[0] === +f[0] && 65535 > f.length) {
- return Math.max.apply(Math, f)
- }
- var k = -Infinity,
- g = -Infinity;
- Y(f,
- function(b, d, c) {
- d = e ? e.call(l, b, d, c) : b;
- d > g && (k = b, g = d)
- });
- return k
- };
- an.min = function(f, e, l) {
- if (!e && an.isArray(f) && f[0] === +f[0] && 65535 > f.length) {
- return Math.min.apply(Math, f)
- }
- var k = Infinity,
- g = Infinity;
- Y(f,
- function(b, d, c) {
- d = e ? e.call(l, b, d, c) : b;
- d < g && (k = b, g = d)
- });
- return k
- };
- an.shuffle = function(f) {
- var e, h = 0,
- g = [];
- Y(f,
- function(b) {
- e = an.random(h++);
- g[h - 1] = g[e];
- g[e] = b
- });
- return g
- };
- an.sample = function(e, d, f) {
- return null == d || f ? (e.length !== +e.length && (e = an.values(e)), e[an.random(e.length - 1)]) : an.shuffle(e).slice(0, Math.max(0, d))
- };
- var ad = function(b) {
- return null == b ? an.identity: an.isFunction(b) ? b: an.property(b)
- };
- an.sortBy = function(e, d, f) {
- d = ad(d);
- return an.pluck(an.map(e,
- function(b, g, c) {
- return {
- value: b,
- index: g,
- criteria: d.call(f, b, g, c)
- }
- }).sort(function(h, g) {
- var l = h.criteria,
- k = g.criteria;
- if (l !== k) {
- if (l > k || void 0 === l) {
- return 1
- }
- if (l < k || void 0 === k) {
- return - 1
- }
- }
- return h.index - g.index
- }), "value")
- };
- var ab = function(b) {
- return function(a, g, f) {
- var e = {};
- g = ad(g);
- Y(a,
- function(h, c) {
- var d = g.call(f, h, c, a);
- b(e, d, h)
- });
- return e
- }
- };
- an.groupBy = ab(function(e, d, f) {
- an.has(e, d) ? e[d].push(f) : e[d] = [f]
- });
- an.indexBy = ab(function(e, d, f) {
- e[d] = f
- });
- an.countBy = ab(function(d, c) {
- an.has(d, c) ? d[c]++:d[c] = 1
- });
- an.sortedIndex = function(k, g, r, q) {
- r = ad(r);
- g = r.call(q, g);
- for (var l = 0,
- p = k.length; l < p;) {
- var f = l + p >>> 1;
- r.call(q, k[f]) < g ? l = f + 1 : p = f
- }
- return l
- };
- an.toArray = function(b) {
- return ! b ? [] : an.isArray(b) ? al.call(b) : b.length === +b.length ? an.map(b, an.identity) : an.values(b)
- };
- an.size = function(b) {
- return null == b ? 0 : b.length === +b.length ? b.length: an.keys(b).length
- };
- an.first = an.head = an.take = function(e, d, f) {
- return null == e ? void 0 : null == d || f ? e[0] : 0 > d ? [] : al.call(e, 0, d)
- };
- an.initial = function(e, d, f) {
- return al.call(e, 0, e.length - (null == d || f ? 1 : d))
- };
- an.last = function(e, d, f) {
- return null == e ? void 0 : null == d || f ? e[e.length - 1] : al.call(e, Math.max(e.length - d, 0))
- };
- an.rest = an.tail = an.drop = function(e, d, f) {
- return al.call(e, null == d || f ? 1 : d)
- };
- an.compact = function(b) {
- return an.filter(b, an.identity)
- };
- var P = function(e, d, f) {
- if (d && an.every(e, an.isArray)) {
- return ag.apply(f, e)
- }
- Y(e,
- function(b) {
- an.isArray(b) || an.isArguments(b) ? d ? aj.apply(f, b) : P(b, d, f) : f.push(b)
- });
- return f
- };
- an.flatten = function(d, c) {
- return P(d, c, [])
- };
- an.without = function(b) {
- return an.difference(b, al.call(arguments, 1))
- };
- an.partition = function(f, e) {
- var h = [],
- g = [];
- Y(f,
- function(b) { (e(b) ? h: g).push(b)
- });
- return [h, g]
- };
- an.uniq = an.unique = function(g, f, p, l) {
- an.isFunction(f) && (l = p, p = f, f = !1);
- p = p ? an.map(g, p, l) : g;
- var k = [],
- e = [];
- Y(p,
- function(b, a) {
- if (f ? !a || e[e.length - 1] !== b: !an.contains(e, b)) {
- e.push(b),
- k.push(g[a])
- }
- });
- return k
- };
- an.union = function() {
- return an.uniq(an.flatten(arguments, !0))
- };
- an.intersection = function(d) {
- var c = al.call(arguments, 1);
- return an.filter(an.uniq(d),
- function(b) {
- return an.every(c,
- function(a) {
- return an.contains(a, b)
- })
- })
- };
- an.difference = function(d) {
- var c = ag.apply(ao, al.call(arguments, 1));
- return an.filter(d,
- function(b) {
- return ! an.contains(c, b)
- })
- };
- an.zip = function() {
- for (var e = an.max(an.pluck(arguments, "length").concat(0)), d = Array(e), f = 0; f < e; f++) {
- d[f] = an.pluck(arguments, "" + f)
- }
- return d
- };
- an.object = function(f, e) {
- if (null == f) {
- return {}
- }
- for (var l = {},
- k = 0,
- g = f.length; k < g; k++) {
- e ? l[f[k]] = e[k] : l[f[k][0]] = f[k][1]
- }
- return l
- };
- an.indexOf = function(f, e, l) {
- if (null == f) {
- return - 1
- }
- var k = 0,
- g = f.length;
- if (l) {
- if ("number" == typeof l) {
- k = 0 > l ? Math.max(0, g + l) : l
- } else {
- return k = an.sortedIndex(f, e),
- f[k] === e ? k: -1
- }
- }
- if (o && f.indexOf === o) {
- return f.indexOf(e, l)
- }
- for (; k < g; k++) {
- if (f[k] === e) {
- return k
- }
- }
- return - 1
- };
- an.lastIndexOf = function(f, e, h) {
- if (null == f) {
- return - 1
- }
- var g = null != h;
- if (R && f.lastIndexOf === R) {
- return g ? f.lastIndexOf(e, h) : f.lastIndexOf(e)
- }
- for (h = g ? h: f.length; h--;) {
- if (f[h] === e) {
- return h
- }
- }
- return - 1
- };
- an.range = function(g, f, p) {
- 1 >= arguments.length && (f = g || 0, g = 0);
- p = arguments[2] || 1;
- for (var m = Math.max(Math.ceil((f - g) / p), 0), k = 0, l = Array(m); k < m;) {
- l[k++] = g,
- g += p
- }
- return l
- };
- var Z = function() {};
- an.bind = function(f, e) {
- var h, g;
- if (af && f.bind === af) {
- return af.apply(f, al.call(arguments, 1))
- }
- if (!an.isFunction(f)) {
- throw new TypeError
- }
- h = al.call(arguments, 2);
- return g = function() {
- if (! (this instanceof g)) {
- return f.apply(e, h.concat(al.call(arguments)))
- }
- Z.prototype = f.prototype;
- var a = new Z;
- Z.prototype = null;
- var b = f.apply(a, h.concat(al.call(arguments)));
- return Object(b) === b ? b: a
- }
- };
- an.partial = function(d) {
- var c = al.call(arguments, 1);
- return function() {
- for (var f = 0,
- e = c.slice(), b = 0, a = e.length; b < a; b++) {
- e[b] === an && (e[b] = arguments[f++])
- }
- for (; f < arguments.length;) {
- e.push(arguments[f++])
- }
- return d.apply(this, e)
- }
- };
- an.bindAll = function(d) {
- var c = al.call(arguments, 1);
- if (0 === c.length) {
- throw Error("bindAll must be passed function names")
- }
- Y(c,
- function(a) {
- d[a] = an.bind(d[a], d)
- });
- return d
- };
- an.memoize = function(e, d) {
- var f = {};
- d || (d = an.identity);
- return function() {
- var a = d.apply(this, arguments);
- return an.has(f, a) ? f[a] : f[a] = e.apply(this, arguments)
- }
- };
- an.delay = function(e, d) {
- var f = al.call(arguments, 2);
- return setTimeout(function() {
- return e.apply(null, f)
- },
- d)
- };
- an.defer = function(b) {
- return an.delay.apply(an, [b, 1].concat(al.call(arguments, 1)))
- };
- an.throttle = function(u, t, r) {
- var q, l, e, p = null,
- v = 0;
- r || (r = {});
- var g = function() {
- v = !1 === r.leading ? 0 : an.now();
- p = null;
- e = u.apply(q, l);
- q = l = null
- };
- return function() {
- var b = an.now(); ! v && !1 === r.leading && (v = b);
- var a = t - (b - v);
- q = this;
- l = arguments;
- 0 >= a ? (clearTimeout(p), p = null, v = b, e = u.apply(q, l), q = l = null) : !p && !1 !== r.trailing && (p = setTimeout(g, a));
- return e
- }
- };
- an.debounce = function(u, t, r) {
- var q, l, e, p, v, g = function() {
- var a = an.now() - p;
- a < t ? q = setTimeout(g, t - a) : (q = null, r || (v = u.apply(e, l), e = l = null))
- };
- return function() {
- e = this;
- l = arguments;
- p = an.now();
- var a = r && !q;
- q || (q = setTimeout(g, t));
- a && (v = u.apply(e, l), e = l = null);
- return v
- }
- };
- an.once = function(e) {
- var d = !1,
- f;
- return function() {
- if (d) {
- return f
- }
- d = !0;
- f = e.apply(this, arguments);
- e = null;
- return f
- }
- };
- an.wrap = function(d, c) {
- return an.partial(c, d)
- };
- an.compose = function() {
- var b = arguments;
- return function() {
- for (var a = arguments,
- d = b.length - 1; 0 <= d; d--) {
- a = [b[d].apply(this, a)]
- }
- return a[0]
- }
- };
- an.after = function(d, c) {
- return function() {
- if (1 > --d) {
- return c.apply(this, arguments)
- }
- }
- };
- an.keys = function(e) {
- if (!an.isObject(e)) {
- return []
- }
- if (Q) {
- return Q(e)
- }
- var d = [],
- f;
- for (f in e) {
- an.has(e, f) && d.push(f)
- }
- return d
- };
- an.values = function(f) {
- for (var e = an.keys(f), l = e.length, k = Array(l), g = 0; g < l; g++) {
- k[g] = f[e[g]]
- }
- return k
- };
- an.pairs = function(f) {
- for (var e = an.keys(f), l = e.length, k = Array(l), g = 0; g < l; g++) {
- k[g] = [e[g], f[e[g]]]
- }
- return k
- };
- an.invert = function(f) {
- for (var e = {},
- l = an.keys(f), k = 0, g = l.length; k < g; k++) {
- e[f[l[k]]] = l[k]
- }
- return e
- };
- an.functions = an.methods = function(e) {
- var d = [],
- f;
- for (f in e) {
- an.isFunction(e[f]) && d.push(f)
- }
- return d.sort()
- };
- an.extend = function(b) {
- Y(al.call(arguments, 1),
- function(a) {
- if (a) {
- for (var d in a) {
- b[d] = a[d]
- }
- }
- });
- return b
- };
- an.pick = function(e) {
- var d = {},
- f = ag.apply(ao, al.call(arguments, 1));
- Y(f,
- function(a) {
- a in e && (d[a] = e[a])
- });
- return d
- };
- an.omit = function(e) {
- var d = {},
- g = ag.apply(ao, al.call(arguments, 1)),
- f;
- for (f in e) {
- an.contains(g, f) || (d[f] = e[f])
- }
- return d
- };
- an.defaults = function(b) {
- Y(al.call(arguments, 1),
- function(a) {
- if (a) {
- for (var d in a) {
- void 0 === b[d] && (b[d] = a[d])
- }
- }
- });
- return b
- };
- an.clone = function(b) {
- return ! an.isObject(b) ? b: an.isArray(b) ? b.slice() : an.extend({},
- b)
- };
- an.tap = function(d, c) {
- c(d);
- return d
- };
- var X = function(k, g, t, r) {
- if (k === g) {
- return 0 !== k || 1 / k == 1 / g
- }
- if (null == k || null == g) {
- return k === g
- }
- k instanceof an && (k = k._wrapped);
- g instanceof an && (g = g._wrapped);
- var p = ac.call(k);
- if (p != ac.call(g)) {
- return ! 1
- }
- switch (p) {
- case "[object String]":
- return k == String(g);
- case "[object Number]":
- return k != +k ? g != +g: 0 == k ? 1 / k == 1 / g: k == +g;
- case "[object Date]":
- case "[object Boolean]":
- return + k == +g;
- case "[object RegExp]":
- return k.source == g.source && k.global == g.global && k.multiline == g.multiline && k.ignoreCase == g.ignoreCase
- }
- if ("object" != typeof k || "object" != typeof g) {
- return ! 1
- }
- for (var e = t.length; e--;) {
- if (t[e] == k) {
- return r[e] == g
- }
- }
- var e = k.constructor,
- q = g.constructor;
- if (e !== q && (!an.isFunction(e) || !(e instanceof e && an.isFunction(q) && q instanceof q)) && "constructor" in k && "constructor" in g) {
- return ! 1
- }
- t.push(k);
- r.push(g);
- e = 0;
- q = !0;
- if ("[object Array]" == p) {
- if (e = k.length, q = e == g.length) {
- for (; e--&&(q = X(k[e], g[e], t, r));) {}
- }
- } else {
- for (var l in k) {
- if (an.has(k, l) && (e++, !(q = an.has(g, l) && X(k[l], g[l], t, r)))) {
- break
- }
- }
- if (q) {
- for (l in g) {
- if (an.has(g, l) && !e--) {
- break
- }
- }
- q = !e
- }
- }
- t.pop();
- r.pop();
- return q
- };
- an.isEqual = function(d, c) {
- return X(d, c, [], [])
- };
- an.isEmpty = function(d) {
- if (null == d) {
- return ! 0
- }
- if (an.isArray(d) || an.isString(d)) {
- return 0 === d.length
- }
- for (var c in d) {
- if (an.has(d, c)) {
- return ! 1
- }
- }
- return ! 0
- };
- an.isElement = function(b) {
- return !! (b && 1 === b.nodeType)
- };
- an.isArray = am ||
- function(b) {
- return "[object Array]" == ac.call(b)
- };
- an.isObject = function(b) {
- return b === Object(b)
- };
- Y("Arguments Function String Number Date RegExp".split(" "),
- function(b) {
- an["is" + b] = function(a) {
- return ac.call(a) == "[object " + b + "]"
- }
- });
- an.isArguments(arguments) || (an.isArguments = function(b) {
- return ! (!b || !an.has(b, "callee"))
- });
- "function" !== typeof / . / &&(an.isFunction = function(b) {
- return "function" === typeof b
- });
- an.isFinite = function(b) {
- return isFinite(b) && !isNaN(parseFloat(b))
- };
- an.isNaN = function(b) {
- return an.isNumber(b) && b != +b
- };
- an.isBoolean = function(b) {
- return ! 0 === b || !1 === b || "[object Boolean]" == ac.call(b)
- };
- an.isNull = function(b) {
- return null === b
- };
- an.isUndefined = function(b) {
- return void 0 === b
- };
- an.has = function(d, c) {
- return S.call(d, c)
- };
- an.noConflict = function() {
- ar._ = aq;
- return this
- };
- an.identity = function(b) {
- return b
- };
- an.constant = function(b) {
- return function() {
- return b
- }
- };
- an.property = function(b) {
- return function(a) {
- return a[b]
- }
- };
- an.matches = function(b) {
- return function(a) {
- if (a === b) {
- return ! 0
- }
- for (var d in b) {
- if (b[d] !== a[d]) {
- return ! 1
- }
- }
- return ! 0
- }
- };
- an.times = function(f, e, l) {
- for (var k = Array(Math.max(0, f)), g = 0; g < f; g++) {
- k[g] = e.call(l, g)
- }
- return k
- };
- an.random = function(d, c) {
- null == c && (c = d, d = 0);
- return d + Math.floor(Math.random() * (c - d + 1))
- };
- an.now = Date.now ||
- function() {
- return (new Date).getTime()
- };
- var O = {
- escape: {
- "\x26": "\x26amp;",
- "\x3c": "\x26lt;",
- "\x3e": "\x26gt;",
- '"': "\x26quot;",
- "'": "\x26#x27;"
- }
- };
- O.unescape = an.invert(O.escape);
- var N = {
- escape: RegExp("[" + an.keys(O.escape).join("") + "]", "g"),
- unescape: RegExp("(" + an.keys(O.unescape).join("|") + ")", "g")
- };
- an.each(["escape", "unescape"],
- function(b) {
- an[b] = function(a) {
- return null == a ? "": ("" + a).replace(N[b],
- function(c) {
- return O[b][c]
- })
- }
- });
- an.result = function(e, d) {
- if (null != e) {
- var f = e[d];
- return an.isFunction(f) ? f.call(e) : f
- }
- };
- an.mixin = function(b) {
- Y(an.functions(b),
- function(a) {
- var d = an[a] = b[a];
- an.prototype[a] = function() {
- var c = [this._wrapped];
- aj.apply(c, arguments);
- c = d.apply(an, c);
- return this._chain ? an(c).chain() : c
- }
- })
- };
- var n = 0;
- an.uniqueId = function(d) {
- var c = ++n + "";
- return d ? d + c: c
- };
- an.templateSettings = {
- evaluate: /<%([\s\S]+?)%>/g,
- interpolate: /<%=([\s\S]+?)%>/g,
- escape: /<%-([\s\S]+?)%>/g
- };
- var V = /(.)^/,
- j = {
- "'": "'",
- "\\": "\\",
- "\r": "r",
- "\n": "n",
- "\t": "t",
- "\u2028": "u2028",
- "\u2029": "u2029"
- },
- i = /\\|'|\r|\n|\t|\u2028|\u2029/g;
- an.template = function(k, g, t) {
- var r;
- t = an.defaults({},
- t, an.templateSettings);
- var p = RegExp([(t.escape || V).source, (t.interpolate || V).source, (t.evaluate || V).source].join("|") + "|$", "g"),
- e = 0,
- q = "__p+\x3d'";
- k.replace(p,
- function(a, u, s, f, m) {
- q += k.slice(e, m).replace(i,
- function(b) {
- return "\\" + j[b]
- });
- u && (q += "'+\n((__t\x3d(" + u + "))\x3d\x3dnull?'':_.escape(__t))+\n'");
- s && (q += "'+\n((__t\x3d(" + s + "))\x3d\x3dnull?'':__t)+\n'");
- f && (q += "';\n" + f + "\n__p+\x3d'");
- e = m + a.length;
- return a
- });
- q += "';\n";
- t.variable || (q = "with(obj||{}){\n" + q + "}\n");
- q = "var __t,__p\x3d'',__j\x3dArray.prototype.join,print\x3dfunction(){__p+\x3d__j.call(arguments,'');};\n" + q + "return __p;\n";
- try {
- r = new Function(t.variable || "obj", "_", q)
- } catch(l) {
- throw l.source = q,
- l
- }
- if (g) {
- return r(g, an)
- }
- g = function(b) {
- return r.call(this, b, an)
- };
- g.source = "function(" + (t.variable || "obj") + "){\n" + q + "}";
- return g
- };
- an.chain = function(b) {
- return an(b).chain()
- };
- an.mixin(an);
- Y("pop push reverse shift sort splice unshift".split(" "),
- function(d) {
- var c = ao[d];
- an.prototype[d] = function() {
- var a = this._wrapped;
- c.apply(a, arguments); ("shift" == d || "splice" == d) && 0 === a.length && delete a[0];
- return this._chain ? an(a).chain() : a
- }
- });
- Y(["concat", "join", "slice"],
- function(d) {
- var c = ao[d];
- an.prototype[d] = function() {
- var b = c.apply(this._wrapped, arguments);
- return this._chain ? an(b).chain() : b
- }
- });
- an.extend(an.prototype, {
- chain: function() {
- this._chain = !0;
- return this
- },
- value: function() {
- return this._wrapped
- }
- });
- "function" === typeof define && define.amd && define("underscore", [],
- function() {
- return an
- })
- }).call(this); !
- function(t, s) {
- var q = s.prototype.trim,
- o = s.prototype.trimRight,
- n = s.prototype.trimLeft,
- j = function(f, d) {
- if (1 > d) {
- return ""
- }
- for (var g = ""; 0 < d;) {
- d & 1 && (g += f),
- d >>= 1,
- f += f
- }
- return g
- },
- m = [].slice,
- h = function(b) {
- return null == b ? "\\s": b.source ? b.source: "[" + i.escapeRegExp(b) + "]"
- },
- e = {
- lt: "\x3c",
- gt: "\x3e",
- quot: '"',
- apos: "'",
- amp: "\x26"
- },
- x = {},
- z;
- for (z in e) {
- x[e[z]] = z
- }
- var y = function() {
- function b(a) {
- return Object.prototype.toString.call(a).slice(8, -1).toLowerCase()
- }
- var d = function() {
- d.cache.hasOwnProperty(arguments[0]) || (d.cache[arguments[0]] = d.parse(arguments[0]));
- return d.format.call(null, d.cache[arguments[0]], arguments)
- };
- d.format = function(E, D) {
- var v = 1,
- B = E.length,
- A = "",
- u = [],
- C,
- w,
- k,
- a;
- for (C = 0; C < B; C++) {
- if (A = b(E[C]), "string" === A) {
- u.push(E[C])
- } else {
- if ("array" === A) {
- k = E[C];
- if (k[2]) {
- A = D[v];
- for (w = 0; w < k[2].length; w++) {
- if (!A.hasOwnProperty(k[2][w])) {
- throw Error(y('[_.sprintf] property "%s" does not exist', k[2][w]))
- }
- A = A[k[2][w]]
- }
- } else {
- A = k[1] ? D[k[1]] : D[v++]
- }
- if (/[^s]/.test(k[8]) && "number" != b(A)) {
- throw Error(y("[_.sprintf] expecting number but found %s", b(A)))
- }
- switch (k[8]) {
- case "b":
- A = A.toString(2);
- break;
- case "c":
- A = s.fromCharCode(A);
- break;
- case "d":
- A = parseInt(A, 10);
- break;
- case "e":
- A = k[7] ? A.toExponential(k[7]) : A.toExponential();
- break;
- case "f":
- A = k[7] ? parseFloat(A).toFixed(k[7]) : parseFloat(A);
- break;
- case "o":
- A = A.toString(8);
- break;
- case "s":
- A = (A = s(A)) && k[7] ? A.substring(0, k[7]) : A;
- break;
- case "u":
- A = Math.abs(A);
- break;
- case "x":
- A = A.toString(16);
- break;
- case "X":
- A = A.toString(16).toUpperCase()
- }
- A = /[def]/.test(k[8]) && k[3] && 0 <= A ? "+" + A: A;
- w = k[4] ? "0" == k[4] ? "0": k[4].charAt(1) : " ";
- a = k[6] - s(A).length;
- w = k[6] ? j(w, a) : "";
- u.push(k[5] ? A + w: w + A)
- }
- }
- }
- return u.join("")
- };
- d.cache = {};
- d.parse = function(k) {
- for (var g = [], u = [], r = 0; k;) {
- if (null !== (g = /^[^\x25]+/.exec(k))) {
- u.push(g[0])
- } else {
- if (null !== (g = /^\x25{2}/.exec(k))) {
- u.push("%")
- } else {
- if (null !== (g = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(k))) {
- if (g[2]) {
- var r = r | 1,
- l = [],
- f = g[2],
- p = [];
- if (null !== (p = /^([a-z_][a-z_\d]*)/i.exec(f))) {
- for (l.push(p[1]);
- "" !== (f = f.substring(p[0].length));) {
- if (null !== (p = /^\.([a-z_][a-z_\d]*)/i.exec(f))) {
- l.push(p[1])
- } else {
- if (null !== (p = /^\[(\d+)\]/.exec(f))) {
- l.push(p[1])
- } else {
- throw Error("[_.sprintf] huh?")
- }
- }
- }
- } else {
- throw Error("[_.sprintf] huh?")
- }
- g[2] = l
- } else {
- r |= 2
- }
- if (3 === r) {
- throw Error("[_.sprintf] mixing positional and named placeholders is not (yet) supported")
- }
- u.push(g)
- } else {
- throw Error("[_.sprintf] huh?")
- }
- }
- }
- k = k.substring(g[0].length)
- }
- return u
- };
- return d
- } (),
- i = {
- VERSION: "2.3.0",
- isBlank: function(b) {
- null == b && (b = "");
- return /^\s*$/.test(b)
- },
- stripTags: function(b) {
- return null == b ? "": s(b).replace(/<\/?[^>]+>/g, "")
- },
- capitalize: function(b) {
- b = null == b ? "": s(b);
- return b.charAt(0).toUpperCase() + b.slice(1)
- },
- chop: function(b, d) {
- if (null == b) {
- return []
- }
- b = s(b);
- d = ~~d;
- return 0 < d ? b.match(RegExp(".{1," + d + "}", "g")) : [b]
- },
- clean: function(b) {
- return i.strip(b).replace(/\s+/g, " ")
- },
- count: function(b, d) {
- return null == b || null == d ? 0 : s(b).split(d).length - 1
- },
- chars: function(b) {
- return null == b ? [] : s(b).split("")
- },
- swapCase: function(b) {
- return null == b ? "": s(b).replace(/\S/g,
- function(c) {
- return c === c.toUpperCase() ? c.toLowerCase() : c.toUpperCase()
- })
- },
- escapeHTML: function(b) {
- return null == b ? "": s(b).replace(/[&<>"']/g,
- function(c) {
- return "\x26" + x[c] + ";"
- })
- },
- unescapeHTML: function(b) {
- return null == b ? "": s(b).replace(/\&([^;]+);/g,
- function(f, k) {
- var g;
- return k in e ? e[k] : (g = k.match(/^#x([\da-fA-F]+)$/)) ? s.fromCharCode(parseInt(g[1], 16)) : (g = k.match(/^#(\d+)$/)) ? s.fromCharCode(~~g[1]) : f
- })
- },
- escapeRegExp: function(b) {
- return null == b ? "": s(b).replace(/([.*+?^=!:${}()|[\]\/\\])/g, "\\$1")
- },
- splice: function(g, f, l, k) {
- g = i.chars(g);
- g.splice(~~f, ~~l, k);
- return g.join("")
- },
- insert: function(f, d, g) {
- return i.splice(f, d, 0, g)
- },
- include: function(b, d) {
- return "" === d ? !0 : null == b ? !1 : -1 !== s(b).indexOf(d)
- },
- join: function() {
- var d = m.call(arguments),
- c = d.shift();
- null == c && (c = "");
- return d.join(c)
- },
- lines: function(b) {
- return null == b ? [] : s(b).split("\n")
- },
- reverse: function(b) {
- return i.chars(b).reverse().join("")
- },
- startsWith: function(b, d) {
- if ("" === d) {
- return ! 0
- }
- if (null == b || null == d) {
- return ! 1
- }
- b = s(b);
- d = s(d);
- return b.length >= d.length && b.slice(0, d.length) === d
- },
- endsWith: function(b, d) {
- if ("" === d) {
- return ! 0
- }
- if (null == b || null == d) {
- return ! 1
- }
- b = s(b);
- d = s(d);
- return b.length >= d.length && b.slice(b.length - d.length) === d
- },
- succ: function(b) {
- if (null == b) {
- return ""
- }
- b = s(b);
- return b.slice(0, -1) + s.fromCharCode(b.charCodeAt(b.length - 1) + 1)
- },
- titleize: function(b) {
- return null == b ? "": s(b).replace(/(?:^|\s)\S/g,
- function(c) {
- return c.toUpperCase()
- })
- },
- camelize: function(b) {
- return i.trim(b).replace(/[-_\s]+(.)?/g,
- function(d, c) {
- return c.toUpperCase()
- })
- },
- underscored: function(b) {
- return i.trim(b).replace(/([a-z\d])([A-Z]+)/g, "$1_$2").replace(/[-\s]+/g, "_").toLowerCase()
- },
- dasherize: function(b) {
- return i.trim(b).replace(/([A-Z])/g, "-$1").replace(/[-_\s]+/g, "-").toLowerCase()
- },
- classify: function(b) {
- return i.titleize(s(b).replace(/_/g, " ")).replace(/\s/g, "")
- },
- humanize: function(b) {
- return i.capitalize(i.underscored(b).replace(/_id$/, "").replace(/_/g, " "))
- },
- trim: function(b, c) {
- if (null == b) {
- return ""
- }
- if (!c && q) {
- return q.call(b)
- }
- c = h(c);
- return s(b).replace(RegExp("^" + c + "+|" + c + "+$", "g"), "")
- },
- ltrim: function(b, d) {
- if (null == b) {
- return ""
- }
- if (!d && n) {
- return n.call(b)
- }
- d = h(d);
- return s(b).replace(RegExp("^" + d + "+"), "")
- },
- rtrim: function(b, d) {
- if (null == b) {
- return ""
- }
- if (!d && o) {
- return o.call(b)
- }
- d = h(d);
- return s(b).replace(RegExp(d + "+$"), "")
- },
- truncate: function(b, g, f) {
- if (null == b) {
- return ""
- }
- b = s(b);
- g = ~~g;
- return b.length > g ? b.slice(0, g) + (f || "...") : b
- },
- prune: function(b, g, f) {
- if (null == b) {
- return ""
- }
- b = s(b);
- g = ~~g;
- f = null != f ? s(f) : "...";
- if (b.length <= g) {
- return b
- }
- g = b.slice(0, g + 1).replace(/.(?=\W*\w*$)/g,
- function(c) {
- return c.toUpperCase() !== c.toLowerCase() ? "A": " "
- });
- g = g.slice(g.length - 2).match(/\w\w/) ? g.replace(/\s*\S+$/, "") : i.rtrim(g.slice(0, g.length - 1));
- return (g + f).length > b.length ? b: b.slice(0, g.length) + f
- },
- words: function(d, c) {
- return i.isBlank(d) ? [] : i.trim(d, c).split(c || /\s+/)
- },
- pad: function(b, r, p, l) {
- b = null == b ? "": s(b);
- r = ~~r;
- var k = 0;
- p ? 1 < p.length && (p = p.charAt(0)) : p = " ";
- switch (l) {
- case "right":
- return k = r - b.length,
- b + j(p, k);
- case "both":
- return k = r - b.length,
- j(p, Math.ceil(k / 2)) + b + j(p, Math.floor(k / 2));
- default:
- return k = r - b.length,
- j(p, k) + b
- }
- },
- lpad: function(f, d, g) {
- return i.pad(f, d, g)
- },
- rpad: function(f, d, g) {
- return i.pad(f, d, g, "right")
- },
- lrpad: function(f, d, g) {
- return i.pad(f, d, g, "both")
- },
- sprintf: y,
- vsprintf: function(d, c) {
- c.unshift(d);
- return y.apply(null, c)
- },
- toNumber: function(b, g) {
- if (null == b || "" == b) {
- return 0
- }
- b = s(b);
- var f;
- f = 1 * (1 * b || 0).toFixed(~~g) || 0;
- return 0 === f && !b.match(/^0+$/) ? Number.NaN: f
- },
- numberFormat: function(g, f, l, k) {
- if (isNaN(g) || null == g) {
- return ""
- }
- g = g.toFixed(~~f);
- k = k || ",";
- g = g.split(".");
- l = g[1] ? (l || ".") + g[1] : "";
- return g[0].replace(/(\d)(?=(?:\d{3})+$)/g, "$1" + k) + l
- },
- strRight: function(b, g) {
- if (null == b) {
- return ""
- }
- b = s(b);
- g = null != g ? s(g) : g;
- var f = !g ? -1 : b.indexOf(g);
- return~f ? b.slice(f + g.length, b.length) : b
- },
- strRightBack: function(b, g) {
- if (null == b) {
- return ""
- }
- b = s(b);
- g = null != g ? s(g) : g;
- var f = !g ? -1 : b.lastIndexOf(g);
- return~f ? b.slice(f + g.length, b.length) : b
- },
- strLeft: function(b, g) {
- if (null == b) {
- return ""
- }
- b = s(b);
- g = null != g ? s(g) : g;
- var f = !g ? -1 : b.indexOf(g);
- return~f ? b.slice(0, f) : b
- },
- strLeftBack: function(f, d) {
- if (null == f) {
- return ""
- }
- f += "";
- var g = f.lastIndexOf(null != d ? "" + d: d);
- return~g ? f.slice(0, g) : f
- },
- toSentence: function(l, k, v, u) {
- k = k || ", ";
- v = v || " and ";
- var r = l.slice(),
- p = r.pop();
- 2 < l.length && u && (v = i.rtrim(k) + v);
- return r.length ? r.join(k) + v + p: p
- },
- toSentenceSerial: function() {
- var b = m.call(arguments);
- b[3] = !0;
- return i.toSentence.apply(i, b)
- },
- slugify: function(b) {
- if (null == b) {
- return ""
- }
- var d = RegExp(h("\u0105\u00e0\u00e1\u00e4\u00e2\u00e3\u00e5\u00e6\u0107\u0119\u00e8\u00e9\u00eb\u00ea\u00ec\u00ed\u00ef\u00ee\u0142\u0144\u00f2\u00f3\u00f6\u00f4\u00f5\u00f8\u00f9\u00fa\u00fc\u00fb\u00f1\u00e7\u017c\u017a"), "g");
- b = s(b).toLowerCase().replace(d,
- function(c) {
- c = "\u0105\u00e0\u00e1\u00e4\u00e2\u00e3\u00e5\u00e6\u0107\u0119\u00e8\u00e9\u00eb\u00ea\u00ec\u00ed\u00ef\u00ee\u0142\u0144\u00f2\u00f3\u00f6\u00f4\u00f5\u00f8\u00f9\u00fa\u00fc\u00fb\u00f1\u00e7\u017c\u017a".indexOf(c);
- return "aaaaaaaaceeeeeiiiilnoooooouuuunczz".charAt(c) || "-"
- });
- return i.dasherize(b.replace(/[^\w\s-]/g, ""))
- },
- surround: function(d, c) {
- return [c, d, c].join("")
- },
- quote: function(b) {
- return i.surround(b, '"')
- },
- exports: function() {
- var d = {},
- c;
- for (c in this) {
- this.hasOwnProperty(c) && !c.match(/^(?:include|contains|reverse)$/) && (d[c] = this[c])
- }
- return d
- },
- repeat: function(b, l, k) {
- if (null == b) {
- return ""
- }
- l = ~~l;
- if (null == k) {
- return j(s(b), l)
- }
- for (var g = []; 0 < l; g[--l] = b) {}
- return g.join(k)
- },
- levenshtein: function(p, A) {
- if (null == p && null == A) {
- return 0
- }
- if (null == p) {
- return s(A).length
- }
- if (null == A) {
- return s(p).length
- }
- p = s(p);
- A = s(A);
- for (var w = [], v, u, r = 0; r <= A.length; r++) {
- for (var b = 0; b <= p.length; b++) {
- u = r && b ? p.charAt(b - 1) === A.charAt(r - 1) ? v: Math.min(w[b], w[b - 1], v) + 1 : r + b,
- v = w[b],
- w[b] = u
- }
- }
- return w.pop()
- }
- };
- i.strip = i.trim;
- i.lstrip = i.ltrim;
- i.rstrip = i.rtrim;
- i.center = i.lrpad;
- i.rjust = i.lpad;
- i.ljust = i.rpad;
- i.contains = i.include;
- i.q = i.quote;
- "undefined" !== typeof exports ? ("undefined" !== typeof module && module.exports && (module.exports = i), exports._s = i) : "function" === typeof define && define.amd ? define("underscore.string", [],
- function() {
- return i
- }) : (t._ = t._ || {},
- t._.string = t._.str = i)
- } (this, String);
- _.mixin(_.str.exports());
- bs = bs || {};
- bs.s_sharelayer_ccbi = "js_bscommon/res/shareLayer.ccbi";
- bs.init = function() {
- cc.Sequence.createWithArray = function(d) {
- if (0 === d.length) {
- return cc.Sequence.create()
- }
- if (1 === d.length) {
- return cc.Sequence.create(d[0])
- }
- if (2 === d.length) {
- return cc.Sequence.create(d[0], d[1])
- }
- var c = d.pop();
- return cc.Sequence.create(cc.Sequence.createWithArray(d), c)
- };
- bs.isInBrowser() && (bs._originEGLViewConvertToLocationInView || (bs._originEGLViewConvertToLocationInView = cc.view.convertToLocationInView), cc.view.convertToLocationInView = function(e, d, f) {
- e = bs._originEGLViewConvertToLocationInView.call(cc.view, e, d, f);
- window && window.canvasScale && (d = window.canvasScale, e.x /= d, e.y /= d);
- return e
- });
- cc.PhysicsSprite && (cc.PhysicsSprite.extend = cc.Class.extend);
- cc.ClippingNode && (cc.ClippingNode.extend = cc.Class.extend);
- cc.Scale9Sprite && (cc.Scale9Sprite.extend = cc.Class.extend);
- cc.ParallaxNode && (cc.ParallaxNode.extend = cc.Class.extend)
- };
- bs.System = bs.System || {};
- bs.System.currentTimeMillis = function() {
- return (new Date).getTime()
- };
- bs.onPlatformBuyGoodSuccess = function() {};
- bs.onPlatformBuyGoodFail = function() {};
- bs.onPlatformRestoreFinish = function() {};
- bs.onPlatformRestoreFail = function() {};
- bs.Pay = bs.Pay || {};
- bs.Pay.kPayMethodAppstore = 1;
- bs.Pay.kPayMethodChinaMobile = 2;
- bs.Pay.kPayMethodChinaUnicom = 3;
- bs.Pay.kPayMethodChinaTelecom = 4;
- bs.Pay.kPayMethodAlipay = 5;
- bs.Pay.kPayMethodWechat = 6;
- bs.Pay.kPayMethodQQ = 7;
- "undefined" === typeof cc.GRAY && (cc.GRAY = {
- r: 166,
- g: 166,
- b: 166
- });
- String.prototype.format = function(b) {
- return this.replace(String.prototype.format.regex,
- function(a) {
- a = parseInt(a.substring(1, a.length - 1));
- return 0 <= a ? b[a] : -1 === a ? "{": -2 === a ? "}": ""
- })
- };
- String.prototype.format.regex = /{-?[0-9]+}/g;
- bs.stringFromFormat = function(d, c) {
- return d.format(c)
- };
- bs.fabs = function(b) {
- return 0 > b ? -b: b
- };
- bs.stringFromSecondsClockStyle = function(e) {
- var d = Math.floor(e / 3600),
- f = Math.floor((e - 3600 * d) / 60);
- return "{0}:{1}:{2}".format([d, f, e - 3600 * d - 60 * f])
- };
- bs.middleOfNode = function(b) {
- return cc.p(b.getContentSize().width / 2, b.getContentSize().height / 2)
- };
- bs.middleOfWindow = function() {
- var b = cc.director.getWinSize();
- return cc.p(b.width / 2, b.height / 2)
- };
- bs.c4BFromccc3B = function(b) {
- return cc.color(b.r, b.g, b.b, 255)
- };
- bs.jsonFromFile = function(a) {
- return eval("(" + cc.FileUtils.getInstance().getStringFromFile(a) + ")")
- };
- bs.parseJSON = function(d) {
- try {
- return JSON.parse(d)
- } catch(c) {
- return cc.log("[JSON]:" + c.message),
- cc.log("[JSON]:" + c.description),
- null
- }
- };
- bs.toJSONString = function(d) {
- try {
- return JSON.stringify(d)
- } catch(c) {
- return cc.log(c.message),
- cc.log(c.description),
- null
- }
- };
- bs.SAFE_REMOVE = function(b) {
- b && b.removeFromParent()
- };
- bs.RAND = function(d, c) {
- return d + Math.floor(Math.random() * (c - d))
- };
- bs.surround = function(f, e, h, g) {
- return _.filter([[f - 1, e - 1], [f, e - 1], [f + 1, e - 1], [f - 1, e], [f, e], [f + 1, e], [f - 1, e + 1], [f, e + 1], [f + 1, e + 1]],
- function(b) {
- return 0 <= b[0] && 0 <= b[1] && b[0] < h && b[1] < g
- })
- };
- bs.isInBrowser = function() {
- return ! cc.sys.isNative
- };
- bs.ALLOCATE_PRIORITY = function() {
- return bs.TouchPriorityManager.getInstance().allocatePriority()
- };
- bs._s4 = function() {
- return Math.floor(65536 * (1 + Math.random())).toString(16).substring(1)
- };
- bs.guid = function() {
- return bs._s4() + bs._s4() + "-" + bs._s4() + "-" + bs._s4() + "-" + bs._s4() + "-" + bs._s4() + bs._s4() + bs._s4()
- };
- bs.setFlipX = function(d, c) {
- d.setFlipX ? d.setFlipX(c) : d.setFlippedX(c)
- };
- bs.setFlipY = function(d, c) {
- d.setFlipY ? d.setFlipY(c) : d.setFlippedY(c)
- };
- bs.getTop = function(b) {
- return cc.rectGetMaxY(b.getBoundingBox())
- };
- bs.getTopOnScreen = function(b) {
- return cc.rectGetMaxY(b.getBoundingBoxToWorld())
- };
- bs.getBottom = function(b) {
- return cc.rectGetMinY(b.getBoundingBox())
- };
- bs.getBottomOnScreen = function(b) {
- return cc.rectGetMinY(b.getBoundingBoxToWorld())
- };
- bs.getLeft = function(b) {
- return cc.rectGetMinX(b.getBoundingBox())
- };
- bs.getRight = function(b) {
- return cc.rectGetMaxX(b.getBoundingBox())
- };
- bs.getVisualWidth = function(b) {
- return b.getContentSize().width * b.getScaleX()
- };
- bs.getVisualHeight = function(b) {
- return b.getContentSize().height * b.getScaleY()
- };
- bs.getVisualSize = function(d) {
- var c = d.getContentSize();
- return cc.size(c.width * d.getScaleX(), c.height * d.getScaleY())
- };
- bs.centerNodeToParent = function(d, c) {
- bs.positionNodeToParentPercent(d, c, 0.5, 0.5)
- };
- bs.positionNodeToParentPercent = function(g, e, l, j) {
- e = (e || g.getParent()).getContentSize();
- var i = bs.getVisualSize(g),
- h = g.isIgnoreAnchorPointForPosition() ? cc.p(0, 0) : g.getAnchorPoint();
- g.setPosition(cc.p(e.width * l + (h.x - 0.5) * i.width, e.height * j + (h.y - 0.5) * i.height))
- };
- bs.centerNodeXToParent = function(d, c) {
- c = c || d.getParent();
- d.setPositionX(c.getContentSize().width / 2 + (d.getAnchorPoint().x - 0.5) * d.getContentSize().width)
- };
- bs.centerNodeYToParent = function(d, c) {
- c = c || d.getParent();
- d.setPositionY(c.getContentSize().height / 2 + (d.getAnchorPoint().y - 0.5) * d.getContentSize().height)
- };
- bs.scaleToWidth = function(d, c) {
- d.setScale(c / d.getContentSize().width)
- };
- bs.scaleToHeight = function(d, c) {
- d.setScale(c / d.getContentSize().height)
- };
- bs.scaleToSize = function(f, e, h) {
- var g = h ? e: e.width;
- h = h ? h: e.height;
- bs.scaleXToWidth(f, g);
- bs.scaleYToHeight(f, h)
- };
- bs.scaleXToWidth = function(d, c) {
- d.setScaleX(c / d.getContentSize().width)
- };
- bs.scaleYToHeight = function(d, c) {
- d.setScaleY(c / d.getContentSize().height)
- };
- bs.TexParams = function(g, e, j, i) {
- var h = {};
- h.minFilter = g || 0;
- h.magFilter = e || 0;
- h.wrapS = j || 0;
- h.wrapT = i || 0;
- return h
- };
- bs.autoSprite = function(b) {
- return cc.spriteFrameCache.getSpriteFrame(b) ? new cc.Sprite("#" + b) : cc.Sprite.create(b)
- };
- bs.isInWechat = function() {
- return ! _.isUndefined(navigator) && !_.isUndefined(navigator.userAgent) ? -1 != navigator.userAgent.toLowerCase().indexOf("micromessenger") : !1
- };
- bs.headimgForQQ = function(d, c) {
- return "/proxy?url\x3d" + encodeURIComponent(d.replace(/\/[0-9]+$/, "/" + c))
- };
- bs.setAllMenuEnabledWithNode = function(e, d) {
- for (var f = 0; f < e.getChildrenCount(); ++f) {
- this.setAllMenuEnabledWithNode(e.getChildren()[f], d)
- }
- e instanceof cc.Menu && e.setEnabled(d)
- };
- bs.versionCompare = function(g, e) {
- if ("stringstring" != typeof g + typeof e) {
- return ! 1
- }
- for (var l = g.split("."), j = e.split("."), i = 0, h = Math.max(l.length, j.length); i < h; i++) {
- if (l[i] && !j[i] && 0 < parseInt(l[i]) || parseInt(l[i]) > parseInt(j[i])) {
- return 1
- }
- if (j[i] && !l[i] && 0 < parseInt(j[i]) || parseInt(l[i]) < parseInt(j[i])) {
- return - 1
- }
- }
- return 0
- };
- bs.createSpriteWithAnimate = function(h, e, n, m, l, i) {
- var j = new cc.Sprite("#" + h + e + ".png");
- h = bs.createAnimate(h, e + 1, n, m); - 1 == l ? j.runAction(cc.RepeatForever.create(h)) : (0 < l && (h = cc.Repeat.create(h, l)), i && (h = cc.Sequence.create(h, cc.RemoveSelf.create())), j.runAction(h));
- return j
- };
- bs.createAnimate = function(h, e, o, n, l) {
- var i = h + "_" + e + "_" + o,
- j = cc.animationCache.getAnimation(i);
- if (!j) {
- for (j = []; - 1 == o || e <= o; ++e) {
- var m = bs.spriteFrameFromName(h + e + ".png");
- if (!m) {
- break
- }
- j.push(m)
- }
- j = new cc.Animation(j, n);
- cc.animationCache.addAnimation(j, i)
- }
- h = cc.Animate.create(j);
- l && ( - 1 == l ? h.repeatForever() : h.repeat(l));
- return h
- };
- bs.spriteFrameFromName = function(b) {
- _.endsWith(b, ".png") || (b += ".png");
- return cc.spriteFrameCache.getSpriteFrame(b)
- };
- bs.setSpriteDisplayFrameName = function(e, d, f) {
- d = bs.spriteFrameFromName(d);
- e.setSpriteFrame(d);
- f && e.setContentSize(d.getOriginalSize())
- };
- bs.logf = function() {
- var b = _.sprintf.apply(_, arguments);
- cc.sys.isNative ? cc.log(b) : cc.IS_SHOW_DEBUG_ON_PAGE ? cc._logToWebPage(b) : console.log(b)
- };
- bs.isTouchInside = function(f, e, h) {
- f = e.convertTouchToNodeSpace(f);
- var g = e.getContentSize().width * e.getScaleX();
- e = e.getContentSize().height * e.getScaleY();
- h = h || cc.rect(0, 0, g, e);
- return cc.rectContainsPoint(h, f)
- };
- bs.createClippingNode = function(e) {
- var d = cc.DrawNode.create(),
- f = cc.color(1, 1, 1, 1);
- e = [cc.p(e.x, e.y), cc.p(e.x + e.width, e.y), cc.p(e.x + e.width, e.y + e.height), cc.p(e.x, e.y + e.height)];
- d.drawPoly(e, f, 1, f);
- return cc.ClippingNode.create(d)
- };
- bs.clone = function(e) {
- var d = e instanceof Array ? [] : {},
- f;
- for (f in e) {
- e.hasOwnProperty(f) && !_.isFunction(e[f]) && (d[f] = _.isObject(e[f]) ? bs.clone(e[f]) : e[f])
- }
- return d
- };
- bs.convertPositionToTargetNodeSpace = function(g, e, j) {
- var i = g.getAnchorPoint(),
- h = g.getContentSize();
- j = j || cc.p(h.width * i.x, h.height * i.y);
- g = g.convertToWorldSpace(j);
- return e.convertToNodeSpace(g)
- };
- bs.jsonFromConfFile = function(d) {
- if (this.isInBrowser()) {
- var c = cc.loader.getRes("conf/" + d + ".json");
- if (c) {
- return c
- }
- d = cc.loader._loadTxtSync("res/conf/" + d + ".json")
- } else {
- d = bs.Config.shared().loadConf("conf/" + d + ".bjs")
- }
- return bs.parseJSON(d)
- };
- bs.isNodeVisible = function(b) {
- for (; b && b.isVisible();) {
- b = b.getParent()
- }
- return ! b
- };
- bs.layerWithChildrenHorizontal = function(h, e, n, m) {
- var l = cc.Layer.create(),
- i = 0;
- null == n && (n = cc.VERTICAL_TEXT_ALIGNMENT_CENTER);
- m || (m = 0, _.each(h,
- function(b) {
- b = bs.getVisualSize(b).height;
- m < b && (m = b)
- }));
- var j = [1, 0.5, 0];
- _.each(h,
- function(c) {
- if (c) {
- var f = bs.getVisualSize(c),
- b = c.getAnchorPoint();
- c.isIgnoreAnchorPointForPosition() && (b = cc.p(0, 0));
- var d = cc.p(i, j[n] * (m - f.height));
- c.setPosition(cc.pAdd(d, cc.pCompMult(b, cc.pFromSize(f))));
- i += f.width + e;
- l.addChild(c)
- }
- });
- l.setContentSize(i - e, m);
- l.setAnchorPoint(0, 0);
- return l
- };
- bs.layerWithChildrenVertical = function(h, e, n, m) {
- var l = cc.Layer.create(),
- i = 0;
- if (_.isUndefined(n) || _.isNull(n)) {
- n = cc.TEXT_ALIGNMENT_CENTER
- }
- m || (m = 0, _.each(h,
- function(b) {
- b && (b = b.getContentSize().width, m < b && (m = b))
- }));
- var j = [0, 0.5, 1];
- h.reverse();
- _.each(h,
- function(c) {
- if (c) {
- var f = bs.getVisualSize(c),
- b = c.getAnchorPoint();
- c.isIgnoreAnchorPointForPosition() && (b = cc.p(0, 0));
- var d = cc.p(j[n] * (m - f.width), i);
- c.setPosition(cc.pAdd(d, cc.pCompMult(b, cc.pFromSize(f))));
- i += f.height + e;
- l.addChild(c)
- }
- });
- l.setContentSize(m, i - e);
- l.setAnchorPoint(0, 0);
- return l
- };
- bs.formatTime = function(f) {
- var e = Math.floor(f / 3600);
- f = Math.floor(f % 3600);
- var h = Math.floor(f / 60);
- f %= 60;
- var g = "",
- g = 10 <= e ? e: "0" + e,
- g = 10 <= h ? g + ":" + h: g + ":0" + h;
- return 10 <= f ? g + ":" + f: g + ":0" + f
- };
- bs.roundingTime = function(f) {
- var e = Math.floor(f / 86400),
- h = Math.floor(f / 3600),
- g = Math.floor(f / 60);
- return 0 != e ? e + "\u5929": 0 != h ? h + "\u5c0f\u65f6": 0 != g ? g + "\u5206\u949f": f + "\u79d2"
- };
- bs.registerTouchEventOneByOne = function(e, d, f) {
- d = {
- event: cc.EventListener.TOUCH_ONE_BY_ONE,
- swallowTouches: null == d ? !0 : d,
- onTouchBegan: e.onTouchBegan.bind(e)
- };
- e.onTouchMoved && (d.onTouchMoved = e.onTouchMoved.bind(e));
- e.onTouchEnded && (d.onTouchEnded = e.onTouchEnded.bind(e));
- e.onTouchCanceled && (d.onTouchCanceled = e.onTouchCanceled.bind(e));
- d = cc.EventListener.create(d);
- cc.eventManager.addListener(d, f || e);
- return d
- };
- bs.kSocialTypeNone = 0;
- bs.kSocialTypeQQ = 1;
- bs.kSocialTypeWechat = 2;
- bs.kSocialTypeLaiwang = 3;
- bs.kBSSocialTypeWeibo = 4;
- bs.Sound = {
- _isMute: !1,
- _isMusicMute: !1,
- _isEffectMute: !1,
- _musicVolume: 1,
- _effectVolume: 1,
- _stack: [],
- getEffectVolume: function() {
- return this._effectVolume
- },
- setEffectVolume: function(b) {
- this._effectVolume = b;
- cc.audioEngine.setEffectsVolume(b)
- },
- getMusicVolume: function() {
- return this._musicVolume
- },
- setMusicVolume: function(b) {
- this._musicVolume = b;
- cc.audioEngine.setMusicVolume(b)
- },
- getIsMute: function() {
- return this._isMute
- },
- setIsMute: function(b) {
- this._isMute = b;
- this.setIsEffectMute(b);
- this.setIsMusicMute(b)
- },
- getIsMusicMute: function() {
- return this._isMusicMute
- },
- setIsMusicMute: function(b) {
- this._isMusicMute = b;
- cc.audioEngine.setMusicVolume(b ? 0 : this._musicVolume)
- },
- switchMusicMute: function() {
- this.setIsMusicMute(!this.getIsEffectMute())
- },
- getIsEffectMute: function() {
- return this._isEffectMute
- },
- setIsEffectMute: function(b) {
- this._isEffectMute = b;
- cc.audioEngine.setEffectsVolume(b ? 0 : this._effectVolume)
- },
- switchEffectMute: function() {
- this.setIsEffectMute(!this.getIsEffectMute())
- },
- playEffect: function(d, c) {
- return cc.audioEngine.playEffect(d, c)
- },
- stopEffect: function(b) {
- cc.audioEngine.stopEffect(b)
- },
- stopAllEffects: function() {
- cc.audioEngine.stopAllEffects()
- },
- playMusic: function(b) {
- cc.audioEngine.playMusic(b)
- },
- stopMusic: function() {
- cc.audioEngine.stopMusic()
- },
- pushMusic: function(e, d) {
- var f = this._stack;
- return 0 >= f.length || d <= _.last(f).priority ? (f.push({
- file: e,
- priority: d
- }), this._playMusic(e), !0) : !1
- },
- popMusic: function() {
- var b = this._stack;
- 0 >= b.length || (cc.audioEngine.stopMusic(), b.pop(), 0 < b.length && this._playMusic(_.last(b).file))
- },
- dump: function() {
- cc.log("bs.Sound.dump not implemented.")
- },
- destroy: function() {},
- configure: function() {},
- active: function() {},
- init: function() {},
- _playMusic: function(b) {
- cc.audioEngine.stopMusic();
- cc.audioEngine.playMusic(b, !0)
- },
- shared: function() {
- return this
- }
- };
- bs.kResourceStatusServerError = -3;
- bs.kResourceStatusCacheDirError = -2;
- bs.kResourceStatusUnknown = -1;
- bs.kResourceStatusUpToDate = 0;
- bs.kResourceStatusChecking = 1;
- bs.kResourceStatusNeedUpdate = 2;
- bs.kResourceStatusUpdating = 3;
- bs.kResourceStatusFinish = 4;
- bs.kMessageResourceStatusChanged = "message-resource-status-changed";
- bs.kMessageResourceUpdateProgressChanged = "message-resource-update-progress-changed";
- bs.onResourceCheckStatusChanged = function(d, c) {
- bs.postMessage(bs.kMessageResourceStatusChanged, {
- module: d,
- status: c
- });
- bs.logf("[BSResource] onResourceCheckStatusChanged: %s, %d", d, c)
- };
- bs.onResourceUpdateStatusChanged = function(d, c) {
- bs.postMessage(bs.kMessageResourceStatusChanged, {
- module: d,
- status: c
- });
- bs.logf("[BSResource] onResourceUpdateStatusChanged: %s, %d", d, c)
- };
- bs.onResourceUpdateProgressChanged = function(e, d, f) {
- bs.postMessage(bs.kMessageResourceUpdateProgressChanged, {
- module: e,
- finished: d,
- total: f
- });
- bs.logf("[BSResource] onResourceUpdateProgressChanged: %s, %d, %d", e, d, f)
- };
- bs.Http = bs.Http || {};
- bs.Http.TIME_OUT = 10000;
- bs.Http.proxy = function(d, c) {
- bs.Http.get("/proxy?url\x3d" + encodeURIComponent(d), c)
- };
- bs.Http.get = function(e, d) {
- var f = new XMLHttpRequest;
- f.open("GET", e, !0);
- f.onreadystatechange = function() {
- 4 == f.readyState && _.isFunction(d) && (200 == f.status ? d(null, f.responseText) : (cc.log("[BSHttp] response status error :" + f.status), 0 >= f.status ? d(f.status, null) : d(f.status, f.responseText)))
- };
- f.timeout = bs.Http.TIME_OUT;
- f.ontimeout = d;
- f.send()
- };
- bs.Http.post = function(g, e, j, i) {
- var h = new XMLHttpRequest;
- h.open("POST", g, !0);
- i && h.setRequestHeader("Content-Type", i);
- h.onreadystatechange = function() {
- 4 == h.readyState && _.isFunction(j) && (200 == h.status ? j(null, h.responseText) : (cc.log("[BSHttp] response status error :" + h.status), 0 >= h.status ? j(h.status, null) : j(h.status, h.responseText)))
- };
- h.timeout = bs.Http.TIME_OUT;
- h.send(e)
- };
- bs.Http._signingFunc = null;
- bs.Http.setSigningFunction = function(b) {
- bs.Http._signingFunc = b
- };
- bs.Http.addSignature = function(e, d) {
- if (_.isFunction(bs.Http._signingFunc)) {
- var f = bs.Http._signingFunc(e, d);
- _.isArray(d) ? d.push(f) : d._sig = f
- }
- };
- bs.Http.jsonrpc = function(f, e, h, g) {
- bs.Http.addSignature(e, h);
- bs.Http.post(f, JSON.stringify({
- jsonrpc: "2.0",
- method: e,
- params: h,
- id: 0
- }),
- function(b, i) {
- if (b) {
- g(b, null)
- } else {
- var d = bs.parseJSON(i); ! d || d.error ? (cc.log("[BSHTTP] rpc:" + e + ", return error:" + JSON.stringify(d)), g(d, null)) : g(null, bs.parseJSON(i).result)
- }
- },
- "application/json")
- };
- bs.TouchPriorityManager = cc.Class.extend({
- _currentPriority: 1000000,
- allocatePriority: function() {
- this._currentPriority--;
- this._currentPriority == this.kHighestPriority && (cc.log("[TouchPriorityManager] touch priority overflow"), this._currentPriority = this.kLowestPriority);
- return this._currentPriority
- }
- });
- bs.gTouchPriorityManagerInstance = null;
- bs.TouchPriorityManager.getInstance = function() {
- null == bs.gTouchPriorityManagerInstance && (bs.gTouchPriorityManagerInstance = new bs.TouchPriorityManager);
- return bs.gTouchPriorityManagerInstance
- };
- bs.TouchPriorityManager.kLowestPriority = 1000000;
- bs.TouchPriorityManager.kHighestPriority = 1024;
- bs.TouchableSprite = cc.Layer.extend({
- RGBAProtocol: !0,
- _target: null,
- _callback: null,
- _isSwallowTouch: !1,
- _isTouchMoved: !1,
- _conditionalRect: null,
- _internalImg: null,
- _cancelTouchOnMove: !1,
- _cancelTouchOnMoveOut: !0,
- _enable: !0,
- _originTouchPoint: null,
- _foregroundImg: null,
- _normalSpriteFrameName: null,
- _selectedSpriteFrameName: null,
- _disabledSpriteFrameName: null,
- _fadeOutCallback: null,
- ctor: function() {
- this._super()
- },
- _isTouchInside: function(d) {
- d = this.convertToNodeSpace(d.getLocation());
- var c = this.rect();
- c.x = 0;
- c.y = 0;
- return cc.rectEqualToRect(this._conditionalRect, cc.rect(0, 0, 0, 0)) ? cc.rectContainsPoint(c, d) : cc.rectContainsPoint(this._conditionalRect, d)
- },
- init: function(d, c) {
- this._super();
- this._target = c;
- this._callback = d;
- this._conditionalRect = cc.rect(0, 0, 0, 0);
- this._eventListener = bs.registerTouchEventOneByOne(this);
- this.ignoreAnchorPointForPosition(!1)
- },
- initWithSize: function(e, d, f) {
- this.init(d, f);
- this.setContentSize(e)
- },
- initWithSpriteName: function(e, d, f) {
- this.init(d, f);
- e = this._internalImg = new cc.Sprite(e);
- e.setAnchorPoint(0, 0);
- this.addChild(e);
- this.setContentSize(e.getContentSize())
- },
- initWithSpriteFrameName: function(e, d, f) {
- this.init(d, f);
- e = this._internalImg = new cc.Sprite("#" + e);
- e.setAnchorPoint(0, 0);
- this.addChild(e);
- this.setContentSize(e.getContentSize())
- },
- initWithTwoStateSpriteFrameName: function(f, e, h, g) {
- this.init(h, g);
- h = this._internalImg = new cc.Sprite("#" + f);
- this.setNormalSpriteFrameName(f);
- this.setSelectedSpriteFrameName(e);
- h.setAnchorPoint(0, 0);
- this.addChild(h);
- this.setContentSize(h.getContentSize())
- },
- initWithThreeStateSpriteFrameName: function(g, e, j, i, h) {
- this.init(i, h);
- i = this._internalImg = new cc.Sprite("#" + g);
- this.setNormalSpriteFrameName(g);
- this.setSelectedSpriteFrameName(e);
- this.setDisabledSpriteFrameName(j);
- i.setAnchorPoint(0, 0);
- this.addChild(i);
- this.setContentSize(i.getContentSize())
- },
- initWithScale9SpriteFrameName: function(g, e, j, i, h) {
- this.init(i, h);
- g = this._internalImg = cc.Scale9Sprite.createWithSpriteFrameName(g, e);
- g.setAnchorPoint(0, 0);
- this.addChild(g);
- this.setContentSize(j)
- },
- initWithSprite: function(e, d, f) {
- this.init(d, f);
- this._internalImg = e;
- e.setAnchorPoint(0, 0);
- this.addChild(e);
- this.setContentSize(e.getContentSize())
- },
- setIsSwallowTouch: function(b) {
- this._eventListener.setSwallowTouches(b)
- },
- rect: function() {
- var e = this.getPosition(),
- d = this.getContentSize(),
- f = this.getAnchorPoint();
- return cc.rect(e.x - d.width * f.x, e.y - d.height * f.y, d.width, d.height)
- },
- setForegroundImg: function(f, e, h) {
- this._foregroundImg = {
- node: f,
- anchor: _.clone(e),
- pos: _.clone(h)
- };
- var g = this.getContentSize();
- e && (f.setAnchorPoint(e), f.setPosition(h.x + g.width * e.x, h.y + g.height * e.y));
- this.addChild(f, 1)
- },
- setContentSize: function(b) {
- cc.sizeEqualToSize(b, this.getContentSize()) || (this._super(b), this._internalImg && this._internalImg.setContentSize(b))
- },
- setFlipX: function(b) {
- bs.setFlipX(this._internalImg, b)
- },
- setFlipY: function(b) {
- bs.setFlipY(this._internalImg, b)
- },
- setSpriteFrame: function(f) {
- if (this._internalImg instanceof cc.Scale9Sprite) {
- var e = this._internalImg.getCapInsets(),
- h = _.clone(this._internalImg.getContentSize()),
- g = _.clone(this._internalImg.getAnchorPoint());
- this._internalImg.initWithSpriteFrame(f, e);
- this._internalImg.setAnchorPoint(g);
- this._internalImg.setContentSize(h)
- } else {
- this._updateDisplayFrame(f)
- }
- },
- setNormalSpriteFrameName: function(d) {
- var c = !!this._normalSpriteFrameName;
- this._normalSpriteFrameName = d;
- c && (d = cc.spriteFrameCache.getSpriteFrame(d), this._updateDisplayFrame(d))
- },
- setSelectedSpriteFrameName: function(b) {
- this._selectedSpriteFrameName = b
- },
- setDisabledSpriteFrameName: function(b) {
- this._disabledSpriteFrameName = b
- },
- setCancelTouchOnMove: function(b) {
- this._cancelTouchOnMove = b
- },
- setCancelTouchOnMoveOut: function(b) {
- this._cancelTouchOnMoveOut = b
- },
- onTouchBegan: function(e, d) {
- if (!bs.isNodeVisible(this)) {
- return ! 1
- }
- this._originTouchPoint = _.clone(e.getLocation());
- if (this._isTouchInside(e) && this._enable) {
- if (this._selectedSpriteFrameName) {
- var f = cc.spriteFrameCache.getSpriteFrame(this._selectedSpriteFrameName);
- this._updateDisplayFrame(f)
- }
- return ! 0
- }
- return ! 1
- },
- onTouchMoved: function(d, c) {
- 15 < cc.pDistance(d.getLocation(), this._originTouchPoint) && (this._isTouchMoved = !0)
- },
- onTouchEnded: function(f, e) {
- if (this._normalSpriteFrameName && this._enable) {
- var h = cc.spriteFrameCache.getSpriteFrame(this._normalSpriteFrameName);
- this._updateDisplayFrame(h)
- }
- if (this._enable && (!this._cancelTouchOnMoveOut || this._isTouchInside(f))) {
- if (h = this._isTouchMoved, this._isTouchMoved = !1, !h || !this._cancelTouchOnMove) {
- var h = this._target,
- g = this._callback;
- if (g) {
- if (h && "string" == typeof g) {
- h[g](this)
- } else {
- h && "function" == typeof g ? g.call(h, this, f) : g(this)
- }
- }
- }
- }
- },
- isCascadeColorEnabled: function() {
- return ! 1
- },
- isCascadeOpacityEnabled: function() {
- return ! 1
- },
- getColor: function() {
- return this._internalImg.getColor()
- },
- setColor: function(f) {
- for (var e = this.getChildren(), h = 0; h < e.length; h++) {
- var g = e[h];
- g && g.setColor && g.setColor(f)
- }
- },
- getOpacity: function() {
- return this._internalImg.getOpacity()
- },
- setOpacity: function(f) {
- for (var e = this.getChildren(), h = 0; h < e.length; h++) {
- var g = e[h];
- g && g.setOpacity && g.setOpacity(f)
- }
- },
- setEnabled: function(b) {
- b != this._enable && (this._enable = b, this._disabledSpriteFrameName && (b = cc.spriteFrameCache.getSpriteFrame(b ? this._normalSpriteFrameName: this._disabledSpriteFrameName), this._updateDisplayFrame(b)))
- },
- setTouchEnabled: function() {
- cc.log("do not use bs.TouchableSprite.setTouchEnabled, use setEnabled instead")
- },
- _updateDisplayFrame: function(f) {
- if (this._foregroundImg) {
- var e = this._internalImg.displayFrame().getOriginalSize(),
- h = f.getOriginalSize();
- this._internalImg.setSpriteFrame(f);
- if (!cc.sizeEqualToSize(e, h)) {
- f = this._foregroundImg;
- var e = f.pos,
- g = f.anchor;
- f.node.setPosition(e.x + h.width * g.x, e.y + h.height * g.y)
- }
- } else {
- this._internalImg.setSpriteFrame(f)
- }
- },
- fadeOut: function(d, c) {
- this._fadeOutStep = 255 / d;
- this._fadeOutCallback = c;
- this.scheduleUpdate()
- },
- update: function(b) {
- b = this.getOpacity() - this._fadeOutStep * b;
- 0 >= b && (b = 0, this.unscheduleUpdate(), this._fadeOutCallback && (this._fadeOutCallback(), this._fadeOutCallback = null));
- this.setOpacity(b)
- }
- });
- bs.TouchableSprite.createWithSize = function(f, e, h) {
- var g = new this;
- g.initWithSize(f, e, h);
- return g
- };
- bs.TouchableSprite.createWithSprite = function(e, d, f) {
- e = new this;
- e.initWithSprite(e, d, f);
- return e
- };
- bs.TouchableSprite.createWithSpriteName = function(f, e, h) {
- var g = new this;
- g.initWithSpriteName(f, e, h);
- return g
- };
- bs.TouchableSprite.createWithSpriteFrameName = function(f, e, h) {
- var g = new this;
- g.initWithSpriteFrameName(f, e, h);
- return g
- };
- bs.TouchableSprite.createWithTwoStateSpriteFrameName = function(g, e, j, i) {
- var h = new this;
- h.initWithTwoStateSpriteFrameName(g, e, j, i);
- return h
- };
- bs.TouchableSprite.createWithThreeStateSpriteFrameName = function(g, e, l, j, i) {
- var h = new this;
- h.initWithThreeStateSpriteFrameName(g, e, l, j, i);
- return h
- };
- bs.TouchableSprite.createWithScale9SpriteFrameName = function(g, e, l, j, i) {
- var h = new this;
- h.initWithScale9SpriteFrameName(g, e, l, j, i);
- return h
- };
- bs.TouchableSpriteWithSwitch = bs.TouchableSprite.extend({
- _frameOn: null,
- _frameOff: null,
- _sp_on: null,
- _sp_off: null,
- _on: null,
- _delta: null,
- initWithFrameName: function(g, e, l, j, i, h) {
- bs.TouchableSprite.prototype.initWithSize.call(this, g, h, i, e);
- this._frameOn = cc.spriteFrameCache.getSpriteFrame(l);
- this._frameOff = cc.spriteFrameCache.getSpriteFrame(j);
- this._sp_on = cc.Sprite.createWithSpriteFrame(this._frameOn);
- this._sp_on.setAnchorPoint(cc.p(0, 0));
- this._sp_off = cc.Sprite.createWithSpriteFrame(this._frameOff);
- this._sp_off.setAnchorPoint(cc.p(0, 0));
- this._on = !1;
- this.addChild(this._sp_on);
- this.addChild(this._sp_off);
- this._sp_off.setVisible(!0);
- this._sp_on.setVisible(!1);
- return ! 0
- },
- toggle: function() {
- this.switchTo(!this._on)
- },
- switchOn: function() {
- this.switchTo(!0)
- },
- switchOff: function() {
- this.switchTo(!1)
- },
- switchTo: function(b) {
- this._on = b;
- this._sp_off.setVisible(!1);
- this._sp_on.setVisible(!1);
- b ? this._sp_on.setVisible(!0) : this._sp_off.setVisible(!0)
- },
- isOn: function() {
- return this._on
- },
- setDeltaForStateChanging: function(b) {
- this._delta = b
- }
- });
- bs.TouchableSpriteWithSwitch.switchSpriteWithFrameName = function(h, e, n, m, l, i) {
- var j = new bs.TouchableSpriteWithSwitch;
- j.initWithFrameName(h, e, n, m, l, i);
- return j
- };
- bs.kMessageAppEnterForeground = "bs-message-app-enter-foreground";
- bs.kMessageAppEnterBackground = "bs-message-app-enter-background";
- bs.kMessageSocialUserInfoUpdated = "bs-message-social-user-info-updated";
- bs.kMessageRegisterRemoteNotification = "bs-message-register-remote-notification";
- bs.kMessageSocialWechatCode = "bs-message-social-wechat-code";
- bs.kMessagePayRestoreFinished = "bs-message-pay-restore-finish";
- bs.kMessagePaySuccess = "bs-message-pay-success";
- bs.kMessagePayFail = "bs-message-pay-fail";
- bs.MessageManager = cc.Class.extend({
- _handlers: {},
- _delayedMessages: [],
- registerHandler: function(e, d, f) {
- null == this._handlers[e] && (this._handlers[e] = []);
- this._handlers[e].push({
- target: d,
- callback: f
- })
- },
- unregisterHandler: function(f, e, h) {
- var g = this._handlers[f];
- null != g && (this._handlers[f] = _.filter(g,
- function(b) {
- return b.target != e || b.callback != h
- }))
- },
- unregisterAllHandlerForTarget: function(d) {
- var c = this._handlers;
- _.each(c,
- function(b, a) {
- _.isEmpty(b) || (c[a] = _.filter(b,
- function(e) {
- return e.target != d
- }))
- })
- },
- postDelayedMessage: function(d, c) {
- this._delayedMessages.push([d, c])
- },
- flushMessage: function() {
- _.each(this._delayedMessages,
- function(b) {
- this.postMessage(b[0], b[1])
- }.bind(this))
- },
- postMessage: function(g, e) {
- var j = this._handlers[g];
- if (null != j) {
- for (var i = 0; i < _.size(j); i++) {
- var h = j[i];
- h.callback.call(h.target, e, g)
- }
- }
- }
- });
- bs.g_messageManager = null;
- bs.MessageManager.getInstance = function() {
- null == bs.g_messageManager && (bs.g_messageManager = new bs.MessageManager);
- return bs.g_messageManager
- };
- bs.registerMessageHandler = function(e, d, f) {
- bs.MessageManager.getInstance().registerHandler(e, d, f)
- };
- bs.unregisterMessageHandler = function(e, d, f) {
- bs.MessageManager.getInstance().unregisterHandler(e, d, f)
- };
- bs.unregisterAllMessageHandlerForTarget = function(b) {
- bs.MessageManager.getInstance().unregisterAllHandlerForTarget(b)
- };
- bs.postMessage = function(d, c) {
- bs.MessageManager.getInstance().postMessage(d, c)
- };
- bs.postDelayedMessage = function(d, c) {
- bs.MessageManager.getInstance().postDelayedMessage(d, c)
- };
- bs.BIND_MESSAGE = bs.registerMessageHandler;
- bs.UNBIND_MESSAGE = bs.unregisterMessageHandler;
- bs.POST_MESSAGE = bs.postMessage;
- bs.POST_DELAYED_MESSAGE = bs.postDelayedMessage;
- bs.Share = bs.Share || {};
- bs.Share.kShareTargetWeixinSession = 0;
- bs.Share.kShareTargetWeixinTimeline = 1;
- bs.Share.kShareTargetQQ = 2;
- bs.Share.kShareTargetQZone = 3;
- bs.Share.kTargetWeixinSession = 0;
- bs.Share.kTargetWeixinTimeline = 1;
- bs.Share.kTargetQQ = 2;
- bs.Share.kTargetQZone = 3;
- bs.Layer = cc.Layer.extend({
- _plistUsed: null,
- init: function() {
- this._super();
- this._plistUsed = []
- },
- use: function(b) {
- this._plistUsed.push(b);
- bs.Resource.shared().useResource(b)
- },
- onExit: function() {
- this._super();
- bs.unregisterAllMessageHandlerForTarget(this);
- _.each(this._plistUsed,
- function(b) {
- bs.Resource.shared().unuseResource(b)
- })
- },
- setDebugDraw: function() {
- var d = this.getContentSize(),
- d = [cc.p(0, 0), cc.p(d.width, 0), cc.p(d.width, d.height), cc.p(0, d.height)],
- c = cc.DrawNode.create();
- this.addChild(c, -1);
- c.drawPoly(d, new cc.Color4F(0, 0, 1, 0.5), 1, new cc.Color4F(1, 0, 1, 1))
- }
- });
- bs.ToggleButton = bs.TouchableSprite.extend({
- _img1: null,
- _img2: null,
- _status: 0,
- initWithSprite: function(g, e, j, i, h) {
- this._img1 = bs.autoSprite(g);
- this._img2 = bs.autoSprite(e);
- bs.TouchableSprite.prototype.initWithSize.call(this, this._img1.getContentSize(), j, i, h);
- this._img1.setAnchorPoint(cc.p(0, 0));
- this._img2.setAnchorPoint(cc.p(0, 0));
- this.addChild(this._img1);
- this.addChild(this._img2);
- this._img1.setVisible(0 === this._status);
- this._img2.setVisible(1 === this._status)
- },
- onTouchBegan: function(d, c) {
- return this._super(d, c)
- },
- onTouchEnded: function(d, c) {
- this._isTouchInside(d) && (this._status = (this._status + 1) % 2, this._img1.setVisible(0 === this._status), this._img2.setVisible(1 === this._status));
- this._super(d, c)
- }
- });
- bs.ToggleButton.create = function(g, e, l, j, i) {
- var h = new bs.ToggleButton;
- h.initWithSprite(g, e, l, j, i);
- return h
- };
- var Util = {
- scene: function(d) {
- var c = cc.Scene.create();
- d = d instanceof cc.Layer ? d: new d;
- c.addChild(d);
- return c
- },
- fullscreenNode: function(e, d) {
- d && e.setContentSize(d);
- var f = cc.winSize;
- e.width / e.height > f.width / f.height ? (bs.scaleToHeight(e, f.height), e.x = (f.width - e.width * e.scale) / 2) : (bs.scaleToWidth(e, f.width), e.y = (f.height - e.height * e.scale) / 2)
- },
- randomReal: function(d, c) {
- _.isArray(d) && (c = d[1], d = d[0]);
- return Math.random() * (c - d) + d
- },
- randomInt: function(d, c) {
- return Math.floor(Math.random() * (c - d + 1)) + d
- },
- randomRate: function(b) {
- return Math.random() < b
- },
- randomItemByRate: function(q, o, n) {
- var m = 0,
- l = 0;
- _.each(q,
- function(b) {
- if (void 0 != b[o] && (!_.isFunction(n) || n(b))) {
- m += b[o]
- }
- });
- var m = 10000 * m,
- i = this.randomReal(0, m),
- j;
- for (j in q) {
- var h = q[j];
- if (!_.isFunction(n) || n(h)) {
- var e = l + 10000 * h[o];
- if (i > l && i <= e) {
- return h
- }
- l = e
- }
- }
- return null
- },
- trackEvent: function(f, e, h) {
- if (window._hmt) {
- var g = ["_trackEvent", wx.game, f];
- e || (e = wx.game + "-" + f);
- e && g.push(e);
- h && g.push(h);
- _hmt.push(g)
- }
- }
- };
- var wx = wx || {};
- wx.game = "chess";
- wx.chess = {
- designHeight: 533,
- font: "\u9ed1\u4f53",
- moreGamesUrl: "http://game.ikongzhong.cn/",
- resources: ["texture.png", "texture.plist", "step.mp3"],
- gridSize: {
- width: 64,
- height: 64
- },
- touchRadius: 20,
- row: 4,
- col: 4,
- shareType: "normal",
- getTitle: function(b) {
- b = b || wx.chess.lastScore || 0;
- return 11 == b ? "BUG": 41 <= b ? "\u53bf\u5b98": 36 <= b && 41 > b ? "\u540f\u90e8\u4f8d\u90ce": 31 <= b && 35 > b ? "\u5927\u7406\u5bfa\u537f": 25 <= b && 31 > b ? "\u4e24\u5e7f\u603b\u7763": 21 <= b && 25 > b ? "\u90e1\u738b": "\u5927\u5b66\u58eb"
- },
- lastScore: 0
- };
- cc.game.onStart = function() {
- cc.view.adjustViewPort(!0);
- var d = cc.winSize,
- c = d.width,
- d = d.height;
- cc.view.enableAutoFullScreen(!1);
- cc.view.setDesignResolutionSize(320, 320 * (d / c), cc.ResolutionPolicy.FIXED_WIDTH);
- cc.view.resizeWithBrowserSize(!0);
- cc.LoaderScene.preload(wx.chess.resources,
- function() {
- wx.init();
- cc.director.runScene(Util.scene(wx.chess.UILayer))
- },
- this)
- };
- cc.game.run();
- wx.chess.Board = cc.Node.extend({
- col: 0,
- row: 0,
- horse: null,
- holes: {},
- moving: !1,
- passed: !1,
- gameLayer: null,
- ctor: function(f) {
- this._super();
- this.init();
- bs.registerTouchEventOneByOne(this, !0);
- this.gameLayer = f;
- f = wx.chess.gridSize;
- this.attr({
- width: (wx.chess.col - 1) * f.width,
- height: (wx.chess.row - 1) * f.height
- });
- var e = new cc.Sprite("#ma_board.png");
- e.attr({
- anchorX: 135 / e.width,
- anchorY: 213 / e.height,
- x: this.width / 2,
- y: this.height / 2
- });
- this.addChild(e);
- for (e = 0; e < wx.chess.col; ++e) {
- this.addLine(this.height, {
- x: e * f.width
- })
- }
- for (var h = 0; h < wx.chess.row; ++h) {
- this.addLine(this.width, {
- rotation: 90,
- y: h * f.height
- })
- }
- for (e = 0; e < wx.chess.col; ++e) {
- this.holes[e] = {};
- for (h = 0; h < wx.chess.row; ++h) {
- var g = new cc.Sprite("#ma_hole.png");
- g.x = e * f.width;
- g.y = h * f.height;
- this.holes[e][h] = g;
- this.addChild(g)
- }
- }
- f = this.horse = new cc.Sprite("#ma_horse.png");
- this.addChild(f);
- this.reset()
- },
- addLine: function(e, d) {
- var f = new cc.Sprite("#ma_line.png");
- f.anchorY = 0;
- bs.scaleYToHeight(f, e);
- f.attr(d);
- this.addChild(f)
- },
- onTouchBegan: function(h) {
- if (!this.moving) {
- var e = wx.chess,
- o = e.gridSize.width,
- n = e.gridSize.height,
- l = e.touchRadius,
- i = this.convertTouchToNodeSpace(h);
- h = Math.abs(i.x) % o;
- var j = Math.abs(i.y) % n,
- m = Math.round(Math.abs(i.x) / o),
- i = Math.round(Math.abs(i.y) / n),
- n = 0 <= i && i < e.row && (j <= l || n - j <= l);
- return 0 <= m && (m < e.col && (h <= l || o - h <= l)) && n ? (this.moveTo(m, i), !0) : !1
- }
- },
- reset: function() {
- var d = _.sample(_.range(0, wx.chess.col * wx.chess.row), Util.randomInt(2, 5)),
- c = 0;
- _.each(this.holes,
- function(a) {
- _.each(a,
- function(b) {
- b.isOn = -1 !== d.indexOf(c);
- b.setSpriteFrame(bs.spriteFrameFromName(b.isOn ? "ma_hole1.png": "ma_hole.png"));
- c++
- })
- });
- this.col = Util.randomInt(0, wx.chess.col - 1);
- this.row = Util.randomInt(0, wx.chess.row - 1);
- this.horse.x = wx.chess.gridSize.width * this.col;
- this.horse.y = wx.chess.gridSize.height * this.row;
- this.passed = !1
- },
- moveTo: function(f, e) {
- var h = Math.abs(this.col - f),
- g = Math.abs(this.row - e);
- if (1 == h && 2 == g || 2 == h && 1 == g) {
- h = wx.chess.gridSize,
- this.col = f,
- this.row = e,
- this.moving = !0,
- this.gameLayer.incrScore(),
- this.horse.runAction(cc.sequence(cc.jumpTo(0.3, cc.p(h.width * f, h.height * e), 50, 1), cc.callFunc(this.onMoveEnd.bind(this)))),
- h = this.holes[f][e],
- h.isOn = !h.isOn,
- h.setSpriteFrame(bs.spriteFrameFromName(h.isOn ? "ma_hole1.png": "ma_hole.png"))
- }
- },
- onMoveEnd: function() {
- this.moving = !1;
- cc.audioEngine.playEffect("step.mp3");
- _.find(this.holes,
- function(b) {
- return _.find(b,
- function(c) {
- return ! c.isOn
- })
- }) || (this.passed = !0, bs.postMessage("game-over", this.gameLayer.score))
- }
- });
- wx.chess.GameLayer = bs.Layer.extend({
- score: 0,
- board: null,
- ctor: function() {
- this._super();
- this.init();
- var d = this.board = new wx.chess.Board(this);
- this.addChild(d);
- bs.centerNodeToParent(d);
- var c = this.scoreLbl = cc.LabelTTF.create("\u5df2\u8d70\u6b65\u6570 0", wx.chess.font, 22);
- c.y = bs.getTop(d) + 32;
- c.x = cc.winSize.width / 2;
- this.addChild(c);
- this.height = bs.getTop(c)
- },
- onEnter: function() {
- this._super()
- },
- incrScore: function() {
- this.score++;
- this.scoreLbl.setString("\u5df2\u8d70\u6b65\u6570 " + this.score)
- },
- restart: function() {
- this.board.reset();
- this.score = 0;
- this.scoreLbl.setString("\u5df2\u8d70\u6b65\u6570 0")
- }
- });
- wx.init = function() {
- bs.init();
- cc.spriteFrameCache.addSpriteFrames("texture.plist")
- };
- wx.chess.Button = bs.TouchableSprite.extend({
- ctor: function(f, e, h, g) {
- this._super();
- this.initWithSpriteFrameName(e + ".png", h, g);
- this.setIsSwallowTouch(!0);
- f && (f = cc.LabelTTF.create(f, "\u9ed1\u4f53", 22), this.addChild(f), bs.centerNodeToParent(f))
- }
- });
- wx.chess.ShareTip = cc.LayerColor.extend({
- tip: null,
- ctor: function() {
- this._super();
- this.init(cc.color(0, 0, 0, 200));
- this.setContentSize(cc.winSize);
- bs.registerTouchEventOneByOne(this, !0);
- var b = this.tip = new cc.Sprite("#ma_sharetip.png");
- b.setAnchorPoint(1, 1);
- b.setPosition(cc.winSize.width, cc.winSize.height);
- this.addChild(b)
- },
- onTouchBegan: function() {
- this.scheduleOnce(this.removeFromParent.bind(this), 0);
- return ! 0
- }
- });
- wx.chess.GameTip = wx.chess.ShareTip.extend({
- ctor: function() {
- this._super();
- var e = cc.winSize,
- d = cc.LabelTTF.create("\u8c61\u68cb\u89c4\u5219\uff1a\u201c\u99ac\u201d\u8d70\u201c\u65e5\u201d", "Arial-Bold", 20);
- d.setHorizontalAlignment(cc.TEXT_ALIGNMENT_CENTER);
- d.setDimensions(cc.size(0.8 * e.width, 0));
- d.x = this.width / 2;
- d.y = bs.getBottom(this.tip) - 40;
- this.addChild(d);
- e = new cc.Sprite("#ma_tip.png");
- e.anchorY = 1;
- e.x = d.x;
- e.y = bs.getBottom(d) - 10;
- this.addChild(e);
- var f = cc.LabelTTF.create("\u5b9e\u5728\u662f\u597d\u96be\u554a~\u4f46\u662f\u4e0d\u80fd\u5f97\u7f6a\u7687\u4e0a\u5440~~\u5feb\u5feb\u53eb\u5c0f\u4f19\u4f34\u6765\u5e2e\u4f60\u89e3\u56f4\u5427\uff01", "Arial-Bold", 20);
- f.setHorizontalAlignment(cc.TEXT_ALIGNMENT_CENTER);
- f.setDimensions(d.getDimensions());
- f.x = d.x;
- f.y = bs.getBottom(e) - 50;
- this.addChild(f)
- },
- onEnter: function() {
- this._super();
- wx.chess.shareType = "help"
- },
- onExit: function() {
- this._super();
- wx.chess.shareType = "normal"
- }
- });
- wx.chess.UILayer = cc.LayerGradient.extend({
- mainMenu: null,
- gameLayer: null,
- shareTip: null,
- first: !0,
- introLayer: null,
- ctor: function() {
- this._super();
- var f = cc.winSize,
- e = f.height / wx.chess.designHeight;
- this.init(cc.color(149, 196, 60), cc.color(111, 151, 47), cc.p(1, 1));
- var h = cc.LabelTTF.create("", "Arial", 12);
- bs.positionNodeToParentPercent(h, this, 0.5, 1);
- h.anchorY = 1;
- this.addChild(h);
- h = this.title = new cc.Sprite("#ma_title.png");
- h.x = f.width / 2;
- h.y = f.height - 90 * e + 30;
- this.addChild(h);
- e = cc.LabelTTF.create("\u63d0\u793a\uff1a\u2460\u99ac\u8d70\u201c\u65e5\u201d \u2461\u70b9\u4eae\u6240\u6709\u706f", wx.chess.font, 16);
- e.x = f.width / 2;
- e.y = bs.getBottom(h) - 15;
- this.addChild(e);
- e = this.gameLayer = new wx.chess.GameLayer;
- this.addChild(e);
- h = bs.getBottom(this.title) - bs.getTop(e);
- 25 > h && (e.y = e.y + h - 25);
- var e = new wx.chess.Button("", "ma_button_play", this.play, this),
- h = new wx.chess.Button("", "ma_button_help", this.help, this),
- g = new wx.chess.Button("", "ma_button_more", this.more, this);
- e.x = 0.25 * f.width;
- h.x = 0.5 * f.width;
- g.x = 0.75 * f.width;
- e.y = h.y = g.y = 60 + 30 * (f.height - 455) / 120;
- this.addChild(e);
- this.addChild(h);
- this.addChild(g);
- Util.trackEvent("play")
- },
- onEnter: function() {
- this._super();
- bs.registerMessageHandler("game-over", this, this.gameOver)
- },
- play: function() {
- this.retryDlg && (this.retryDlg.removeFromParent(), delete this.retryDlg);
- this.gameLayer.restart();
- Util.trackEvent("replay");
- },
- help: function() {
- Util.trackEvent("help");
- this.addChild(new wx.chess.GameTip)
- },
- more: function() {
- Util.trackEvent("more");
- //window.location.href = wx.chess.moreGamesUrl
- clickMore();
- },
- share: function() {
- click_share_action()
- },
- gameOver: function(d) {
- wx.chess.lastScore = d;
- Util.trackEvent("end", "score", d);
- /*var c = _.sprintf("\u606d\u559c\u60a8\u53ea\u7528%d\u6b65\u5c31\u89e3\u5f00\u4e86\u8ff7\u5c40\uff01\u7687\u4e0a\u9f99\u989c\u5927\u60a6\uff0c\u5c01\u60a8\u4e3a\u3010%s\u3011\uff0c\u5feb\u53bb\u70ab\u8000\u4e00\u4e0b\u5427\uff01", d, wx.chess.getTitle());
- Util.trackEvent("end", "score", d);
- c = new wx.chess.Dialog(c, "取消",
- function() {
- this.showRetryDlg(d)
- }.bind(this), "分享",
- function() {
- //this.showRetryDlg(d);
- //this.share()
- }.bind(this));
- this.addChild(c);
- bs.centerNodeToParent(c)
- */
- this.showRetryDlg(d);
- dp_submitScore(d);
- },
- showRetryDlg: function(b) {
- b = this.retryDlg = new wx.chess.Dialog(_.sprintf("\u60a8\u7528\u4e86%d\u6b65\u89e3\u5f00\u4e86\u8ff7\u5c40", b), "再玩一次", this.play.bind(this), "更多游戏", this.more.bind(this));
- this.addChild(b);
- bs.centerNodeToParent(b)
- }
- });
- wx.chess.Dialog = cc.Sprite.extend({
- ctor: function(g, e, l, j, i) {
- this._super();
- this.initWithSpriteFrameName("ma_dialog_bg.png");
- g = cc.LabelTTF.create(g, "\u9ed1\u4f53", 18);
- g.setColor(cc.color(0, 0, 0));
- g.setHorizontalAlignment(cc.TEXT_ALIGNMENT_CENTER);
- g.setDimensions(cc.size(this.width - 40, 0));
- bs.positionNodeToParentPercent(g, this, 0.5, 0.65);
- this.addChild(g);
- var h = this;
- g = function(b) {
- return function() {
- h.removeFromParent();
- b()
- }
- };
- e = new wx.chess.Button(e, "ma_button_blue", g(l), this);
- bs.positionNodeToParentPercent(e, this, 0.28, 0.27);
- this.addChild(e);
- j = new wx.chess.Button(j, "ma_button_red", g(i), this);
- bs.positionNodeToParentPercent(j, this, 0.72, 0.27);
- this.addChild(j)
- }
- });
|