1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930 |
- System.register("chunks:///_virtual/Action.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports('default', get_new_action_center);
- cclegacy._RF.push({}, "24a1fbkvW9AQJ+cc5f2eMnl", "Action", undefined);
- function get_new_action_center() {
- return new ActionCenter();
- }
- /**行为机*/
- var ActionCenter = /*#__PURE__*/function () {
- function ActionCenter() {
- this._list = [];
- this._current = void 0;
- }
- var _proto = ActionCenter.prototype;
- /**加入一个创建行为的闭包的函数
- * ActionCreat = (...args: any) => Action;
- * Action ={check:() => boolean,entry:() => void,do:(dt:number)=>void}
- */
- _proto.add = function add(actionCreat) {
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- args[_key - 1] = arguments[_key];
- }
- this._list.push(actionCreat.apply(void 0, args));
- }
- /**检测和进入行为*/;
- _proto.check_entry = function check_entry() {
- var _this$_current;
- if ((_this$_current = this._current) != null && _this$_current.check()) return;
- for (var i = 0; i < this._list.length; i++) {
- if (this._current != this._list[i] && this._list[i].check()) {
- this._current = this._list[i];
- this._current.entry();
- return;
- }
- }
- this._current = null;
- }
- /**是否有正在执行的行为 */;
- /**执行行为*/
- _proto["do"] = function _do(dt) {
- if (this._current) this._current["do"](dt);
- }
- /**清除所有行为*/;
- _proto.clean = function clean() {
- for (var i = 0; i < this._list.length; i++) {
- this._list[i].dispose();
- }
- this._list.length = 0;
- this._current = null;
- }
- /*例子
- public test():void{
- const who={state:0};
- this.add((who:{state:number})=>{
- const w = who;
- let time:number=0;
- return{
- check:()=>{
- if(w.state==0){
- return true;
- }
- return false;
- },
- entry:()=>{
- time=0;
- console.log("entry 行为1",time);
- },
- do:(dt:number)=>{
- time+=dt;
- if(time>=2){
- console.log("do",time);
- w.state=1;
- };
- }
- }
- },who);
- this.add((who:{state:number})=>{
- const w = who;
- let time:number=0;
- return{
- check:()=>{
- if(w.state==1){
- return true;
- }
- return false;
- },
- entry:()=>{
- time=0;
- console.log("entry 行为2",time);
- },
- do:(dt:number)=>{
- time+=dt;
- if(time>=2){
- console.log("do",time);
- w.state=0;
- };
- }
- }
- },who);
- }*/;
- _createClass(ActionCenter, [{
- key: "isAction",
- get: function get() {
- return this._current != null;
- }
- }]);
- return ActionCenter;
- }();
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ArrayUtil.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "83341COeitPRIHcw18VS7g3", "ArrayUtil", undefined);
- var ArrayUtil = exports('default', /*#__PURE__*/function () {
- function ArrayUtil() {}
- /**随机打乱一个数组 */
- ArrayUtil.shuffleArray = function shuffleArray(array) {
- var currentIndex = array.length;
- var temporaryValue;
- var randomIndex;
- // While there remain elements to shuffle...
- while (currentIndex !== 0) {
- // Pick a remaining element...
- randomIndex = Math.floor(Math.random() * currentIndex);
- currentIndex--;
- // And swap it with the current element.
- temporaryValue = array[currentIndex];
- array[currentIndex] = array[randomIndex];
- array[randomIndex] = temporaryValue;
- }
- return array;
- }
- // Fisher-Yates 洗牌算法
- //const originalArray = [1, 2, 3, 4, 5];
- //const shuffledArray = shuffleArray([...originalArray]);
- ;
- ArrayUtil.shuffleArray2 = function shuffleArray2(array) {
- for (var i = array.length - 1; i > 0; i--) {
- // 生成一个随机索引
- var j = Math.floor(Math.random() * (i + 1));
- // 交换元素
- var _ref = [array[j], array[i]];
- array[i] = _ref[0];
- array[j] = _ref[1];
- }
- return array;
- }
- /**合并两个数组元素,移除相同的 */;
- ArrayUtil.MergeAndRemoveDuplicates = function MergeAndRemoveDuplicates(arr1, arr2) {
- var merged = [].concat(arr1, arr2); // 合并两个数组
- var uniqueValues = Array.from(new Set(merged)); // 去重
- return uniqueValues;
- }
- /**排除数组1在数组2里有的元素,返回新数组*/;
- ArrayUtil.ExcludeElements = function ExcludeElements(array1, array2) {
- var set = new Set(array2); // 将 array2 转换为 Set
- return array1.filter(function (item) {
- return !set.has(item);
- });
- }
- /**检测数组元素是否能满足顺序的组合*/;
- ArrayUtil.checkSequentialCombination = function checkSequentialCombination(arr) {
- var sortedArr = arr.slice().sort(function (a, b) {
- return a - b;
- });
- for (var i = 0; i < sortedArr.length - 1; i++) {
- if (sortedArr[i] + 1 !== sortedArr[i + 1]) {
- return [];
- }
- }
- return sortedArr;
- }
- /**从一个数组中找出是否有连续的组合*/;
- ArrayUtil.findSequentialCombinations = function findSequentialCombinations(arr) {
- var result = [];
- arr.sort(function (a, b) {
- return a - b;
- });
- var currentSequence = [];
- for (var i = 0; i < arr.length; i++) {
- if (currentSequence.length === 0 || arr[i] === currentSequence[currentSequence.length - 1] + 1) {
- currentSequence.push(arr[i]);
- } else {
- if (currentSequence.length > 1) {
- result.push(currentSequence);
- }
- currentSequence = [arr[i]];
- }
- }
- if (currentSequence.length > 1) {
- result.push(currentSequence);
- }
- return result;
- }
- /*eg:const arr = [2, 4,2, 5, 3, 6, 9,9,10,11,];
- const combinations = this.findSequentialCombinations(arr);
-
- if (combinations.length > 0) {
- console.log("所有可能的连续顺序组合为:");
- combinations.forEach(combination => {
- console.log(combination);
- });
- } else {
- console.log("无法找到连续顺序组合");
- }*/
- /**数组中删除一个合条件的*/;
- ArrayUtil.DeleteOneItem = function DeleteOneItem(list, check) {
- var length = list.length;
- for (var i = 0; i < length; i++) {
- if (check(list[i])) {
- return list.splice(i, 1)[0];
- //i--;
- //length--;
- }
- }
- return null;
- }
- /**插入排序(适用于差异不会很大,相对有序的数据)Array.sort() 快速排序 算法更适用于混乱无章的数据 */;
- ArrayUtil.InsertionSort = function InsertionSort(array) {
- var count = array.length;
- if (count <= 1) return;
- var t1;
- var t2;
- for (var i = 1; i < count; i++) {
- t1 = array[i];
- var j = void 0;
- for (j = i; j > 0 && t1.sortValue > (t2 = array[j - 1]).sortValue; j--) {
- array[j] = t2;
- }
- array[j] = t1;
- }
- }
- // 元素排序
- /*示例
- 负数在前
- const checkMinusNumber = function (val: number) {
- return val > 0;
- };
- const arr = [2, 4, 5, 6, 7, -8, -10 - 12, -2];
- adjustArrayOrder.reorder(arr, checkMinusNumber);
- console.log(arr);
- */;
- ArrayUtil.reorder = function reorder(arr, checkFun) {
- var end = arr.length - 1;
- var begin = 0;
- while (begin < end) {
- // 向后移动begin
- while (begin < end && !checkFun(arr[begin])) {
- begin++;
- }
- // 向前移动end
- while (begin < end && checkFun(arr[end])) {
- end--;
- }
- // begin与end都指向了正确的位置
- if (begin < end) {
- // 交换两个元素的顺序
- var _ref2 = [arr[end], arr[begin]];
- arr[begin] = _ref2[0];
- arr[end] = _ref2[1];
- }
- }
- }
- //冒泡排序
- /// <summary>
- /// 各种类型冒泡排序比
- /// </summary>/// 例子:
- /// CommonSort<int>(new int[]{2,3,1,45,123,4},compare)
- /// bool compare(int a,int b){
- /// if(a>b)return true;
- /// reutn false;
- /// }
- /// <param name="sortArray"></param>
- /// <param name="compareMethod"></param>
- /// <typeparam name="T"></typeparam>
- ;
- ArrayUtil.CommonSort = function CommonSort(sortArray, compareMethod) {
- var swapped = true;
- do {
- swapped = false;
- for (var i = 0; i < sortArray.length - 1; i++) {
- if (compareMethod(sortArray[i], sortArray[i + 1])) {
- var temp = sortArray[i];
- sortArray[i] = sortArray[i + 1];
- sortArray[i + 1] = temp;
- swapped = true;
- }
- }
- } while (swapped);
- }
- /**归并排序 */
- /*var arr: number[] = [];
- for (var i: number = 0; i < 1000; i++) {
- arr.push(Math.floor(1000 - i));//生成降序的数组
- }
- MergeSort(arr, 0, arr.length);//调用归并排序算法*/
- //拆分数组 分
- ;
- ArrayUtil.MergeSort = function MergeSort(arr, lo, hi) {
- if (hi - lo < 2) return; //单个元素无需考虑
- var mi = lo + hi >> 1; //已中点为界 或者改成Math.floor((lo + hi) / 2)
- this.MergeSort(arr, lo, mi); //对左边排序
- this.MergeSort(arr, mi, hi); //对右边排序
- this.merge(arr, lo, mi, hi); //归并
- }
- //归并算法实现 合
- ;
- ArrayUtil.merge = function merge(arr, lo, mi, hi) {
- var A = arr.slice(lo, hi); //A[lo, hi)=arr[lo, hi)
- var lb = mi - lo;
- var B = new Array(lb);
- for (var i = 0; i < lb; B[i] = A[i++]); //复制左子向量B[0, lb) = arr[lo, mi)
- var lc = hi - mi;
- var C = arr.slice(mi, hi); //后子向量C[0,lc) = arr[mi, hi)
- for (var i = 0, j = 0, k = 0; j < lb;) {
- //反复冲B和C中取出更小者
- if (k < lc && C[k] < B[j]) {
- //将其归入A中
- A[i++] = C[k++];
- }
- if (lc <= k || B[j] <= C[k]) {
- A[i++] = B[j++];
- }
- }
- for (var i = 0; i < A.length; arr[lo + i] = A[i++]); //把A中的值赋给原来的数组
- B.length = 0;
- C.length = 0;
- A.length = 0;
- };
- return ArrayUtil;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/audio.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy, AudioSource, assetManager, AudioClip, Node, director;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- AudioSource = module.AudioSource;
- assetManager = module.assetManager;
- AudioClip = module.AudioClip;
- Node = module.Node;
- director = module.director;
- }],
- execute: function () {
- cclegacy._RF.push({}, "e1803S2AupKB5LQvJ7w31/E", "audio", undefined);
- var ch_log = chsdk.log;
- var ch_storage = chsdk.storage;
- /**音频等资源加载方式*/
- var loadType = exports('loadType', /*#__PURE__*/function (loadType) {
- loadType[loadType["none"] = 0] = "none";
- loadType[loadType["bundle"] = 1] = "bundle";
- loadType[loadType["remote"] = 2] = "remote";
- return loadType;
- }({}));
- /**音频播放控制
- * 需要初始化资源加载方式
- * loadType.bundle 时需要设置 bundle名
- * loadType.remote 测试使用远程的音频需要设置远程地址
- */
- var ch_audio = exports('default', /*#__PURE__*/function () {
- ch_audio.getInstance = function getInstance() {
- if (!this._instance) this._instance = new ch_audio();
- return this._instance;
- };
- function ch_audio() {
- this._volume_music = 1;
- this._volume_effect = 1;
- this._switch_music = true;
- this._switch_effect = true;
- this._effect_max = 5;
- this._effect_index = 0;
- this._effect_source_pool = [];
- this._music_source = void 0;
- this._load_type = loadType.none;
- this._bundle_name = void 0;
- this._remote_url = void 0;
- this._playing_sound = new Set();
- var audio = new Node();
- audio.name = '__ch_audio__';
- director.getScene().addChild(audio);
- director.addPersistRootNode(audio);
- this._music_source = this._create(audio);
- for (var i = 0; i < this._effect_max; i++) {
- this._effect_source_pool.push(this._create(audio));
- }
- this.load();
- }
- /**
- * 创建音频源
- * @param node 节点
- * @param volume 音量
- * @returns AudioSource 音频源组件
- */
- var _proto = ch_audio.prototype;
- _proto._create = function _create(node) {
- var source = node.addComponent(AudioSource);
- source.loop = false;
- source.playOnAwake = false;
- source.volume = 0.5;
- return source;
- }
- /**初始化*/;
- _proto.init = function init(load_type, bundle_name, remote_url) {
- this._load_type = load_type;
- this._bundle_name = bundle_name;
- this._remote_url = remote_url;
- }
- /**切换bundle*/;
- _proto.set_bundle_name = function set_bundle_name(bundle_name) {
- this._bundle_name = bundle_name;
- }
- /**
- * 释放通过 [[load]] 或者 [[loadDir]] 加载的声音资源。
- * @param sound 声音资源路径
- */;
- _proto.release = function release(sound) {
- if (this._load_type == loadType.none) {
- ch_log.warn('音频模块未初始化');
- } else if (this._load_type == loadType.bundle) {
- var bundle = assetManager.getBundle(this._bundle_name);
- if (!sound) {
- bundle.releaseAll();
- } else {
- bundle.release(sound, AudioClip);
- }
- }
- }
- /** 保存音乐音效的音量、开关配置数据到本地 */;
- _proto.save = function save() {
- var local_data = {};
- local_data.volume_music = this._volume_music;
- local_data.volume_effect = this._volume_effect;
- local_data.switch_music = this._switch_music;
- local_data.switch_effect = this._switch_effect;
- ch_storage.set("ch_audio", local_data);
- }
- /** 本地加载音乐音效的音量、开关配置数据并设置到游戏中 */;
- _proto.load = function load() {
- var local_data = ch_storage.getObject("ch_audio");
- if (local_data) {
- try {
- this.setState(local_data);
- } catch (e) {
- this.setStateDefault();
- }
- } else {
- this.setStateDefault();
- }
- };
- _proto.setState = function setState(local_data) {
- this.volumeMusic = local_data.volume_music;
- this.volumeEffect = local_data.volume_effect;
- this.switchMusic = local_data.switch_music;
- this.switchEffect = local_data.switch_effect;
- };
- _proto.setStateDefault = function setStateDefault() {
- this.volumeMusic = 0.8;
- this.volumeEffect = 0.8;
- this.switchMusic = true;
- this.switchEffect = true;
- }
- /**
- * 获取背景音乐音量
- */;
- /**
- * @en
- * play short audio, such as strikes,explosions
- * @zh
- * 播放短音频,比如 打击音效,爆炸音效等
- * @param sound clip or url for the audio
- * @param interval 同名字音频限制播放间隔(毫秒) (默认:0不限制 特殊系数:>0 <=1 使用音频时间X此系数)
- */
- _proto.playOneShot = function playOneShot(sound, interval, remote_ext) {
- var _this = this;
- if (interval === void 0) {
- interval = 0;
- }
- if (remote_ext === void 0) {
- remote_ext = '.mp3';
- }
- if (!this._switch_effect) return;
- if (sound instanceof AudioClip) {
- this.doPlayOneShot(sound, interval);
- } else {
- if (this._load_type == loadType.none) {
- ch_log.warn('音频模块未初始化');
- } else if (this._load_type == loadType.bundle) {
- var bundle = assetManager.getBundle(this._bundle_name);
- if (!bundle) {
- ch_log.warn("\u8BF7\u786E\u4FDD bundle" + this._bundle_name + " \u5DF2\u52A0\u8F7D");
- } else {
- bundle.load(sound, function (err, clip) {
- if (err) {
- ch_log.error(err);
- } else {
- _this.doPlayOneShot(clip, interval);
- }
- });
- }
- } else if (this._load_type == loadType.remote) {
- assetManager.loadRemote(this._remote_url + sound + remote_ext, function (err, clip) {
- if (err) {
- ch_log.error(err);
- } else {
- _this.doPlayOneShot(clip, interval);
- }
- });
- }
- }
- };
- _proto.doPlayOneShot = function doPlayOneShot(clip, interval) {
- var _this2 = this;
- var name = clip.name;
- if (interval > 0) {
- if (this._playing_sound.has(name)) return;
- this._playing_sound.add(name);
- var time = interval <= 1 ? clip.getDuration() * interval * 1000 : interval;
- setTimeout(function () {
- _this2._playing_sound["delete"](name);
- }, time);
- this.getNextEffectSource().playOneShot(clip, this._volume_effect);
- } else {
- this.getNextEffectSource().playOneShot(clip, this._volume_effect);
- }
- };
- _proto.getNextEffectSource = function getNextEffectSource() {
- var source = this._effect_source_pool[this._effect_index];
- this._effect_index = (this._effect_index + 1) % this._effect_max;
- return source;
- }
- /**
- * @en
- * play long audio, such as the bg music
- * @zh
- * 播放长音频,比如 背景音乐
- * @param sound clip or url for the sound
- */;
- _proto.play = function play(sound, remote_ext) {
- var _this3 = this;
- if (remote_ext === void 0) {
- remote_ext = '.mp3';
- }
- if (!this._switch_music) return;
- if (sound instanceof AudioClip) {
- this._music_source.loop = true;
- this._music_source.stop();
- this._music_source.clip = sound;
- this._music_source.play();
- this._music_source.volume = this._volume_music;
- } else {
- if (this._load_type == loadType.none) {
- ch_log.warn('音频模块未初始化');
- } else if (this._load_type == loadType.bundle) {
- var bundle = assetManager.getBundle(this._bundle_name);
- if (!bundle) {
- ch_log.warn("\u8BF7\u786E\u4FDD bundle" + this._bundle_name + " \u5DF2\u52A0\u8F7D");
- } else {
- bundle.load(sound, function (err, clip) {
- if (err) {
- ch_log.error(err);
- } else {
- _this3._music_source.loop = true;
- _this3._music_source.stop();
- _this3._music_source.clip = clip;
- _this3._music_source.play();
- _this3._music_source.volume = _this3._volume_music;
- }
- });
- }
- } else if (this._load_type == loadType.remote) {
- assetManager.loadRemote(this._remote_url + sound + remote_ext, function (err, clip) {
- if (err) {
- ch_log.error(err);
- } else {
- _this3._music_source.loop = true;
- _this3._music_source.stop();
- _this3._music_source.clip = clip;
- _this3._music_source.play();
- _this3._music_source.volume = _this3._volume_music;
- }
- });
- }
- }
- }
- /**
- * stop the audio play
- */;
- _proto.stop = function stop() {
- this._music_source.stop();
- for (var i = 0; i < this._effect_source_pool.length; i++) {
- this._effect_source_pool[i].stop();
- }
- }
- /**stop and clean */;
- _proto.clean = function clean() {
- var _this$_music_source$c;
- this._music_source.stop();
- (_this$_music_source$c = this._music_source.clip) == null || _this$_music_source$c.name;
- this._music_source.clip = null;
- for (var i = 0; i < this._effect_source_pool.length; i++) {
- this._effect_source_pool[i].stop();
- this._effect_source_pool[i].clip = null;
- }
- }
- /**
- * pause the audio play
- */;
- _proto.pause = function pause() {
- this._music_source.pause();
- }
- /**
- * resume the audio play
- */;
- _proto.resume = function resume() {
- if (!this._switch_music) return;
- this._music_source.play();
- }
- /** 重播当前音乐 */;
- _proto.replay_music = function replay_music() {
- this._music_source.stop();
- this._music_source.play();
- };
- _createClass(ch_audio, [{
- key: "volumeMusic",
- get: function get() {
- return this._volume_music;
- }
- /**
- * 设置背景音乐音量
- * @param value 音乐音量值
- */,
- set: function set(value) {
- this._volume_music = value;
- this._music_source.volume = value;
- }
- /**
- * 获取背景音乐开关值
- */
- }, {
- key: "switchMusic",
- get: function get() {
- return this._switch_music;
- }
- /**
- * 设置背景音乐开关值
- * @param value 开关值
- */,
- set: function set(value) {
- this._switch_music = value;
- if (value == false) this._music_source.stop();
- }
- /**
- * 获取音效音量
- */
- }, {
- key: "volumeEffect",
- get: function get() {
- return this._volume_effect;
- }
- /**
- * 设置获取音效音量
- * @param value 音效音量值
- */,
- set: function set(value) {
- this._volume_effect = value;
- for (var i = 0; i < this._effect_source_pool.length; i++) {
- this._effect_source_pool[i].volume = this._volume_effect;
- }
- }
- /**
- * 获取音效开关值
- */
- }, {
- key: "switchEffect",
- get: function get() {
- return this._switch_effect;
- }
- /**
- * 设置音效开关值
- * @param value 音效开关值
- */,
- set: function set(value) {
- this._switch_effect = value;
- if (value == false) {
- for (var i = 0; i < this._effect_source_pool.length; i++) {
- this._effect_source_pool[i].stop();
- }
- }
- }
- }]);
- return ch_audio;
- }());
- ch_audio._instance = void 0;
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ch_pvp.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './ch_util.ts'], function (exports) {
- var _asyncToGenerator, _regeneratorRuntime, cclegacy, ch_util;
- return {
- setters: [function (module) {
- _asyncToGenerator = module.asyncToGenerator;
- _regeneratorRuntime = module.regeneratorRuntime;
- }, function (module) {
- cclegacy = module.cclegacy;
- }, function (module) {
- ch_util = module.default;
- }],
- execute: function () {
- cclegacy._RF.push({}, "8b658c6Uk1Jq4HkHx1ctH2P", "ch_pvp", undefined);
- /**
- * pvp扩展玩法 基于 chsdk
- */
- var ch_pvp = /*#__PURE__*/function () {
- function ch_pvp() {
- this._set_url = '/user/setPvpSceneData';
- this._match_url = '/user/startPvpMatch';
- this._finish_url = '/user/pvpFinishAction';
- this._record_url = '/user/pvpChallengeRecord';
- this._own = void 0;
- //
- this._cache_records = null;
- this._cache_time = void 0;
- }
- ch_pvp.getInstance = function getInstance() {
- if (!this._instance) this._instance = new ch_pvp();
- return this._instance;
- }
- /**
- * 设置自己的 PVP 擂台数据
- * 该方法用于更新当前用户在 PVP 擂台上的数据。数据将根据传入的 extend 参数进行更新,
- * 并返回一个包含操作状态和可能错误信息的 Promise。
- * @param extend - 一个pvp擂台数据对象,包含要更新的具体数据。
- * @returns 一个 Promise,解析为一个包含以下属性的对象:
- * - code: 操作的结果状态。0 表示成功,其他值表示不同的错误类型。
- * - err: 可选字符串,指示错误信息(如果有)。
- */;
- var _proto = ch_pvp.prototype;
- _proto.setSceneData = /*#__PURE__*/
- function () {
- var _setSceneData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(extend) {
- var check, body, ret;
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) switch (_context.prev = _context.next) {
- case 0:
- check = chsdk.check_req_time('setSceneData');
- if (!check) {
- _context.next = 3;
- break;
- }
- return _context.abrupt("return", check);
- case 3:
- body = {
- "extends": ch_util.stringify(extend)
- };
- _context.next = 6;
- return chsdk.makePostTokenRequest(chsdk.getUrl(this._set_url), body);
- case 6:
- ret = _context.sent;
- if (!(ret.code != chsdk.code.success)) {
- _context.next = 11;
- break;
- }
- chsdk.log.warn(ret);
- _context.next = 18;
- break;
- case 11:
- chsdk.log.log("PVP\u64C2\u53F0\u6570\u636E\u4E0A\u62A5\u6210\u529F");
- if (this._own) {
- _context.next = 17;
- break;
- }
- _context.next = 15;
- return this.getOwn();
- case 15:
- _context.next = 18;
- break;
- case 17:
- this._own["extends"] = extend;
- case 18:
- return _context.abrupt("return", ret);
- case 19:
- case "end":
- return _context.stop();
- }
- }, _callee, this);
- }));
- function setSceneData(_x) {
- return _setSceneData.apply(this, arguments);
- }
- return setSceneData;
- }()
- /**
- * 开始匹配
- * @param uid (可选)具体好友的uid,默为空
- * @returns null 匹配失败
- *
- * pvp_data<T>
- extends PVP 擂台数据
- * other 台主信息
- * own 自己的信息
- * head:头像, nickName:名字, uid:id, hid:省id, province:省名, pvp:pvp排位分值, rank:pvp排行榜名次
- */;
- _proto.startMatch = /*#__PURE__*/
- function () {
- var _startMatch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(uid) {
- var check, ret, data;
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
- while (1) switch (_context2.prev = _context2.next) {
- case 0:
- check = chsdk.check_req_time('startMatch');
- if (!check) {
- _context2.next = 3;
- break;
- }
- return _context2.abrupt("return", null);
- case 3:
- _context2.next = 5;
- return chsdk.makePostTokenRequest(chsdk.getUrl(this._match_url), {
- uid: uid ? uid.toString() : ''
- });
- case 5:
- ret = _context2.sent;
- if (!(ret.code != chsdk.code.success)) {
- _context2.next = 11;
- break;
- }
- chsdk.log.warn(ret);
- return _context2.abrupt("return", null);
- case 11:
- data = ret.data.data;
- data.other.uid = Number.parseInt(data.other.uid);
- data.other.hid = Number.parseInt(data.other.hid);
- data.other.province = chsdk.provinceCode2Name(data.other.hid);
- data.own.uid = Number.parseInt(data.own.uid);
- data.own.hid = Number.parseInt(data.own.hid);
- data.own.province = chsdk.provinceCode2Name(data.own.hid);
- return _context2.abrupt("return", {
- "extends": ch_util.parse(data["extends"]),
- other: data.other,
- own: data.own
- });
- case 19:
- case "end":
- return _context2.stop();
- }
- }, _callee2, this);
- }));
- function startMatch(_x2) {
- return _startMatch.apply(this, arguments);
- }
- return startMatch;
- }() /**从一条记录开始匹配,用于复仇*/;
- _proto.startMatchRecord = /*#__PURE__*/
- function () {
- var _startMatchRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(pd) {
- var check, pp;
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
- while (1) switch (_context3.prev = _context3.next) {
- case 0:
- check = chsdk.check_req_time('startMatch');
- if (!check) {
- _context3.next = 3;
- break;
- }
- return _context3.abrupt("return", null);
- case 3:
- _context3.next = 5;
- return this.startMatch(pd.other.uid);
- case 5:
- pp = _context3.sent;
- if (pp) {
- _context3.next = 8;
- break;
- }
- return _context3.abrupt("return", null);
- case 8:
- pp["extends"] = pd["extends"];
- pp.pvpId = pd.pvpId;
- return _context3.abrupt("return", pp);
- case 11:
- case "end":
- return _context3.stop();
- }
- }, _callee3, this);
- }));
- function startMatchRecord(_x3) {
- return _startMatchRecord.apply(this, arguments);
- }
- return startMatchRecord;
- }()
- /**
- * 完成pvp上报
- * @param otherUid 对方uid
- * @param status 0:挑战失败 1:挑战胜利
- * @param ext PVP 擂台数据
- * @param serverData 服务器处理排行数据,订阅消息
- * ..ownValue 增减自己排位分值
- * ..otherValue 增减对方排位分值
- * ..msg 自定义的订阅消息
- * @param pvpId 复仇id
- * @returns 对战结果
- * other 对方的排名和分数变化
- * own 自己的排名和分数变化
- * curRank 当前排名(变动后)
- curScore 当前分数(变动后)
- rank 名数变动
- score 分数变动
- */;
- _proto.finish = /*#__PURE__*/
- function () {
- var _finish = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(otherUid, status, ext, serverData, pvpId) {
- var check, body, ret, data;
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
- while (1) switch (_context4.prev = _context4.next) {
- case 0:
- check = chsdk.check_req_time('finish');
- if (!check) {
- _context4.next = 3;
- break;
- }
- return _context4.abrupt("return", null);
- case 3:
- body = {
- otherUid: otherUid.toString(),
- status: status,
- "extends": ch_util.stringify(ext),
- serverData: ch_util.stringify(serverData),
- pvpId: pvpId
- };
- _context4.next = 6;
- return chsdk.makePostTokenRequest(chsdk.getUrl(this._finish_url), body);
- case 6:
- ret = _context4.sent;
- if (!(ret.code != chsdk.code.success)) {
- _context4.next = 12;
- break;
- }
- chsdk.log.warn(ret);
- return _context4.abrupt("return", null);
- case 12:
- data = ret.data.data;
- chsdk.log.log("pvp\u7ED3\u679C\u6570\u636E\u4E0A\u62A5\u6210\u529F,\u7ED3\u7B97:", data);
- return _context4.abrupt("return", data);
- case 15:
- case "end":
- return _context4.stop();
- }
- }, _callee4, this);
- }));
- function finish(_x4, _x5, _x6, _x7, _x8) {
- return _finish.apply(this, arguments);
- }
- return finish;
- }();
- /**获取自己的pvp擂台数据*/
- _proto.getOwn = /*#__PURE__*/
- function () {
- var _getOwn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
- while (1) switch (_context5.prev = _context5.next) {
- case 0:
- if (this._own) {
- _context5.next = 3;
- break;
- }
- _context5.next = 3;
- return this.getRecords(3, false);
- case 3:
- return _context5.abrupt("return", this._own);
- case 4:
- case "end":
- return _context5.stop();
- }
- }, _callee5, this);
- }));
- function getOwn() {
- return _getOwn.apply(this, arguments);
- }
- return getOwn;
- }();
- _proto.get_cache_records = function get_cache_records() {
- if (chsdk.date.now() - this._cache_time > 6e4) return null;
- return this._cache_records;
- }
- /**
- * 获取pvp对战记录
- * @param type 0:全部纪录 1:被挑战的记录信息(默认) 2:挑战别人的记录 3:不需要纪录
- * @param cache 默认为true,优先缓存拿数据,缓存存在一分钟
- * @returns own:自己的PVP 擂台数据
- * list:交互纪录
- * extends PVP 擂台数据
- * reward 奖励惩罚排位分值,由于serverData中得来
- * type 0:自己的数据 1:被挑战的记录信息 2:挑战别人的记录
- * status 0:挑战失败 1:挑战胜利 2:复仇成功
- * time 时间
- * pvpId pvp复仇id
- * other 对方信息
- * own 自己信息
- */;
- _proto.getRecords = /*#__PURE__*/
- function () {
- var _getRecords = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(typeId, cache) {
- var data, check, ret, _data, d, i, _d;
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
- while (1) switch (_context6.prev = _context6.next) {
- case 0:
- if (typeId === void 0) {
- typeId = 1;
- }
- if (cache === void 0) {
- cache = true;
- }
- if (!cache) {
- _context6.next = 6;
- break;
- }
- data = this.get_cache_records();
- if (!data) {
- _context6.next = 6;
- break;
- }
- return _context6.abrupt("return", data);
- case 6:
- check = chsdk.check_req_time('getRecords');
- if (!check) {
- _context6.next = 9;
- break;
- }
- return _context6.abrupt("return", null);
- case 9:
- _context6.next = 11;
- return chsdk.makePostTokenRequest(chsdk.getUrl(this._record_url), {
- typeId: typeId
- });
- case 11:
- ret = _context6.sent;
- if (!(ret.code != chsdk.code.success)) {
- _context6.next = 17;
- break;
- }
- chsdk.log.warn(ret);
- return _context6.abrupt("return", null);
- case 17:
- _data = ret.data.data;
- if (_data.own) {
- d = _data.own;
- d["extends"] = ch_util.parse(d["extends"]);
- d.own.uid = Number.parseInt(d.own.uid);
- d.own.hid = Number.parseInt(d.own.hid);
- d.own.province = chsdk.provinceCode2Name(d.own.hid);
- } else {
- _data.own = null;
- }
- _data.list || (_data.list = []);
- for (i = 0; i < _data.list.length; i++) {
- _d = _data.list[i];
- _d["extends"] = ch_util.parse(_d["extends"]);
- _d.own.uid = Number.parseInt(_d.own.uid);
- _d.own.hid = Number.parseInt(_d.own.hid);
- _d.own.province = chsdk.provinceCode2Name(_d.own.hid);
- _d.other.uid = Number.parseInt(_d.other.uid);
- _d.other.hid = Number.parseInt(_d.other.hid);
- _d.other.province = chsdk.provinceCode2Name(_d.other.hid);
- }
- this._own = _data.own;
- this._cache_records = _data;
- this._cache_time = chsdk.date.now();
- return _context6.abrupt("return", _data);
- case 25:
- case "end":
- return _context6.stop();
- }
- }, _callee6, this);
- }));
- function getRecords(_x9, _x10) {
- return _getRecords.apply(this, arguments);
- }
- return getRecords;
- }()
- /**
- * 获取pvp排位分值榜单
- * @returns
- */;
- _proto.getRank = /*#__PURE__*/
- function () {
- var _getRank = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
- var d;
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
- while (1) switch (_context7.prev = _context7.next) {
- case 0:
- _context7.next = 2;
- return chsdk.loadRankData('pvp', 1, 100, true);
- case 2:
- d = _context7.sent;
- return _context7.abrupt("return", {
- list: d.data.list,
- ower: d.data.own
- });
- case 4:
- case "end":
- return _context7.stop();
- }
- }, _callee7);
- }));
- function getRank() {
- return _getRank.apply(this, arguments);
- }
- return getRank;
- }()
- /**
- * 分享pvp数据,邀请对战
- * @param player 玩家自己信息
- * @param extend (可选)pvp关卡等数据
- * @param title 分享显示标题
- * @param imageUrl 分享显示图片
- */;
- _proto.sharePvp = /*#__PURE__*/
- function () {
- var _sharePvp = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(player, extend, title, imageUrl) {
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
- while (1) switch (_context8.prev = _context8.next) {
- case 0:
- chsdk.shareAppMessage(title, '', imageUrl, ch_util.stringify({
- type: 'pvp',
- player: player,
- "extends": extend
- }));
- case 1:
- case "end":
- return _context8.stop();
- }
- }, _callee8);
- }));
- function sharePvp(_x11, _x12, _x13, _x14) {
- return _sharePvp.apply(this, arguments);
- }
- return sharePvp;
- }()
- /**
- *获取从好友分享的pvp数据进入游戏的数据
- */;
- _proto.getSharePvpExtends = function getSharePvpExtends() {
- var query = chsdk.getQuery();
- if (!query) return null;
- var message = query.message;
- if (!message) return null;
- var data = ch_util.parse(message);
- if (!data) return null;
- if (data.type != 'pvp') return null;
- query.message = null;
- return {
- player: data.player,
- extend: data["extends"]
- };
- };
- return ch_pvp;
- }(); //
- ch_pvp._instance = void 0;
- var pvp = exports('default', ch_pvp.getInstance());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ch_sdk_comp.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _inheritsLoose, cclegacy, _decorator, game, Game, Component;
- return {
- setters: [function (module) {
- _inheritsLoose = module.inheritsLoose;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- game = module.game;
- Game = module.Game;
- Component = module.Component;
- }],
- execute: function () {
- var _dec, _class;
- cclegacy._RF.push({}, "9a64dfa1IRPk5UQTCy9WxRi", "ch_sdk_comp", undefined);
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- var ch_sdk_comp = exports('ch_sdk_comp', (_dec = ccclass('ch_sdk_comp'), _dec(_class = /*#__PURE__*/function (_Component) {
- _inheritsLoose(ch_sdk_comp, _Component);
- function ch_sdk_comp() {
- return _Component.apply(this, arguments) || this;
- }
- var _proto = ch_sdk_comp.prototype;
- _proto.onLoad = function onLoad() {
- game.on(Game.EVENT_SHOW, function () {
- chsdk.sdk_event.emit(chsdk.sdk_event.key.show);
- }, this);
- game.on(Game.EVENT_HIDE, function () {
- chsdk.sdk_event.emit(chsdk.sdk_event.key.hide);
- }, this);
- /*window.addEventListener("blur", () => {
- chsdk.sdk_event.emit(chsdk.sdk_event.key.hide);
- });
- window.addEventListener("focus", () => {
- chsdk.sdk_event.emit(chsdk.sdk_event.key.show);
- });*/
- };
- return ch_sdk_comp;
- }(Component)) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ch_start_pack.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './ch.ts', './audio.ts', './ch_sdk_comp.ts'], function (exports) {
- var _applyDecoratedDescriptor, _inheritsLoose, _initializerDefineProperty, _assertThisInitialized, _createClass, _asyncToGenerator, _regeneratorRuntime, cclegacy, _decorator, Enum, Component, Node, director, ch, loadType, ch_sdk_comp;
- return {
- setters: [function (module) {
- _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
- _inheritsLoose = module.inheritsLoose;
- _initializerDefineProperty = module.initializerDefineProperty;
- _assertThisInitialized = module.assertThisInitialized;
- _createClass = module.createClass;
- _asyncToGenerator = module.asyncToGenerator;
- _regeneratorRuntime = module.regeneratorRuntime;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- Enum = module.Enum;
- Component = module.Component;
- Node = module.Node;
- director = module.director;
- }, function (module) {
- ch = module.ch;
- }, function (module) {
- loadType = module.loadType;
- }, function (module) {
- ch_sdk_comp = module.ch_sdk_comp;
- }],
- execute: function () {
- var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _dec21, _dec22, _dec23, _dec24, _dec25, _dec26, _dec27, _dec28, _dec29, _dec30, _dec31, _dec32, _dec33, _dec34, _dec35, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14, _descriptor15, _descriptor16, _descriptor17, _descriptor18;
- cclegacy._RF.push({}, "4aa63NubuJJqLakcBFHXiHV", "ch_start_pack", undefined);
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- /**包id*/
- var pack = exports('pack', /*#__PURE__*/function (pack) {
- pack[pack["id0"] = 0] = "id0";
- pack[pack["id1"] = 1] = "id1";
- pack[pack["id2"] = 2] = "id2";
- pack[pack["id3"] = 3] = "id3";
- pack[pack["id4"] = 4] = "id4";
- pack[pack["id5"] = 5] = "id5";
- pack[pack["id6"] = 6] = "id6";
- pack[pack["id7"] = 7] = "id7";
- pack[pack["id8"] = 8] = "id8";
- pack[pack["id9"] = 9] = "id9";
- return pack;
- }({}));
- var ch_start_pack = exports('ch_start_pack', (_dec = ccclass('ch_start_pack'), _dec2 = property({
- visible: false
- }), _dec3 = property({
- visible: false
- }), _dec4 = property({
- visible: false
- }), _dec5 = property({
- visible: false
- }), _dec6 = property({
- visible: false
- }), _dec7 = property({
- visible: false
- }), _dec8 = property({
- visible: false
- }), _dec9 = property({
- visible: false
- }), _dec10 = property({
- visible: false
- }), _dec11 = property({
- visible: false
- }), _dec12 = property({
- visible: false
- }), _dec13 = property({
- visible: false
- }), _dec14 = property({
- visible: false
- }), _dec15 = property({
- visible: false
- }), _dec16 = property({
- type: Enum(pack),
- displayName: '包id',
- group: {
- name: '选包',
- id: 'pack',
- displayOrder: 0
- }
- }), _dec17 = property({
- displayName: '游戏名',
- group: {
- name: '选包',
- id: 'pack',
- displayOrder: 0
- }
- }), _dec18 = property({
- displayName: '游戏id',
- group: {
- name: '选包',
- id: 'pack',
- displayOrder: 0
- }
- }), _dec19 = property({
- displayName: '是否单机',
- group: {
- name: 'ch.sdk模块',
- id: 'sdk',
- displayOrder: 0
- }
- }), _dec20 = property({
- type: Enum(chsdk.serverType),
- displayName: '服务器地址',
- visible: function visible() {
- return !this.is_local;
- },
- group: {
- name: 'ch.sdk模块',
- id: 'sdk',
- displayOrder: 0
- },
- tooltip: "local 局域网 \n dev 测试服 \n online 正式服"
- }), _dec21 = property({
- displayName: '本地服测试ip',
- visible: function visible() {
- return this.server == chsdk.serverType.test;
- },
- group: {
- name: 'ch.sdk模块',
- id: 'sdk',
- displayOrder: 0
- }
- }), _dec22 = property({
- type: Enum(chsdk.reportType),
- displayName: '上报类型',
- group: {
- name: '基本参数',
- id: 'sdk',
- displayOrder: 0
- },
- tooltip: "off 不上报 \n ch 使用ch服务器(需要在ch后台配置事件) \n platform 使用微信/抖音平台(需要在平台后台设置事件)\nch__platflorm所有平台自定义事件都上报"
- }), _dec23 = property({
- type: Enum(chsdk.loglevel),
- displayName: '日志等级',
- group: {
- name: '基本参数',
- id: 'sdk',
- displayOrder: 0
- }
- }), _dec24 = property({
- displayName: '抖音奖励广告id',
- group: {
- name: '基本参数',
- id: 'sdk',
- displayOrder: 0
- }
- }), _dec25 = property({
- displayName: '抖音插屏广告id',
- group: {
- name: '基本参数',
- id: 'sdk',
- displayOrder: 0
- }
- }), _dec26 = property({
- displayName: '抖音订阅id(,隔开)',
- group: {
- name: '基本参数',
- id: 'sdk',
- displayOrder: 0
- }
- }), _dec27 = property({
- displayName: '微信奖励广告id',
- group: {
- name: '基本参数',
- id: 'sdk',
- displayOrder: 0
- }
- }), _dec28 = property({
- displayName: '微信插屏广告id',
- group: {
- name: '基本参数',
- id: 'sdk',
- displayOrder: 0
- }
- }), _dec29 = property({
- displayName: '微信订阅id(,隔开)',
- group: {
- name: '基本参数',
- id: 'sdk',
- displayOrder: 0
- }
- }), _dec30 = property({
- visible: false
- }), _dec31 = property({
- type: Enum(loadType),
- visible: false
- }), _dec32 = property({
- displayName: '是否使用ch.audio模块',
- group: {
- name: 'ch.audio模块',
- id: 'audio',
- displayOrder: 1
- }
- }), _dec33 = property({
- type: Enum(loadType),
- displayName: '音频资源加载模式',
- group: {
- name: 'ch.audio模块',
- id: 'audio',
- displayOrder: 1
- },
- visible: function visible() {
- return this._use_ch_audio;
- }
- }), _dec34 = property({
- displayName: '音频资源默认bundle名',
- group: {
- name: 'ch.audio模块',
- id: 'audio',
- displayOrder: 1
- },
- visible: function visible() {
- return this._use_ch_audio && this._ch_audio_type == loadType.bundle;
- }
- }), _dec35 = property({
- displayName: '音频资源远程地址',
- group: {
- name: 'ch.audio模块',
- id: 'audio',
- displayOrder: 1
- },
- visible: function visible() {
- return this._use_ch_audio && this._ch_audio_type == loadType.remote;
- }
- }), _dec(_class = (_class2 = /*#__PURE__*/function (_Component) {
- _inheritsLoose(ch_start_pack, _Component);
- function ch_start_pack() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _initializerDefineProperty(_this, "_gname", _descriptor, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_gid", _descriptor2, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_is_local", _descriptor3, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_server", _descriptor4, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_report", _descriptor5, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_log", _descriptor6, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_ttad", _descriptor7, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_ttiad", _descriptor8, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_tttmpid", _descriptor9, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_wxad", _descriptor10, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_wxiad", _descriptor11, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_wxtmpid", _descriptor12, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_serverIP", _descriptor13, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_pid", _descriptor14, _assertThisInitialized(_this));
- //
- _initializerDefineProperty(_this, "_use_ch_audio", _descriptor15, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_ch_audio_type", _descriptor16, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "sound_bundle", _descriptor17, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "sound_url", _descriptor18, _assertThisInitialized(_this));
- return _this;
- }
- var _proto = ch_start_pack.prototype;
- _proto.onLoad = function onLoad() {
- console.log('包Id:' + this.pid, '游戏名:' + this.gname, '游戏Id:' + this.gid, '单机:' + this.is_local, '服务器:' + chsdk.serverType[this.server]);
- }
- /**初始化*/;
- _proto.init = /*#__PURE__*/
- function () {
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
- var ret, sdk;
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) switch (_context.prev = _context.next) {
- case 0:
- chsdk.setConf(chsdk.pf.tt, {
- adUnitId: this.ttad,
- multiton: false,
- inster_unitId: this.ttiad,
- tmplIds: this.tttmpid ? this.tttmpid.split(',') : null
- });
- chsdk.setConf(chsdk.pf.wx, {
- adUnitId: this.wxad,
- multiton: false,
- inster_unitId: this.wxiad,
- tmplIds: this.wxtmpid ? this.wxtmpid.split(',') : null
- });
- _context.next = 4;
- return chsdk.init_inside(this.gid, this.log, this.server == chsdk.serverType.test ? this.serverIP : this.server, this.is_local, this.report);
- case 4:
- ret = _context.sent;
- if (!(ret.code == chsdk.code.success)) {
- _context.next = 11;
- break;
- }
- if (this.use_ch_audio) {
- ch.audio.init(this.sount_load_type, this.sound_bundle, this.sound_url);
- }
- if (chsdk.get_pf() === chsdk.pf.web) {
- sdk = new Node();
- sdk.name = '__ch_sdk__';
- sdk.addComponent(ch_sdk_comp);
- director.getScene().addChild(sdk);
- director.addPersistRootNode(sdk);
- }
- return _context.abrupt("return", true);
- case 11:
- chsdk.log.error(ret.err);
- return _context.abrupt("return", false);
- case 13:
- case "end":
- return _context.stop();
- }
- }, _callee, this);
- }));
- function init() {
- return _init.apply(this, arguments);
- }
- return init;
- }()
- /**初化始并在遇到问题时以单机模式进入
- * @param try_count 重试次数
- * @param try_interval 重试间隔时间(MS)
- */;
- _proto.try_init = /*#__PURE__*/
- function () {
- var _try_init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(try_count, try_interval) {
- var ret;
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
- while (1) switch (_context2.prev = _context2.next) {
- case 0:
- if (try_count === void 0) {
- try_count = 5;
- }
- if (try_interval === void 0) {
- try_interval = 2000;
- }
- _context2.next = 4;
- return this.init();
- case 4:
- ret = _context2.sent;
- if (!ret) {
- _context2.next = 7;
- break;
- }
- return _context2.abrupt("return");
- case 7:
- try_count--;
- if (!(try_count < 0)) {
- _context2.next = 15;
- break;
- }
- this.is_local = true;
- _context2.next = 12;
- return this.init();
- case 12:
- return _context2.abrupt("return");
- case 15:
- _context2.next = 17;
- return new Promise(function (resolve) {
- return setTimeout(resolve, try_interval);
- });
- case 17:
- return _context2.abrupt("return", this.try_init(try_count, try_interval));
- case 18:
- case "end":
- return _context2.stop();
- }
- }, _callee2, this);
- }));
- function try_init(_x, _x2) {
- return _try_init.apply(this, arguments);
- }
- return try_init;
- }();
- _createClass(ch_start_pack, [{
- key: "pid",
- get: function get() {
- return this._pid;
- },
- set: function set(val) {
- this._pid = val;
- for (var i = 0; i <= this._pid; i++) {
- var _this$_gname, _i, _this$_gname$_i, _this$_is_local, _i2, _this$_is_local$_i, _this$_is_local2, _this$_gid, _i3, _this$_gid$_i, _this$_gid2, _this$_server, _i4, _this$_server$_i, _this$_server2, _this$_report, _i5, _this$_report$_i, _this$_report2, _this$_log, _i6, _this$_log$_i, _this$_log2, _this$_ttad, _i7, _this$_ttad$_i, _this$_ttiad, _i8, _this$_ttiad$_i, _this$_tttmpid, _i9, _this$_tttmpid$_i, _this$_wxad, _i10, _this$_wxad$_i, _this$_wxiad, _i11, _this$_wxiad$_i, _this$_wxtmpid, _i12, _this$_wxtmpid$_i, _this$_serverIP, _i13, _this$_serverIP$_i;
- (_this$_gname$_i = (_this$_gname = this._gname)[_i = i]) != null ? _this$_gname$_i : _this$_gname[_i] = '';
- (_this$_is_local$_i = (_this$_is_local = this._is_local)[_i2 = i]) != null ? _this$_is_local$_i : _this$_is_local[_i2] = (_this$_is_local2 = this._is_local[i - 1]) != null ? _this$_is_local2 : true;
- (_this$_gid$_i = (_this$_gid = this._gid)[_i3 = i]) != null ? _this$_gid$_i : _this$_gid[_i3] = (_this$_gid2 = this._gid[i - 1]) != null ? _this$_gid2 : '0';
- (_this$_server$_i = (_this$_server = this._server)[_i4 = i]) != null ? _this$_server$_i : _this$_server[_i4] = (_this$_server2 = this._server[i - 1]) != null ? _this$_server2 : chsdk.serverType.online;
- (_this$_report$_i = (_this$_report = this._report)[_i5 = i]) != null ? _this$_report$_i : _this$_report[_i5] = (_this$_report2 = this._report[i - 1]) != null ? _this$_report2 : chsdk.reportType.off;
- (_this$_log$_i = (_this$_log = this._log)[_i6 = i]) != null ? _this$_log$_i : _this$_log[_i6] = (_this$_log2 = this._log[i - 1]) != null ? _this$_log2 : chsdk.loglevel.DEBUG;
- (_this$_ttad$_i = (_this$_ttad = this._ttad)[_i7 = i]) != null ? _this$_ttad$_i : _this$_ttad[_i7] = '';
- (_this$_ttiad$_i = (_this$_ttiad = this._ttiad)[_i8 = i]) != null ? _this$_ttiad$_i : _this$_ttiad[_i8] = '';
- (_this$_tttmpid$_i = (_this$_tttmpid = this._tttmpid)[_i9 = i]) != null ? _this$_tttmpid$_i : _this$_tttmpid[_i9] = '';
- (_this$_wxad$_i = (_this$_wxad = this._wxad)[_i10 = i]) != null ? _this$_wxad$_i : _this$_wxad[_i10] = '';
- (_this$_wxiad$_i = (_this$_wxiad = this._wxiad)[_i11 = i]) != null ? _this$_wxiad$_i : _this$_wxiad[_i11] = '';
- (_this$_wxtmpid$_i = (_this$_wxtmpid = this._wxtmpid)[_i12 = i]) != null ? _this$_wxtmpid$_i : _this$_wxtmpid[_i12] = '';
- (_this$_serverIP$_i = (_this$_serverIP = this._serverIP)[_i13 = i]) != null ? _this$_serverIP$_i : _this$_serverIP[_i13] = 'http://192.168.1.120:8787/v1';
- }
- }
- }, {
- key: "gname",
- get: function get() {
- var _this$_gname$this$_pi;
- return (_this$_gname$this$_pi = this._gname[this._pid]) != null ? _this$_gname$this$_pi : '';
- },
- set: function set(val) {
- this._gname[this._pid] = val;
- }
- }, {
- key: "gid",
- get: function get() {
- return this._gid[this._pid];
- },
- set: function set(val) {
- this._gid[this._pid] = val;
- }
- //
- }, {
- key: "is_local",
- get: function get() {
- return this._is_local[this._pid];
- },
- set: function set(val) {
- this._is_local[this._pid] = val;
- }
- //
- }, {
- key: "server",
- get: function get() {
- return this._server[this._pid];
- },
- set: function set(val) {
- this._server[this._pid] = val;
- }
- }, {
- key: "serverIP",
- get: function get() {
- return this._serverIP[this._pid];
- },
- set: function set(val) {
- this._serverIP[this._pid] = val;
- }
- }, {
- key: "report",
- get: function get() {
- return this._report[this._pid];
- },
- set: function set(val) {
- this._report[this._pid] = val;
- }
- }, {
- key: "log",
- get: function get() {
- return this._log[this._pid];
- },
- set: function set(val) {
- this._log[this._pid] = val;
- }
- //
- }, {
- key: "ttad",
- get: function get() {
- return this._ttad[this._pid];
- },
- set: function set(val) {
- this._ttad[this._pid] = val;
- }
- }, {
- key: "ttiad",
- get: function get() {
- return this._ttiad[this._pid];
- },
- set: function set(val) {
- this._ttiad[this._pid] = val;
- }
- }, {
- key: "tttmpid",
- get: function get() {
- return this._tttmpid[this._pid];
- },
- set: function set(val) {
- this._tttmpid[this._pid] = val;
- }
- }, {
- key: "wxad",
- get: function get() {
- return this._wxad[this._pid];
- },
- set: function set(val) {
- this._wxad[this._pid] = val;
- }
- }, {
- key: "wxiad",
- get: function get() {
- return this._wxiad[this._pid];
- },
- set: function set(val) {
- this._wxiad[this._pid] = val;
- }
- }, {
- key: "wxtmpid",
- get: function get() {
- return this._wxtmpid[this._pid];
- },
- set: function set(val) {
- this._wxtmpid[this._pid] = val;
- }
- }, {
- key: "use_ch_audio",
- get: function get() {
- return this._use_ch_audio;
- },
- set: function set(val) {
- this._use_ch_audio = val;
- }
- }, {
- key: "sount_load_type",
- get: function get() {
- return this._ch_audio_type;
- },
- set: function set(val) {
- this._ch_audio_type = val;
- }
- }]);
- return ch_start_pack;
- }(Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "_gname", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "_gid", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "_is_local", [_dec4], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "_server", [_dec5], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [chsdk.serverType.dev];
- }
- }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "_report", [_dec6], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [chsdk.reportType.off];
- }
- }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "_log", [_dec7], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "_ttad", [_dec8], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "_ttiad", [_dec9], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "_tttmpid", [_dec10], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "_wxad", [_dec11], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "_wxiad", [_dec12], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "_wxtmpid", [_dec13], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor13 = _applyDecoratedDescriptor(_class2.prototype, "_serverIP", [_dec14], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor14 = _applyDecoratedDescriptor(_class2.prototype, "_pid", [_dec15], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return pack.id0;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "pid", [_dec16], Object.getOwnPropertyDescriptor(_class2.prototype, "pid"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "gname", [_dec17], Object.getOwnPropertyDescriptor(_class2.prototype, "gname"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "gid", [_dec18], Object.getOwnPropertyDescriptor(_class2.prototype, "gid"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "is_local", [_dec19], Object.getOwnPropertyDescriptor(_class2.prototype, "is_local"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "server", [_dec20], Object.getOwnPropertyDescriptor(_class2.prototype, "server"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "serverIP", [_dec21], Object.getOwnPropertyDescriptor(_class2.prototype, "serverIP"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "report", [_dec22], Object.getOwnPropertyDescriptor(_class2.prototype, "report"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "log", [_dec23], Object.getOwnPropertyDescriptor(_class2.prototype, "log"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "ttad", [_dec24], Object.getOwnPropertyDescriptor(_class2.prototype, "ttad"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "ttiad", [_dec25], Object.getOwnPropertyDescriptor(_class2.prototype, "ttiad"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "tttmpid", [_dec26], Object.getOwnPropertyDescriptor(_class2.prototype, "tttmpid"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "wxad", [_dec27], Object.getOwnPropertyDescriptor(_class2.prototype, "wxad"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "wxiad", [_dec28], Object.getOwnPropertyDescriptor(_class2.prototype, "wxiad"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "wxtmpid", [_dec29], Object.getOwnPropertyDescriptor(_class2.prototype, "wxtmpid"), _class2.prototype), _descriptor15 = _applyDecoratedDescriptor(_class2.prototype, "_use_ch_audio", [_dec30], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor16 = _applyDecoratedDescriptor(_class2.prototype, "_ch_audio_type", [_dec31], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return loadType.bundle;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "use_ch_audio", [_dec32], Object.getOwnPropertyDescriptor(_class2.prototype, "use_ch_audio"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "sount_load_type", [_dec33], Object.getOwnPropertyDescriptor(_class2.prototype, "sount_load_type"), _class2.prototype), _descriptor17 = _applyDecoratedDescriptor(_class2.prototype, "sound_bundle", [_dec34], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 'res';
- }
- }), _descriptor18 = _applyDecoratedDescriptor(_class2.prototype, "sound_url", [_dec35], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return '';
- }
- })), _class2)) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ch_util.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _asyncToGenerator, _regeneratorRuntime, cclegacy, sys, UITransform, size, screen, view, assetManager, SpriteFrame, Texture2D, ImageAsset;
- return {
- setters: [function (module) {
- _asyncToGenerator = module.asyncToGenerator;
- _regeneratorRuntime = module.regeneratorRuntime;
- }, function (module) {
- cclegacy = module.cclegacy;
- sys = module.sys;
- UITransform = module.UITransform;
- size = module.size;
- screen = module.screen;
- view = module.view;
- assetManager = module.assetManager;
- SpriteFrame = module.SpriteFrame;
- Texture2D = module.Texture2D;
- ImageAsset = module.ImageAsset;
- }],
- execute: function () {
- cclegacy._RF.push({}, "1badftMxAdA7p5/bxrvSF8o", "ch_util", undefined);
- /**工具*/
- var ch_util = /*#__PURE__*/function () {
- function ch_util() {
- this._k = 1000;
- this._k_sizes_en = ['', 'K', 'M', 'G', 'T', 'P', 'E'];
- this._k_sizes_cn = ['', '千', '百万', '十亿', '万亿', '拍(千万亿)', '艾(十亿亿)'];
- this._w = 10000;
- this._w_sizes_en = ['', 'W', 'M', 'B', 'T'];
- this._w_sizes_cn = ['', '万', '亿', '万亿'];
- this._url_data = null;
- }
- ch_util.getInstance = function getInstance() {
- if (!this._instance) this._instance = new ch_util();
- return this._instance;
- }
- /**
- * 随机数 (包含min,不包含max)
- * @param min
- * @param max
- * @param isInt
- * @return {*}
- */;
- var _proto = ch_util.prototype;
- _proto.getRandom = function getRandom(min, max) {
- if (min === void 0) {
- min = 0;
- }
- if (max === void 0) {
- max = 1;
- }
- if (min == null) min = 0;
- if (max == null) max = 1;
- if (min === max) return min;
- return min + Math.random() * (max - min);
- }
- /**
- * 随机整数-不包含最大值
- * @param min
- * @param max
- * @return {*}
- */;
- _proto.getRandomInt = function getRandomInt(min, max) {
- min = Math.ceil(min);
- max = Math.ceil(max);
- return Math.floor(Math.random() * (max - min)) + min;
- }
- /** 生成随机整数 -1 或 1*/;
- _proto.getRandomDir = function getRandomDir() {
- return Math.floor(Math.random() * 2) === 0 ? -1 : 1;
- }
- /**
- * 在指定数组中随机取出N个不重复的数据
- * @param resArr
- * @param ranNum
- * @returns {Array}
- */;
- _proto.getRandomDiffValueFromArr = function getRandomDiffValueFromArr(resArr, ranNum) {
- var arr = new Array();
- var result = new Array();
- if (!resArr || resArr.length <= 0 || ranNum <= 0) {
- return result;
- }
- for (var i = 0; i < resArr.length; i++) {
- arr.push(resArr[i]);
- }
- if (ranNum >= arr.length) return arr;
- ranNum = Math.min(ranNum, arr.length - 1);
- for (var _i = 0; _i < ranNum; _i++) {
- var ran = this.getRandomInt(0, arr.length - 1);
- result.push(arr.splice(ran, 1)[0]);
- }
- return result;
- }
- /**
- * 取小数位
- * @param decimal 小数
- * @param places 位数
- * @return {number}
- */;
- _proto.numberToDecimal = function numberToDecimal(decimal, places) {
- var round = Math.pow(10, places);
- return Math.round(decimal * round) / round;
- };
- _proto.parse = function parse(text, reciver) {
- try {
- return JSON.parse(text, reciver);
- } catch (error) {
- //ch_log.error(error);
- return null;
- }
- };
- _proto.stringify = function stringify(value, replacer, space) {
- try {
- return JSON.stringify(value, replacer, space);
- } catch (error) {
- return null;
- }
- }
- /**
- * 判断字符是否为双字节字符(如中文字符)
- * @param string 原字符串
- */;
- _proto.str_isDoubleWord = function str_isDoubleWord(string) {
- return /[^\x00-\xff]/.test(string);
- }
- /**
- * 是否为空
- * @param str
- */;
- _proto.str_isEmpty = function str_isEmpty(str) {
- if (str == null || str == undefined || str.length == 0) {
- return true;
- }
- return false;
- }
- /**
- * 转美式计数字符串
- * @param value 数字
- * @example
- * 123456789 = 123,456,789
- */;
- _proto.numberTotPermil = function numberTotPermil(value) {
- return value.toLocaleString();
- };
- /**
- * 通用单位转换方法
- */
- _proto.convertNumber = function convertNumber(value, base, sizes, fixed) {
- if (value < base) return value.toString();
- var i = Math.floor(Math.log(value) / Math.log(base));
- var r = value / Math.pow(base, i);
- if (i >= sizes.length) return value.toString();
- return "" + r.toFixed(fixed) + sizes[i];
- }
- /**
- * 转单位计数(默认英文)
- * @param value 数字
- * @param fixed 保留小数位数
- * @param isEn 是否英文
- * @example
- * 12345 = 12.35K
- */;
- _proto.numberToThousand = function numberToThousand(value, fixed, isEn) {
- if (fixed === void 0) {
- fixed = 2;
- }
- if (isEn === void 0) {
- isEn = true;
- }
- var sizes = isEn ? this._k_sizes_en : this._k_sizes_cn;
- return this.convertNumber(value, this._k, sizes, fixed);
- }
- /**
- * 转单位计数(默认中文)
- * @param value 数字
- * @param fixed 保留小数位数
- * @param isEn 是否英文
- * @example
- * 12345 = 1.23万
- */;
- _proto.numberToTenThousand = function numberToTenThousand(value, fixed, isEn) {
- if (fixed === void 0) {
- fixed = 2;
- }
- if (isEn === void 0) {
- isEn = false;
- }
- var sizes = isEn ? this._w_sizes_en : this._w_sizes_cn;
- return this.convertNumber(value, this._w, sizes, fixed);
- }
- /**获取一个唯一标识的字符串 */;
- _proto.guid = function guid() {
- var guid = Math.random().toString(36).substring(2);
- return guid;
- }
- /**排序一个json Object*/;
- _proto.obj_sort = function obj_sort(obj) {
- var sorted_keys = Object.keys(obj).sort();
- var new_obj = {};
- for (var i = 0; i < sorted_keys.length; i++) {
- var _key = sorted_keys[i];
- var _value = obj[_key];
- var t = this.obj_get_value_type(_value);
- new_obj[_key] = t == 'object' ? this.obj_sort(_value) : _value;
- }
- return new_obj;
- }
- /**获取一个josn值的类型*/;
- _proto.obj_get_value_type = function obj_get_value_type(value) {
- var type;
- if (value === null) {
- type = 'null';
- } else {
- type = typeof value;
- }
- // 如果是对象或数组,还可以进一步判断
- if (type === 'object') {
- if (Array.isArray(value)) {
- type = 'array';
- }
- //else if (value instanceof Date) { type = 'date'; }
- }
- return type;
- }
- /**
- * 判断指定的值是否为对象
- * @param value 值
- */;
- _proto.valueIsObject = function valueIsObject(value) {
- return Object.prototype.toString.call(value) === '[object Object]';
- }
- /**
- * 深拷贝
- * @param target 目标
- */
- /** 克隆对象 */;
- _proto.obj_clone = function obj_clone(target_, record_set) {
- if (record_set === void 0) {
- record_set = new Set();
- }
- var result;
- switch (typeof target_) {
- case "object":
- {
- // 数组:遍历拷贝
- if (Array.isArray(target_)) {
- if (record_set.has(target_)) {
- return target_;
- }
- record_set.add(target_);
- result = [];
- for (var k_n = 0; k_n < target_.length; ++k_n) {
- // 递归克隆数组中的每一项
- result.push(this.obj_clone(target_[k_n], record_set));
- }
- }
- // null:直接赋值
- else if (target_ === null) {
- result = null;
- }
- // RegExp:直接赋值
- else if (target_.constructor === RegExp) {
- result = target_;
- }
- // 普通对象:循环递归赋值对象的所有值
- else {
- if (record_set.has(target_)) {
- return target_;
- }
- record_set.add(target_);
- result = {};
- for (var k_s in target_) {
- result[k_s] = this.obj_clone(target_[k_s], record_set);
- }
- }
- break;
- }
- case "function":
- {
- result = target_.bind({});
- break;
- }
- default:
- {
- result = target_;
- }
- }
- return result;
- }
- /**
- * 拷贝对象
- * @param target 目标
- */;
- _proto.copy = function copy(target) {
- return this.parse(this.stringify(target));
- }
- //请求相关--------------------------------------------
- ;
- _proto.getReqId = function getReqId() {
- return Date.now() + "_" + Math.ceil(1e3 * Math.random());
- };
- /**获取链接中传入的某个值*/
- _proto.getUrlData = function getUrlData(key) {
- if (!this._url_data) {
- this._url_data = this.parseUrl();
- }
- var value = this._url_data[key];
- if (value === undefined) return null;
- if (typeof value === 'string') {
- var numberValue = parseFloat(value);
- if (!isNaN(numberValue)) return numberValue;
- return value;
- }
- return null;
- };
- _proto.parseUrl = function parseUrl() {
- if (!sys.isBrowser || typeof window !== "object" || !window.document) return {};
- var url = window.document.location.href;
- var queryString = url.split("?")[1];
- if (!queryString) return {};
- return queryString.split("&").reduce(function (acc, param) {
- var _param$split = param.split("="),
- key = _param$split[0],
- value = _param$split[1];
- if (key) acc[decodeURIComponent(key)] = value ? decodeURIComponent(value) : '';
- return acc;
- }, {});
- }
- /**获到node的坐标和范围用于平台在对应位置创建按纽*/;
- _proto.getBtnOp = function getBtnOp(btnNode) {
- var btnNodeUiTransform = btnNode.getComponent(UITransform);
- var btnSize = size(btnNodeUiTransform.width + 0, btnNodeUiTransform.height + 0);
- //let frameWidth = screen.windowSize.width / screen.devicePixelRatio
- var frameHeight = screen.windowSize.height / screen.devicePixelRatio;
- //const winSize = screen.windowSize;
- //const designSize = view.getDesignResolutionSize();
- //console.log('designSize', designSize);
- //console.log('winSize:', winSize);
- //console.log('frameSize:', frameWidth,frameHeight);
- //适配不同机型来创建微信授权按钮
- var rect = btnNodeUiTransform.getBoundingBoxToWorld();
- var ratio = screen.devicePixelRatio;
- var scale = view.getScaleX();
- var factor = scale / ratio;
- var offsetX = 0;
- var offsetY = 0;
- var top = frameHeight - (rect.y + rect.height) * factor - offsetY;
- var left = rect.x * factor + offsetX;
- var width = btnSize.width * factor;
- var height = btnSize.height * factor;
- return {
- left: left,
- top: top,
- width: width,
- height: height
- };
- }
- /**远程加载图片*/;
- _proto.loadImage = /*#__PURE__*/
- function () {
- var _loadImage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
- var idata;
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) switch (_context.prev = _context.next) {
- case 0:
- if (!(chsdk.get_pf() == chsdk.pf.web)) {
- _context.next = 6;
- break;
- }
- _context.next = 3;
- return this.loadRemoteSprite(url);
- case 3:
- return _context.abrupt("return", _context.sent);
- case 6:
- _context.next = 8;
- return chsdk.loadImage(url);
- case 8:
- idata = _context.sent;
- return _context.abrupt("return", this.getSpriteFrame(idata));
- case 10:
- case "end":
- return _context.stop();
- }
- }, _callee, this);
- }));
- function loadImage(_x) {
- return _loadImage.apply(this, arguments);
- }
- return loadImage;
- }() /**cocos加载远程图片*/;
- _proto.loadRemoteSprite = function loadRemoteSprite(remoteUrl, ext) {
- if (ext === void 0) {
- ext = '.png';
- }
- return new Promise(function (resolve) {
- assetManager.loadRemote(remoteUrl, {
- ext: ext
- }, function (err, imageAsset) {
- var spriteFrame = new SpriteFrame();
- var texture = new Texture2D();
- texture.image = imageAsset;
- spriteFrame.texture = texture;
- resolve(spriteFrame);
- });
- });
- }
- /**远程加载的图片数据转成spriteFrame*/;
- _proto.getSpriteFrame = function getSpriteFrame(img) {
- if (!img) return null;
- try {
- var spriteFrame = new SpriteFrame();
- var texture = new Texture2D();
- texture.image = img instanceof ImageAsset ? img : new ImageAsset(img);
- spriteFrame.texture = texture;
- return spriteFrame;
- } catch (error) {
- //ch_log.warn(error);
- return null;
- }
- };
- return ch_util;
- }();
- ch_util._instance = void 0;
- var ch_util$1 = exports('default', ch_util.getInstance());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ch.ts", ['cc', './audio.ts', './ch_pvp.ts', './ch_util.ts', './sign.ts', './net.ts', './NetPlayer.ts', './NetRoom.ts'], function (exports) {
- var cclegacy, ch_audio, pvp, ch_util, ch_sign, ch_net;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }, function (module) {
- ch_audio = module.default;
- }, function (module) {
- pvp = module.default;
- }, function (module) {
- ch_util = module.default;
- }, function (module) {
- ch_sign = module.default;
- }, function (module) {
- ch_net = module.ch_net;
- }, function (module) {
- exports('NetPlayer', module.NetPlayer);
- }, function (module) {
- exports('NetRoom', module.NetRoom);
- }],
- execute: function () {
- cclegacy._RF.push({}, "16801Kyc0VO+7VDvNW2CiaJ", "ch", undefined);
- var ch = exports('ch', {
- /**主sdk(需要初始化)*/
- sdk: chsdk,
- /**日志*/
- log: chsdk.log,
- /**本地缓存*/
- storage: chsdk.storage,
- /**日期*/
- date: chsdk.date,
- /**创建一个模块事件*/get_new_event: function get_new_event() {
- return chsdk.get_new_event();
- },
- //---------------------------------------------
- /**交互*/
- pvp: pvp,
- /**创建一个新的网络连接管理*/get_new_net: function get_new_net() {
- return new ch_net();
- },
- /**工具*/
- util: ch_util,
- /**登录签到模块*/
- get sign() {
- return ch_sign.getInstance();
- },
- /**音频播放模块(需要初始化)*/
- get audio() {
- return ch_audio.getInstance();
- }
- });
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ClickPenetrate.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _applyDecoratedDescriptor, _inheritsLoose, _initializerDefineProperty, _assertThisInitialized, cclegacy, _decorator, EventHandler, Vec2, Button, Input, Component;
- return {
- setters: [function (module) {
- _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
- _inheritsLoose = module.inheritsLoose;
- _initializerDefineProperty = module.initializerDefineProperty;
- _assertThisInitialized = module.assertThisInitialized;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- EventHandler = module.EventHandler;
- Vec2 = module.Vec2;
- Button = module.Button;
- Input = module.Input;
- Component = module.Component;
- }],
- execute: function () {
- var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4;
- cclegacy._RF.push({}, "739bfHpcHtB3IXOkilm3JV7", "ClickPenetrate", undefined);
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- /*** 按钮 点击穿透*/
- var ClickPenetrate = exports('ClickPenetrate', (_dec = ccclass('ClickPenetrate'), _dec2 = property({
- tooltip: "滑动会关闭 end 触摸事件"
- }), _dec3 = property({
- tooltip: "触摸开始",
- type: EventHandler
- }), _dec4 = property({
- tooltip: "触摸移动",
- type: EventHandler
- }), _dec5 = property({
- tooltip: "触摸结束",
- type: EventHandler
- }), _dec(_class = (_class2 = /*#__PURE__*/function (_Component) {
- _inheritsLoose(ClickPenetrate, _Component);
- function ClickPenetrate() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _initializerDefineProperty(_this, "move_began_end", _descriptor, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "on_touch_began", _descriptor2, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "on_touch_move", _descriptor3, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "on_touch_end", _descriptor4, _assertThisInitialized(_this));
- // @property({ tooltip: "触摸关闭", type: cc.EventHandler })
- // private on_touch_cancel: Array<cc.EventHandler> = [];
- _this.has_began = false;
- _this.comp_btn = null;
- /** 是移动状态 */
- _this.is_move = null;
- /** 本次点击所移动的距离 */
- _this.delta = new Vec2(0, 0);
- return _this;
- }
- var _proto = ClickPenetrate.prototype;
- _proto.onLoad = function onLoad() {
- this.comp_btn = this.node.getComponent(Button) || this.node.addComponent(Button);
- this.comp_btn.node.on(Input.EventType.TOUCH_START, this.onTouchBegan, this);
- this.comp_btn.node.on(Input.EventType.TOUCH_MOVE, this.onTouchMoved, this);
- this.comp_btn.node.on(Input.EventType.TOUCH_END, this.onTouchEnded, this);
- this.comp_btn.node.on(Input.EventType.TOUCH_CANCEL, this.onTouchCancelled, this);
- };
- _proto.onTouchBegan = function onTouchBegan(touch, param) {
- var _this2 = this;
- touch.preventSwallow = true;
- this.has_began = true;
- this.is_move = false;
- this.delta = new Vec2(0, 0);
- this.on_touch_began.forEach(function (value, key) {
- value.emit([_this2.comp_btn]);
- });
- };
- _proto.onTouchMoved = function onTouchMoved(touch, param) {
- var _this3 = this;
- touch.preventSwallow = true;
- if (!this.has_began) return;
- this.on_touch_move.forEach(function (value, key) {
- value.emit([_this3.comp_btn]);
- });
- var delta = touch.getDelta();
- this.delta.x += delta.x;
- this.delta.y += delta.y;
- var distance = this.delta.length();
- if (distance >= 20) this.is_move = true;
- // 滑动超过20像素,算作点击
- };
- _proto.onTouchEnded = function onTouchEnded(touch, param) {
- var _this4 = this;
- touch.preventSwallow = true;
- if (!this.has_began) return;
- if (this.move_began_end && this.is_move) return;
- this.on_touch_end.forEach(function (value, key) {
- value.emit([_this4.comp_btn]);
- });
- this.has_began = false;
- this.is_move = false;
- };
- _proto.onTouchCancelled = function onTouchCancelled(touch, param) {
- touch.preventSwallow = true;
- };
- return ClickPenetrate;
- }(Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "move_began_end", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "on_touch_began", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "on_touch_move", [_dec4], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "on_touch_end", [_dec5], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- })), _class2)) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Container.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "7b367Ns5DhICaZLmc2yobWd", "Container", undefined);
- var Container = exports('Container', /*#__PURE__*/function () {
- function Container() {
- this._itemList = null;
- this._itemList = new Array();
- }
- var _proto = Container.prototype;
- _proto.addCount = function addCount(type, count) {
- return this.addItem({
- type: type,
- count: count
- });
- };
- _proto.useCount = function useCount(type, count) {
- for (var i = 0; i < this._itemList.length; i++) {
- if (this._itemList[i].type == type) {
- if (this._itemList[i].count >= count) {
- this._itemList[i].count -= count;
- return this._itemList[i];
- }
- }
- }
- return null;
- }
- /**
- * 添加物品
- * @param item
- * @returns
- */;
- _proto.addItem = function addItem(item) {
- for (var i = 0; i < this._itemList.length; i++) {
- if (this._itemList[i].type == item.type) {
- this._itemList[i].count += item.count;
- return this._itemList[i];
- }
- }
- this._itemList.push(item);
- return item;
- };
- _proto.getCount = function getCount(type) {
- for (var i = 0; i < this._itemList.length; i++) {
- if (this._itemList[i].type == type) {
- return this._itemList[i].count;
- }
- }
- return 0;
- };
- /**
- * 序列化(数据库存储)
- */
- _proto.serialize = function serialize() {
- var list = [];
- for (var i = 0; i < this._itemList.length; i++) {
- var item = this._itemList[i];
- list.push({
- type: item.type,
- count: item.count
- });
- }
- var data = {
- "list": list
- };
- return data;
- }
- /**
- * 反序列化(数据库读取)
- * @param data
- */;
- _proto.unserialize = function unserialize(data) {
- if (!data) return;
- var list = data.list;
- this._itemList = [];
- for (var i = 0; i < list.length; i++) {
- this._itemList.push({
- type: list[i].type,
- count: list[i].count
- });
- }
- };
- _createClass(Container, [{
- key: "itemList",
- get: function get() {
- return this._itemList;
- },
- set: function set(arr) {
- this._itemList = arr;
- }
- }]);
- return Container;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/DataTimeUtil.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "6aa3eXS6PhBSro7Xyyel0Vs", "DataTimeUtil", undefined);
- var DataTimeUtil = exports('default', /*#__PURE__*/function () {
- function DataTimeUtil() {}
- /**
- * 当前时间戳(毫秒)
- * @returns
- */
- DataTimeUtil.currentTimeMillis = function currentTimeMillis() {
- return new Date().getTime() + this.offset;
- }
- /**
- * 当前时间戳(秒)
- * @returns
- */;
- DataTimeUtil.currentTimeSeconds = function currentTimeSeconds() {
- return Math.floor((new Date().getTime() + this.offset) / 1000);
- }
- /**当前服务器日期*/;
- DataTimeUtil.currentDate = function currentDate() {
- return new Date(this.currentTimeMillis());
- }
- /**将毫秒时间戳转到当天0点时的毫秒时间戳*/;
- DataTimeUtil.timestampToStartOfDay = function timestampToStartOfDay(timestamp) {
- var date = new Date(timestamp); // 将时间戳转换为日期对象
- date.setHours(0, 0, 0, 0); // 将时、分、秒、毫秒部分设置为0
- return date.getTime(); // 将日期转换回时间戳
- }
- /**将秒时间戳转到当天0点时的秒时间戳*/;
- DataTimeUtil.timestampSecondsToStartOfDay = function timestampSecondsToStartOfDay(timestamp) {
- var date = new Date(timestamp * 1000); // 将时间戳转换为日期对象
- date.setHours(0, 0, 0, 0); // 将时、分、秒、毫秒部分设置为0
- return Math.floor(date.getTime() / 1000); // 将日期转换回时间戳
- }
- /**获取服务器到明天0点时长 */;
- DataTimeUtil.longToTomorrow = function longToTomorrow() {
- // 获取当前时间
- var now = this.currentDate();
- // 获取明天的日期
- var tomorrow = new Date(now);
- tomorrow.setDate(now.getDate() + 1);
- tomorrow.setHours(0, 0, 0, 0);
- // 计算时间差
- return tomorrow.getTime() - now.getTime();
- }
- /**当前服务器月份*/;
- DataTimeUtil.currentMonth = function currentMonth() {
- return this.currentDate().getMonth() + 1; // 月份从0开始,所以需要加1
- }
- /**当前服务器日期月有多少天 */;
- DataTimeUtil.daysInCurrentMonth = function daysInCurrentMonth() {
- var currentYear = this.currentDate().getFullYear();
- var daysInCurrentMonth = new Date(currentYear, this.currentMonth(), 0).getDate();
- return daysInCurrentMonth;
- };
- DataTimeUtil.timeMillisToDate = function timeMillisToDate(ms) {
- return new Date(ms);
- };
- DataTimeUtil.stringToStamp = function stringToStamp(dateString) {
- var timestamp = Date.parse(dateString) - new Date().getTimezoneOffset() * 60 * 1000;
- return timestamp;
- };
- DataTimeUtil.stringToDate = function stringToDate(dateString) {
- return new Date(dateString);
- };
- DataTimeUtil.dateToString = function dateToString(date) {
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- var day = date.getDate();
- var hours = date.getHours();
- var minutes = date.getMinutes();
- var seconds = date.getSeconds();
- // 自定义格式化日期和时间
- var formattedDateTime = year + "-" + month.toString().padStart(2, '0') + "-" + day.toString().padStart(2, '0') + " " + hours.toString().padStart(2, '0') + ":" + minutes.toString().padStart(2, '0') + ":" + seconds.toString().padStart(2, '0');
- return formattedDateTime;
- }
- /**本周一0点的时间戳*/;
- DataTimeUtil.mondayTimestamp = function mondayTimestamp() {
- var currentDate = this.currentDate();
- // 获取当前日期的星期几(星期天为0,星期一为1,以此类推)
- var currentDayOfWeek = currentDate.getDay();
- // 计算当前日期距离周一的天数差值
- var daysUntilMonday = currentDayOfWeek === 0 ? 6 : currentDayOfWeek - 1;
- return currentDate.getTime() - daysUntilMonday * 24 * 60 * 60 * 1000;
- }
- /*private _day_s = 864e5;
- private _diff:number=0;
- private updateServerTime(s:number):void{ this._diff = s - (new Date).getTime()}
- public now():number{return this.getTime()}
- public getTime():number { return (new Date).getTime() + this._diff;}
- public getDayStartTime(s:number):number {return new Date(s).setHours(0, 0, 0, 0)}
- public getDayEndTime(e:number):number { return new Date(e).setHours(23, 59, 59, 999)}
- public getWeekEndTime (e:number):number {
- var t = new Date(e).getDay();
- return this.getDayEndTime(e) + (0 === t ? 0 : (7 - t) * this._day_s)
- }
- public getMonthEndTime(e:number):number {
- var t = new Date(e);
- return 11 === t.getMonth() ? t.setFullYear(t.getFullYear() + 1, 0, 0) : t.setMonth(t.getMonth() + 1, 0), t.setHours(23, 59, 59, 999)
- }
- public getDiffDayNum (e:number, t:number) {
- var r = this.getDayStartTime(e),o = this.getDayStartTime(t);
- return Math.ceil(Math.abs(r - o) / this._day_s)
- }*/
- /**获取时间戳*/;
- DataTimeUtil.getTickCount = function getTickCount() {
- if (window && window.performance) {
- return window.performance.now();
- }
- return new Date().getTime();
- }
- //-----------------------------------------------------------------------------------------------------------------------------
- /**
- * 根据秒数格式化字符串
- * @param second 秒数
- * @param type 1:00:00:00 2:yyyy-mm-dd h:m:s 3:00:00(分:秒) 4:xx天前,xx小时前,xx分钟前 6:00:00(时:分)
- * @return
- *
- */;
- DataTimeUtil.getFormatBySecond = function getFormatBySecond(second, type) {
- if (type === void 0) {
- type = 1;
- }
- var str = "";
- switch (type) {
- case 1:
- str = this.getFormatBySecond1(second);
- break;
- case 2:
- str = this.getFormatBySecond2(second);
- break;
- case 3:
- str = this.getFormatBySecond3(second);
- break;
- case 4:
- str = this.getFormatBySecond4(second);
- break;
- case 5:
- str = this.getFormatBySecond5(second);
- break;
- case 6:
- str = this.getFormatBySecond6(second);
- break;
- }
- return str;
- }
- //1: 00:00:00
- ;
- DataTimeUtil.getFormatBySecond1 = function getFormatBySecond1(t) {
- if (t === void 0) {
- t = 0;
- }
- var hourst = Math.floor(t / 3600);
- var hours;
- if (hourst == 0) {
- hours = "00";
- } else {
- if (hourst < 10) hours = "0" + hourst;else hours = "" + hourst;
- }
- var minst = Math.floor((t - hourst * 3600) / 60);
- var secondt = Math.floor((t - hourst * 3600) % 60);
- var mins;
- var sens;
- if (minst == 0) {
- mins = "00";
- } else if (minst < 10) {
- mins = "0" + minst;
- } else {
- mins = "" + minst;
- }
- if (secondt == 0) {
- sens = "00";
- } else if (secondt < 10) {
- sens = "0" + secondt;
- } else {
- sens = "" + secondt;
- }
- return hours + ":" + mins + ":" + sens;
- }
- //3:00:00(分:秒)
- ;
- DataTimeUtil.getFormatBySecond3 = function getFormatBySecond3(t) {
- if (t === void 0) {
- t = 0;
- }
- var hourst = Math.floor(t / 3600);
- var minst = Math.floor((t - hourst * 3600) / 60);
- var secondt = Math.floor((t - hourst * 3600) % 60);
- var mins;
- var sens;
- if (minst == 0) {
- mins = "00";
- } else if (minst < 10) {
- mins = "0" + minst;
- } else {
- mins = "" + minst;
- }
- if (secondt == 0) {
- sens = "00";
- } else if (secondt < 10) {
- sens = "0" + secondt;
- } else {
- sens = "" + secondt;
- }
- return mins + ":" + sens;
- }
- //2:yyyy-mm-dd h:m:s
- ;
- DataTimeUtil.getFormatBySecond2 = function getFormatBySecond2(time) {
- var date = new Date(time * 1000);
- var year = date.getFullYear();
- var month = date.getMonth() + 1; //返回的月份从0-11;
- var day = date.getDate();
- var hours = date.getHours();
- var minute = date.getMinutes();
- var second = date.getSeconds();
- return year + "-" + month + "-" + day + " " + hours + ":" + minute + ":" + second;
- }
- //4:xx天前,xx小时前,xx分钟前
- ;
- DataTimeUtil.getFormatBySecond4 = function getFormatBySecond4(time) {
- var t = Math.floor(time / 3600);
- if (t > 0) {
- if (t > 24) {
- return Math.floor(t / 24) + "天前";
- } else {
- return t + "小时前";
- }
- } else {
- return Math.floor(time / 60) + "分钟前";
- }
- };
- DataTimeUtil.getFormatBySecond5 = function getFormatBySecond5(time) {
- //每个时间单位所对应的秒数
- var oneDay = 3600 * 24;
- var oneHourst = 3600;
- var oneMinst = 60;
- var days = Math.floor(time / oneDay);
- var hourst = Math.floor(time % oneDay / oneHourst);
- var minst = Math.floor((time - hourst * oneHourst) / oneMinst); //Math.floor(time % oneDay % oneHourst / oneMinst);
- var secondt = Math.floor((time - hourst * oneHourst) % oneMinst); //time;
- var dayss = "";
- var hourss = "";
- var minss = "";
- var secss = "";
- if (time > 0) {
- //天
- if (days == 0) {
- dayss = "";
- //小时
- if (hourst == 0) {
- hourss = "";
- //分
- if (minst == 0) {
- minss = "";
- if (secondt == 0) {
- secss = "";
- } else if (secondt < 10) {
- secss = "0" + secondt + "秒";
- } else {
- secss = "" + secondt + "秒";
- }
- return secss;
- } else {
- minss = "" + minst + "分";
- if (secondt == 0) {
- secss = "";
- } else if (secondt < 10) {
- secss = "0" + secondt + "秒";
- } else {
- secss = "" + secondt + "秒";
- }
- }
- return minss + secss;
- } else {
- hourss = hourst + "小时";
- if (minst == 0) {
- minss = "";
- if (secondt == 0) {
- secss = "";
- } else if (secondt < 10) {
- secss = "0" + secondt + "秒";
- } else {
- secss = "" + secondt + "秒";
- }
- return secss;
- } else if (minst < 10) {
- minss = "0" + minst + "分";
- } else {
- minss = "" + minst + "分";
- }
- return hourss + minss;
- }
- } else {
- dayss = days + "天";
- if (hourst == 0) {
- hourss = "";
- } else {
- if (hourst < 10) hourss = "0" + hourst + "小时";else hourss = "" + hourst + "小时";
- }
- return dayss + hourss;
- }
- }
- return "";
- }
- //6:00:00(时:分)
- ;
- DataTimeUtil.getFormatBySecond6 = function getFormatBySecond6(t) {
- if (t === void 0) {
- t = 0;
- }
- var hourst = Math.floor(t / 3600);
- var minst = Math.floor((t - hourst * 3600) / 60);
- var houers;
- var mins;
- if (hourst == 0) {
- houers = "00";
- } else if (hourst < 10) {
- houers = "0" + hourst;
- } else {
- houers = "" + hourst;
- }
- if (minst == 0) {
- mins = "00";
- } else if (minst < 10) {
- mins = "0" + minst;
- } else {
- mins = "" + minst;
- }
- return houers + ":" + mins;
- }
- /**
- * 获取当前是周几
- * ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
- */;
- DataTimeUtil.getDay = function getDay(timestamp) {
- var date = new Date(timestamp);
- return date.getDay();
- }
- /**
- * 判定两个时间是否是同一天
- */;
- DataTimeUtil.isSameDate = function isSameDate(timestamp1, timestamp2) {
- var date1 = new Date(timestamp1);
- var date2 = new Date(timestamp2);
- return date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate();
- }
- /**
- * 日期格式化
- */;
- DataTimeUtil.format = function format(d, fmt) {
- if (fmt === void 0) {
- fmt = "yyyy-MM-dd hh:mm:ss";
- }
- var o = {
- "M+": d.getMonth() + 1,
- //month
- "d+": d.getDate(),
- //day
- "h+": d.getHours(),
- //hour
- "m+": d.getMinutes(),
- //minute
- "s+": d.getSeconds(),
- //second
- "q+": Math.floor((d.getMonth() + 3) / 3),
- //quarter
- "S": d.getMilliseconds() //millisecond
- };
- if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (d.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
- return fmt;
- }
- /**
- * 计算两个时间(秒)相差天数(不满一天算0天)
- */;
- DataTimeUtil.getDayCountSeconds = function getDayCountSeconds(timestamp1, timestamp2) {
- var d_value = Math.abs(timestamp2 - timestamp1);
- return Math.floor(d_value / (24 * 60 * 60));
- }
- /**
- * 计算两个时间相差天数
- */;
- DataTimeUtil.dateDifference = function dateDifference(timestamp1, timestamp2) {
- var d_value = Math.abs(timestamp2 - timestamp1);
- return Math.ceil(d_value / (24 * 60 * 60 * 1000));
- };
- return DataTimeUtil;
- }());
- /**时间偏移*/
- DataTimeUtil.offset = 0;
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Delay.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports('default', get_new_delay);
- cclegacy._RF.push({}, "8e7b9WCurJPu4fjNX9PZbRY", "Delay", undefined);
- var Delay = /*#__PURE__*/function () {
- function Delay() {
- this.delays = [];
- this.paused = false;
- }
- var _proto = Delay.prototype;
- // 创建一个新的延迟
- _proto.start = function start(seconds) {
- var _this = this;
- var duration = seconds;
- return new Promise(function (resolve) {
- _this.delays.push({
- duration: duration,
- elapsed: 0,
- resolve: resolve
- });
- });
- };
- _proto.pause = function pause() {
- this.paused = true;
- };
- _proto.resume = function resume() {
- this.paused = false;
- }
- //更新所有延迟的状态,传入更新时间间隔(秒)
- ;
- _proto.update = function update(deltaTime) {
- if (this.paused) return;
- for (var i = this.delays.length - 1; i >= 0; i--) {
- var delay = this.delays[i];
- delay.elapsed += deltaTime; // 累加已过时间
- if (delay.elapsed >= delay.duration) {
- if (delay.resolve) {
- delay.resolve(); // 解析 Promise
- delay.resolve = null; // 清空引用
- }
- this.delays.splice(i, 1); // 从数组中移除已完成的延迟对象
- }
- }
- }
- //取消所有延迟
- ;
- _proto.cancelAll = function cancelAll() {
- this.delays.forEach(function (delay) {
- delay.resolve = null;
- });
- this.delays = []; //清空所有延迟
- }
- //检查是否有活动的延迟
- ;
- _proto.isActive = function isActive() {
- return this.delays.length > 0;
- };
- return Delay;
- }();
- function get_new_delay() {
- return new Delay();
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/DirectorUtil.ts", ['cc'], function (exports) {
- var cclegacy, director, AnimationManager, sp, TweenSystem, PhysicsSystem2D, PhysicsSystem, Animation;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- director = module.director;
- AnimationManager = module.AnimationManager;
- sp = module.sp;
- TweenSystem = module.TweenSystem;
- PhysicsSystem2D = module.PhysicsSystem2D;
- PhysicsSystem = module.PhysicsSystem;
- Animation = module.Animation;
- }],
- execute: function () {
- cclegacy._RF.push({}, "0dd04xSWM1G07cwb9c87Tja", "DirectorUtil", undefined);
- var DirectorUtil = exports('default', /*#__PURE__*/function () {
- function DirectorUtil() {}
- /**暂停游戏 */
- DirectorUtil.pause = function pause(config_) {
- var _this = this;
- if (this.pause_data.state_b) return;
- // 暂停定时器
- this.pause_data.scheduler_as = director.getScheduler().pauseAllTargets();
- // 暂停当前动画
- {
- var _this$pause_data$anim;
- var anim_system = director.getSystem(AnimationManager.ID);
- (_this$pause_data$anim = this.pause_data.anim_as).splice.apply(_this$pause_data$anim, [0, this.pause_data.anim_as.length].concat(anim_system["_anims"].array));
- this.pause_data.anim_as.forEach(function (v1) {
- v1.pause();
- });
- }
- // 暂停spine动画
- {
- this.pause_data.spine_as = director.getScene().getComponentsInChildren(sp.Skeleton);
- this.pause_data.spine_as.forEach(function (v1) {
- v1.timeScale = 0;
- });
- }
- // 暂停龙骨动画
- // {
- //this.pause_data.dragon_bones_as = director.getScene().getComponentsInChildren(dragonBones.ArmatureDisplay);
- //this.pause_data.dragon_bones_as.forEach(v1 => {v1.timeScale = 0;});
- //}
- // 暂停当前缓动
- this.pause_data.tween_target_as = TweenSystem.instance.ActionManager.pauseAllRunningActions();
- // 暂停物理系统
- {
- if (PhysicsSystem2D && PhysicsSystem2D.instance.enable) {
- this.pause_data.physics_2d_b = PhysicsSystem2D.instance.enable;
- PhysicsSystem2D.instance.enable = false;
- }
- if (PhysicsSystem && PhysicsSystem.instance.enable) {
- this.pause_data.physics_3d_b = PhysicsSystem.instance.enable;
- PhysicsSystem.instance.enable = false;
- }
- }
- // 恢复排除节点
- if (config_) {
- var _config_$recu_exclude;
- var exclude_as = [];
- exclude_as.push.apply(exclude_as, config_.exclude_as);
- (_config_$recu_exclude = config_.recu_exclude_as) == null || _config_$recu_exclude.forEach(function (v1) {
- exclude_as.push.apply(exclude_as, _this.recu_node_list(v1));
- });
- exclude_as.forEach(function (v1) {
- _this.resume_node(v1);
- });
- }
- this.pause_data.state_b = true;
- };
- DirectorUtil.recu_node_list = function recu_node_list(node_, result_as) {
- var _this2 = this;
- if (result_as === void 0) {
- result_as = [];
- }
- if (!node_) {
- return result_as;
- }
- result_as.push(node_);
- node_.children.forEach(function (v1) {
- result_as.push(v1);
- _this2.recu_node_list(v1);
- });
- return result_as;
- }
- /**恢复游戏 */;
- DirectorUtil.resume = function resume() {
- // 恢复定时器
- director.getScheduler().resumeTargets(this.pause_data.scheduler_as);
- // 恢复动画
- this.pause_data.anim_as.forEach(function (v1) {
- if (v1.isPlaying && v1.isPaused) {
- v1.play();
- }
- });
- // 恢复龙骨动画
- //this.pause_data.dragon_bones_as.forEach(v1 => {
- //v1.timeScale = 1;
- //});
- this.pause_data.spine_as.forEach(function (v1) {
- v1.timeScale = 1;
- });
- // 恢复缓动
- TweenSystem.instance.ActionManager.resumeTargets(this.pause_data.tween_target_as);
- // 恢复物理系统
- {
- if (this.pause_data.physics_2d_b) {
- PhysicsSystem2D.instance.enable = this.pause_data.physics_2d_b;
- }
- if (this.pause_data.physics_3d_b) {
- PhysicsSystem.instance.enable = this.pause_data.physics_3d_b;
- }
- }
- this.pause_data.state_b = false;
- }
- /**暂停节点
- * -物理系统需手动启用/禁用
- */;
- DirectorUtil.pause_node = function pause_node(args1_) {
- var node_as;
- if (Array.isArray(args1_)) {
- node_as = args1_;
- } else {
- node_as = [args1_];
- }
- node_as.forEach(function (v1) {
- var _v1$getComponent;
- // 暂停定时器
- director.getScheduler().pauseTarget(v1);
- // 暂停动画
- (_v1$getComponent = v1.getComponent(Animation)) == null || _v1$getComponent.pause();
- //暂停spine动画
- if (v1.getComponent(sp.Skeleton)) {
- v1.getComponent(sp.Skeleton).timeScale = 0;
- }
- // 暂停龙骨
- //if (v1.getComponent(dragonBones.ArmatureDisplay)) {
- //v1.getComponent(dragonBones.ArmatureDisplay).timeScale = 0;
- //}
- // 暂停缓动
- TweenSystem.instance.ActionManager.pauseTarget(v1);
- });
- }
- /**恢复节点 */;
- DirectorUtil.resume_node = function resume_node(args1_) {
- var node_as;
- if (Array.isArray(args1_)) {
- node_as = args1_;
- } else {
- node_as = [args1_];
- }
- node_as.forEach(function (v1) {
- var _v1$getComponent2;
- // 恢复定时器
- director.getScheduler().resumeTarget(v1);
- // 恢复动画
- (_v1$getComponent2 = v1.getComponent(Animation)) == null || _v1$getComponent2.resume();
- //恢复spine动画
- if (v1.getComponent(sp.Skeleton)) {
- v1.getComponent(sp.Skeleton).timeScale = 1;
- }
- //恢复龙骨
- //if (v1.getComponent(dragonBones.ArmatureDisplay)) {
- //v1.getComponent(dragonBones.ArmatureDisplay).timeScale = 1;
- //}
- // 恢复缓动
- TweenSystem.instance.ActionManager.resumeTarget(v1);
- });
- }
- //
- ;
- return DirectorUtil;
- }());
- //没有用到龙骨 dragon_bones_as:dragonBones.ArmatureDisplay[]
- DirectorUtil.pause_data = {
- /**暂停状态 */
- state_b: false,
- /**2d物理系统状态 */
- physics_2d_b: false,
- /**3d物理系统状态 */
- physics_3d_b: false,
- /**定时器对象列表 */
- scheduler_as: [],
- /**动画列表 */
- anim_as: [],
- /**缓动对象列表 */
- tween_target_as: [],
- /**龙骨组件列表 */
- //dragon_bones_as:[],
- spine_as: []
- };
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/FMS.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports({
- FMSRegister: FMSRegister,
- default: get_new_fms
- });
- cclegacy._RF.push({}, "bbc25Bst09Pm7REKGq+Wn2J", "FMS", undefined);
- /**注册一个继承IFMS的状态类型 */
- function FMSRegister(name) {
- return function (target) {
- var instance = new target();
- instance.type = name;
- FMS.IFMS.set(name, instance);
- };
- }
- /**状态接口*/
- /**全局状态机,游戏流程 (私有有行为机更灵活)*/
- var FMS = /*#__PURE__*/function () {
- function FMS() {
- this._current = void 0;
- }
- var _proto = FMS.prototype;
- /**初始1个状态*/
- _proto.Init = function Init(type) {
- this.Change(type);
- }
- /**切换状态*/;
- _proto.Change = function Change(type) {
- if (this._current) this._current.onExit();
- this._current = FMS.IFMS.get(type);
- if (this._current) this._current.onEntry();
- };
- _createClass(FMS, [{
- key: "Current",
- get: /**当前状态*/
- function get() {
- return this._current;
- }
- }, {
- key: "CurrentTaype",
- get: function get() {
- return this._current ? null : this._current.type;
- }
- }]);
- return FMS;
- }();
- /**例子:
- @FMSRegister("Init")
- export class FMSInit implements IFMS{
- type: string;
- onExit: () => void;
- onEntry():void{
- console.log(this.type,"---------------------");
- }
- }
- */
- FMS.IFMS = new Map();
- function get_new_fms() {
- return new FMS();
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Game.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './Delay.ts', './FMS.ts', './TimeJobCenter.ts', './Random.ts', './PrefabPool.ts', './DirectorUtil.ts'], function (exports) {
- var _inheritsLoose, _createClass, cclegacy, Component, get_new_delay, get_new_fms, get_new_job, get_new_random, get_new_prefab_pool, DirectorUtil;
- return {
- setters: [function (module) {
- _inheritsLoose = module.inheritsLoose;
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- Component = module.Component;
- }, function (module) {
- get_new_delay = module.default;
- }, function (module) {
- get_new_fms = module.default;
- }, function (module) {
- get_new_job = module.default;
- }, function (module) {
- get_new_random = module.default;
- }, function (module) {
- get_new_prefab_pool = module.default;
- }, function (module) {
- DirectorUtil = module.default;
- }],
- execute: function () {
- cclegacy._RF.push({}, "c8af7nfrdRHqaACOmm328nQ", "Game", undefined);
- /**
- * 游戏模块
- *
- const { ccclass, property } = _decorator;
- @ccclass('GameStar')
- export class GameStar extends Game<GameStar> {
- public cc:number=99;
- public tcc():void{
- console.log("goaodfjadsofjosadjfo"+this.cc);
- }
- onLoad(): void {
- super.onLoad();
- }
- update(deltaTime: number) {
- super.update(deltaTime);
- }
- async start() {
- console.log("111111111111111111111111111")
- await this.delay.start(3);
- console.log("3333333333333333333333333")
- GameStar.getInst().tcc();
- }
- }
- */
- var Game = exports('Game', /*#__PURE__*/function (_Component) {
- _inheritsLoose(Game, _Component);
- function Game() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- /**游戏流程状态*/
- _this.FMS = get_new_fms();
- /**时间任务管理 暂停后不运行*/
- _this.job = get_new_job();
- /**延时管理*/
- _this.delay = get_new_delay();
- /**可设置种子的随机数*/
- _this.ranodm = get_new_random(new Date().getTime());
- /**预制体对象池*/
- _this.prefabPool = get_new_prefab_pool();
- _this._paused = false;
- return _this;
- }
- Game.getInst = function getInst() {
- var _class = this;
- return _class.instance;
- };
- var _proto = Game.prototype;
- _proto.onLoad = function onLoad() {
- Game.instance = this;
- };
- //
- _proto.pause = function pause() {
- this._paused = true;
- DirectorUtil.pause();
- }
- //
- ;
- _proto.resume = function resume() {
- this._paused = false;
- DirectorUtil.resume();
- };
- _proto.update = function update(deltaTime) {
- this.delay.update(deltaTime);
- if (this._paused) return;
- this.job.Run(deltaTime);
- };
- _createClass(Game, [{
- key: "is_paused",
- get: function get() {
- return this._paused;
- }
- }]);
- return Game;
- }(Component));
- Game.instance = void 0;
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/GameData.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './ch.ts', './PeriodData.ts'], function (exports) {
- var _createClass, _asyncToGenerator, _regeneratorRuntime, cclegacy, ch, PeriodData, PeriodDataUpdate;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- _asyncToGenerator = module.asyncToGenerator;
- _regeneratorRuntime = module.regeneratorRuntime;
- }, function (module) {
- cclegacy = module.cclegacy;
- }, function (module) {
- ch = module.ch;
- }, function (module) {
- PeriodData = module.default;
- PeriodDataUpdate = module.PeriodDataUpdate;
- }],
- execute: function () {
- cclegacy._RF.push({}, "c88bd5RDxxIJ7YUSwv6V1cm", "GameData", undefined);
- /**游戏数据
- * 有额外自定义数据可以继承此类
- */
- var GameData = exports('default', /*#__PURE__*/function () {
- function GameData(gid, uid, name, limt, day_limt, week_limt, month_limt) {
- this._key = void 0;
- this._uid = void 0;
- this._gid = void 0;
- this._save_time = void 0;
- this._ver = void 0;
- this._data = void 0;
- this._day_data = void 0;
- this._week_data = void 0;
- this._month_data = void 0;
- //
- this._dirty = false;
- this._key = name;
- this._gid = gid;
- this._uid = uid;
- this._data = new PeriodData(PeriodDataUpdate.none, limt);
- this._day_data = new PeriodData(PeriodDataUpdate.day, day_limt);
- this._week_data = new PeriodData(PeriodDataUpdate.week, week_limt);
- this._month_data = new PeriodData(PeriodDataUpdate.month, month_limt);
- }
- //
- var _proto = GameData.prototype;
- _proto.checkNewDay = function checkNewDay() {
- var _this$_day_data, _this$_week_data, _this$_month_data;
- var now = ch.date.now();
- (_this$_day_data = this._day_data) == null || _this$_day_data.check(now);
- (_this$_week_data = this._week_data) == null || _this$_week_data.check(now);
- (_this$_month_data = this._month_data) == null || _this$_month_data.check(now);
- }
- //
- ;
- _proto.compareVersion = function compareVersion(version1, version2) {
- // 移除前面的 'v' 字符
- var v1 = version1.replace(/^V/, '');
- var v2 = version2.replace(/^V/, '');
- // 分割版本号
- var parts1 = v1.split('.').map(Number); // 将版本号分割并转为数字
- var parts2 = v2.split('.').map(Number);
- // 比较每一部分
- for (var i = 0; i < Math.max(parts1.length, parts2.length); i++) {
- var num1 = parts1[i] || 0; // 如果没有该部分,默认为 0
- var num2 = parts2[i] || 0;
- if (num1 < num2) {
- return -1; // version1 < version2
- }
- if (num1 > num2) {
- return 1; // version1 > version2
- }
- }
- return 0; // 两个版本号相等
- }
- //
- ;
- _proto.loadGameDataWithRetry = /*#__PURE__*/
- function () {
- var _loadGameDataWithRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(maxRetries, delayMs) {
- var attempt, _data;
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) switch (_context.prev = _context.next) {
- case 0:
- if (maxRetries === void 0) {
- maxRetries = 3;
- }
- if (delayMs === void 0) {
- delayMs = 1000;
- }
- attempt = 0;
- case 3:
- if (!(attempt < maxRetries)) {
- _context.next = 16;
- break;
- }
- _context.next = 6;
- return this.load_data();
- case 6:
- _data = _context.sent;
- if (!(_data != null)) {
- _context.next = 11;
- break;
- }
- return _context.abrupt("return", _data != null ? _data : null);
- case 11:
- attempt++;
- _context.next = 14;
- return new Promise(function (resolve) {
- return setTimeout(resolve, delayMs);
- });
- case 14:
- _context.next = 3;
- break;
- case 16:
- return _context.abrupt("return", null);
- case 17:
- case "end":
- return _context.stop();
- }
- }, _callee, this);
- }));
- function loadGameDataWithRetry(_x, _x2) {
- return _loadGameDataWithRetry.apply(this, arguments);
- }
- return loadGameDataWithRetry;
- }() //
- ;
- _proto.saveGameDataWithRetry = /*#__PURE__*/
- function () {
- var _saveGameDataWithRetry = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(save_data, maxRetries, delayMs) {
- var attempt, ret;
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
- while (1) switch (_context2.prev = _context2.next) {
- case 0:
- if (maxRetries === void 0) {
- maxRetries = 3;
- }
- if (delayMs === void 0) {
- delayMs = 1000;
- }
- attempt = 0;
- case 3:
- if (!(attempt < maxRetries)) {
- _context2.next = 16;
- break;
- }
- _context2.next = 6;
- return this.save_data(save_data);
- case 6:
- ret = _context2.sent;
- if (!ret) {
- _context2.next = 11;
- break;
- }
- return _context2.abrupt("return", true);
- case 11:
- attempt++;
- _context2.next = 14;
- return new Promise(function (resolve) {
- return setTimeout(resolve, delayMs);
- });
- case 14:
- _context2.next = 3;
- break;
- case 16:
- return _context2.abrupt("return", false);
- case 17:
- case "end":
- return _context2.stop();
- }
- }, _callee2, this);
- }));
- function saveGameDataWithRetry(_x3, _x4, _x5) {
- return _saveGameDataWithRetry.apply(this, arguments);
- }
- return saveGameDataWithRetry;
- }() /**加载数据*/;
- _proto.load = /*#__PURE__*/
- function () {
- var _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(ver) {
- var load_data, remote_data;
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
- while (1) switch (_context3.prev = _context3.next) {
- case 0:
- this.on_load(0);
- load_data = ch.storage.getObject(this._key, this._gid);
- if (load_data) {
- if (ch.sdk.get_inited() && load_data.uid != this._uid) load_data = null;
- }
- //
- if (load_data) {
- _context3.next = 8;
- break;
- }
- _context3.next = 6;
- return this.loadGameDataWithRetry();
- case 6:
- remote_data = _context3.sent;
- load_data = remote_data;
- case 8:
- // } else if (remote_data && this.on_check(load_data, remote_data)) {
- // load_data = remote_data;
- // }
- //
- if (!load_data) {
- this.on_init();
- console.log("无数据所以初始化");
- } else {
- this.unserialize(load_data);
- console.log("有数据初始化");
- }
- this.checkVer(ver);
- this.checkNewDay();
- this.on_load(1);
- case 12:
- case "end":
- return _context3.stop();
- }
- }, _callee3, this);
- }));
- function load(_x6) {
- return _load.apply(this, arguments);
- }
- return load;
- }() /**远程调用保存,如果不是强制远程保存,必并先设置脏数据*/;
- _proto.save = /*#__PURE__*/
- function () {
- var _save = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(force) {
- var ret;
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
- while (1) switch (_context4.prev = _context4.next) {
- case 0:
- if (force === void 0) {
- force = false;
- }
- this.on_save(0);
- if (!force) {
- _context4.next = 6;
- break;
- }
- this.setDirty();
- _context4.next = 9;
- break;
- case 6:
- if (this._dirty) {
- _context4.next = 9;
- break;
- }
- this.on_save(1);
- return _context4.abrupt("return", false);
- case 9:
- _context4.next = 11;
- return this.saveGameDataWithRetry(this.serialize());
- case 11:
- ret = _context4.sent;
- this.on_save(1);
- if (ret) this._dirty = false;
- return _context4.abrupt("return", ret);
- case 15:
- case "end":
- return _context4.stop();
- }
- }, _callee4, this);
- }));
- function save(_x7) {
- return _save.apply(this, arguments);
- }
- return save;
- }() /**设置脏数据后保存到本地*/;
- _proto.setDirty = function setDirty() {
- this._dirty = true;
- ch.storage.set(this._key, this.serialize(), this._gid);
- };
- _proto.checkVer = function checkVer(new_v) {
- if (!new_v) return;
- if (!this._ver) {
- this.on_ver(true, this._ver, new_v);
- }
- var k = this.compareVersion(this._ver, new_v);
- this.on_ver(k < 0, this._ver, new_v);
- this._ver = new_v;
- }
- /**
- * 序列化(数据库存储)
- */;
- _proto.serialize = function serialize() {
- var save_data = {};
- if (this._data) save_data.data = this._data.serialize();
- if (this._day_data) save_data.day_data = this._day_data.serialize();
- if (this._week_data) save_data.week_data = this._week_data.serialize();
- if (this._month_data) save_data.month_data = this._month_data.serialize();
- save_data.uid = this._uid;
- save_data.gid = this._gid;
- this._save_time = ch.date.now();
- save_data.save_time = this._save_time;
- if (this._ver) save_data.ver = this._ver;
- this.on_serialize(save_data);
- return save_data;
- }
- /**
- * 反序列化
- */;
- _proto.unserialize = function unserialize(load_data) {
- var _this$_data, _this$_day_data2, _this$_week_data2, _this$_month_data2, _load_data$uid, _load_data$gid, _ref;
- if (!load_data) return;
- (_this$_data = this._data) == null || _this$_data.unserialize(load_data.data);
- (_this$_day_data2 = this._day_data) == null || _this$_day_data2.unserialize(load_data.day_data);
- (_this$_week_data2 = this._week_data) == null || _this$_week_data2.unserialize(load_data.week_data);
- (_this$_month_data2 = this._month_data) == null || _this$_month_data2.unserialize(load_data.month_data);
- this._uid = (_load_data$uid = load_data.uid) != null ? _load_data$uid : this._uid;
- this._gid = (_load_data$gid = load_data.gid) != null ? _load_data$gid : this._gid;
- this._save_time = (_ref = load_data.save_time) != null ? _ref : ch.date.now();
- if (load_data.ver) this._ver = load_data.ver;
- this.on_unserialize(load_data);
- }
- /**重写此方法初始自定义数据*/;
- _proto.on_init = function on_init() {}
- /**重写此方法检测是否使用远程数据*/;
- _proto.on_check = function on_check(local, remote) {
- return true;
- }
- /**重写 版本检测数据处理*/;
- _proto.on_ver = function on_ver(is_new, old_v, new_v) {}
- /**重写序列化加入自定义的数据*/;
- _proto.on_serialize = function on_serialize(data) {}
- /**重写反序列化*/;
- _proto.on_unserialize = function on_unserialize(data) {}
- /**保存数据(0开始 1结束)*/;
- _proto.on_save = function on_save(step) {}
- /**加载数据(0开始 1结束)*/;
- _proto.on_load = function on_load(step) {
- if (step == 0) {
- console.log("开始加载数据");
- } else if (step == 1) {
- console.log("加载数据结束");
- }
- }
- /**重写成其它加载方式*/;
- _proto.load_data = /*#__PURE__*/
- function () {
- var _load_data = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
- var ret;
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
- while (1) switch (_context5.prev = _context5.next) {
- case 0:
- _context5.next = 2;
- return ch.sdk.loadGameData(this._key);
- case 2:
- ret = _context5.sent;
- if (!(ret.code === 0)) {
- _context5.next = 7;
- break;
- }
- return _context5.abrupt("return", ret.data);
- case 7:
- ch.log.warn("\u5C1D\u8BD5\u52A0\u8F7D\u6570\u636E\u5931\u8D25\uFF0C\u9519\u8BEF\u4EE3\u7801: " + ret.code + " " + ret.err);
- case 8:
- return _context5.abrupt("return", null);
- case 9:
- case "end":
- return _context5.stop();
- }
- }, _callee5, this);
- }));
- function load_data() {
- return _load_data.apply(this, arguments);
- }
- return load_data;
- }() /**重写成其它保存方式*/;
- _proto.save_data = /*#__PURE__*/
- function () {
- var _save_data2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_save_data) {
- var ret;
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
- while (1) switch (_context6.prev = _context6.next) {
- case 0:
- _context6.next = 2;
- return ch.sdk.saveGameData(this._key, _save_data);
- case 2:
- ret = _context6.sent;
- if (!(ret.code == 0)) {
- _context6.next = 7;
- break;
- }
- return _context6.abrupt("return", true);
- case 7:
- ch.log.warn("\u5C1D\u8BD5\u4FDD\u5B58\u6570\u636E\u5931\u8D25\uFF0C\u9519\u8BEF\u4EE3\u7801: " + ret.code + " " + ret.err);
- return _context6.abrupt("return", false);
- case 9:
- case "end":
- return _context6.stop();
- }
- }, _callee6, this);
- }));
- function save_data(_x8) {
- return _save_data2.apply(this, arguments);
- }
- return save_data;
- }();
- _createClass(GameData, [{
- key: "data",
- get: function get() {
- return this._data;
- }
- }, {
- key: "day_data",
- get: function get() {
- return this._day_data;
- }
- }, {
- key: "week_data",
- get: function get() {
- return this._week_data;
- }
- }, {
- key: "month_data",
- get: function get() {
- return this._month_data;
- }
- }, {
- key: "uid",
- get: function get() {
- return this._uid;
- }
- }]);
- return GameData;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/HeadIcon.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './ch.ts'], function (exports) {
- var _asyncToGenerator, _regeneratorRuntime, cclegacy, ch;
- return {
- setters: [function (module) {
- _asyncToGenerator = module.asyncToGenerator;
- _regeneratorRuntime = module.regeneratorRuntime;
- }, function (module) {
- cclegacy = module.cclegacy;
- }, function (module) {
- ch = module.ch;
- }],
- execute: function () {
- exports('default', get_new_head_icon);
- cclegacy._RF.push({}, "e8ef1bG3LhBg7/PvloyUrDD", "HeadIcon", undefined);
- var HeadIcon = /*#__PURE__*/function () {
- function HeadIcon() {
- this._map = new Map();
- this._map_uid = new Map();
- }
- var _proto = HeadIcon.prototype;
- _proto.showIcon = /*#__PURE__*/function () {
- var _showIcon = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(uid, remoteUrl, sp, def) {
- var spr, map, map_uid, spriteFrame;
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) switch (_context.prev = _context.next) {
- case 0:
- if (sp === void 0) {
- sp = null;
- }
- if (!(!remoteUrl || remoteUrl == "image")) {
- _context.next = 4;
- break;
- }
- if (sp) sp.spriteFrame = def;
- return _context.abrupt("return");
- case 4:
- if (!this._map.has(uid)) {
- _context.next = 10;
- break;
- }
- spr = this._map.get(uid);
- if (sp) sp.spriteFrame = spr;
- return _context.abrupt("return", spr);
- case 10:
- map = this._map;
- map_uid = this._map_uid;
- if (sp && sp.isValid) map_uid.set(sp, uid);
- _context.next = 15;
- return ch.util.loadImage(remoteUrl);
- case 15:
- spriteFrame = _context.sent;
- if (sp && sp.isValid) if (map_uid.get(sp) == uid) sp.spriteFrame = spriteFrame;
- map.set(uid, spriteFrame);
- return _context.abrupt("return", spriteFrame);
- case 19:
- case "end":
- return _context.stop();
- }
- }, _callee, this);
- }));
- function showIcon(_x, _x2, _x3, _x4) {
- return _showIcon.apply(this, arguments);
- }
- return showIcon;
- }();
- _proto.clean = function clean() {
- this._map.clear();
- this._map_uid.clear();
- };
- return HeadIcon;
- }();
- function get_new_head_icon() {
- return new HeadIcon();
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Instance.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _construct, cclegacy;
- return {
- setters: [function (module) {
- _construct = module.construct;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "f298auxhOZIcJjqKwn1kGP+", "Instance", undefined);
- /**单例
- * 加方法型
- * public static getInstance(): XXX{
- return Instance.get(XXX);
- }
- */
- var Instance = exports('default', /*#__PURE__*/function () {
- function Instance() {}
- Instance.get = function get(clazz) {
- for (var _len = arguments.length, param = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- param[_key - 1] = arguments[_key];
- }
- if (clazz["__Instance__"] == null) {
- clazz["__Instance__"] = _construct(clazz, param);
- }
- return clazz["__Instance__"];
- };
- return Instance;
- }());
- var Singleton = exports('Singleton', /*#__PURE__*/function () {
- /**
- * 获取实例
- */
- Singleton.getInstance = function getInstance() {
- var _class = this;
- if (!_class._instance) {
- _class._instantiateByGetInstance = true;
- _class._instance = new _class();
- _class._instantiateByGetInstance = false;
- }
- return _class._instance;
- }
- /**
- * 构造函数
- * @protected
- */;
- function Singleton() {
- if (!this.constructor._instantiateByGetInstance) {
- throw new Error("Singleton class can't be instantiated more than once.");
- }
- }
- return Singleton;
- }());
- // 实例
- Singleton._instance = void 0;
- // 是否是通过getInstance实例化
- Singleton._instantiateByGetInstance = false;
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Line2DMove.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy, Vec2;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- Vec2 = module.Vec2;
- }],
- execute: function () {
- cclegacy._RF.push({}, "24592yMfD9O6qsVldhDD3Pb", "Line2DMove", undefined);
- //直线移动
- var Line2DMove = exports('Line2DMove', /*#__PURE__*/function () {
- /**
- * @param start_x 起始点
- * @param start_y
- * @param end_x 终点
- * @param end_y
- * @param speed 速度
- * @param addSpeed 加速度
- * 起点终点一致时没有速度将不起作用
- */
- function Line2DMove(start_x, start_y, end_x, end_y, speed, addSpeed) {
- this._s = void 0;
- //起始点
- this._e = void 0;
- //终点
- this._percentSpeed = void 0;
- this._percentAddSpeed = void 0;
- this._percent = void 0;
- //进度
- this._current = void 0;
- this._currentDir = void 0;
- /**
- * 获取进度位置
- * @param t 当前时间进度 0-1
- * @param a 起点
- * @param b 控制点
- * @param c 终点
- */
- this._ab = new Vec2();
- this._s = new Vec2(start_x, start_y);
- this._e = new Vec2(end_x, end_y);
- this._current = new Vec2(start_x, start_y);
- this._currentDir = new Vec2(this._e.x - this._s.x, this._e.y - this._s.y).normalize();
- var dis = new Vec2(end_x, end_y).subtract2f(start_x, start_y).length();
- if (dis <= 0) {
- this._percent = 1;
- this._percentSpeed = 0;
- this._percentAddSpeed = 0;
- } else {
- this._percent = 0;
- this._percentSpeed = speed / dis;
- this._percentAddSpeed = addSpeed / dis;
- }
- }
- var _proto = Line2DMove.prototype;
- /**
- * 向目标运动
- * @param dt 帧时间
- * @param mb 目标点,没有的话为初始定义的点
- * @returns
- */
- _proto.MoveTo = function MoveTo(dt, mb) {
- if (mb === void 0) {
- mb = null;
- }
- if (this._percentSpeed == 0 && this._percentAddSpeed == 0) return this._current;
- this._percentSpeed += this._percentAddSpeed * dt;
- this._percent += this._percentSpeed * dt;
- var nextpos = this.getPos(this._percent, this._s, mb == null ? this._e : mb);
- this._current.x = nextpos.x;
- this._current.y = nextpos.y;
- return this._current;
- };
- _proto.getPos = function getPos(t, a, b) {
- Vec2.lerp(this._ab, a, b, t);
- return this._ab;
- };
- _createClass(Line2DMove, [{
- key: "target_pos_x",
- get: function get() {
- return this._e.x;
- }
- }, {
- key: "target_pos_y",
- get: function get() {
- return this._e.y;
- }
- }, {
- key: "current_dir",
- get: function get() {
- return this._currentDir;
- }
- }, {
- key: "isEnd",
- get: function get() {
- return this._percent >= 1;
- }
- }, {
- key: "percent",
- get: function get() {
- return this._percent;
- }
- }]);
- return Line2DMove;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/List.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './env', './ListItem.ts'], function (exports) {
- var _applyDecoratedDescriptor, _inheritsLoose, _initializerDefineProperty, _assertThisInitialized, _createClass, cclegacy, _decorator, ScrollView, Enum, Node, Prefab, CCFloat, EventHandler, CCBoolean, CCInteger, isValid, UITransform, Layout, instantiate, NodePool, Vec3, Size, Widget, tween, Component, DEV, ListItem;
- return {
- setters: [function (module) {
- _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
- _inheritsLoose = module.inheritsLoose;
- _initializerDefineProperty = module.initializerDefineProperty;
- _assertThisInitialized = module.assertThisInitialized;
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- ScrollView = module.ScrollView;
- Enum = module.Enum;
- Node = module.Node;
- Prefab = module.Prefab;
- CCFloat = module.CCFloat;
- EventHandler = module.EventHandler;
- CCBoolean = module.CCBoolean;
- CCInteger = module.CCInteger;
- isValid = module.isValid;
- UITransform = module.UITransform;
- Layout = module.Layout;
- instantiate = module.instantiate;
- NodePool = module.NodePool;
- Vec3 = module.Vec3;
- Size = module.Size;
- Widget = module.Widget;
- tween = module.tween;
- Component = module.Component;
- }, function (module) {
- DEV = module.DEV;
- }, function (module) {
- ListItem = module.default;
- }],
- execute: function () {
- var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _dec21, _dec22, _dec23, _dec24, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _descriptor13, _descriptor14, _descriptor15, _descriptor16, _descriptor17;
- cclegacy._RF.push({}, "30e50g9bStDgYX3Y3vvH6ye", "List", undefined);
- /******************************************
- * @author kL <klk0@qq.com>
- * @date 2020/12/9
- * @doc 列表组件.
- * @end
- ******************************************/
- var ccclass = _decorator.ccclass,
- property = _decorator.property,
- disallowMultiple = _decorator.disallowMultiple,
- menu = _decorator.menu,
- executionOrder = _decorator.executionOrder,
- requireComponent = _decorator.requireComponent;
- var TemplateType = /*#__PURE__*/function (TemplateType) {
- TemplateType[TemplateType["NODE"] = 1] = "NODE";
- TemplateType[TemplateType["PREFAB"] = 2] = "PREFAB";
- return TemplateType;
- }(TemplateType || {});
- var SlideType = /*#__PURE__*/function (SlideType) {
- SlideType[SlideType["NORMAL"] = 1] = "NORMAL";
- SlideType[SlideType["ADHERING"] = 2] = "ADHERING";
- SlideType[SlideType["PAGE"] = 3] = "PAGE";
- return SlideType;
- }(SlideType || {}); //页面模式,将强制关闭滚动惯性
- var SelectedType = /*#__PURE__*/function (SelectedType) {
- SelectedType[SelectedType["NONE"] = 0] = "NONE";
- SelectedType[SelectedType["SINGLE"] = 1] = "SINGLE";
- SelectedType[SelectedType["MULT"] = 2] = "MULT";
- return SelectedType;
- }(SelectedType || {}); //多选
- var List = exports('default', (_dec = disallowMultiple(), _dec2 = menu('List'), _dec3 = requireComponent(ScrollView), _dec4 = executionOrder(-5000), _dec5 = property({
- type: Enum(TemplateType),
- tooltip: DEV
- }), _dec6 = property({
- type: Node,
- tooltip: DEV,
- visible: function visible() {
- return this.templateType == TemplateType.NODE;
- }
- }), _dec7 = property({
- type: Prefab,
- tooltip: DEV,
- visible: function visible() {
- return this.templateType == TemplateType.PREFAB;
- }
- }), _dec8 = property({}), _dec9 = property({
- type: Enum(SlideType),
- tooltip: DEV
- }), _dec10 = property({
- type: CCFloat,
- range: [0, 1, .1],
- tooltip: DEV,
- slide: true,
- visible: function visible() {
- return this._slideMode == SlideType.PAGE;
- }
- }), _dec11 = property({
- type: EventHandler,
- tooltip: DEV,
- visible: function visible() {
- return this._slideMode == SlideType.PAGE;
- }
- }), _dec12 = property({}), _dec13 = property({
- type: CCBoolean,
- tooltip: DEV
- }), _dec14 = property({
- tooltip: DEV,
- visible: function visible() {
- var val = /*this.virtual &&*/this.slideMode == SlideType.NORMAL;
- if (!val) this.cyclic = false;
- return val;
- }
- }), _dec15 = property({
- tooltip: DEV,
- visible: function visible() {
- return this.virtual;
- }
- }), _dec16 = property({
- tooltip: DEV,
- visible: function visible() {
- var val = this.virtual && !this.lackCenter;
- if (!val) this.lackSlide = false;
- return val;
- }
- }), _dec17 = property({
- type: CCInteger
- }), _dec18 = property({
- type: CCInteger,
- range: [0, 6, 1],
- tooltip: DEV,
- slide: true
- }), _dec19 = property({
- type: CCInteger,
- range: [0, 12, 1],
- tooltip: DEV,
- slide: true
- }), _dec20 = property({
- type: EventHandler,
- tooltip: DEV
- }), _dec21 = property({
- type: Enum(SelectedType),
- tooltip: DEV
- }), _dec22 = property({
- type: EventHandler,
- tooltip: DEV,
- visible: function visible() {
- return this.selectedMode > SelectedType.NONE;
- }
- }), _dec23 = property({
- tooltip: DEV,
- visible: function visible() {
- return this.selectedMode == SelectedType.SINGLE;
- }
- }), _dec24 = property({
- serializable: false
- }), ccclass(_class = _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = (_class2 = /*#__PURE__*/function (_Component) {
- _inheritsLoose(List, _Component);
- function List() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- //模板类型
- _initializerDefineProperty(_this, "templateType", _descriptor, _assertThisInitialized(_this));
- //模板Item(Node)
- _initializerDefineProperty(_this, "tmpNode", _descriptor2, _assertThisInitialized(_this));
- //模板Item(Prefab)
- _initializerDefineProperty(_this, "tmpPrefab", _descriptor3, _assertThisInitialized(_this));
- //滑动模式
- _initializerDefineProperty(_this, "_slideMode", _descriptor4, _assertThisInitialized(_this));
- //翻页作用距离
- _initializerDefineProperty(_this, "pageDistance", _descriptor5, _assertThisInitialized(_this));
- //页面改变事件
- _initializerDefineProperty(_this, "pageChangeEvent", _descriptor6, _assertThisInitialized(_this));
- //是否为虚拟列表(动态列表)
- _initializerDefineProperty(_this, "_virtual", _descriptor7, _assertThisInitialized(_this));
- //是否为循环列表
- _initializerDefineProperty(_this, "cyclic", _descriptor8, _assertThisInitialized(_this));
- //缺省居中
- _initializerDefineProperty(_this, "lackCenter", _descriptor9, _assertThisInitialized(_this));
- //缺省可滑动
- _initializerDefineProperty(_this, "lackSlide", _descriptor10, _assertThisInitialized(_this));
- //刷新频率
- _initializerDefineProperty(_this, "_updateRate", _descriptor11, _assertThisInitialized(_this));
- //分帧渲染(每帧渲染的Item数量(<=0时关闭分帧渲染))
- _initializerDefineProperty(_this, "frameByFrameRenderNum", _descriptor12, _assertThisInitialized(_this));
- //渲染事件(渲染器)
- _initializerDefineProperty(_this, "renderEvent", _descriptor13, _assertThisInitialized(_this));
- //选择模式
- _initializerDefineProperty(_this, "selectedMode", _descriptor14, _assertThisInitialized(_this));
- //触发选择事件
- _initializerDefineProperty(_this, "selectedEvent", _descriptor15, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "repeatEventSingle", _descriptor16, _assertThisInitialized(_this));
- //当前选择id
- _this._selectedId = -1;
- _this._lastSelectedId = void 0;
- _this.multSelected = void 0;
- _this._forceUpdate = false;
- _this._align = void 0;
- _this._horizontalDir = void 0;
- _this._verticalDir = void 0;
- _this._startAxis = void 0;
- _this._alignCalcType = void 0;
- _this.content = void 0;
- _this._contentUt = void 0;
- _this.firstListId = void 0;
- _this.displayItemNum = void 0;
- _this._updateDone = true;
- _this._updateCounter = void 0;
- _this._actualNumItems = void 0;
- _this._cyclicNum = void 0;
- _this._cyclicPos1 = void 0;
- _this._cyclicPos2 = void 0;
- //列表数量
- _initializerDefineProperty(_this, "_numItems", _descriptor17, _assertThisInitialized(_this));
- _this._inited = false;
- _this._scrollView = void 0;
- _this._layout = void 0;
- _this._resizeMode = void 0;
- _this._topGap = void 0;
- _this._rightGap = void 0;
- _this._bottomGap = void 0;
- _this._leftGap = void 0;
- _this._columnGap = void 0;
- _this._lineGap = void 0;
- _this._colLineNum = void 0;
- _this._lastDisplayData = void 0;
- _this.displayData = void 0;
- _this._pool = void 0;
- _this._itemTmp = void 0;
- _this._itemTmpUt = void 0;
- _this._needUpdateWidget = false;
- _this._itemSize = void 0;
- _this._sizeType = void 0;
- _this._customSize = void 0;
- _this.frameCount = void 0;
- _this._aniDelRuning = false;
- _this._aniDelCB = void 0;
- _this._aniDelItem = void 0;
- _this._aniDelBeforePos = void 0;
- _this._aniDelBeforeScale = void 0;
- _this.viewTop = void 0;
- _this.viewRight = void 0;
- _this.viewBottom = void 0;
- _this.viewLeft = void 0;
- _this._doneAfterUpdate = false;
- _this.elasticTop = void 0;
- _this.elasticRight = void 0;
- _this.elasticBottom = void 0;
- _this.elasticLeft = void 0;
- _this.scrollToListId = void 0;
- _this.adhering = false;
- _this._adheringBarrier = false;
- _this.nearestListId = void 0;
- _this.curPageNum = 0;
- _this._beganPos = void 0;
- _this._scrollPos = void 0;
- _this._curScrollIsTouch = void 0;
- //当前滑动是否为手动
- _this._scrollToListId = void 0;
- _this._scrollToEndTime = void 0;
- _this._scrollToSo = void 0;
- _this._lack = void 0;
- _this._allItemSize = void 0;
- _this._allItemSizeNoEdge = void 0;
- _this._scrollItem = void 0;
- //当前控制 ScrollView 滚动的 Item
- _this._thisNodeUt = void 0;
- return _this;
- }
- var _proto = List.prototype;
- //----------------------------------------------------------------------------
- _proto.onLoad = function onLoad() {
- this._init();
- };
- _proto.onDestroy = function onDestroy() {
- var t = this;
- if (isValid(t._itemTmp)) t._itemTmp.destroy();
- if (isValid(t.tmpNode)) t.tmpNode.destroy();
- t._pool && t._pool.clear();
- };
- _proto.onEnable = function onEnable() {
- // if (!EDITOR)
- this._registerEvent();
- this._init();
- // 处理重新显示后,有可能上一次的动画移除还未播放完毕,导致动画卡住的问题
- if (this._aniDelRuning) {
- this._aniDelRuning = false;
- if (this._aniDelItem) {
- if (this._aniDelBeforePos) {
- this._aniDelItem.position = this._aniDelBeforePos;
- delete this._aniDelBeforePos;
- }
- if (this._aniDelBeforeScale) {
- this._aniDelItem.scale = this._aniDelBeforeScale;
- delete this._aniDelBeforeScale;
- }
- delete this._aniDelItem;
- }
- if (this._aniDelCB) {
- this._aniDelCB();
- delete this._aniDelCB;
- }
- }
- };
- _proto.onDisable = function onDisable() {
- // if (!EDITOR)
- this._unregisterEvent();
- }
- //注册事件
- ;
- _proto._registerEvent = function _registerEvent() {
- var t = this;
- t.node.on(Node.EventType.TOUCH_START, t._onTouchStart, t);
- t.node.on('touch-up', t._onTouchUp, t);
- t.node.on(Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t);
- t.node.on('scroll-began', t._onScrollBegan, t);
- t.node.on('scroll-ended', t._onScrollEnded, t);
- t.node.on('scrolling', t._onScrolling, t);
- t.node.on(Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
- }
- //卸载事件
- ;
- _proto._unregisterEvent = function _unregisterEvent() {
- var t = this;
- t.node.off(Node.EventType.TOUCH_START, t._onTouchStart, t);
- t.node.off('touch-up', t._onTouchUp, t);
- t.node.off(Node.EventType.TOUCH_CANCEL, t._onTouchCancelled, t);
- t.node.off('scroll-began', t._onScrollBegan, t);
- t.node.off('scroll-ended', t._onScrollEnded, t);
- t.node.off('scrolling', t._onScrolling, t);
- t.node.off(Node.EventType.SIZE_CHANGED, t._onSizeChanged, t);
- }
- //初始化各种..
- ;
- _proto._init = function _init() {
- var t = this;
- if (t._inited) return;
- t._thisNodeUt = t.node.getComponent(UITransform);
- t._scrollView = t.node.getComponent(ScrollView);
- t.content = t._scrollView.content;
- t._contentUt = t.content.getComponent(UITransform);
- if (!t.content) {
- console.error(t.node.name + "'s ScrollView unset content!");
- return;
- }
- t._layout = t.content.getComponent(Layout);
- t._align = t._layout.type; //排列模式
- t._resizeMode = t._layout.resizeMode; //自适应模式
- t._startAxis = t._layout.startAxis;
- t._topGap = t._layout.paddingTop; //顶边距
- t._rightGap = t._layout.paddingRight; //右边距
- t._bottomGap = t._layout.paddingBottom; //底边距
- t._leftGap = t._layout.paddingLeft; //左边距
- t._columnGap = t._layout.spacingX; //列距
- t._lineGap = t._layout.spacingY; //行距
- t._colLineNum; //列数或行数(非GRID模式则=1,表示单列或单行);
- t._verticalDir = t._layout.verticalDirection; //垂直排列子节点的方向
- t._horizontalDir = t._layout.horizontalDirection; //水平排列子节点的方向
- t.setTemplateItem(instantiate(t.templateType == TemplateType.PREFAB ? t.tmpPrefab : t.tmpNode));
- // 特定的滑动模式处理
- if (t._slideMode == SlideType.ADHERING || t._slideMode == SlideType.PAGE) {
- t._scrollView.inertia = false;
- t._scrollView._onMouseWheel = function () {
- return;
- };
- }
- if (!t.virtual)
- // lackCenter 仅支持 Virtual 模式
- t.lackCenter = false;
- t._lastDisplayData = []; //最后一次刷新的数据
- t.displayData = []; //当前数据
- t._pool = new NodePool(); //这是个池子..
- t._forceUpdate = false; //是否强制更新
- t._updateCounter = 0; //当前分帧渲染帧数
- t._updateDone = true; //分帧渲染是否完成
- t.curPageNum = 0; //当前页数
- if (t.cyclic || 0) {
- t._scrollView._processAutoScrolling = this._processAutoScrolling.bind(t);
- t._scrollView._startBounceBackIfNeeded = function () {
- return false;
- };
- }
- switch (t._align) {
- case Layout.Type.HORIZONTAL:
- {
- switch (t._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- t._alignCalcType = 1;
- break;
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- t._alignCalcType = 2;
- break;
- }
- break;
- }
- case Layout.Type.VERTICAL:
- {
- switch (t._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- t._alignCalcType = 3;
- break;
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- t._alignCalcType = 4;
- break;
- }
- break;
- }
- case Layout.Type.GRID:
- {
- switch (t._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- switch (t._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- t._alignCalcType = 3;
- break;
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- t._alignCalcType = 4;
- break;
- }
- break;
- case Layout.AxisDirection.VERTICAL:
- switch (t._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- t._alignCalcType = 1;
- break;
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- t._alignCalcType = 2;
- break;
- }
- break;
- }
- break;
- }
- }
- // 清空 content
- // t.content.children.forEach((child: Node) => {
- // child.removeFromParent();
- // if (child != t.tmpNode && child.isValid)
- // child.destroy();
- // });
- t.content.removeAllChildren();
- t._inited = true;
- }
- /**
- * 为了实现循环列表,必须覆写cc.ScrollView的某些函数
- * @param {Number} dt
- */;
- _proto._processAutoScrolling = function _processAutoScrolling(dt) {
- // ------------- scroll-view 里定义的一些常量 -------------
- var OUT_OF_BOUNDARY_BREAKING_FACTOR = 0.05;
- var EPSILON = 1e-4;
- var ZERO = new Vec3();
- var quintEaseOut = function quintEaseOut(time) {
- time -= 1;
- return time * time * time * time * time + 1;
- };
- // ------------- scroll-view 里定义的一些常量 -------------
- var sv = this._scrollView;
- var isAutoScrollBrake = sv['_isNecessaryAutoScrollBrake']();
- var brakingFactor = isAutoScrollBrake ? OUT_OF_BOUNDARY_BREAKING_FACTOR : 1;
- sv['_autoScrollAccumulatedTime'] += dt * (1 / brakingFactor);
- var percentage = Math.min(1, sv['_autoScrollAccumulatedTime'] / sv['_autoScrollTotalTime']);
- if (sv['_autoScrollAttenuate']) {
- percentage = quintEaseOut(percentage);
- }
- var clonedAutoScrollTargetDelta = sv['_autoScrollTargetDelta'].clone();
- clonedAutoScrollTargetDelta.multiplyScalar(percentage);
- var clonedAutoScrollStartPosition = sv['_autoScrollStartPosition'].clone();
- clonedAutoScrollStartPosition.add(clonedAutoScrollTargetDelta);
- var reachedEnd = Math.abs(percentage - 1) <= EPSILON;
- var fireEvent = Math.abs(percentage - 1) <= sv['getScrollEndedEventTiming']();
- if (fireEvent && !sv['_isScrollEndedWithThresholdEventFired']) {
- sv['_dispatchEvent'](ScrollView.EventType.SCROLL_ENG_WITH_THRESHOLD);
- sv['_isScrollEndedWithThresholdEventFired'] = true;
- }
- if (sv['elastic']) {
- var brakeOffsetPosition = clonedAutoScrollStartPosition.clone();
- brakeOffsetPosition.subtract(sv['_autoScrollBrakingStartPosition']);
- if (isAutoScrollBrake) {
- brakeOffsetPosition.multiplyScalar(brakingFactor);
- }
- clonedAutoScrollStartPosition.set(sv['_autoScrollBrakingStartPosition']);
- clonedAutoScrollStartPosition.add(brakeOffsetPosition);
- } else {
- var moveDelta = clonedAutoScrollStartPosition.clone();
- moveDelta.subtract(sv['_getContentPosition']());
- var outOfBoundary = sv['_getHowMuchOutOfBoundary'](moveDelta);
- if (!outOfBoundary.equals(ZERO, EPSILON)) {
- clonedAutoScrollStartPosition.add(outOfBoundary);
- reachedEnd = true;
- }
- }
- if (reachedEnd) {
- sv['_autoScrolling'] = false;
- }
- var deltaMove = new Vec3(clonedAutoScrollStartPosition);
- deltaMove.subtract(sv['_getContentPosition']());
- sv['_clampDelta'](deltaMove);
- sv['_moveContent'](deltaMove, reachedEnd);
- sv['_dispatchEvent'](ScrollView.EventType.SCROLLING);
- if (!sv['_autoScrolling']) {
- sv['_isBouncing'] = false;
- sv['_scrolling'] = false;
- sv['_dispatchEvent'](ScrollView.EventType.SCROLL_ENDED);
- }
- }
- //设置模板Item
- ;
- _proto.setTemplateItem = function setTemplateItem(item) {
- if (!item) return;
- var t = this;
- t._itemTmp = item;
- t._itemTmpUt = item.getComponent(UITransform);
- if (t._resizeMode == Layout.ResizeMode.CHILDREN) t._itemSize = t._layout.cellSize;else {
- var itemUt = item.getComponent(UITransform);
- t._itemSize = new Size(itemUt.width, itemUt.height);
- }
- //获取ListItem,如果没有就取消选择模式
- var com = item.getComponent(ListItem);
- var remove = false;
- if (!com) remove = true;
- // if (com) {
- // if (!com._btnCom && !item.getComponent(cc.Button)) {
- // remove = true;
- // }
- // }
- if (remove) {
- t.selectedMode = SelectedType.NONE;
- }
- com = item.getComponent(Widget);
- if (com && com.enabled) {
- t._needUpdateWidget = true;
- }
- if (t.selectedMode == SelectedType.MULT) t.multSelected = [];
- switch (t._align) {
- case Layout.Type.HORIZONTAL:
- t._colLineNum = 1;
- t._sizeType = false;
- break;
- case Layout.Type.VERTICAL:
- t._colLineNum = 1;
- t._sizeType = true;
- break;
- case Layout.Type.GRID:
- switch (t._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- //计算列数
- var trimW = t._contentUt.width - t._leftGap - t._rightGap;
- t._colLineNum = Math.floor((trimW + t._columnGap) / (t._itemSize.width + t._columnGap));
- t._sizeType = true;
- break;
- case Layout.AxisDirection.VERTICAL:
- //计算行数
- var trimH = t._contentUt.height - t._topGap - t._bottomGap;
- t._colLineNum = Math.floor((trimH + t._lineGap) / (t._itemSize.height + t._lineGap));
- t._sizeType = false;
- break;
- }
- break;
- }
- }
- /**
- * 检查是否初始化
- * @param {Boolean} printLog 是否打印错误信息
- * @returns
- */;
- _proto.checkInited = function checkInited(printLog) {
- if (printLog === void 0) {
- printLog = true;
- }
- if (!this._inited) {
- if (printLog) console.error('List initialization not completed!');
- return false;
- }
- return true;
- }
- //禁用 Layout 组件,自行计算 Content Size
- ;
- _proto._resizeContent = function _resizeContent() {
- var t = this;
- var result;
- switch (t._align) {
- case Layout.Type.HORIZONTAL:
- {
- if (t._customSize) {
- var fixed = t._getFixedSize(null);
- result = t._leftGap + fixed.val + t._itemSize.width * (t._numItems - fixed.count) + t._columnGap * (t._numItems - 1) + t._rightGap;
- } else {
- result = t._leftGap + t._itemSize.width * t._numItems + t._columnGap * (t._numItems - 1) + t._rightGap;
- }
- break;
- }
- case Layout.Type.VERTICAL:
- {
- if (t._customSize) {
- var _fixed = t._getFixedSize(null);
- result = t._topGap + _fixed.val + t._itemSize.height * (t._numItems - _fixed.count) + t._lineGap * (t._numItems - 1) + t._bottomGap;
- } else {
- result = t._topGap + t._itemSize.height * t._numItems + t._lineGap * (t._numItems - 1) + t._bottomGap;
- }
- break;
- }
- case Layout.Type.GRID:
- {
- //网格模式不支持居中
- if (t.lackCenter) t.lackCenter = false;
- switch (t._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- var lineNum = Math.ceil(t._numItems / t._colLineNum);
- result = t._topGap + t._itemSize.height * lineNum + t._lineGap * (lineNum - 1) + t._bottomGap;
- break;
- case Layout.AxisDirection.VERTICAL:
- var colNum = Math.ceil(t._numItems / t._colLineNum);
- result = t._leftGap + t._itemSize.width * colNum + t._columnGap * (colNum - 1) + t._rightGap;
- break;
- }
- break;
- }
- }
- var layout = t.content.getComponent(Layout);
- if (layout) layout.enabled = false;
- t._allItemSize = result;
- t._allItemSizeNoEdge = t._allItemSize - (t._sizeType ? t._topGap + t._bottomGap : t._leftGap + t._rightGap);
- if (t.cyclic) {
- var totalSize = t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width;
- t._cyclicPos1 = 0;
- totalSize -= t._cyclicPos1;
- t._cyclicNum = Math.ceil(totalSize / t._allItemSizeNoEdge) + 1;
- var spacing = t._sizeType ? t._lineGap : t._columnGap;
- t._cyclicPos2 = t._cyclicPos1 + t._allItemSizeNoEdge + spacing;
- t._cyclicAllItemSize = t._allItemSize + t._allItemSizeNoEdge * (t._cyclicNum - 1) + spacing * (t._cyclicNum - 1);
- t._cycilcAllItemSizeNoEdge = t._allItemSizeNoEdge * t._cyclicNum;
- t._cycilcAllItemSizeNoEdge += spacing * (t._cyclicNum - 1);
- // cc.log('_cyclicNum ->', t._cyclicNum, t._allItemSizeNoEdge, t._allItemSize, t._cyclicPos1, t._cyclicPos2);
- }
- t._lack = !t.cyclic && t._allItemSize < (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width);
- var slideOffset = (!t._lack || !t.lackCenter) && t.lackSlide ? 0 : .1;
- var targetWH = t._lack ? (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width) - slideOffset : t.cyclic ? t._cyclicAllItemSize : t._allItemSize;
- if (targetWH < 0) targetWH = 0;
- if (t._sizeType) {
- t._contentUt.height = targetWH;
- } else {
- t._contentUt.width = targetWH;
- }
- // cc.log('_resizeContent() numItems =', t._numItems, ',content =', t.content);
- }
- //滚动进行时...
- ;
- _proto._onScrolling = function _onScrolling(ev) {
- if (ev === void 0) {
- ev = null;
- }
- if (this.frameCount == null) this.frameCount = this._updateRate;
- if (!this._forceUpdate && ev && ev.type != 'scroll-ended' && this.frameCount > 0) {
- this.frameCount--;
- return;
- } else this.frameCount = this._updateRate;
- if (this._aniDelRuning) return;
- //循环列表处理
- if (this.cyclic) {
- var scrollPos = this.content.getPosition();
- scrollPos = this._sizeType ? scrollPos.y : scrollPos.x;
- var addVal = this._allItemSizeNoEdge + (this._sizeType ? this._lineGap : this._columnGap);
- var add = this._sizeType ? new Vec3(0, addVal, 0) : new Vec3(addVal, 0, 0);
- var contentPos = this.content.getPosition();
- switch (this._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- if (scrollPos > -this._cyclicPos1) {
- contentPos.set(-this._cyclicPos2, contentPos.y, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
- }
- // if (this._beganPos) {
- // this._beganPos += add;
- // }
- } else if (scrollPos < -this._cyclicPos2) {
- contentPos.set(-this._cyclicPos1, contentPos.y, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
- }
- // if (this._beganPos) {
- // this._beganPos -= add;
- // }
- }
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- if (scrollPos < this._cyclicPos1) {
- contentPos.set(this._cyclicPos2, contentPos.y, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
- }
- } else if (scrollPos > this._cyclicPos2) {
- contentPos.set(this._cyclicPos1, contentPos.y, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
- }
- }
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- if (scrollPos < this._cyclicPos1) {
- contentPos.set(contentPos.x, this._cyclicPos2, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
- }
- } else if (scrollPos > this._cyclicPos2) {
- contentPos.set(contentPos.x, this._cyclicPos1, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
- }
- }
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- if (scrollPos > -this._cyclicPos1) {
- contentPos.set(contentPos.x, -this._cyclicPos2, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].subtract(add);
- }
- } else if (scrollPos < -this._cyclicPos2) {
- contentPos.set(contentPos.x, -this._cyclicPos1, contentPos.z);
- this.content.setPosition(contentPos);
- if (this._scrollView.isAutoScrolling()) {
- this._scrollView['_autoScrollStartPosition'] = this._scrollView['_autoScrollStartPosition'].add(add);
- }
- }
- break;
- }
- }
- this._calcViewPos();
- var vTop, vRight, vBottom, vLeft;
- if (this._sizeType) {
- vTop = this.viewTop;
- vBottom = this.viewBottom;
- } else {
- vRight = this.viewRight;
- vLeft = this.viewLeft;
- }
- if (this._virtual) {
- this.displayData = [];
- var itemPos;
- var curId = 0;
- var endId = this._numItems - 1;
- if (this._customSize) {
- var breakFor = false;
- //如果该item的位置在可视区域内,就推入displayData
- for (; curId <= endId && !breakFor; curId++) {
- itemPos = this._calcItemPos(curId);
- switch (this._align) {
- case Layout.Type.HORIZONTAL:
- if (itemPos.right >= vLeft && itemPos.left <= vRight) {
- this.displayData.push(itemPos);
- } else if (curId != 0 && this.displayData.length > 0) {
- breakFor = true;
- }
- break;
- case Layout.Type.VERTICAL:
- if (itemPos.bottom <= vTop && itemPos.top >= vBottom) {
- this.displayData.push(itemPos);
- } else if (curId != 0 && this.displayData.length > 0) {
- breakFor = true;
- }
- break;
- case Layout.Type.GRID:
- switch (this._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- if (itemPos.bottom <= vTop && itemPos.top >= vBottom) {
- this.displayData.push(itemPos);
- } else if (curId != 0 && this.displayData.length > 0) {
- breakFor = true;
- }
- break;
- case Layout.AxisDirection.VERTICAL:
- if (itemPos.right >= vLeft && itemPos.left <= vRight) {
- this.displayData.push(itemPos);
- } else if (curId != 0 && this.displayData.length > 0) {
- breakFor = true;
- }
- break;
- }
- break;
- }
- }
- } else {
- var ww = this._itemSize.width + this._columnGap;
- var hh = this._itemSize.height + this._lineGap;
- switch (this._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- curId = (vLeft - this._leftGap) / ww;
- endId = (vRight - this._leftGap) / ww;
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- curId = (-vRight - this._rightGap) / ww;
- endId = (-vLeft - this._rightGap) / ww;
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- curId = (-vTop - this._topGap) / hh;
- endId = (-vBottom - this._topGap) / hh;
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- curId = (vBottom - this._bottomGap) / hh;
- endId = (vTop - this._bottomGap) / hh;
- break;
- }
- curId = Math.floor(curId) * this._colLineNum;
- endId = Math.ceil(endId) * this._colLineNum;
- endId--;
- if (curId < 0) curId = 0;
- if (endId >= this._numItems) endId = this._numItems - 1;
- for (; curId <= endId; curId++) {
- this.displayData.push(this._calcItemPos(curId));
- }
- }
- this._delRedundantItem();
- if (this.displayData.length <= 0 || !this._numItems) {
- //if none, delete all.
- this._lastDisplayData = [];
- return;
- }
- this.firstListId = this.displayData[0].id;
- this.displayItemNum = this.displayData.length;
- var len = this._lastDisplayData.length;
- var haveDataChange = this.displayItemNum != len;
- if (haveDataChange) {
- // 如果是逐帧渲染,需要排序
- if (this.frameByFrameRenderNum > 0) {
- this._lastDisplayData.sort(function (a, b) {
- return a - b;
- });
- }
- // 因List的显示数据是有序的,所以只需要判断数组长度是否相等,以及头、尾两个元素是否相等即可。
- haveDataChange = this.firstListId != this._lastDisplayData[0] || this.displayData[this.displayItemNum - 1].id != this._lastDisplayData[len - 1];
- }
- if (this._forceUpdate || haveDataChange) {
- //如果是强制更新
- if (this.frameByFrameRenderNum > 0) {
- // if (this._updateDone) {
- // this._lastDisplayData = [];
- //逐帧渲染
- if (this._numItems > 0) {
- if (!this._updateDone) {
- this._doneAfterUpdate = true;
- } else {
- this._updateCounter = 0;
- }
- this._updateDone = false;
- } else {
- this._updateCounter = 0;
- this._updateDone = true;
- }
- // }
- } else {
- //直接渲染
- this._lastDisplayData = [];
- // cc.log('List Display Data II::', this.displayData);
- for (var c = 0; c < this.displayItemNum; c++) {
- this._createOrUpdateItem(this.displayData[c]);
- }
- this._forceUpdate = false;
- }
- }
- this._calcNearestItem();
- }
- }
- //计算可视范围
- ;
- _proto._calcViewPos = function _calcViewPos() {
- var scrollPos = this.content.getPosition();
- switch (this._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- this.elasticLeft = scrollPos.x > 0 ? scrollPos.x : 0;
- this.viewLeft = (scrollPos.x < 0 ? -scrollPos.x : 0) - this.elasticLeft;
- this.viewRight = this.viewLeft + this._thisNodeUt.width;
- this.elasticRight = this.viewRight > this._contentUt.width ? Math.abs(this.viewRight - this._contentUt.width) : 0;
- this.viewRight += this.elasticRight;
- // cc.log(this.elasticLeft, this.elasticRight, this.viewLeft, this.viewRight);
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- this.elasticRight = scrollPos.x < 0 ? -scrollPos.x : 0;
- this.viewRight = (scrollPos.x > 0 ? -scrollPos.x : 0) + this.elasticRight;
- this.viewLeft = this.viewRight - this._thisNodeUt.width;
- this.elasticLeft = this.viewLeft < -this._contentUt.width ? Math.abs(this.viewLeft + this._contentUt.width) : 0;
- this.viewLeft -= this.elasticLeft;
- // cc.log(this.elasticLeft, this.elasticRight, this.viewLeft, this.viewRight);
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- this.elasticTop = scrollPos.y < 0 ? Math.abs(scrollPos.y) : 0;
- this.viewTop = (scrollPos.y > 0 ? -scrollPos.y : 0) + this.elasticTop;
- this.viewBottom = this.viewTop - this._thisNodeUt.height;
- this.elasticBottom = this.viewBottom < -this._contentUt.height ? Math.abs(this.viewBottom + this._contentUt.height) : 0;
- this.viewBottom += this.elasticBottom;
- // cc.log(this.elasticTop, this.elasticBottom, this.viewTop, this.viewBottom);
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- this.elasticBottom = scrollPos.y > 0 ? Math.abs(scrollPos.y) : 0;
- this.viewBottom = (scrollPos.y < 0 ? -scrollPos.y : 0) - this.elasticBottom;
- this.viewTop = this.viewBottom + this._thisNodeUt.height;
- this.elasticTop = this.viewTop > this._contentUt.height ? Math.abs(this.viewTop - this._contentUt.height) : 0;
- this.viewTop -= this.elasticTop;
- // cc.log(this.elasticTop, this.elasticBottom, this.viewTop, this.viewBottom);
- break;
- }
- }
- //计算位置 根据id
- ;
- _proto._calcItemPos = function _calcItemPos(id) {
- var width, height, top, bottom, left, right, itemX, itemY;
- switch (this._align) {
- case Layout.Type.HORIZONTAL:
- switch (this._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- {
- if (this._customSize) {
- var fixed = this._getFixedSize(id);
- left = this._leftGap + (this._itemSize.width + this._columnGap) * (id - fixed.count) + (fixed.val + this._columnGap * fixed.count);
- var cs = this._customSize[id];
- width = cs > 0 ? cs : this._itemSize.width;
- } else {
- left = this._leftGap + (this._itemSize.width + this._columnGap) * id;
- width = this._itemSize.width;
- }
- if (this.lackCenter) {
- left -= this._leftGap;
- var offset = this._contentUt.width / 2 - this._allItemSizeNoEdge / 2;
- left += offset;
- }
- right = left + width;
- return {
- id: id,
- left: left,
- right: right,
- x: left + this._itemTmpUt.anchorX * width,
- y: this._itemTmp.y
- };
- }
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- {
- if (this._customSize) {
- var _fixed2 = this._getFixedSize(id);
- right = -this._rightGap - (this._itemSize.width + this._columnGap) * (id - _fixed2.count) - (_fixed2.val + this._columnGap * _fixed2.count);
- var _cs = this._customSize[id];
- width = _cs > 0 ? _cs : this._itemSize.width;
- } else {
- right = -this._rightGap - (this._itemSize.width + this._columnGap) * id;
- width = this._itemSize.width;
- }
- if (this.lackCenter) {
- right += this._rightGap;
- var _offset = this._contentUt.width / 2 - this._allItemSizeNoEdge / 2;
- right -= _offset;
- }
- left = right - width;
- return {
- id: id,
- right: right,
- left: left,
- x: left + this._itemTmpUt.anchorX * width,
- y: this._itemTmp.y
- };
- }
- }
- break;
- case Layout.Type.VERTICAL:
- {
- switch (this._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- {
- if (this._customSize) {
- var _fixed3 = this._getFixedSize(id);
- top = -this._topGap - (this._itemSize.height + this._lineGap) * (id - _fixed3.count) - (_fixed3.val + this._lineGap * _fixed3.count);
- var _cs2 = this._customSize[id];
- height = _cs2 > 0 ? _cs2 : this._itemSize.height;
- } else {
- top = -this._topGap - (this._itemSize.height + this._lineGap) * id;
- height = this._itemSize.height;
- }
- if (this.lackCenter) {
- top += this._topGap;
- var _offset2 = this._contentUt.height / 2 - this._allItemSizeNoEdge / 2;
- top -= _offset2;
- }
- bottom = top - height;
- return {
- id: id,
- top: top,
- bottom: bottom,
- x: this._itemTmp.x,
- y: bottom + this._itemTmpUt.anchorY * height
- };
- }
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- {
- if (this._customSize) {
- var _fixed4 = this._getFixedSize(id);
- bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * (id - _fixed4.count) + (_fixed4.val + this._lineGap * _fixed4.count);
- var _cs3 = this._customSize[id];
- height = _cs3 > 0 ? _cs3 : this._itemSize.height;
- } else {
- bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * id;
- height = this._itemSize.height;
- }
- if (this.lackCenter) {
- bottom -= this._bottomGap;
- var _offset3 = this._contentUt.height / 2 - this._allItemSizeNoEdge / 2;
- bottom += _offset3;
- }
- top = bottom + height;
- return {
- id: id,
- top: top,
- bottom: bottom,
- x: this._itemTmp.x,
- y: bottom + this._itemTmpUt.anchorY * height
- };
- }
- }
- }
- case Layout.Type.GRID:
- {
- var colLine = Math.floor(id / this._colLineNum);
- switch (this._startAxis) {
- case Layout.AxisDirection.HORIZONTAL:
- {
- switch (this._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- {
- top = -this._topGap - (this._itemSize.height + this._lineGap) * colLine;
- bottom = top - this._itemSize.height;
- itemY = bottom + this._itemTmpUt.anchorY * this._itemSize.height;
- break;
- }
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- {
- bottom = this._bottomGap + (this._itemSize.height + this._lineGap) * colLine;
- top = bottom + this._itemSize.height;
- itemY = bottom + this._itemTmpUt.anchorY * this._itemSize.height;
- break;
- }
- }
- itemX = this._leftGap + id % this._colLineNum * (this._itemSize.width + this._columnGap);
- switch (this._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- {
- itemX += this._itemTmpUt.anchorX * this._itemSize.width;
- itemX -= this._contentUt.anchorX * this._contentUt.width;
- break;
- }
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- {
- itemX += (1 - this._itemTmpUt.anchorX) * this._itemSize.width;
- itemX -= (1 - this._contentUt.anchorX) * this._contentUt.width;
- itemX *= -1;
- break;
- }
- }
- return {
- id: id,
- top: top,
- bottom: bottom,
- x: itemX,
- y: itemY
- };
- }
- case Layout.AxisDirection.VERTICAL:
- {
- switch (this._horizontalDir) {
- case Layout.HorizontalDirection.LEFT_TO_RIGHT:
- {
- left = this._leftGap + (this._itemSize.width + this._columnGap) * colLine;
- right = left + this._itemSize.width;
- itemX = left + this._itemTmpUt.anchorX * this._itemSize.width;
- itemX -= this._contentUt.anchorX * this._contentUt.width;
- break;
- }
- case Layout.HorizontalDirection.RIGHT_TO_LEFT:
- {
- right = -this._rightGap - (this._itemSize.width + this._columnGap) * colLine;
- left = right - this._itemSize.width;
- itemX = left + this._itemTmpUt.anchorX * this._itemSize.width;
- itemX += (1 - this._contentUt.anchorX) * this._contentUt.width;
- break;
- }
- }
- itemY = -this._topGap - id % this._colLineNum * (this._itemSize.height + this._lineGap);
- switch (this._verticalDir) {
- case Layout.VerticalDirection.TOP_TO_BOTTOM:
- {
- itemY -= (1 - this._itemTmpUt.anchorY) * this._itemSize.height;
- itemY += (1 - this._contentUt.anchorY) * this._contentUt.height;
- break;
- }
- case Layout.VerticalDirection.BOTTOM_TO_TOP:
- {
- itemY -= this._itemTmpUt.anchorY * this._itemSize.height;
- itemY += this._contentUt.anchorY * this._contentUt.height;
- itemY *= -1;
- break;
- }
- }
- return {
- id: id,
- left: left,
- right: right,
- x: itemX,
- y: itemY
- };
- }
- }
- break;
- }
- }
- }
- //计算已存在的Item的位置
- ;
- _proto._calcExistItemPos = function _calcExistItemPos(id) {
- var item = this.getItemByListId(id);
- if (!item) return null;
- var ut = item.getComponent(UITransform);
- var pos = item.getPosition();
- var data = {
- id: id,
- x: pos.x,
- y: pos.y
- };
- if (this._sizeType) {
- data.top = pos.y + ut.height * (1 - ut.anchorY);
- data.bottom = pos.y - ut.height * ut.anchorY;
- } else {
- data.left = pos.x - ut.width * ut.anchorX;
- data.right = pos.x + ut.width * (1 - ut.anchorX);
- }
- return data;
- }
- //获取Item位置
- ;
- _proto.getItemPos = function getItemPos(id) {
- if (this._virtual) return this._calcItemPos(id);else {
- if (this.frameByFrameRenderNum) return this._calcItemPos(id);else return this._calcExistItemPos(id);
- }
- }
- //获取固定尺寸
- ;
- _proto._getFixedSize = function _getFixedSize(listId) {
- if (!this._customSize) return null;
- if (listId == null) listId = this._numItems;
- var fixed = 0;
- var count = 0;
- for (var id in this._customSize) {
- if (parseInt(id) < listId) {
- fixed += this._customSize[id];
- count++;
- }
- }
- return {
- val: fixed,
- count: count
- };
- }
- //滚动结束时..
- ;
- _proto._onScrollBegan = function _onScrollBegan() {
- this._beganPos = this._sizeType ? this.viewTop : this.viewLeft;
- }
- //滚动结束时..
- ;
- _proto._onScrollEnded = function _onScrollEnded() {
- var t = this;
- t._curScrollIsTouch = false;
- if (t.scrollToListId != null) {
- var item = t.getItemByListId(t.scrollToListId);
- t.scrollToListId = null;
- if (item) {
- tween(item).to(.1, {
- scale: 1.06
- }).to(.1, {
- scale: 1
- }).start();
- }
- }
- t._onScrolling();
- if (t._slideMode == SlideType.ADHERING && !t.adhering) {
- //cc.log(t.adhering, t._scrollView.isAutoScrolling(), t._scrollView.isScrolling());
- t.adhere();
- } else if (t._slideMode == SlideType.PAGE) {
- if (t._beganPos != null && t._curScrollIsTouch) {
- this._pageAdhere();
- } else {
- t.adhere();
- }
- }
- }
- // 触摸时
- ;
- _proto._onTouchStart = function _onTouchStart(ev, captureListeners) {
- if (this._scrollView['_hasNestedViewGroup'](ev, captureListeners)) return;
- this._curScrollIsTouch = true;
- var isMe = ev.eventPhase === 2 && ev.target === this.node;
- if (!isMe) {
- var itemNode = ev.target;
- while (itemNode._listId == null && itemNode.parent) itemNode = itemNode.parent;
- this._scrollItem = itemNode._listId != null ? itemNode : ev.target;
- }
- }
- //触摸抬起时..
- ;
- _proto._onTouchUp = function _onTouchUp() {
- var t = this;
- t._scrollPos = null;
- if (t._slideMode == SlideType.ADHERING) {
- if (this.adhering) this._adheringBarrier = true;
- t.adhere();
- } else if (t._slideMode == SlideType.PAGE) {
- if (t._beganPos != null) {
- this._pageAdhere();
- } else {
- t.adhere();
- }
- }
- this._scrollItem = null;
- };
- _proto._onTouchCancelled = function _onTouchCancelled(ev, captureListeners) {
- var t = this;
- if (t._scrollView['_hasNestedViewGroup'](ev, captureListeners) || ev.simulate) return;
- t._scrollPos = null;
- if (t._slideMode == SlideType.ADHERING) {
- if (t.adhering) t._adheringBarrier = true;
- t.adhere();
- } else if (t._slideMode == SlideType.PAGE) {
- if (t._beganPos != null) {
- t._pageAdhere();
- } else {
- t.adhere();
- }
- }
- this._scrollItem = null;
- }
- //当尺寸改变
- ;
- _proto._onSizeChanged = function _onSizeChanged() {
- if (this.checkInited(false)) this._onScrolling();
- }
- //当Item自适应
- ;
- _proto._onItemAdaptive = function _onItemAdaptive(item) {
- var ut = item.getComponent(UITransform);
- // if (this.checkInited(false)) {
- if (!this._sizeType && ut.width != this._itemSize.width || this._sizeType && ut.height != this._itemSize.height) {
- if (!this._customSize) this._customSize = {};
- var val = this._sizeType ? ut.height : ut.width;
- if (this._customSize[item._listId] != val) {
- this._customSize[item._listId] = val;
- this._resizeContent();
- // this.content.children.forEach((child: Node) => {
- // this._updateItemPos(child);
- // });
- this.updateAll();
- // 如果当前正在运行 scrollTo,肯定会不准确,在这里做修正
- if (this._scrollToListId != null) {
- this._scrollPos = null;
- this.unschedule(this._scrollToSo);
- this.scrollTo(this._scrollToListId, Math.max(0, this._scrollToEndTime - new Date().getTime() / 1000));
- }
- }
- }
- // }
- }
- //PAGE粘附
- ;
- _proto._pageAdhere = function _pageAdhere() {
- var t = this;
- if (!t.cyclic && (t.elasticTop > 0 || t.elasticRight > 0 || t.elasticBottom > 0 || t.elasticLeft > 0)) return;
- var curPos = t._sizeType ? t.viewTop : t.viewLeft;
- var dis = (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width) * t.pageDistance;
- var canSkip = Math.abs(t._beganPos - curPos) > dis;
- if (canSkip) {
- var timeInSecond = .5;
- switch (t._alignCalcType) {
- case 1: //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- if (t._beganPos > curPos) {
- t.prePage(timeInSecond);
- // cc.log('_pageAdhere PPPPPPPPPPPPPPP');
- } else {
- t.nextPage(timeInSecond);
- // cc.log('_pageAdhere NNNNNNNNNNNNNNN');
- }
- break;
- case 2: //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- if (t._beganPos < curPos) {
- t.prePage(timeInSecond);
- } else {
- t.nextPage(timeInSecond);
- }
- break;
- }
- } else if (t.elasticTop <= 0 && t.elasticRight <= 0 && t.elasticBottom <= 0 && t.elasticLeft <= 0) {
- t.adhere();
- }
- t._beganPos = null;
- }
- //粘附
- ;
- _proto.adhere = function adhere() {
- var t = this;
- if (!t.checkInited()) return;
- if (t.elasticTop > 0 || t.elasticRight > 0 || t.elasticBottom > 0 || t.elasticLeft > 0) return;
- t.adhering = true;
- t._calcNearestItem();
- var offset = (t._sizeType ? t._topGap : t._leftGap) / (t._sizeType ? t._thisNodeUt.height : t._thisNodeUt.width);
- var timeInSecond = .7;
- t.scrollTo(t.nearestListId, timeInSecond, offset);
- }
- //Update..
- ;
- _proto.update = function update() {
- if (this.frameByFrameRenderNum <= 0 || this._updateDone) return;
- // cc.log(this.displayData.length, this._updateCounter, this.displayData[this._updateCounter]);
- if (this._virtual) {
- var len = this._updateCounter + this.frameByFrameRenderNum > this.displayItemNum ? this.displayItemNum : this._updateCounter + this.frameByFrameRenderNum;
- for (var n = this._updateCounter; n < len; n++) {
- var data = this.displayData[n];
- if (data) {
- this._createOrUpdateItem(data);
- }
- }
- if (this._updateCounter >= this.displayItemNum - 1) {
- //最后一个
- if (this._doneAfterUpdate) {
- this._updateCounter = 0;
- this._updateDone = false;
- // if (!this._scrollView.isScrolling())
- this._doneAfterUpdate = false;
- } else {
- this._updateDone = true;
- this._delRedundantItem();
- this._forceUpdate = false;
- this._calcNearestItem();
- if (this.slideMode == SlideType.PAGE) this.curPageNum = this.nearestListId;
- }
- } else {
- this._updateCounter += this.frameByFrameRenderNum;
- }
- } else {
- if (this._updateCounter < this._numItems) {
- var _len2 = this._updateCounter + this.frameByFrameRenderNum > this._numItems ? this._numItems : this._updateCounter + this.frameByFrameRenderNum;
- for (var _n = this._updateCounter; _n < _len2; _n++) {
- this._createOrUpdateItem2(_n);
- }
- this._updateCounter += this.frameByFrameRenderNum;
- } else {
- this._updateDone = true;
- this._calcNearestItem();
- if (this.slideMode == SlideType.PAGE) this.curPageNum = this.nearestListId;
- }
- }
- }
- /**
- * 创建或更新Item(虚拟列表用)
- * @param {Object} data 数据
- */;
- _proto._createOrUpdateItem = function _createOrUpdateItem(data) {
- var item = this.getItemByListId(data.id);
- if (!item) {
- //如果不存在
- var canGet = this._pool.size() > 0;
- if (canGet) {
- item = this._pool.get();
- // cc.log('从池中取出:: 旧id =', item['_listId'], ',新id =', data.id, item);
- } else {
- item = instantiate(this._itemTmp);
- // cc.log('新建::', data.id, item);
- }
- if (!canGet || !isValid(item)) {
- item = instantiate(this._itemTmp);
- canGet = false;
- }
- if (item._listId != data.id) {
- item._listId = data.id;
- var ut = item.getComponent(UITransform);
- ut.setContentSize(this._itemSize);
- }
- item.setPosition(new Vec3(data.x, data.y, 0));
- this._resetItemSize(item);
- this.content.addChild(item);
- if (canGet && this._needUpdateWidget) {
- var widget = item.getComponent(Widget);
- if (widget) widget.updateAlignment();
- }
- item.setSiblingIndex(this.content.children.length - 1);
- var listItem = item.getComponent(ListItem);
- item['listItem'] = listItem;
- if (listItem) {
- listItem.listId = data.id;
- listItem.list = this;
- listItem._registerEvent();
- }
- if (this.renderEvent) {
- EventHandler.emitEvents([this.renderEvent], item, data.id % this._actualNumItems);
- }
- } else if (this._forceUpdate && this.renderEvent) {
- //强制更新
- item.setPosition(new Vec3(data.x, data.y, 0));
- this._resetItemSize(item);
- // cc.log('ADD::', data.id, item);
- if (this.renderEvent) {
- EventHandler.emitEvents([this.renderEvent], item, data.id % this._actualNumItems);
- }
- }
- this._resetItemSize(item);
- this._updateListItem(item['listItem']);
- if (this._lastDisplayData.indexOf(data.id) < 0) {
- this._lastDisplayData.push(data.id);
- }
- }
- //创建或更新Item(非虚拟列表用)
- ;
- _proto._createOrUpdateItem2 = function _createOrUpdateItem2(listId) {
- var item = this.content.children[listId];
- var listItem;
- if (!item) {
- //如果不存在
- item = instantiate(this._itemTmp);
- item._listId = listId;
- this.content.addChild(item);
- listItem = item.getComponent(ListItem);
- item['listItem'] = listItem;
- if (listItem) {
- listItem.listId = listId;
- listItem.list = this;
- listItem._registerEvent();
- }
- if (this.renderEvent) {
- EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
- }
- } else if (this._forceUpdate && this.renderEvent) {
- //强制更新
- item._listId = listId;
- if (listItem) listItem.listId = listId;
- if (this.renderEvent) {
- EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
- }
- }
- this._updateListItem(listItem);
- if (this._lastDisplayData.indexOf(listId) < 0) {
- this._lastDisplayData.push(listId);
- }
- };
- _proto._updateListItem = function _updateListItem(listItem) {
- if (!listItem) return;
- if (this.selectedMode > SelectedType.NONE) {
- var item = listItem.node;
- switch (this.selectedMode) {
- case SelectedType.SINGLE:
- listItem.selected = this.selectedId == item._listId;
- break;
- case SelectedType.MULT:
- listItem.selected = this.multSelected.indexOf(item._listId) >= 0;
- break;
- }
- }
- }
- //仅虚拟列表用
- ;
- _proto._resetItemSize = function _resetItemSize(item) {
- return;
- }
- /**
- * 更新Item位置
- * @param {Number||Node} listIdOrItem
- */;
- _proto._updateItemPos = function _updateItemPos(listIdOrItem) {
- var item = isNaN(listIdOrItem) ? listIdOrItem : this.getItemByListId(listIdOrItem);
- var pos = this.getItemPos(item._listId);
- item.setPosition(pos.x, pos.y);
- }
- /**
- * 设置多选
- * @param {Array} args 可以是单个listId,也可是个listId数组
- * @param {Boolean} bool 值,如果为null的话,则直接用args覆盖
- */;
- _proto.setMultSelected = function setMultSelected(args, bool) {
- var t = this;
- if (!t.checkInited()) return;
- if (!Array.isArray(args)) {
- args = [args];
- }
- if (bool == null) {
- t.multSelected = args;
- } else {
- var listId, sub;
- if (bool) {
- for (var n = args.length - 1; n >= 0; n--) {
- listId = args[n];
- sub = t.multSelected.indexOf(listId);
- if (sub < 0) {
- t.multSelected.push(listId);
- }
- }
- } else {
- for (var _n2 = args.length - 1; _n2 >= 0; _n2--) {
- listId = args[_n2];
- sub = t.multSelected.indexOf(listId);
- if (sub >= 0) {
- t.multSelected.splice(sub, 1);
- }
- }
- }
- }
- t._forceUpdate = true;
- t._onScrolling();
- }
- /**
- * 获取多选数据
- * @returns
- */;
- _proto.getMultSelected = function getMultSelected() {
- return this.multSelected;
- }
- /**
- * 多选是否有选择
- * @param {number} listId 索引
- * @returns
- */;
- _proto.hasMultSelected = function hasMultSelected(listId) {
- return this.multSelected && this.multSelected.indexOf(listId) >= 0;
- }
- /**
- * 更新指定的Item
- * @param {Array} args 单个listId,或者数组
- * @returns
- */;
- _proto.updateItem = function updateItem(args) {
- if (!this.checkInited()) return;
- if (!Array.isArray(args)) {
- args = [args];
- }
- for (var n = 0, len = args.length; n < len; n++) {
- var listId = args[n];
- var item = this.getItemByListId(listId);
- if (item) EventHandler.emitEvents([this.renderEvent], item, listId % this._actualNumItems);
- }
- }
- /**
- * 更新全部
- */;
- _proto.updateAll = function updateAll() {
- if (!this.checkInited()) return;
- this.numItems = this.numItems;
- }
- /**
- * 根据ListID获取Item
- * @param {Number} listId
- * @returns
- */;
- _proto.getItemByListId = function getItemByListId(listId) {
- if (this.content) {
- for (var n = this.content.children.length - 1; n >= 0; n--) {
- var item = this.content.children[n];
- if (item._listId == listId) return item;
- }
- }
- }
- /**
- * 获取在显示区域外的Item
- * @returns
- */;
- _proto._getOutsideItem = function _getOutsideItem() {
- var item;
- var result = [];
- for (var n = this.content.children.length - 1; n >= 0; n--) {
- item = this.content.children[n];
- if (!this.displayData.find(function (d) {
- return d.id == item._listId;
- })) {
- result.push(item);
- }
- }
- return result;
- }
- //删除显示区域以外的Item
- ;
- _proto._delRedundantItem = function _delRedundantItem() {
- if (this._virtual) {
- var arr = this._getOutsideItem();
- for (var n = arr.length - 1; n >= 0; n--) {
- var item = arr[n];
- if (this._scrollItem && item._listId == this._scrollItem._listId) continue;
- item.isCached = true;
- this._pool.put(item);
- for (var m = this._lastDisplayData.length - 1; m >= 0; m--) {
- if (this._lastDisplayData[m] == item._listId) {
- this._lastDisplayData.splice(m, 1);
- break;
- }
- }
- }
- // cc.log('存入::', str, ' pool.length =', this._pool.length);
- } else {
- while (this.content.children.length > this._numItems) {
- this._delSingleItem(this.content.children[this.content.children.length - 1]);
- }
- }
- }
- //删除单个Item
- ;
- _proto._delSingleItem = function _delSingleItem(item) {
- // cc.log('DEL::', item['_listId'], item);
- item.removeFromParent();
- if (item.destroy) item.destroy();
- item = null;
- }
- /**
- * 动效删除Item(此方法只适用于虚拟列表,即_virtual=true)
- * 一定要在回调函数里重新设置新的numItems进行刷新,毕竟本List是靠数据驱动的。
- */;
- _proto.aniDelItem = function aniDelItem(listId, callFunc, aniType) {
- var t = this;
- if (!t.checkInited() || t.cyclic || !t._virtual) return console.error('This function is not allowed to be called!');
- if (!callFunc) return console.error('CallFunc are not allowed to be NULL, You need to delete the corresponding index in the data array in the CallFunc!');
- if (t._aniDelRuning) return console.warn('Please wait for the current deletion to finish!');
- var item = t.getItemByListId(listId);
- var listItem;
- if (!item) {
- callFunc(listId);
- return;
- } else {
- listItem = item.getComponent(ListItem);
- }
- t._aniDelRuning = true;
- t._aniDelCB = callFunc;
- t._aniDelItem = item;
- t._aniDelBeforePos = item.position;
- t._aniDelBeforeScale = item.scale;
- var curLastId = t.displayData[t.displayData.length - 1].id;
- var resetSelectedId = listItem.selected;
- listItem.showAni(aniType, function () {
- //判断有没有下一个,如果有的话,创建粗来
- var newId;
- if (curLastId < t._numItems - 2) {
- newId = curLastId + 1;
- }
- if (newId != null) {
- var newData = t._calcItemPos(newId);
- t.displayData.push(newData);
- if (t._virtual) t._createOrUpdateItem(newData);else t._createOrUpdateItem2(newId);
- } else t._numItems--;
- if (t.selectedMode == SelectedType.SINGLE) {
- if (resetSelectedId) {
- t._selectedId = -1;
- } else if (t._selectedId - 1 >= 0) {
- t._selectedId--;
- }
- } else if (t.selectedMode == SelectedType.MULT && t.multSelected.length) {
- var sub = t.multSelected.indexOf(listId);
- if (sub >= 0) {
- t.multSelected.splice(sub, 1);
- }
- //多选的数据,在其后的全部减一
- for (var n = t.multSelected.length - 1; n >= 0; n--) {
- var id = t.multSelected[n];
- if (id >= listId) t.multSelected[n]--;
- }
- }
- if (t._customSize) {
- if (t._customSize[listId]) delete t._customSize[listId];
- var newCustomSize = {};
- var size;
- for (var _id in t._customSize) {
- size = t._customSize[_id];
- var idNumber = parseInt(_id);
- newCustomSize[idNumber - (idNumber >= listId ? 1 : 0)] = size;
- }
- t._customSize = newCustomSize;
- }
- //后面的Item向前怼的动效
- var sec = .2333;
- var twe, haveCB;
- for (var _n3 = newId != null ? newId : curLastId; _n3 >= listId + 1; _n3--) {
- item = t.getItemByListId(_n3);
- if (item) {
- var posData = t._calcItemPos(_n3 - 1);
- twe = tween(item).to(sec, {
- position: new Vec3(posData.x, posData.y, 0)
- });
- if (_n3 <= listId + 1) {
- haveCB = true;
- twe.call(function () {
- t._aniDelRuning = false;
- callFunc(listId);
- delete t._aniDelCB;
- });
- }
- twe.start();
- }
- }
- if (!haveCB) {
- t._aniDelRuning = false;
- callFunc(listId);
- t._aniDelCB = null;
- }
- }, true);
- }
- /**
- * 滚动到..
- * @param {Number} listId 索引(如果<0,则滚到首个Item位置,如果>=_numItems,则滚到最末Item位置)
- * @param {Number} timeInSecond 时间
- * @param {Number} offset 索引目标位置偏移,0-1
- * @param {Boolean} overStress 滚动后是否强调该Item(这只是个实验功能)
- */;
- _proto.scrollTo = function scrollTo(listId, timeInSecond, offset, overStress) {
- if (timeInSecond === void 0) {
- timeInSecond = .5;
- }
- if (offset === void 0) {
- offset = null;
- }
- if (overStress === void 0) {
- overStress = false;
- }
- var t = this;
- if (!t.checkInited(false)) return;
- // t._scrollView.stopAutoScroll();
- if (timeInSecond == null)
- //默认0.5
- timeInSecond = .5;else if (timeInSecond < 0) timeInSecond = 0;
- if (listId < 0) listId = 0;else if (listId >= t._numItems) listId = t._numItems - 1;
- // 以防设置了numItems之后layout的尺寸还未更新
- if (!t._virtual && t._layout && t._layout.enabled) t._layout.updateLayout();
- var pos = t.getItemPos(listId);
- if (!pos) {
- return DEV;
- }
- var targetX, targetY;
- switch (t._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- targetX = pos.left;
- if (offset != null) targetX -= t._thisNodeUt.width * offset;else targetX -= t._leftGap;
- pos = new Vec3(targetX, 0, 0);
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- targetX = pos.right - t._thisNodeUt.width;
- if (offset != null) targetX += t._thisNodeUt.width * offset;else targetX += t._rightGap;
- pos = new Vec3(targetX + t._contentUt.width, 0, 0);
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- targetY = pos.top;
- if (offset != null) targetY += t._thisNodeUt.height * offset;else targetY += t._topGap;
- pos = new Vec3(0, -targetY, 0);
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- targetY = pos.bottom + t._thisNodeUt.height;
- if (offset != null) targetY -= t._thisNodeUt.height * offset;else targetY -= t._bottomGap;
- pos = new Vec3(0, -targetY + t._contentUt.height, 0);
- break;
- }
- var viewPos = t.content.getPosition();
- viewPos = Math.abs(t._sizeType ? viewPos.y : viewPos.x);
- var comparePos = t._sizeType ? pos.y : pos.x;
- var runScroll = Math.abs((t._scrollPos != null ? t._scrollPos : viewPos) - comparePos) > .5;
- // cc.log(runScroll, t._scrollPos, viewPos, comparePos)
- // t._scrollView.stopAutoScroll();
- if (runScroll) {
- t._scrollView.scrollToOffset(pos, timeInSecond);
- t._scrollToListId = listId;
- t._scrollToEndTime = new Date().getTime() / 1000 + timeInSecond;
- // cc.log(listId, t.content.width, t.content.getPosition(), pos);
- t._scrollToSo = t.scheduleOnce(function () {
- if (!t._adheringBarrier) {
- t.adhering = t._adheringBarrier = false;
- }
- t._scrollPos = t._scrollToListId = t._scrollToEndTime = t._scrollToSo = null;
- //cc.log('2222222222', t._adheringBarrier)
- if (overStress) {
- // t.scrollToListId = listId;
- var item = t.getItemByListId(listId);
- if (item) {
- tween(item).to(.1, {
- scale: 1.05
- }).to(.1, {
- scale: 1
- }).start();
- }
- }
- }, timeInSecond + .1);
- if (timeInSecond <= 0) {
- t._onScrolling();
- }
- }
- }
- /**
- * 计算当前滚动窗最近的Item
- */;
- _proto._calcNearestItem = function _calcNearestItem() {
- var t = this;
- t.nearestListId = null;
- var data, center;
- if (t._virtual) t._calcViewPos();
- var vTop, vRight, vBottom, vLeft;
- vTop = t.viewTop;
- vRight = t.viewRight;
- vBottom = t.viewBottom;
- vLeft = t.viewLeft;
- var breakFor = false;
- for (var n = 0; n < t.content.children.length && !breakFor; n += t._colLineNum) {
- data = t._virtual ? t.displayData[n] : t._calcExistItemPos(n);
- if (data) {
- center = t._sizeType ? (data.top + data.bottom) / 2 : center = (data.left + data.right) / 2;
- switch (t._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- if (data.right >= vLeft) {
- t.nearestListId = data.id;
- if (vLeft > center) t.nearestListId += t._colLineNum;
- breakFor = true;
- }
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- if (data.left <= vRight) {
- t.nearestListId = data.id;
- if (vRight < center) t.nearestListId += t._colLineNum;
- breakFor = true;
- }
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- if (data.bottom <= vTop) {
- t.nearestListId = data.id;
- if (vTop < center) t.nearestListId += t._colLineNum;
- breakFor = true;
- }
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- if (data.top >= vBottom) {
- t.nearestListId = data.id;
- if (vBottom > center) t.nearestListId += t._colLineNum;
- breakFor = true;
- }
- break;
- }
- }
- }
- //判断最后一个Item。。。(哎,这些判断真心恶心,判断了前面的还要判断最后一个。。。一开始呢,就只有一个布局(单列布局),那时候代码才三百行,后来就想着完善啊,艹..这坑真深,现在这行数都一千五了= =||)
- data = t._virtual ? t.displayData[t.displayItemNum - 1] : t._calcExistItemPos(t._numItems - 1);
- if (data && data.id == t._numItems - 1) {
- center = t._sizeType ? (data.top + data.bottom) / 2 : center = (data.left + data.right) / 2;
- switch (t._alignCalcType) {
- case 1:
- //单行HORIZONTAL(LEFT_TO_RIGHT)、网格VERTICAL(LEFT_TO_RIGHT)
- if (vRight > center) t.nearestListId = data.id;
- break;
- case 2:
- //单行HORIZONTAL(RIGHT_TO_LEFT)、网格VERTICAL(RIGHT_TO_LEFT)
- if (vLeft < center) t.nearestListId = data.id;
- break;
- case 3:
- //单列VERTICAL(TOP_TO_BOTTOM)、网格HORIZONTAL(TOP_TO_BOTTOM)
- if (vBottom < center) t.nearestListId = data.id;
- break;
- case 4:
- //单列VERTICAL(BOTTOM_TO_TOP)、网格HORIZONTAL(BOTTOM_TO_TOP)
- if (vTop > center) t.nearestListId = data.id;
- break;
- }
- }
- // cc.log('t.nearestListId =', t.nearestListId);
- }
- //上一页
- ;
- _proto.prePage = function prePage(timeInSecond) {
- if (timeInSecond === void 0) {
- timeInSecond = .5;
- }
- // cc.log('👈');
- if (!this.checkInited()) return;
- this.skipPage(this.curPageNum - 1, timeInSecond);
- }
- //下一页
- ;
- _proto.nextPage = function nextPage(timeInSecond) {
- if (timeInSecond === void 0) {
- timeInSecond = .5;
- }
- // cc.log('👉');
- if (!this.checkInited()) return;
- this.skipPage(this.curPageNum + 1, timeInSecond);
- }
- //跳转到第几页
- ;
- _proto.skipPage = function skipPage(pageNum, timeInSecond) {
- var t = this;
- if (!t.checkInited()) return;
- if (t._slideMode != SlideType.PAGE) return console.error('This function is not allowed to be called, Must SlideMode = PAGE!');
- if (pageNum < 0 || pageNum >= t._numItems) return;
- if (t.curPageNum == pageNum) return;
- // cc.log(pageNum);
- t.curPageNum = pageNum;
- if (t.pageChangeEvent) {
- EventHandler.emitEvents([t.pageChangeEvent], pageNum);
- }
- t.scrollTo(pageNum, timeInSecond);
- }
- //计算 CustomSize(这个函数还是保留吧,某些罕见的情况的确还是需要手动计算customSize的)
- ;
- _proto.calcCustomSize = function calcCustomSize(numItems) {
- var t = this;
- if (!t.checkInited()) return;
- if (!t._itemTmp) return console.error('Unset template item!');
- if (!t.renderEvent) return console.error('Unset Render-Event!');
- t._customSize = {};
- var temp = instantiate(t._itemTmp);
- var ut = temp.getComponent(UITransform);
- t.content.addChild(temp);
- for (var n = 0; n < numItems; n++) {
- EventHandler.emitEvents([t.renderEvent], temp, n);
- if (ut.height != t._itemSize.height || ut.width != t._itemSize.width) {
- t._customSize[n] = t._sizeType ? ut.height : ut.width;
- }
- }
- if (!Object.keys(t._customSize).length) t._customSize = null;
- temp.removeFromParent();
- if (temp.destroy) temp.destroy();
- return t._customSize;
- };
- _createClass(List, [{
- key: "slideMode",
- get: function get() {
- return this._slideMode;
- },
- set: function set(val) {
- this._slideMode = val;
- }
- }, {
- key: "virtual",
- get: function get() {
- return this._virtual;
- },
- set: function set(val) {
- if (val != null) this._virtual = val;
- if (this._numItems != 0) {
- this._onScrolling();
- }
- }
- }, {
- key: "updateRate",
- get: function get() {
- return this._updateRate;
- },
- set: function set(val) {
- if (val >= 0 && val <= 6) {
- this._updateRate = val;
- }
- }
- }, {
- key: "selectedId",
- get: function get() {
- return this._selectedId;
- },
- set: function set(val) {
- var t = this;
- var item;
- switch (t.selectedMode) {
- case SelectedType.SINGLE:
- {
- if (!t.repeatEventSingle && val == t._selectedId) return;
- item = t.getItemByListId(val);
- // if (!item && val >= 0)
- // return;
- var listItem;
- if (t._selectedId >= 0) t._lastSelectedId = t._selectedId;else
- //如果<0则取消选择,把_lastSelectedId也置空吧,如果以后有特殊需求再改吧。
- t._lastSelectedId = null;
- t._selectedId = val;
- if (item) {
- listItem = item.getComponent(ListItem);
- listItem.selected = true;
- }
- if (t._lastSelectedId >= 0 && t._lastSelectedId != t._selectedId) {
- var lastItem = t.getItemByListId(t._lastSelectedId);
- if (lastItem) {
- lastItem.getComponent(ListItem).selected = false;
- }
- }
- if (t.selectedEvent) {
- EventHandler.emitEvents([t.selectedEvent], item, val % this._actualNumItems, t._lastSelectedId == null ? null : t._lastSelectedId % this._actualNumItems);
- }
- break;
- }
- case SelectedType.MULT:
- {
- item = t.getItemByListId(val);
- if (!item) return;
- var _listItem = item.getComponent(ListItem);
- if (t._selectedId >= 0) t._lastSelectedId = t._selectedId;
- t._selectedId = val;
- var bool = !_listItem.selected;
- _listItem.selected = bool;
- var sub = t.multSelected.indexOf(val);
- if (bool && sub < 0) {
- t.multSelected.push(val);
- } else if (!bool && sub >= 0) {
- t.multSelected.splice(sub, 1);
- }
- if (t.selectedEvent) {
- EventHandler.emitEvents([t.selectedEvent], item, val % this._actualNumItems, t._lastSelectedId == null ? null : t._lastSelectedId % this._actualNumItems, bool);
- }
- break;
- }
- }
- }
- }, {
- key: "numItems",
- get: function get() {
- return this._actualNumItems;
- },
- set: function set(val) {
- var t = this;
- if (!t.checkInited(false)) return;
- if (val == null || val < 0) {
- console.error('numItems set the wrong::', val);
- return;
- }
- t._actualNumItems = t._numItems = val;
- t._forceUpdate = true;
- if (t._virtual) {
- t._resizeContent();
- if (t.cyclic) {
- t._numItems = t._cyclicNum * t._numItems;
- }
- t._onScrolling();
- if (!t.frameByFrameRenderNum && t.slideMode == SlideType.PAGE) t.curPageNum = t.nearestListId;
- } else {
- if (t.cyclic) {
- t._resizeContent();
- t._numItems = t._cyclicNum * t._numItems;
- }
- var layout = t.content.getComponent(Layout);
- if (layout) {
- layout.enabled = true;
- }
- t._delRedundantItem();
- t.firstListId = 0;
- if (t.frameByFrameRenderNum > 0) {
- //先渲染几个出来
- var len = t.frameByFrameRenderNum > t._numItems ? t._numItems : t.frameByFrameRenderNum;
- for (var n = 0; n < len; n++) {
- t._createOrUpdateItem2(n);
- }
- if (t.frameByFrameRenderNum < t._numItems) {
- t._updateCounter = t.frameByFrameRenderNum;
- t._updateDone = false;
- }
- } else {
- for (var _n4 = 0; _n4 < t._numItems; _n4++) {
- t._createOrUpdateItem2(_n4);
- }
- t.displayItemNum = t._numItems;
- }
- }
- }
- }, {
- key: "scrollView",
- get: function get() {
- return this._scrollView;
- }
- }]);
- return List;
- }(Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "templateType", [_dec5], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return TemplateType.NODE;
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "tmpNode", [_dec6], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "tmpPrefab", [_dec7], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "_slideMode", [_dec8], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return SlideType.NORMAL;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "slideMode", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "slideMode"), _class2.prototype), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "pageDistance", [_dec10], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return .3;
- }
- }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "pageChangeEvent", [_dec11], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return new EventHandler();
- }
- }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "_virtual", [_dec12], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return true;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "virtual", [_dec13], Object.getOwnPropertyDescriptor(_class2.prototype, "virtual"), _class2.prototype), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "cyclic", [_dec14], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "lackCenter", [_dec15], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "lackSlide", [_dec16], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "_updateRate", [_dec17], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "updateRate", [_dec18], Object.getOwnPropertyDescriptor(_class2.prototype, "updateRate"), _class2.prototype), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "frameByFrameRenderNum", [_dec19], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- }), _descriptor13 = _applyDecoratedDescriptor(_class2.prototype, "renderEvent", [_dec20], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return new EventHandler();
- }
- }), _descriptor14 = _applyDecoratedDescriptor(_class2.prototype, "selectedMode", [_dec21], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return SelectedType.NONE;
- }
- }), _descriptor15 = _applyDecoratedDescriptor(_class2.prototype, "selectedEvent", [_dec22], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return new EventHandler();
- }
- }), _descriptor16 = _applyDecoratedDescriptor(_class2.prototype, "repeatEventSingle", [_dec23], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor17 = _applyDecoratedDescriptor(_class2.prototype, "_numItems", [_dec24], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- })), _class2)) || _class) || _class) || _class) || _class) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ListItem.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './env'], function (exports) {
- var _applyDecoratedDescriptor, _inheritsLoose, _initializerDefineProperty, _assertThisInitialized, _createClass, cclegacy, _decorator, Sprite, Node, Enum, SpriteFrame, EventHandler, UITransform, tween, Vec3, Button, Component, DEV;
- return {
- setters: [function (module) {
- _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
- _inheritsLoose = module.inheritsLoose;
- _initializerDefineProperty = module.initializerDefineProperty;
- _assertThisInitialized = module.assertThisInitialized;
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- Sprite = module.Sprite;
- Node = module.Node;
- Enum = module.Enum;
- SpriteFrame = module.SpriteFrame;
- EventHandler = module.EventHandler;
- UITransform = module.UITransform;
- tween = module.tween;
- Vec3 = module.Vec3;
- Button = module.Button;
- Component = module.Component;
- }, function (module) {
- DEV = module.DEV;
- }],
- execute: function () {
- var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6;
- cclegacy._RF.push({}, "d2ed4KwTq5JtZePzUbNaDYC", "ListItem", undefined);
- /******************************************
- * @author kL <klk0@qq.com>
- * @date 2019/12/9
- * @doc 列表Item组件.
- * 说明:
- * 1、此组件须配合List组件使用。(配套的配套的..)
- * @end
- ******************************************/
- var ccclass = _decorator.ccclass,
- property = _decorator.property,
- disallowMultiple = _decorator.disallowMultiple,
- menu = _decorator.menu,
- executionOrder = _decorator.executionOrder;
- var SelectedType = /*#__PURE__*/function (SelectedType) {
- SelectedType[SelectedType["NONE"] = 0] = "NONE";
- SelectedType[SelectedType["TOGGLE"] = 1] = "TOGGLE";
- SelectedType[SelectedType["SWITCH"] = 2] = "SWITCH";
- return SelectedType;
- }(SelectedType || {});
- var ListItem = exports('default', (_dec = disallowMultiple(), _dec2 = menu('List Item'), _dec3 = executionOrder(-5001), _dec4 = property({
- type: Sprite,
- tooltip: DEV
- }), _dec5 = property({
- type: Node,
- tooltip: DEV
- }), _dec6 = property({
- type: Enum(SelectedType),
- tooltip: DEV
- }), _dec7 = property({
- type: Node,
- tooltip: DEV,
- visible: function visible() {
- return this.selectedMode > SelectedType.NONE;
- }
- }), _dec8 = property({
- type: SpriteFrame,
- tooltip: DEV,
- visible: function visible() {
- return this.selectedMode == SelectedType.SWITCH;
- }
- }), _dec9 = property({
- tooltip: DEV
- }), ccclass(_class = _dec(_class = _dec2(_class = _dec3(_class = (_class2 = /*#__PURE__*/function (_Component) {
- _inheritsLoose(ListItem, _Component);
- function ListItem() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- //图标
- _initializerDefineProperty(_this, "icon", _descriptor, _assertThisInitialized(_this));
- //标题
- _initializerDefineProperty(_this, "title", _descriptor2, _assertThisInitialized(_this));
- //选择模式
- _initializerDefineProperty(_this, "selectedMode", _descriptor3, _assertThisInitialized(_this));
- //被选标志
- _initializerDefineProperty(_this, "selectedFlag", _descriptor4, _assertThisInitialized(_this));
- //被选择的SpriteFrame
- _initializerDefineProperty(_this, "selectedSpriteFrame", _descriptor5, _assertThisInitialized(_this));
- //未被选择的SpriteFrame
- _this._unselectedSpriteFrame = null;
- //自适应尺寸
- _initializerDefineProperty(_this, "adaptiveSize", _descriptor6, _assertThisInitialized(_this));
- //选择
- _this._selected = false;
- //按钮组件
- _this._btnCom = void 0;
- //依赖的List组件
- _this.list = void 0;
- //是否已经注册过事件
- _this._eventReg = false;
- //序列id
- _this.listId = void 0;
- return _this;
- }
- var _proto = ListItem.prototype;
- _proto.onLoad = function onLoad() {
- // //没有按钮组件的话,selectedFlag无效
- // if (!this.btnCom)
- // this.selectedMode == SelectedType.NONE;
- //有选择模式时,保存相应的东西
- if (this.selectedMode == SelectedType.SWITCH) {
- var com = this.selectedFlag.getComponent(Sprite);
- this._unselectedSpriteFrame = com.spriteFrame;
- }
- };
- _proto.onDestroy = function onDestroy() {
- this.node.off(Node.EventType.SIZE_CHANGED, this._onSizeChange, this);
- };
- _proto._registerEvent = function _registerEvent() {
- if (!this._eventReg) {
- if (this.btnCom && this.list.selectedMode > 0) {
- this.btnCom.clickEvents.unshift(this.createEvt(this, 'onClickThis'));
- }
- if (this.adaptiveSize) {
- this.node.on(Node.EventType.SIZE_CHANGED, this._onSizeChange, this);
- }
- this._eventReg = true;
- }
- };
- _proto._onSizeChange = function _onSizeChange() {
- this.list._onItemAdaptive(this.node);
- }
- /**
- * 创建事件
- * @param {cc.Component} component 组件脚本
- * @param {string} handlerName 触发函数名称
- * @param {cc.Node} node 组件所在node(不传的情况下取component.node)
- * @returns cc.Component.EventHandler
- */;
- _proto.createEvt = function createEvt(component, handlerName, node) {
- if (node === void 0) {
- node = null;
- }
- if (!component.isValid) return; //有些异步加载的,节点以及销毁了。
- component['comName'] = component['comName'] || component.name.match(/\<(.*?)\>/g).pop().replace(/\<|>/g, '');
- var evt = new EventHandler();
- evt.target = node || component.node;
- evt.component = component['comName'];
- evt.handler = handlerName;
- return evt;
- };
- _proto.showAni = function showAni(aniType, callFunc, del) {
- var t = this;
- var twe;
- var ut = t.node.getComponent(UITransform);
- switch (aniType) {
- case 0:
- //向上消失
- twe = tween(t.node).to(.2, {
- scale: new Vec3(.7, .7)
- }).by(.3, {
- position: new Vec3(0, ut.height * 2)
- });
- break;
- case 1:
- //向右消失
- twe = tween(t.node).to(.2, {
- scale: new Vec3(.7, .7)
- }).by(.3, {
- position: new Vec3(ut.width * 2, 0)
- });
- break;
- case 2:
- //向下消失
- twe = tween(t.node).to(.2, {
- scale: new Vec3(.7, .7)
- }).by(.3, {
- position: new Vec3(0, ut.height * -2)
- });
- break;
- case 3:
- //向左消失
- twe = tween(t.node).to(.2, {
- scale: new Vec3(.7, .7)
- }).by(.3, {
- position: new Vec3(ut.width * -2, 0)
- });
- break;
- default:
- //默认:缩小消失
- twe = tween(t.node).to(.3, {
- scale: new Vec3(.1, .1)
- });
- break;
- }
- if (callFunc || del) {
- twe.call(function () {
- if (del) {
- t.list._delSingleItem(t.node);
- for (var n = t.list.displayData.length - 1; n >= 0; n--) {
- if (t.list.displayData[n].id == t.listId) {
- t.list.displayData.splice(n, 1);
- break;
- }
- }
- }
- callFunc();
- });
- }
- twe.start();
- };
- _proto.onClickThis = function onClickThis() {
- this.list.selectedId = this.listId;
- };
- _createClass(ListItem, [{
- key: "selected",
- get: function get() {
- return this._selected;
- },
- set: function set(val) {
- this._selected = val;
- if (!this.selectedFlag) return;
- switch (this.selectedMode) {
- case SelectedType.TOGGLE:
- this.selectedFlag.active = val;
- break;
- case SelectedType.SWITCH:
- var sp = this.selectedFlag.getComponent(Sprite);
- if (sp) {
- sp.spriteFrame = val ? this.selectedSpriteFrame : this._unselectedSpriteFrame;
- }
- break;
- }
- }
- }, {
- key: "btnCom",
- get: function get() {
- if (!this._btnCom) this._btnCom = this.node.getComponent(Button);
- return this._btnCom;
- }
- }]);
- return ListItem;
- }(Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "icon", [_dec4], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "title", [_dec5], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "selectedMode", [_dec6], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return SelectedType.NONE;
- }
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "selectedFlag", [_dec7], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "selectedSpriteFrame", [_dec8], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "adaptiveSize", [_dec9], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- })), _class2)) || _class) || _class) || _class) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/LocalStorageUtil.ts", ['cc'], function (exports) {
- var cclegacy, sys;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- sys = module.sys;
- }],
- execute: function () {
- cclegacy._RF.push({}, "d8e88J+Q9RPtY3fFaop4Z7i", "LocalStorageUtil", undefined);
- var LocalStorageUtil = exports('LocalStorageUtil', /*#__PURE__*/function () {
- LocalStorageUtil.getInstance = function getInstance() {
- if (!this._inst) this._inst = new LocalStorageUtil();
- return this._inst;
- }
- //缓存
- ;
- function LocalStorageUtil() {
- this.temporary = void 0;
- this._user_id = void 0;
- this.temporary = new Map();
- }
- var _proto = LocalStorageUtil.prototype;
- _proto.setUserId = function setUserId(uk) {
- this._user_id = uk;
- }
- /**
- * 缓存变量存储区别用户
- * @param {*} key
- * @param {*} value
- */;
- _proto.set = function set(key, value) {
- if (typeof value === 'object') {
- try {
- value = JSON.stringify(value);
- } catch (e) {
- console.error("\u89E3\u6790\u5931\u8D25\uFF0Cstr = " + value);
- return;
- }
- } else if (typeof value === 'number') {
- value = value + "";
- }
- if (this._user_id) sys.localStorage.setItem(this._user_id + "_" + key, value);else sys.localStorage.setItem(key, value);
- return value;
- }
- /**
- * 获取缓存变量区别用户
- * @param {*} key
- * @returns
- */;
- _proto.get = function get(key) {
- if (null == key) {
- console.error("存储的key不能为空");
- return null;
- }
- var data;
- if (this._user_id) data = sys.localStorage.getItem(this._user_id + "_" + key);else data = sys.localStorage.getItem(key);
- if (!data) return undefined;
- return data;
- }
- /** 获取指定关键字的数值 */;
- _proto.getNumber = function getNumber(key, defaultValue) {
- if (defaultValue === void 0) {
- defaultValue = 0;
- }
- var r = this.get(key);
- if (r == "0") {
- return Number(r);
- }
- return Number(r) || defaultValue;
- }
- /** 获取指定关键字的布尔值 */;
- _proto.getBoolean = function getBoolean(key) {
- var r = this.get(key);
- return Boolean(r) || false;
- }
- /** 获取指定关键字的JSON对象 */;
- _proto.getJson = function getJson(key, defaultValue) {
- var r = this.get(key);
- return r && JSON.parse(r) || defaultValue;
- }
- /** 获取指定关键字的JSON对象 */;
- _proto.getObject = function getObject(key) {
- var data = this.get(key);
- try {
- var jsonObj = JSON.parse(data);
- return jsonObj;
- } catch (error) {
- return data;
- }
- }
- /**
- * 删除缓存变量
- * @param {*} key
- */;
- _proto.removeNormalObject = function removeNormalObject(key) {
- sys.localStorage.removeItem(key);
- }
- /**
- * 缓存变量存储
- * @param {*} key
- * @param {*} value
- */;
- _proto.setNormalObject = function setNormalObject(key, value) {
- sys.localStorage.setItem(key, JSON.stringify(value));
- return value;
- }
- /**
- * 获取缓存变量
- * @param {*} key
- * @returns
- */;
- _proto.getNormalObject = function getNormalObject(key) {
- var data;
- data = sys.localStorage.getItem(key);
- if (!data) return undefined;
- try {
- var jsonObj = JSON.parse(data);
- return jsonObj;
- } catch (error) {
- return data;
- }
- }
- /**
- * 删除缓存变量
- * @param {*} key
- */;
- _proto.removeObject = function removeObject(key) {
- sys.localStorage.removeItem(key);
- }
- /**
- * 临时变量存储
- * @param {*} key
- * @param {*} value
- */;
- _proto.setTempObject = function setTempObject(key, value) {
- this.temporary.set(key, value);
- }
- /**
- * 获取临时变量
- * @param {*} key
- * @returns
- */;
- _proto.getTempObject = function getTempObject(key) {
- return this.temporary.get(key);
- }
- /**
- * 删除临时变量
- * @param {*} key
- */;
- _proto.removeTempObject = function removeTempObject(key) {
- this.temporary["delete"](key);
- };
- return LocalStorageUtil;
- }());
- LocalStorageUtil._inst = void 0;
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/main", ['./ModuleDef.ts', './SceneDef.ts', './audio.ts', './ch.ts', './ch_util.ts', './NetBase.ts', './NetPlayer.ts', './NetRoom.ts', './NetTeam.ts', './WsClient.ts', './net.ts', './ch_pvp.ts', './sign.ts', './ch_sdk_comp.ts', './ch_start_pack.ts', './ui.ts', './ui_ResolutionAutoFit.ts', './ui_base.ts', './ArrayUtil.ts', './DataTimeUtil.ts', './DirectorUtil.ts', './Instance.ts', './LocalStorageUtil.ts', './MathUtil.ts', './PathUtil.ts', './ProjectileMathUtil.ts', './ResUtil.ts', './StringUtil.ts', './TableLoadUtil.ts', './UrlUtil.ts', './Utils.ts', './Action.ts', './Container.ts', './Delay.ts', './FMS.ts', './GameData.ts', './HeadIcon.ts', './Line2DMove.ts', './PeriodData.ts', './PrefabPool.ts', './Queue.ts', './Random.ts', './SafeNumber.ts', './Shake.ts', './State.ts', './TimeJobCenter.ts', './Timer.ts', './Toast.ts', './Wait.ts', './ClickPenetrate.ts', './Game.ts', './List.ts', './ListItem.ts', './MotionTrail.ts', './MovieClip.ts', './RewardFly.ts', './SpineView.ts', './UISpineMovie.ts', './Start.ts'], function () {
- return {
- setters: [null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null],
- execute: function () {}
- };
- });
- System.register("chunks:///_virtual/MathUtil.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy, Vec3, Vec2, misc;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- Vec3 = module.Vec3;
- Vec2 = module.Vec2;
- misc = module.misc;
- }],
- execute: function () {
- cclegacy._RF.push({}, "5df23qNkJ5Jco4b72bZLJJf", "MathUtil", undefined);
- /** 用于计算的临时工 */
- var tempVec3 = new Vec3();
- /** 用于弧度转角度 */
- var rad2Deg = 180 / Math.PI;
- /** 用于角度转弧度 */
- var deg2Rad = Math.PI / 180;
- var MathUtil = exports('MathUtil', /*#__PURE__*/function () {
- function MathUtil() {}
- /**
- * 弧度转角度
- * @param radians
- */
- MathUtil.radiansToDegrees = function radiansToDegrees(radians) {
- return radians * rad2Deg;
- }
- /**
- * 角度转弧度
- * @param degree
- */;
- MathUtil.degreesToRadians = function degreesToRadians(degree) {
- return degree * deg2Rad;
- }
- /**限制数大小 */;
- MathUtil.Clamp = function Clamp(value, min, max) {
- if (value < min) {
- value = min;
- } else if (value > max) {
- value = max;
- }
- return value;
- };
- MathUtil.Clamp01 = function Clamp01(value) {
- return this.Clamp(value, 0, 1);
- };
- MathUtil.PingPong = function PingPong(t, length) {
- t = this.Repeat(t, length * 2);
- return length - Math.abs(t - length);
- };
- MathUtil.Repeat = function Repeat(t, length) {
- return t - Math.floor(t / length) * length;
- };
- MathUtil.Round = function Round(num) {
- return Math.floor(num + 0.5);
- };
- MathUtil.Sign = function Sign(num) {
- if (num > 0) {
- num = 1;
- } else if (num < 0) {
- num = -1;
- } else {
- num = 0;
- }
- return num;
- };
- MathUtil.InverseLerp = function InverseLerp(from, to, value) {
- if (from < to) {
- if (value < from) return 0;
- if (value > to) return 1;
- value = value - from;
- value = value / (to - from);
- return value;
- }
- if (from <= to) return 0;
- if (value < to) return 1;
- if (value > from) return 0;
- return 1 - (value - to) / (from - to);
- };
- MathUtil.Lerp = function Lerp(from, to, t) {
- return from + (to - from) * this.Clamp01(t);
- };
- MathUtil.LerpUnclamped = function LerpUnclamped(a, b, t) {
- return a + (b - a) * t;
- };
- MathUtil.DeltaAngle = function DeltaAngle(current, target) {
- var num = this.Repeat(target - current, 360);
- if (num > 180) num = num - 360;
- return num;
- };
- MathUtil.LerpAngle = function LerpAngle(a, b, t) {
- var num = this.Repeat(b - a, 360);
- if (num > 180) num = num - 360;
- return a + num * this.Clamp01(t);
- }
- /**
- * 在最小值和最大值之间进行插值,并在极限处进行平滑处理
- * @param from
- * @param to
- * @param t
- */;
- MathUtil.smoothStep = function smoothStep(from, to, t) {
- t = this.Clamp01(t);
- t = -2.0 * t * t * t + 3.0 * t * t;
- return to * t + from * (1.0 - t);
- }
- /**
- * 平滑控制
- * @param current 当前值
- * @param target 目标值
- * @param currentVelocity 当前速度
- * @param smoothTime 平滑时间
- * @param maxSpeed 最大速度
- * @param deltaTime 时间增量
- */;
- MathUtil.smoothDamp = function smoothDamp(current, target, currentVelocity, smoothTime, deltaTime, maxSpeed) {
- if (maxSpeed === void 0) {
- maxSpeed = Number.POSITIVE_INFINITY;
- }
- smoothTime = Math.max(0.0001, smoothTime);
- var num1 = 2 / smoothTime;
- var num2 = num1 * deltaTime;
- var num3 = 1 / (1 + num2 + 0.47999998927116394 * num2 * num2 + 0.23499999940395355 * num2 * num2 * num2);
- var num4 = current - target;
- var num5 = target;
- var max = maxSpeed * smoothTime;
- var num6 = this.Clamp(num4, -max, max);
- target = current - num6;
- var num7 = (currentVelocity + num1 * num6) * deltaTime;
- var velocity = (currentVelocity - num1 * num7) * num3;
- var num8 = target + (num6 + num7) * num3;
- if (num5 - current > 0 === num8 > num5) {
- num8 = num5;
- velocity = (num8 - num5) / deltaTime;
- }
- return {
- value: num8,
- velocity: velocity
- };
- }
- /**
- * 垂直于原向量V的单位向量
- * @param v 一个向量
- * @returns
- */;
- MathUtil.getPerpendicular = function getPerpendicular(v) {
- var perpendicular = new Vec2(-v.y, v.x); //计算垂直向量
- var normal = perpendicular.normalize(); //归一化
- return normal;
- }
- //角度转向量
- ;
- MathUtil.angleToVector = function angleToVector(angle) {
- return this.zore.clone().rotate(-misc.degreesToRadians(angle));
- }
- // 向量转角度
- ;
- MathUtil.vectorToAngle = function vectorToAngle(dir) {
- return -misc.radiansToDegrees(dir.signAngle(this.zore));
- }
- // 角度转向量
- ;
- MathUtil.angle_to_vector = function angle_to_vector(angle) {
- // tan = sin / cos
- // 将传入的角度转为弧度
- var radian = this.degreesToRadians(angle);
- // 算出cos,sin和tan
- var cos = Math.cos(radian); // 邻边 / 斜边
- var sin = Math.sin(radian); // 对边 / 斜边
- // 结合在一起并归一化
- var vec = new Vec2(cos, sin).normalize();
- // 返回向量
- return vec;
- }
- // !!!!!!!!其实使用Math.atan2求出弧度再转角度一样的效果
- // 向量转角度
- ;
- MathUtil.vector_to_angle = function vector_to_angle(dir) {
- // 将传入的向量归一化 一般已经归一化了
- //dir.normalize();
- // 计算出目标角度的弧度
- var radian = dir.signAngle(this.zore);
- // 把弧度计算成角度
- var angle = -this.radiansToDegrees(radian);
- // 返回角度
- return angle;
- }
- //向量转弧度
- ;
- MathUtil.vector_to_radian = function vector_to_radian(dir) {
- return dir.signAngle(this.zore);
- }
- /// <summary>
- /// 旋转向量,使其方向改变,大小不变
- /// </summary>
- /// <param name="v">需要旋转的向量</param>
- /// <param name="angle">旋转的角度</param>
- /// <returns>旋转后的向量</returns>
- ;
- MathUtil.RotationMatrix = function RotationMatrix(x, y, angle) {
- var radian = this.degreesToRadians(angle);
- var sin = Math.sin(radian);
- var cos = Math.cos(radian);
- var newX = x * cos + y * sin;
- var newY = x * -sin + y * cos;
- //var newX = x * cos - y * sin;
- //var newY = x * sin + y * cos;
- return new Vec2(newX, newY);
- };
- MathUtil.RotationDir = function RotationDir(dir, angle) {
- var radian = this.radiansToDegrees(angle);
- var sin = Math.sin(radian);
- var cos = Math.cos(radian);
- var newX = dir.x * cos + dir.y * sin;
- var newY = dir.x * -sin + dir.y * cos;
- dir.x = newX;
- dir.y = newY;
- return dir;
- }
- //扇形范围
- ;
- MathUtil.CheckInView = function CheckInView(mPos, faceDir, tPos, dis, angle) {
- //let t = tPos.subtract(mPos);
- //let distance = Vec2.lengthSqr(t);
- //if(distance<dis*dis)
- var distance = Vec2.distance(mPos, tPos);
- if (distance < dis) {
- if (angle >= 360) return true;
- var dir = tPos.subtract(mPos).normalize();
- var ang = this.radiansToDegrees(Vec2.angle(faceDir, dir));
- if (ang <= angle * 0.5) {
- return true;
- }
- }
- return false;
- }
- //检测点是否在一个凸四边形内
- ;
- MathUtil.InConvexQuad = function InConvexQuad(point, pointA, pointB, pointC, pointD) {
- var vec1, vec2;
- vec1.x = pointB.x - pointA.x;
- vec1.y = pointB.y - pointA.y;
- vec2.x = point.x - pointA.x;
- vec2.y = point.y - pointA.y;
- if (this.cross2DPoint(vec2.x, vec2.y, vec1.x, vec1.y)) return false;
- vec1.x = pointC.x - pointB.x;
- vec1.y = pointC.y - pointB.y;
- vec2.x = point.x - pointB.x;
- vec2.y = point.y - pointB.y;
- if (this.cross2DPoint(vec2.x, vec2.y, vec1.x, vec1.y)) return false;
- vec1.x = pointD.x - pointC.x;
- vec1.y = pointD.y - pointC.y;
- vec2.x = point.x - pointC.x;
- vec2.y = point.y - pointC.y;
- if (this.cross2DPoint(vec2.x, vec2.y, vec1.x, vec1.y)) return false;
- vec1.x = pointA.x - pointD.x;
- vec1.y = pointA.y - pointD.y;
- vec2.x = point.x - pointD.x;
- vec2.y = point.y - pointD.y;
- if (this.cross2DPoint(vec2.x, vec2.y, vec1.x, vec1.y)) return false;
- return true;
- }
- /**等同于Vec2.cross */;
- MathUtil.cross2DPoint = function cross2DPoint(x1, y1, x2, y2) {
- return x1 * y2 - x2 * y1;
- }
- /**检测两个2D包围盒(xy为中心点 wh分别为x轴半径宽 y轴半径宽) 是否相交*/;
- MathUtil.AABBAABB2D = function AABBAABB2D(pointX1, pointY1, w1, h1, pointX2, pointY2, w2, h2) {
- if (Math.abs(pointX1 - pointX2) > w1 + w2) return false;
- if (Math.abs(pointY1 - pointY2) > h1 + h2) return false;
- return true;
- }
- /**检测两个3D包围盒 是否相交*/;
- MathUtil.AABBAABB3D = function AABBAABB3D(pointX1, pointY1, pointZ1, w1, h1, t1, pointX2, pointY2, pointZ2, w2, h2, t2) {
- if (Math.abs(pointX1 - pointX2) > w1 + w2) return false;
- if (Math.abs(pointY1 - pointY2) > h1 + h2) return false;
- if (Math.abs(pointZ1 - pointZ2) > t1 + t2) return false;
- return true;
- }
- /**点与点*/;
- MathUtil.pointPoint = function pointPoint(point1, point2) {
- if (point1.x == point2.x && point1.y == point2.y) {
- return true;
- }
- return false;
- }
- //判断点是否在线上,在返回1,不在返回0
- ;
- MathUtil.onSegement = function onSegement(Q, p1, p2) {
- var maxx, minx, maxy, miny;
- maxx = p1.x > p2.x ? p1.x : p2.x; //矩形的右边长
- minx = p1.x > p2.x ? p2.x : p1.x; //矩形的左边长
- maxy = p1.y > p2.y ? p1.y : p2.y; //矩形的上边长
- miny = p1.y > p2.y ? p2.y : p1.y; //矩形的下边长
- if ((Q.x - p1.x) * (p2.y - p1.y) == (p2.x - p1.x) * (Q.y - p1.y) && Q.x >= minx && Q.x <= maxx && Q.y >= miny && Q.y <= maxy) {
- return true;
- }
- return false;
- }
- //点与圆的碰撞
- //通过计算点到圆心的距离与半径比较判断circle(由中心点和半径构成)
- ;
- MathUtil.pointInCircle = function pointInCircle(point, center, radius) {
- return Vec2.squaredDistance(point, center) <= radius * radius;
- }
- //点与矩形的碰撞
- //通过判断点坐标是否在矩形四个顶点围成的坐标区域内
- ;
- MathUtil.pointInRect = function pointInRect(point, rect) {
- if (point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height) return true;
- return false;
- }
- //线与矩形的碰撞
- ;
- MathUtil.lineInRect = function lineInRect(p1, p2, rect) {
- var height = p1.y - p2.y;
- var width = p2.x - p1.x;
- var c = p1.x * p2.y - p2.x - p1.y; //计算叉乘
- if (height * rect.xMin + width * rect.yMin + c >= 0 && height * rect.xMax + width * rect.yMax + c <= 0 || height * rect.xMin + width * rect.yMin + c <= 0 && height * rect.xMax + width * rect.yMax + c >= 0 || height * rect.xMin + width * rect.yMax + c >= 0 && height * rect.xMax + width * rect.yMin + c <= 0 || height * rect.xMin + width * rect.yMax + c <= 0 && height * rect.xMax + width * rect.yMin + c >= 0) {
- if (p1.x < rect.xMin && p2.x < rect.xMin || p1.x > rect.xMax && p2.x > rect.xMax || p1.y > rect.yMin && p2.y > rect.yMin || p1.y < rect.yMax && p2.y < rect.yMax) {
- return false;
- } else {
- return true;
- }
- } else {
- return false;
- }
- }
- //两个rect是否相交
- ;
- MathUtil.collisionRectWithRect = function collisionRectWithRect(rect1, rect2) {
- //计算相交部分的矩形
- //左下角坐标:( lx , ly ) //右上角坐标:( rx , ry )
- var lx = Math.max(rect1.xMin, rect2.xMin);
- var ly = Math.max(rect1.yMin, rect2.yMin);
- var rx = Math.min(rect1.xMax, rect2.xMax);
- var ry = Math.min(rect1.yMax, rect2.yMax);
- //判断是否能构成小矩形
- if (lx > rx || ly > ry) return false; //矩形不相交
- return true; //发生碰撞
- }
- //圆与矩形是否相交
- ;
- MathUtil.collisionRectWithCircle = function collisionRectWithCircle(rect, p, r) {
- //获取矩形信息
- //左下角坐标:( lx , ly )
- //右上角坐标:( rx , ry )
- var lx = rect.xMin;
- var ly = rect.yMin;
- var rx = rect.xMax;
- var ry = rect.yMax;
- //计算圆心到四个顶点的距离
- var d1 = Vec2.distance(p, new Vec2(lx, ly));
- var d2 = Vec2.distance(p, new Vec2(lx, ry));
- var d3 = Vec2.distance(p, new Vec2(rx, ly));
- var d4 = Vec2.distance(p, new Vec2(rx, ry));
- //判断是否碰撞//判断距离是否小于半径
- if (d1 < r || d2 < r || d3 < r || d4 < r) return true;
- //是否在圆角矩形的,横向矩形内
- if (p.x > lx - r && p.x < rx + r && p.y > ly && p.y < ry) return true;
- //是否在圆角矩形的,纵向矩形内
- if (p.x > lx && p.x < rx && p.y > ly - r && p.y < ry + r) return true;
- //不发生碰撞
- return false;
- }
- /**
- * 计算向量在指定平面上的投影
- * @param vector 被投影的向量
- * @param planeNormal 平面法线
- */;
- MathUtil.projectOnPlane = function projectOnPlane(vector, planeNormal) {
- // 也可以直接用 Vec3 自带的平面投影函数
- // return Vec3.projectOnPlane(new Vec3, targetDir, planeNormal);
- // 使用点乘计算方向矢量在平面法线上的投影长度
- var projectionLength = Vec3.dot(vector, planeNormal);
- // 平面法线与长度相乘得到方向矢量在平面法线上的投影矢量
- var vectorOnPlane = tempVec3.set(planeNormal).multiplyScalar(projectionLength);
- // 方向矢量减去其在平面法线上的投影矢量即是其在平面上的投影矢量
- return Vec3.subtract(new Vec3(), vector, vectorOnPlane);
- }
- /**
- * 计算两个向量基于指定轴的夹角(逆时针方向为正方向,值范围 -180 ~ 180)
- * @param a 向量 a
- * @param b 向量 b
- * @param axis 参照轴向量(请确保是归一化的)
- */;
- MathUtil.signedAngle = function signedAngle(a, b, axis) {
- // 将向量 a 和 b 分别投影到以 axis 为法线的平面上
- var aOnAxisPlane = this.projectOnPlane(a, axis);
- var bOnAxisPlane = this.projectOnPlane(b, axis);
- // 归一化处理
- var aNormalized = aOnAxisPlane.normalize();
- var bNormalized = bOnAxisPlane.normalize();
- // 求出同时垂直于 a 和 b 的法向量
- var abNormal = Vec3.cross(new Vec3(), aNormalized, bNormalized).normalize();
- // 将法向量到 axis 上的投影长度
- // 若投影长度为正值(+1)则表示法向量与 axis 同向(向量叉乘的右手法则)
- var sign = Vec3.dot(abNormal, axis);
- // 求出向量 a 和 b 的夹角
- var radian = Math.acos(Vec3.dot(aNormalized, bNormalized));
- // 混合在一起!
- return radian * sign * this.rad2Deg;
- }
- //获取某点到某点的Y轴方向
- ;
- MathUtil.GetYDir = function GetYDir(from, to) {
- var dir = to.subtract(from);
- dir.y = from.y;
- return dir.normalize();
- }
- //向量绕Y轴转一个角度
- ;
- MathUtil.RotateAroundAxisY = function RotateAroundAxisY(dir, angle) {
- dir = dir.clone();
- var rad = this.degreesToRadians(angle);
- var cos = Math.cos(rad);
- var sin = Math.sin(rad);
- dir.x = dir.x * cos + dir.z * sin;
- dir.z = dir.x * -sin + dir.z * cos;
- return dir;
- }
- //将一个向量围绕X轴旋转angle个角度
- ;
- MathUtil.RotateAroundAxisX = function RotateAroundAxisX(dir, angle) {
- dir = dir.clone();
- var rad = this.degreesToRadians(angle);
- var cos = Math.cos(rad);
- var sin = Math.sin(rad);
- dir.y = dir.y * cos - dir.z * sin;
- dir.z = dir.y * sin + dir.z * cos;
- return dir;
- }
- //将一个向量围绕Z轴旋转angle个角度
- ;
- MathUtil.RotateAroundAxisZ = function RotateAroundAxisZ(dir, angle) {
- dir = dir.clone();
- var rad = this.degreesToRadians(angle);
- var cos = Math.cos(rad);
- var sin = Math.sin(rad);
- dir.x = dir.x * cos - dir.y * sin;
- dir.y = dir.x * sin + dir.y * cos;
- return dir;
- }
- //线段是否与矩形相交
- ;
- MathUtil.LineRectIntersection = function LineRectIntersection(lineStartPoint, lineEndPoint, rectMinX, rectMaxX, rectMinY, rectMaxY) {
- //针对四种不同的情况,进行碰撞检测
- var minXLinePoint = lineEndPoint;
- if (lineStartPoint.x <= lineEndPoint.x) {
- minXLinePoint = lineStartPoint;
- }
- var maxXLinePoint = lineStartPoint;
- if (lineStartPoint.x <= lineEndPoint.x) {
- maxXLinePoint = lineEndPoint;
- }
- var minYLinePoint = lineEndPoint;
- if (lineStartPoint.y <= lineEndPoint.y) {
- minYLinePoint = lineStartPoint;
- }
- var maxYLinePoint = lineStartPoint;
- if (lineStartPoint.y <= lineEndPoint.y) {
- maxYLinePoint = lineEndPoint;
- }
- if (minXLinePoint.x <= rectMinX && rectMinX <= maxXLinePoint.x) {
- var m = (maxXLinePoint.y - minXLinePoint.y) / (maxXLinePoint.x - minXLinePoint.x);
- var intersectionY = (rectMinX - minXLinePoint.x) * m + minXLinePoint.y;
- if (minYLinePoint.y <= intersectionY && intersectionY <= maxYLinePoint.y && rectMinY <= intersectionY && intersectionY <= rectMaxY) {
- return true; //new Vec2(rectMinX, intersectionY)
- }
- }
- if (minXLinePoint.x <= rectMaxX && rectMaxX <= maxXLinePoint.x) {
- var _m = (maxXLinePoint.y - minXLinePoint.y) / (maxXLinePoint.x - minXLinePoint.x);
- var _intersectionY = (rectMaxX - minXLinePoint.x) * _m + minXLinePoint.y;
- if (minYLinePoint.y <= _intersectionY && _intersectionY <= maxYLinePoint.y && rectMinY <= _intersectionY && _intersectionY <= rectMaxY) {
- return true; //new Vec2(rectMaxX, intersectionY)
- }
- }
- if (minYLinePoint.y <= rectMaxY && rectMaxY <= maxYLinePoint.y) {
- var rm = (maxYLinePoint.x - minYLinePoint.x) / (maxYLinePoint.y - minYLinePoint.y);
- var intersectionX = (rectMaxY - minYLinePoint.y) * rm + minYLinePoint.x;
- if (minXLinePoint.x <= intersectionX && intersectionX <= maxXLinePoint.x && rectMinX <= intersectionX && intersectionX <= rectMaxX) {
- return true; //new Vec2(intersectionX, rectMaxY)
- }
- }
- if (minYLinePoint.y <= rectMinY && rectMinY <= maxYLinePoint.y) {
- var _rm = (maxYLinePoint.x - minYLinePoint.x) / (maxYLinePoint.y - minYLinePoint.y);
- var _intersectionX = (rectMinY - minYLinePoint.y) * _rm + minYLinePoint.x;
- if (minXLinePoint.x <= _intersectionX && _intersectionX <= maxXLinePoint.x && rectMinX <= _intersectionX && _intersectionX <= rectMaxX) {
- return true; //new Vec2(intersectionX, rectMinY)
- }
- }
- return false;
- };
- _createClass(MathUtil, null, [{
- key: "rad2Deg",
- get:
- /**
- * 用于弧度转角度
- */
- function get() {
- return rad2Deg;
- }
- /**
- * 用于角度转弧度
- */
- }, {
- key: "deg2Rad",
- get: function get() {
- return deg2Rad;
- }
- }]);
- return MathUtil;
- }());
- MathUtil.zore = new Vec2(1, 0);
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ModuleDef.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "755bdpf6lRIfLHpmBltN1fn", "ModuleDef", undefined);
- var ModuleDef = exports('ModuleDef', function ModuleDef() {});
- ModuleDef.BASIC = 'module_basic';
- ModuleDef.EXTRA = 'module_extra';
- ModuleDef.GAME = 'module_game';
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/MotionTrail.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _applyDecoratedDescriptor, _inheritsLoose, _initializerDefineProperty, _assertThisInitialized, _createClass, cclegacy, _decorator, SpriteFrame, CCInteger, CurveRange, GradientRange, UITransform, director, Director, UIRenderer, v2, DynamicAtlasManager;
- return {
- setters: [function (module) {
- _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
- _inheritsLoose = module.inheritsLoose;
- _initializerDefineProperty = module.initializerDefineProperty;
- _assertThisInitialized = module.assertThisInitialized;
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- SpriteFrame = module.SpriteFrame;
- CCInteger = module.CCInteger;
- CurveRange = module.CurveRange;
- GradientRange = module.GradientRange;
- UITransform = module.UITransform;
- director = module.director;
- Director = module.Director;
- UIRenderer = module.UIRenderer;
- v2 = module.v2;
- DynamicAtlasManager = module.DynamicAtlasManager;
- }],
- execute: function () {
- var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6;
- cclegacy._RF.push({}, "bb8ffN3AwpEqJr3cZDOVdXJ", "MotionTrail", undefined);
- var TrailData = function TrailData() {
- this.x = 0;
- this.y = 0;
- this.dis = 0;
- this.cos = 0;
- this.sin = 0;
- };
- var ccclass = _decorator.ccclass,
- property = _decorator.property,
- executeInEditMode = _decorator.executeInEditMode,
- menu = _decorator.menu;
- var MotionTrail = exports('default', (_dec = menu('Comp/MotionTrail'), _dec2 = executeInEditMode(), _dec3 = property({
- visible: false
- }), _dec4 = property({
- type: SpriteFrame,
- displayName: 'SpriteFrame'
- }), _dec5 = property({
- displayName: '世界坐标',
- tooltip: '顶点坐标是世界坐标还是本地坐标'
- }), _dec6 = property({
- displayName: '偏移'
- }), _dec7 = property({
- type: CCInteger,
- displayName: '拖尾长度'
- }), _dec8 = property({
- type: CurveRange,
- displayName: '宽度变化',
- range: [0, 1]
- }), _dec9 = property({
- type: CurveRange,
- displayName: '宽度变化',
- range: [0, 1]
- }), _dec10 = property({
- type: GradientRange,
- displayName: '颜色变化'
- }), _dec11 = property({
- type: GradientRange,
- displayName: '颜色变化'
- }), ccclass(_class = _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_UIRenderer) {
- _inheritsLoose(MotionTrail, _UIRenderer);
- function MotionTrail() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _UIRenderer.call.apply(_UIRenderer, [this].concat(args)) || this;
- _initializerDefineProperty(_this, "_spriteFrame", _descriptor, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_isWorldXY", _descriptor2, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "offset", _descriptor3, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_length", _descriptor4, _assertThisInitialized(_this));
- _this.trailData = [];
- _initializerDefineProperty(_this, "_sizeCurveRange", _descriptor5, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "_colorCurveRange", _descriptor6, _assertThisInitialized(_this));
- _this._useVertexOpacity = true;
- return _this;
- }
- var _proto = MotionTrail.prototype;
- _proto._render = function _render(render) {
- render.commitComp(this, this.renderData, this._spriteFrame, this._assembler, null);
- };
- _proto._flushAssembler = function _flushAssembler() {
- this._assembler = simple;
- if (!this._renderData) {
- this._renderData = this.requestRenderData();
- this._renderData.material = this.getRenderMaterial(0);
- this.freshBuffer();
- this.markForUpdateRenderData();
- if (this._spriteFrame) {
- this._assembler.updateUVs(this);
- }
- this._updateColor();
- }
- }
- //更新buffer
- ;
- _proto.freshBuffer = function freshBuffer() {
- var len = this.length;
- var count = 4 + (len - 2) * 2;
- this._renderData.dataLength = count;
- this._renderData.resize(count, (count - 2) * 3);
- };
- _proto.updateLength = function updateLength() {
- var trailLen = this.length;
- var sub = trailLen - this.trailData.length;
- if (sub > 0) {
- for (var i = 0; i < sub; ++i) {
- this.trailData.push(new TrailData());
- }
- } else if (sub < 0) {
- this.trailData.splice(trailLen);
- }
- };
- _proto.updateWidth = function updateWidth() {
- var data = this.trailData;
- var trailLen = this.length;
- var width = this.getComponent(UITransform).width / 2;
- for (var i = 0; i < trailLen; ++i) {
- data[i].dis = this.sizeCurveRange.evaluate(i / (trailLen - 1), 0) * width;
- }
- };
- _proto.resetPos = function resetPos() {
- var data = this.trailData;
- var tx = this.offset.x;
- var ty = this.offset.y;
- if (this.isWorldXY) {
- tx += this.node.worldPosition.x;
- ty += this.node.worldPosition.y;
- } else {
- tx += this.node.position.x;
- ty += this.node.position.y;
- }
- for (var i = 0, len = this.length; i < len; i++) {
- data[i].x = tx;
- data[i].y = ty;
- }
- };
- _proto.onLoad = function onLoad() {
- this.length = this._length;
- };
- _proto.onEnable = function onEnable() {
- _UIRenderer.prototype.onEnable.call(this);
- director.once(Director.EVENT_BEFORE_DRAW, this.resetPos, this);
- };
- _createClass(MotionTrail, [{
- key: "color",
- get: function get() {
- return this._color;
- }
- }, {
- key: "spriteFrame",
- get: function get() {
- return this._spriteFrame;
- },
- set: function set(value) {
- this._spriteFrame = value;
- }
- }, {
- key: "isWorldXY",
- get: function get() {
- return this._isWorldXY;
- },
- set: function set(value) {
- this._isWorldXY = value;
- }
- }, {
- key: "length",
- get: function get() {
- return this._length;
- },
- set: function set(value) {
- this._length = Math.max(value, 0);
- this.updateLength();
- this.updateWidth();
- this.resetPos();
- this.freshBuffer();
- }
- }, {
- key: "sizeCurveRange",
- get: function get() {
- return this._sizeCurveRange;
- },
- set: function set(value) {
- this._sizeCurveRange = value;
- this.updateWidth();
- }
- }, {
- key: "colorCurveRange",
- get: function get() {
- return this._colorCurveRange;
- },
- set: function set(value) {
- this._colorCurveRange = value;
- this._updateColor();
- }
- }]);
- return MotionTrail;
- }(UIRenderer), (_applyDecoratedDescriptor(_class2.prototype, "color", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "color"), _class2.prototype), _descriptor = _applyDecoratedDescriptor(_class2.prototype, "_spriteFrame", [property], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "spriteFrame", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "spriteFrame"), _class2.prototype), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "_isWorldXY", [property], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return true;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "isWorldXY", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "isWorldXY"), _class2.prototype), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "offset", [_dec6], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return v2(0, 0);
- }
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "_length", [property], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 20;
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "length", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "length"), _class2.prototype), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "_sizeCurveRange", [_dec8], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return new CurveRange();
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "sizeCurveRange", [_dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "sizeCurveRange"), _class2.prototype), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "_colorCurveRange", [_dec10], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return new GradientRange();
- }
- }), _applyDecoratedDescriptor(_class2.prototype, "colorCurveRange", [_dec11], Object.getOwnPropertyDescriptor(_class2.prototype, "colorCurveRange"), _class2.prototype)), _class2)) || _class) || _class) || _class));
- var simple = {
- updateRenderData: function updateRenderData(trail) {
- var frame = trail.spriteFrame;
- DynamicAtlasManager.instance.packToDynamicAtlas(trail, frame);
- this.updateUVs(trail); // dirty need
- //this.updateColor(sprite);// dirty need
- var renderData = trail.renderData;
- if (renderData && frame) {
- if (renderData.vertDirty) {
- this.updateVertexData(trail);
- }
- renderData.updateRenderData(trail, frame);
- }
- },
- updateWorldVerts: function updateWorldVerts(trail) {
- var renderData = trail.renderData;
- var vData = renderData.chunk.vb;
- var len = trail.length;
- if (len < 1) return;
- var tx = 0,
- ty = 0;
- var data = trail.trailData;
- if (!trail.isWorldXY) {
- tx = trail.node.position.x;
- ty = trail.node.position.y;
- }
- var ax = 0,
- ay = 0;
- var curIdx = 0;
- var tempData = null;
- var tempNextData = null;
- //
- for (var i = 0; i < len; ++i) {
- tempData = data[i];
- var sameIdx = i;
- for (; sameIdx < len; ++sameIdx) {
- tempNextData = data[sameIdx];
- if (tempNextData.x != tempData.x || tempNextData.y != tempData.y) {
- break;
- }
- }
- sameIdx -= 1;
- if (sameIdx == i) {
- ax = tempData.x - tx;
- ay = tempData.y - ty;
- vData[curIdx] = ax + tempData.dis * tempData.sin;
- vData[curIdx + 1] = ay - tempData.dis * tempData.cos;
- vData[curIdx + 2] = 0;
- curIdx += renderData.floatStride;
- vData[curIdx] = ax - tempData.dis * tempData.sin;
- vData[curIdx + 1] = ay + tempData.dis * tempData.cos;
- vData[curIdx + 2] = 0;
- curIdx += renderData.floatStride;
- } else {
- tempData = data[sameIdx];
- ax = tempData.x - tx;
- ay = tempData.y - ty;
- vData[curIdx] = ax + tempData.dis * tempData.sin;
- vData[curIdx + 1] = ay - tempData.dis * tempData.cos;
- vData[curIdx + 2] = 0;
- curIdx += renderData.floatStride;
- vData[curIdx] = ax - tempData.dis * tempData.sin;
- vData[curIdx + 1] = ay + tempData.dis * tempData.cos;
- vData[curIdx + 2] = 0;
- curIdx += renderData.floatStride;
- for (; i < sameIdx; ++i) {
- vData[curIdx] = vData[curIdx - renderData.floatStride * 2];
- vData[curIdx + 1] = vData[curIdx - renderData.floatStride * 2 + 1];
- vData[curIdx + 2] = 0;
- curIdx += renderData.floatStride;
- vData[curIdx] = vData[curIdx - renderData.floatStride * 2];
- vData[curIdx + 1] = vData[curIdx - renderData.floatStride * 2 + 1];
- vData[curIdx + 2] = 0;
- curIdx += renderData.floatStride;
- }
- }
- }
- },
- fillBuffers: function fillBuffers(trail) {
- if (trail.spriteFrame == null) return;
- var renderData = trail.renderData;
- var chunk = renderData.chunk;
- this.update(trail);
- this.updateWorldVerts(trail, chunk);
- // quick version
- var vidOrigin = chunk.vertexOffset;
- var meshBuffer = chunk.meshBuffer;
- var ib = chunk.meshBuffer.iData;
- var indexOffset = meshBuffer.indexOffset;
- var vid = vidOrigin;
- var len = trail.length - 1;
- for (var i = 0; i < len; i++) {
- ib[indexOffset++] = vid + 0;
- ib[indexOffset++] = vid + 1;
- ib[indexOffset++] = vid + 2;
- ib[indexOffset++] = vid + 1;
- ib[indexOffset++] = vid + 3;
- ib[indexOffset++] = vid + 2;
- vid += 2;
- }
- meshBuffer.indexOffset += len * 6;
- },
- updateVertexData: function updateVertexData(trail) {
- var renderData = trail.renderData;
- renderData.vertDirty = true;
- },
- updateUVs: function updateUVs(trail) {
- if (trail.spriteFrame == null) return;
- var renderData = trail.renderData;
- var vData = renderData.chunk.vb;
- var uv = trail.spriteFrame.uv;
- var length = trail.length - 1;
- var uvStep = length == 0 ? 0 : 1 / length;
- var curIdx = 3;
- var subV = uv[7] - uv[1];
- for (var i = 0; i < length; i++) {
- vData[curIdx] = uv[0];
- vData[curIdx + 1] = uv[1] + subV * i * uvStep;
- curIdx += renderData.floatStride;
- vData[curIdx] = uv[0];
- vData[curIdx + 1] = uv[3] + subV * i * uvStep;
- curIdx += renderData.floatStride;
- }
- vData[curIdx] = uv[0];
- vData[curIdx + 1] = uv[7];
- curIdx += renderData.floatStride;
- vData[curIdx] = uv[0];
- vData[curIdx + 1] = uv[5];
- curIdx += renderData.floatStride;
- },
- updateColor: function updateColor(trail) {
- var renderData = trail.renderData;
- var vData = renderData.chunk.vb;
- var total = 4 + (trail.length - 2) * 2;
- var stepTotal = trail.length;
- var stepIdx = -1;
- var colorOffset = 5;
- var curC, random;
- for (var i = 0; i < total; i++) {
- if (i % 2 == 0) {
- random = trail.colorCurveRange.mode === GradientRange.Mode.TwoGradients || trail.colorCurveRange.mode === GradientRange.Mode.TwoColors ? Math.random() : 0;
- curC = trail.colorCurveRange.evaluate(stepIdx / stepTotal, random);
- stepIdx++;
- }
- vData[colorOffset] = curC.r / 255;
- vData[colorOffset + 1] = curC.g / 255;
- vData[colorOffset + 2] = curC.b / 255;
- vData[colorOffset + 3] = curC.a / 255;
- colorOffset += renderData.floatStride;
- }
- },
- update: function update(trail) {
- if (trail.length === 0) return;
- var data = trail.trailData;
- for (var i = trail.length - 1; i > 0; --i) {
- var cur = data[i],
- prev = data[i - 1];
- cur.x = prev.x;
- cur.y = prev.y;
- cur.sin = prev.sin;
- cur.cos = prev.cos;
- }
- var pos = null;
- if (trail.isWorldXY) {
- pos = trail.node.worldPosition;
- } else {
- pos = trail.node.position;
- }
- var fristData = data[0];
- fristData.x = trail.offset.x + pos.x;
- fristData.y = trail.offset.y + pos.y;
- var secondData = data[1];
- var radian = Math.atan2(secondData.y - fristData.y, secondData.x - fristData.x);
- fristData.sin = Math.sin(radian);
- fristData.cos = Math.cos(radian);
- },
- updateOpacity: function updateOpacity(trail, alpha) {
- var renderData = trail.renderData;
- var vData = renderData.chunk.vb;
- var total = 4 + (trail.length - 2) * 2;
- var stepTotal = trail.length;
- var stepIdx = -1;
- var colorOffset = 5;
- var curC, random;
- for (var i = 0; i < total; i++) {
- if (i % 2 == 0) {
- random = trail.colorCurveRange.mode === GradientRange.Mode.TwoGradients || trail.colorCurveRange.mode === GradientRange.Mode.TwoColors ? Math.random() : 0;
- curC = trail.colorCurveRange.evaluate(stepIdx / stepTotal, random);
- stepIdx++;
- }
- vData[colorOffset + 3] = curC.a / 255 * alpha;
- colorOffset += renderData.floatStride;
- }
- }
- };
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/MovieClip.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _applyDecoratedDescriptor, _inheritsLoose, _initializerDefineProperty, _assertThisInitialized, cclegacy, _decorator, CCFloat, Texture2D, CCInteger, CCBoolean, Sprite, SpriteFrame, Rect, Vec2, Size, UITransform, Component;
- return {
- setters: [function (module) {
- _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
- _inheritsLoose = module.inheritsLoose;
- _initializerDefineProperty = module.initializerDefineProperty;
- _assertThisInitialized = module.assertThisInitialized;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- CCFloat = module.CCFloat;
- Texture2D = module.Texture2D;
- CCInteger = module.CCInteger;
- CCBoolean = module.CCBoolean;
- Sprite = module.Sprite;
- SpriteFrame = module.SpriteFrame;
- Rect = module.Rect;
- Vec2 = module.Vec2;
- Size = module.Size;
- UITransform = module.UITransform;
- Component = module.Component;
- }],
- execute: function () {
- var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11;
- cclegacy._RF.push({}, "008df+Vqs9NT7+AfYBNY6bw", "MovieClip", undefined);
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- /**
- * 动画播放器
- * @author
- *
- */
- var MovieClip = exports('default', (_dec = ccclass('MovieClip'), _dec2 = property({
- type: CCFloat
- }), _dec3 = property({
- type: Texture2D
- }), _dec4 = property({
- type: CCInteger
- }), _dec5 = property({
- type: CCInteger
- }), _dec6 = property({
- type: CCInteger
- }), _dec7 = property({
- type: CCInteger
- }), _dec8 = property(CCBoolean), _dec9 = property(CCBoolean), _dec10 = property(CCBoolean), _dec11 = property(CCFloat), _dec12 = property(CCFloat), _dec(_class = (_class2 = /*#__PURE__*/function (_Component) {
- _inheritsLoose(MovieClip, _Component);
- function MovieClip() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- /** Sprite渲染器 */
- _this.m_sprite = null;
- /** 动画计时间隔 每隔0.1s更新一帧 */
- _this.timer = 0.1;
- /** 播放 时间 间隔 */
- _initializerDefineProperty(_this, "interval", _descriptor, _assertThisInitialized(_this));
- /** 贴图文件名 */
- _initializerDefineProperty(_this, "texture", _descriptor2, _assertThisInitialized(_this));
- /** 播放次数 */
- _initializerDefineProperty(_this, "playTimes", _descriptor3, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "row", _descriptor4, _assertThisInitialized(_this));
- /** 图片切割成几列 */
- _initializerDefineProperty(_this, "col", _descriptor5, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "rowIndex", _descriptor6, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "isAll", _descriptor7, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "autoPlayOnLoad", _descriptor8, _assertThisInitialized(_this));
- /** 播放完自动销毁 */
- _initializerDefineProperty(_this, "autoDestroy", _descriptor9, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "begin", _descriptor10, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "end", _descriptor11, _assertThisInitialized(_this));
- /** 动画帧数 */
- _this.totalFrame = 8;
- /** 当前帧数 */
- _this.currentFrame = 0;
- /** 当前播放了第几次 */
- _this.currentTimes = 0;
- /** 影片是否在跑动中 */
- _this.running = true;
- //private _direction:number = 1;
- _this._playIndex = 0;
- _this._pieceWidth = 0;
- _this._pieceHeight = 0;
- _this._bitmapArr = [];
- return _this;
- }
- var _proto = MovieClip.prototype;
- _proto.onLoad = function onLoad() {
- //this. m_clips = new SpriteFrame[this.row][this.col];
- //Texture2D tex = Resources.Load<Texture2D>("Image/Avatar/" + m_sprite_name);
- //this.begin = 0;
- if (this.end == 0) {
- this.end = this.col;
- }
- this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1);
- this._pieceWidth = this.texture.width / this.col;
- this._pieceHeight = this.texture.height / this.row;
- this.m_sprite = this.getComponent(Sprite);
- if (!this.m_sprite) {
- this.m_sprite = this.addComponent(Sprite);
- }
- for (var i = 0; i < this.row; i++) {
- this._bitmapArr[i] = [];
- for (var j = 0; j < this.col; j++) {
- var spriteFrame = new SpriteFrame();
- spriteFrame.texture = this.texture;
- spriteFrame.rect = new Rect(j * this._pieceWidth, i * this._pieceHeight, this._pieceWidth, this._pieceHeight);
- spriteFrame.rotated = false;
- spriteFrame.offset = new Vec2(0, 0);
- spriteFrame.originalSize = new Size(this._pieceWidth, this._pieceHeight);
- this._bitmapArr[i][j] = spriteFrame;
- }
- }
- this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][0];
- this.m_sprite.spriteFrame.width;
- var uiTransform = this.getComponent(UITransform);
- if (uiTransform) {
- uiTransform.width = this._pieceWidth;
- uiTransform.height = this._pieceHeight;
- }
- this.timer = 0;
- this.running = this.autoPlayOnLoad;
- };
- _proto.update = function update(dt) {
- if (!this.running) return;
- if (this.playTimes != 0 && this.currentTimes == this.playTimes) {
- this.running = false;
- return;
- }
- this.timer -= dt;
- if (this.timer <= 0) {
- this.timer = this.interval;
- this.currentFrame = this.currentFrame % this.col;
- this.playAction();
- this.currentFrame++;
- if (this.currentFrame == this.col) {
- if (this.isAll) {
- this.rowIndex++;
- if (this.rowIndex == this.row) {
- this.currentTimes++;
- this.node.emit("completeTimes");
- if (this.playTimes != 0 && this.currentTimes == this.playTimes) {
- this.node.emit("complete");
- if (this.autoDestroy) {
- this.node.destroy();
- }
- }
- }
- this.rowIndex %= this.row;
- } else {
- this.currentTimes++;
- this.node.emit("completeTimes");
- if (this.playTimes != 0 && this.currentTimes == this.playTimes) {
- this.node.emit("complete");
- if (this.autoDestroy) {
- this.node.destroy();
- }
- }
- }
- }
- }
- };
- _proto.playAction = function playAction() {
- this.rowIndex = this.clamp(this.rowIndex, 0, this.row - 1);
- this._playIndex = this._playIndex % (this.end - this.begin) + this.begin;
- this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex];
- //this.m_sprite.spriteFrame.setRect(this.rect);
- this._playIndex++;
- }
- /** 播放影片 */;
- _proto.play = function play() {
- this.running = true;
- }
- /** 停止播放影片 */;
- _proto.stop = function stop() {
- this.running = false;
- }
- /**
- * 跳帧播放
- * @param frame 帧
- */;
- _proto.gotoAndPlay = function gotoAndPlay(frame) {
- this.running = true;
- this._playIndex = frame;
- this._playIndex = this.clamp(this._playIndex, 0, this.col - 1);
- }
- /**
- * 跳帧停止
- * @param frame 帧
- */;
- _proto.gotoAndStop = function gotoAndStop(frame) {
- this.running = false;
- this._playIndex = frame;
- this._playIndex = this.clamp(this._playIndex, 0, this.col - 1);
- this.m_sprite.spriteFrame = this._bitmapArr[this.rowIndex][this._playIndex];
- };
- _proto.clamp = function clamp(value, minLimit, maxLimit) {
- if (value < minLimit) {
- return minLimit;
- }
- if (value > maxLimit) {
- return maxLimit;
- }
- return value;
- };
- return MovieClip;
- }(Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "interval", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0.1;
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "texture", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "playTimes", [_dec4], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "row", [_dec5], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 4;
- }
- }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "col", [_dec6], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 4;
- }
- }), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "rowIndex", [_dec7], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- }), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "isAll", [_dec8], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "autoPlayOnLoad", [_dec9], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return true;
- }
- }), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "autoDestroy", [_dec10], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return false;
- }
- }), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "begin", [_dec11], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- }), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "end", [_dec12], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return 0;
- }
- })), _class2)) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/net.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './NetRoom.ts', './NetTeam.ts', './WsClient.ts'], function (exports) {
- var _createClass, _asyncToGenerator, _regeneratorRuntime, cclegacy, NetRoom, NetTeam, WsClient;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- _asyncToGenerator = module.asyncToGenerator;
- _regeneratorRuntime = module.regeneratorRuntime;
- }, function (module) {
- cclegacy = module.cclegacy;
- }, function (module) {
- NetRoom = module.NetRoom;
- }, function (module) {
- NetTeam = module.NetTeam;
- }, function (module) {
- WsClient = module.WsClient;
- }],
- execute: function () {
- cclegacy._RF.push({}, "3f10au8XnFG2b0ZjXy1nl0i", "net", undefined);
- /**自定义同步游戏变量(只能以r_或p_开头,按帧率同步,重新进入会收到最新的数据)
- * 只有第一个参数有效,可加上第一个参数跟第一个参数同类型,用于接收改变前的数据
- * t_开头为队伍事件
- * r_开头 主机游戏数据 主机权限
- * revt_ 开头房间事件
- * p_ 开头玩家数据 玩家权限和主机ai权限
- * online 玩家在线下线状态
- * 尽量拆分数据类型,不要设置过于复杂的数据类型*/
- /**网络状态*/
- function isArrayBuffer(it) {
- try {
- return it instanceof ArrayBuffer;
- } catch (_) {
- return false;
- }
- }
- var HEARTBEAT_INTERVAL = 1000; //每秒发送一次 Ping
- var HEARTBEAT_TIMEOUT = 30000; //30 秒的断线超时
- var DIRTYDATACHECK_INTERVAL = 200; //每200毫秒同步一次自定义游戏变量
- var EVTCHECK_INTERVAL = 66; //每66毫秒同步一次自定义游戏事件
- var RECONNECT_COUNT = 10; //默认重连次数
- var RECONNECT_INTERVAL = 2000; //默认重连间隔
- var PING = 'ping';
- var PONG = 'pong';
- //
- var S2C_LOGIN_SUCCESS = 's2c_login_success';
- var S2C_TEAM_SUCCESS = 's2c_team_success';
- var S2C_JOIN_TEAM_FAIL = 's2c_join_team_fail';
- var S2C_TEAM_USER_JOIN = 's2c_team_user_join';
- var S2C_TEAM_USER_EXIT = 's2c_team_user_exit';
- var S2C_TEAM_CHANGE_HOST = 's2c_team_change_host';
- var S2C_USER_RECONNECT = 's2c_user_reconnect';
- var S2C_USER_DISCONNECT = 's2c_user_disconnect';
- var S2C_MATCH = 's2c_match';
- var S2C_MATCH_SUCCESS = 's2c_match_success';
- var S2C_MATCH_CANCEL = 's2c_match_cancel';
- var S2C_ROOM_GAMEDATA_CHANGE = 's2c_room_gameData_change';
- var S2C_USER_GAMEDATA_CHANGE = 's2c_user_gameData_change';
- var S2C_ROOM_CHANGE_HOST = 's2c_room_change_host';
- var S2C_ROOM_CLOSED = 's2c_room_closed';
- var S2C_TALK = 's2c_talk';
- var S2C_FINISH = 's2c_finish';
- var S2C_SETTLEMENT = 's2c_settlement';
- var S2C_READY = 's2c_ready';
- var S2C_NOT_READY = 's2c_not_ready';
- //
- var C2S_UPDATE_USER_GAMEDATA = 'c2s_update_user_gameData';
- var C2S_UPDATE_ROOM_GAMEDATA = 'c2s_update_room_gameData';
- var C2S_SET_TEAM = 'c2s_set_team';
- var C2S_JOIN_TEAM = 'c2s_join_team';
- var C2S_EXIT_TEAM = 'c2s_exit_team';
- var C2S_CLOSE_ROOM = 'c2s_close_room';
- var C2S_ROOM_EXIT = 'c2s_room_exit';
- var C2S_MESSAGE = 'c2s_message';
- var C2S_MESSAGE_TO_HOST = 'c2s_message_to_host';
- var C2S_MESSAGE_TO_OTHER = 'c2s_message_without_self';
- var C2S_TALK = 'c2s_talk';
- var C2S_BACKED_RETURN = 'c2s_backed_return';
- var C2S_BACKED = 'c2s_to_backed';
- var C2S_FINISH = 'c2s_finish';
- //
- var Ver = '0.1.8';
- /**客户端*/
- var ch_net = exports('ch_net', /*#__PURE__*/function () {
- var _proto = ch_net.prototype;
- _proto._new_resolve = function _new_resolve(id) {
- var _this = this;
- return new Promise(function (resolve) {
- return _this._callbacks[id] = resolve;
- });
- };
- _proto._do_resolve = function _do_resolve(id, data) {
- var resolveCallback = this._callbacks[id];
- if (!resolveCallback) return false;
- resolveCallback(data);
- delete this._callbacks[id];
- return true;
- };
- /**
- * 创建一个客户端
- */
- function ch_net() {
- /**连接状态事件*/
- this.state = chsdk.get_new_event();
- this._ws = null;
- this._url = void 0;
- this._ca = void 0;
- this.reconnection = void 0;
- this.reconnectCount = void 0;
- this.reconnectInterval = void 0;
- this.timeoutInterval = void 0;
- this.gameDataInterval = void 0;
- this.gameEvtInterval = void 0;
- this.timeout = null;
- this.json = false;
- this.heartbeatInterval = null;
- // 心跳定时器
- this.dirtyDataCheckInterval = null;
- //变量同步定时器
- this.evtCheckInterval = null;
- //事件同步定时器
- this._currentReconnectCount = 0;
- this._pingTime = 0;
- this._ping = 0;
- //ping值
- this._callbacks = {};
- this._waitSends = [];
- this._lv = {
- LowerRank: 0,
- Rank: 0,
- Star: 0
- };
- this._team = void 0;
- this._room = void 0;
- this._waitSends = [];
- this._callbacks = {};
- }
- /**初始化
- * @param url - 连接的地址 'ws://localhost:3000'
- * @param options - 可选的配置选项对象,支持以下属性:
- * - **ca**: (可选) CA 证书字符串,用于 SSL 连接的验证。
- * - **reconnection**: (可选) 指示是否启用重连机制,默认为 `true`。
- * - **reconnectCount**: (可选) 在连接失败后重连的最大次数,默认值为 `10`。
- * - **reconnectInterval**: (可选) 每次重连之间的间隔时间,以毫秒为单位,默认值为 `2000` (2 秒)。
- * - **timeoutInterval**: (可选) 心跳断线时间,以毫秒为单位,默认值为 `30000` (30 秒)。
- * - **gameEvtInterval**:(可选) 游戏事件同步间隔,默认值为 `66` (0.06秒 1秒钟15次)。
- * - **gameDataInterval**:(可选) 游戏变量同步间隔,默认值为 `200` (0.2秒 1秒钟5次)。
- * - **json**: (可选) 是否用json序列化否则用messagepck 默认为 `false`。
- * @example
- * 自定义消息
- interface message extends message_protocol {
- useItem(userId: string, otherId: string, itemId: number): void//使用道具
- }
- 自定义数据
- export interface gd extends game_data {
- r_lv(lv: number);//关卡信息
- r_time(time: number);//关卡时间
- }
- export const net = ch.get_new_net<gd, message>();
- const url = chsdk.getUrl('/handle').replace(chsdk.getUrl('/handle').split(':')[0], 'ws');
- const token = chsdk.getToken();
- net.init(url,{query: `token=${token}`});
- */
- _proto.init = function init(url, options) {
- var _options$query, _options$reconnection, _options$reconnectCou, _options$reconnectInt, _options$timeoutInter, _options$gameDataInte, _options$gameEvtInter, _options$json;
- this._url = url;
- this._url = "" + this._url + (options != null && (_options$query = options.query) != null && _options$query.length ? '?' + options.query : '');
- this._ca = options == null ? void 0 : options.ca;
- this.reconnection = (_options$reconnection = options == null ? void 0 : options.reconnection) != null ? _options$reconnection : true;
- this.reconnectCount = (_options$reconnectCou = options == null ? void 0 : options.reconnectCount) != null ? _options$reconnectCou : RECONNECT_COUNT;
- this.reconnectInterval = (_options$reconnectInt = options == null ? void 0 : options.reconnectInterval) != null ? _options$reconnectInt : RECONNECT_INTERVAL;
- this.timeoutInterval = (_options$timeoutInter = options == null ? void 0 : options.timeoutInterval) != null ? _options$timeoutInter : HEARTBEAT_TIMEOUT;
- this.gameDataInterval = (_options$gameDataInte = options == null ? void 0 : options.gameDataInterval) != null ? _options$gameDataInte : DIRTYDATACHECK_INTERVAL;
- this.gameEvtInterval = (_options$gameEvtInter = options == null ? void 0 : options.gameEvtInterval) != null ? _options$gameEvtInter : EVTCHECK_INTERVAL;
- this.json = (_options$json = options == null ? void 0 : options.json) != null ? _options$json : false;
- this._ws = new WsClient(this._url, this._ca);
- this._ws.onConnected = this._onConnected.bind(this);
- this._ws.onError = this._onError.bind(this);
- this._ws.onClosing = this._onClosing.bind(this);
- this._ws.onClosed = this._onClosed.bind(this);
- this._ws.onMessage = this._onMessage.bind(this);
- var isbuffer = typeof ArrayBuffer !== 'undefined';
- console.log('ch_net 初始化 ver:', Ver, isbuffer, this.json, this._url);
- //
- chsdk.sdk_event.on('hide', this.on_hide, this);
- chsdk.sdk_event.on('show', this.on_show, this);
- }
- /**主动断开连接*/;
- _proto.dispose = function dispose() {
- this.state.clearAll();
- this._clear_team();
- this._clear_room();
- this._callbacks = {};
- this._waitSends.length = 0;
- this._ws.close(5000, 'client disconnect');
- chsdk.sdk_event.off('hide', this.on_hide, this);
- chsdk.sdk_event.off('show', this.on_show, this);
- };
- _proto.on_hide = function on_hide() {
- if (!this.inRoom) return;
- this.send_data(C2S_BACKED);
- };
- _proto.on_show = function on_show() {
- if (!this.inRoom) return;
- this.send_data(C2S_BACKED_RETURN);
- };
- _proto.encode = function encode(msg) {
- return this.json ? JSON.stringify(msg) : msgpack.encode(msg);
- };
- _proto.decode = function decode(medata) {
- return isArrayBuffer(medata) ? msgpack.decode(new Uint8Array(medata)) : JSON.parse(medata);
- };
- _proto.send_data = function send_data(type, data) {
- this._send(this.encode(data ? {
- type: type,
- data: data
- } : {
- type: type
- }));
- }
- /**开始连接,返回null为成功,否则为错误提示*/;
- _proto.connect = /*#__PURE__*/
- function () {
- var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) switch (_context.prev = _context.next) {
- case 0:
- if (this._ws) {
- _context.next = 3;
- break;
- }
- chsdk.log.error('not init');
- return _context.abrupt("return", 'not init');
- case 3:
- if (this._ws.connect()) {
- _context.next = 5;
- break;
- }
- return _context.abrupt("return", 'no netconnect');
- case 5:
- this.state.emit(this.state.key.Connecting);
- return _context.abrupt("return", this._new_resolve('connect'));
- case 7:
- case "end":
- return _context.stop();
- }
- }, _callee, this);
- }));
- function connect() {
- return _connect.apply(this, arguments);
- }
- return connect;
- }() /**主动重新连接*/;
- _proto.reconnect = function reconnect() {
- if (!this._ws) {
- chsdk.log.error('not init');
- return 'not init';
- }
- this._currentReconnectCount = 1;
- this.do_reconnect();
- };
- _proto.do_reconnect = function do_reconnect() {
- if (!this._ws.connect()) return;
- this.state.emit(this.state.key.Reconnecting, this._currentReconnectCount);
- }
- /**玩家创建队伍,返回null为成功,否则为错误提示*/;
- _proto.creat_team = /*#__PURE__*/
- function () {
- var _creat_team = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(player_count) {
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
- while (1) switch (_context2.prev = _context2.next) {
- case 0:
- if (player_count === void 0) {
- player_count = 4;
- }
- if (this._ws) {
- _context2.next = 3;
- break;
- }
- return _context2.abrupt("return", 'no netconnect');
- case 3:
- if (!this.inTeam) {
- _context2.next = 5;
- break;
- }
- return _context2.abrupt("return", null);
- case 5:
- this.send_data(C2S_SET_TEAM, player_count);
- return _context2.abrupt("return", this._new_resolve('creat_team'));
- case 7:
- case "end":
- return _context2.stop();
- }
- }, _callee2, this);
- }));
- function creat_team(_x) {
- return _creat_team.apply(this, arguments);
- }
- return creat_team;
- }() /**玩家进入队伍,返回null为成功,否则为错误提示*/;
- _proto.join_team = /*#__PURE__*/
- function () {
- var _join_team = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(password) {
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
- while (1) switch (_context3.prev = _context3.next) {
- case 0:
- if (this._ws) {
- _context3.next = 2;
- break;
- }
- return _context3.abrupt("return", 'no netconnect');
- case 2:
- if (!this.inTeam) {
- _context3.next = 4;
- break;
- }
- return _context3.abrupt("return", null);
- case 4:
- this.send_data(C2S_JOIN_TEAM, {
- password: password
- });
- return _context3.abrupt("return", this._new_resolve('join_team'));
- case 6:
- case "end":
- return _context3.stop();
- }
- }, _callee3, this);
- }));
- function join_team(_x2) {
- return _join_team.apply(this, arguments);
- }
- return join_team;
- }() /**玩家退出队伍,返回null为成功,否则为错误提示*/;
- _proto.exit_team = /*#__PURE__*/
- function () {
- var _exit_team = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
- while (1) switch (_context4.prev = _context4.next) {
- case 0:
- if (this._ws) {
- _context4.next = 2;
- break;
- }
- return _context4.abrupt("return", 'no netconnect');
- case 2:
- if (this.inTeam) {
- _context4.next = 4;
- break;
- }
- return _context4.abrupt("return", 'not in team');
- case 4:
- if (!this.inRoom) {
- _context4.next = 6;
- break;
- }
- return _context4.abrupt("return", 'in game');
- case 6:
- this.send_data(C2S_EXIT_TEAM);
- return _context4.abrupt("return", this._new_resolve('exit_team'));
- case 8:
- case "end":
- return _context4.stop();
- }
- }, _callee4, this);
- }));
- function exit_team() {
- return _exit_team.apply(this, arguments);
- }
- return exit_team;
- }() /**主机结束游戏关闭房间,成功后收到房间关闭事件*/;
- _proto.close_room = function close_room() {
- if (!this._ws) return;
- if (!this.inRoom) return;
- if (!this.room.isHost) return;
- this.send_data(C2S_CLOSE_ROOM);
- }
- /**玩家退出房间 ,返回null为成功,否则为错误提示,退出成功后收到房间关闭事件*/;
- _proto.exit_room = /*#__PURE__*/
- function () {
- var _exit_room = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
- while (1) switch (_context5.prev = _context5.next) {
- case 0:
- if (this._ws) {
- _context5.next = 2;
- break;
- }
- return _context5.abrupt("return", 'no netconnect');
- case 2:
- if (this.inRoom) {
- _context5.next = 4;
- break;
- }
- return _context5.abrupt("return", 'not in room');
- case 4:
- this.send_data(C2S_ROOM_EXIT);
- return _context5.abrupt("return", this._new_resolve('exit_room'));
- case 6:
- case "end":
- return _context5.stop();
- }
- }, _callee5, this);
- }));
- function exit_room() {
- return _exit_room.apply(this, arguments);
- }
- return exit_room;
- }();
- _proto._clear_team = function _clear_team() {
- var _this$_team;
- (_this$_team = this._team) == null || _this$_team.dispose();
- this._team = null;
- };
- _proto._clear_room = function _clear_room() {
- var _this$_room;
- if (!this._room) return;
- (_this$_room = this._room) == null || _this$_room.dispose();
- this._room = null;
- };
- _proto._send = function _send(data) {
- if (!this._ws) return;
- if (this._ws.isActive) {
- this._ws.send(data);
- } else {
- this._waitSends.push(data);
- }
- };
- _proto._updatePlayerStatus = function _updatePlayerStatus(id, online) {
- if (this.inTeam) this._team.updatePlayerStatus(id, online);
- if (this.inRoom) this._room.updatePlayerStatus(id, online);
- }
- //
- ;
- _proto._onMessage = function _onMessage(msg) {
- this.resetHeartbeat();
- try {
- var medata = msg.data;
- var _data = this.decode(medata);
- if (_data.type !== PONG) chsdk.log.log('receive', JSON.stringify(_data));
- switch (_data.type) {
- case PONG:
- this._ping = chsdk.date.now() - this._pingTime;
- chsdk.date.updateServerTime(_data.data);
- //chsdk.log.log("pong:", this._ping, data.data, chsdk.date.now());
- break;
- case S2C_LOGIN_SUCCESS:
- this._lv = _data.data;
- if (this._do_resolve('connect', null)) {
- this.state.emit(this.state.key.Connected);
- } else {
- this.state.emit(this.state.key.Reconnected);
- }
- this._callbacks = {};
- this.startHeartbeat();
- while (this._waitSends.length) {
- if (!this._ws) break;
- var _data2 = this._waitSends.shift();
- if (_data2) this._ws.send(_data2);
- }
- break;
- case S2C_TEAM_SUCCESS:
- if (this._team) this._clear_team();
- this._team = new NetTeam(_data.data, this.send_data.bind(this));
- if (!this._do_resolve('creat_team', null)) this._do_resolve('join_team', null);
- break;
- case S2C_JOIN_TEAM_FAIL:
- this._do_resolve('join_team', _data.data);
- break;
- case S2C_TEAM_USER_JOIN:
- var join_user = _data.data;
- join_user.status = true;
- this._team.addPlayer({
- key: join_user.userKey,
- data: join_user
- }, true);
- break;
- case S2C_TEAM_USER_EXIT:
- var esit_id = _data.data;
- if (esit_id === this._team.own.Id) {
- this._team.closed();
- this._clear_team();
- this._do_resolve('exit_team', null);
- } else {
- this._team.removePlayer(esit_id);
- }
- break;
- case S2C_TEAM_CHANGE_HOST:
- this._team.changeHost(_data.data);
- break;
- case S2C_ROOM_CHANGE_HOST:
- this._room.changeHost(_data.data);
- break;
- case S2C_USER_RECONNECT:
- this._updatePlayerStatus(_data.data, true);
- break;
- case S2C_USER_DISCONNECT:
- this._updatePlayerStatus(_data.data, false);
- break;
- case S2C_MATCH:
- this._team.match_start();
- break;
- case S2C_MATCH_CANCEL:
- this._team.match_cancel();
- break;
- case S2C_NOT_READY:
- this._team.not_ready();
- break;
- case S2C_READY:
- this._team.updatePlayerReady(_data.data, true);
- break;
- case S2C_MATCH_SUCCESS:
- this._clear_room();
- var roomData = _data.data.roomData;
- var pData = _data.data.playerData;
- this._room = new NetRoom(roomData, pData);
- if (this._team) this._team.match_success();
- break;
- case S2C_ROOM_GAMEDATA_CHANGE:
- this._room.server_change(_data.data);
- break;
- case S2C_USER_GAMEDATA_CHANGE:
- var p = this._room.getPlayer(_data.data.userKey);
- if (!p) break;
- p.server_change(_data.data.data);
- break;
- case S2C_ROOM_CLOSED:
- this._room.closed(_data.data);
- if (this.inTeam) {
- var list = this.room.all;
- for (var i = 0; i < list.length; i++) {
- var rp = list[i];
- if (rp.isAI) continue;
- var _p = this.team.getPlayer(rp.Id);
- if (!_p) continue;
- _p.set_level(rp.level, rp.rank, rp.score, rp.totalRank);
- }
- }
- this._do_resolve('exit_room', null);
- break;
- case S2C_TALK:
- if (this.inRoom) {
- this._room.onChat(_data.data.userKey, _data.data.msg);
- } else if (this.inTeam) {
- this._team.onChat(_data.data.userKey, _data.data.msg);
- }
- break;
- case S2C_FINISH:
- this._room.finish(_data.data.userKey, _data.data.rank);
- break;
- case S2C_SETTLEMENT:
- this._room.settlement(_data.data);
- break;
- case C2S_MESSAGE:
- if (Array.isArray(_data.data)) {
- for (var _i = 0; _i < _data.data.length; _i++) {
- var d = _data.data[_i];
- this._room._onEvt(d.type, d.data);
- }
- } else {
- chsdk.log.log('no def type:', _data.data);
- //(this.receive as any)._emit(data.type, data.data);
- }
- break;
- default:
- break;
- }
- } catch (error) {
- chsdk.log.warn(error);
- this.state.emit(this.state.key.Error, error);
- }
- };
- _proto._onConnected = function _onConnected(evt) {
- var _this2 = this;
- if (this.timeout) clearTimeout(this.timeout);
- this._currentReconnectCount = 0;
- this.timeout = setTimeout(function () {
- _this2._ws.close();
- chsdk.log.error("Closing connection.");
- }, 3000);
- };
- _proto._onError = function _onError(err) {
- chsdk.log.log('err', err);
- this.state.emit(this.state.key.Error, err);
- };
- _proto._onClosing = function _onClosing() {
- chsdk.log.log('closing');
- this.state.emit(this.state.key.Connecting);
- };
- _proto._onClosed = function _onClosed(event) {
- var _this3 = this;
- chsdk.log.log("WebSocket connection closed", event);
- this.stopHeartbeat();
- if (!this.reconnection || event.reason && event.code > 4000) {
- this.state.emit(this.state.key.Closed, event);
- this._do_resolve('connect', event);
- chsdk.log.log("WebSocket connection closed", event);
- return;
- }
- if (this._currentReconnectCount < this.reconnectCount) {
- this._currentReconnectCount += 1;
- chsdk.log.log("Reconnecting... Attempt " + this._currentReconnectCount);
- setTimeout(function () {
- _this3.do_reconnect();
- }, this.reconnectInterval);
- } else {
- chsdk.log.error("Max reconnect attempts reached. Giving up.");
- this.state.emit(this.state.key.Closed, event);
- this._do_resolve('connect', event);
- }
- };
- _proto.startHeartbeat = function startHeartbeat() {
- var _this4 = this;
- this.heartbeatInterval = setInterval(function () {
- _this4.sendHeartbeat();
- }, HEARTBEAT_INTERVAL);
- this.dirtyDataCheckInterval = setInterval(function () {
- _this4.dirtyDataCheck();
- }, this.gameDataInterval);
- this.evtCheckInterval = setInterval(function () {
- _this4.evtCheck();
- }, this.gameEvtInterval);
- };
- _proto.resetHeartbeat = function resetHeartbeat() {
- var _this5 = this;
- if (this.timeout) clearTimeout(this.timeout);
- this.timeout = setTimeout(function () {
- chsdk.log.error("Heartbeat timeout. Closing connection.");
- _this5._ws.close();
- }, this.timeoutInterval);
- };
- _proto.sendHeartbeat = function sendHeartbeat() {
- this._pingTime = chsdk.date.now();
- this.send_data(PING, this._ping);
- };
- _proto.stopHeartbeat = function stopHeartbeat() {
- if (this.heartbeatInterval) clearInterval(this.heartbeatInterval);
- if (this.timeout) clearTimeout(this.timeout);
- if (this.dirtyDataCheckInterval) clearInterval(this.dirtyDataCheckInterval);
- if (this.evtCheckInterval) clearInterval(this.evtCheckInterval);
- };
- _proto.evtCheck = function evtCheck() {
- var _this6 = this;
- if (this.inRoom) {
- this.room.doSendChat(function (msg) {
- if (!msg) return;
- _this6.send_data(C2S_TALK, msg);
- });
- this.room.doSendMode(function (mode0, mode1, mode2) {
- if (mode0.length > 0) _this6.send_data(C2S_MESSAGE, mode0);
- if (mode1.length > 0) _this6.send_data(C2S_MESSAGE_TO_HOST, mode1);
- if (mode2.length > 0) _this6.send_data(C2S_MESSAGE_TO_OTHER, mode2);
- });
- var ps = this.room.all;
- var _loop = function _loop() {
- var p = ps[i];
- p.doFinishGame(function () {
- _this6.send_data(C2S_FINISH, p.Id);
- });
- };
- for (var i = 0; i < ps.length; i++) {
- _loop();
- }
- } else if (this.inTeam) {
- this.team.doSendChat(function (msg) {
- if (!msg) return;
- _this6.send_data(C2S_TALK, msg);
- });
- }
- };
- _proto.dirtyDataCheck = function dirtyDataCheck() {
- var _this7 = this;
- if (!this.inRoom) return;
- this.room.own.doDirtyData(function (dirty) {
- _this7.send_data(C2S_UPDATE_USER_GAMEDATA, {
- userKey: _this7.room.own.Id,
- data: dirty
- });
- });
- if (!this.room.isHost) return;
- this._room.doDirtyData(function (dirty) {
- _this7.send_data(C2S_UPDATE_ROOM_GAMEDATA, dirty);
- });
- var ais = this.room.all;
- var _loop2 = function _loop2() {
- var ai = ais[i];
- ai.doDirtyData(function (dirty) {
- _this7.send_data(C2S_UPDATE_USER_GAMEDATA, {
- userKey: ai.Id,
- data: dirty
- });
- });
- };
- for (var i = 0; i < ais.length; i++) {
- _loop2();
- }
- }
- /**
- * 分享队伍信息,邀请进队
- * @param extend (可选)分享数据
- * @param title 分享显示标题
- * @param imageUrl 分享显示图片
- */;
- _proto.shareNetTeam = function shareNetTeam(title, imageUrl, extend) {
- if (!this.inTeam) return;
- chsdk.shareAppMessage(title, '', imageUrl, JSON.stringify({
- type: 'NetTeam',
- pw: this.team.Password,
- "extends": extend
- }));
- }
- /**
- *获取从好友分享的net数据进入游戏的数据
- */;
- _proto.getShareNetTeam = function getShareNetTeam() {
- var query = chsdk.getQuery();
- if (!query) return null;
- var message = query.message;
- if (!message) return null;
- var data = JSON.parse(message);
- if (!data) return null;
- if (data.type != 'NetTeam') return null;
- query.message = null;
- return {
- password: data.pw,
- extend: data["extends"]
- };
- };
- _createClass(ch_net, [{
- key: "ownLevel",
- get: function get() {
- return this._lv;
- }
- }, {
- key: "dataInterval",
- get: function get() {
- return this.gameDataInterval * 0.001;
- }
- }, {
- key: "evtInterval",
- get: function get() {
- return this.gameEvtInterval * 0.001;
- }
- }, {
- key: "isActive",
- get: function get() {
- return this._ws && this._ws.isActive;
- }
- }, {
- key: "team",
- get: /**队伍信息*/
- function get() {
- return this._team;
- }
- /**是否在队伍中*/
- }, {
- key: "inTeam",
- get: function get() {
- return this._team != null && this._team.own != null;
- }
- /**房间信息*/
- }, {
- key: "room",
- get: function get() {
- return this._room;
- }
- /**是否在房间中*/
- }, {
- key: "inRoom",
- get: function get() {
- return this._room != null && !this._room.cloosed;
- }
- }]);
- return ch_net;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/NetBase.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "ee4ceP8Y6tOb7rdImpQdJVo", "NetBase", undefined);
- /**网络变量基类*/
- var NetBase = exports('NetBase', /*#__PURE__*/function () {
- function NetBase(id) {
- this._id = void 0;
- this.dataMap = {};
- this.dirtyMap = {};
- this._id = id;
- this.dataMap = {};
- }
- /**初始变量值*/
- var _proto = NetBase.prototype;
- _proto.initValue = function initValue(data) {
- this.dataMap = data != null ? data : {};
- }
- /**修改某个键的值*/;
- _proto.setValue = function setValue(key, value) {
- this.dataMap[key] = value;
- };
- _proto.setValueDirty = function setValueDirty(key, value) {
- this.dirtyMap[key] = value;
- }
- /**获取数据的值*/;
- _proto.getValue = function getValue(key) {
- return this.dataMap[key];
- }
- /**处理脏数据*/;
- _proto.doDirtyData = function doDirtyData(f) {
- if (Object.keys(this.dirtyMap).length === 0) return null;
- f(this.dirtyMap);
- this.dirtyMap = {};
- };
- _proto.dispose = function dispose() {
- this.dataMap = {};
- this.dirtyMap = {};
- };
- _createClass(NetBase, [{
- key: "Id",
- get: function get() {
- return this._id;
- }
- }]);
- return NetBase;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/NetPlayer.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './NetBase.ts'], function (exports) {
- var _inheritsLoose, _createClass, cclegacy, NetBase;
- return {
- setters: [function (module) {
- _inheritsLoose = module.inheritsLoose;
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }, function (module) {
- NetBase = module.NetBase;
- }],
- execute: function () {
- cclegacy._RF.push({}, "6fc05FzfGNCnJsa3eEcsw94", "NetPlayer", undefined);
- /**网络玩家*/
- var NetPlayer = exports('NetPlayer', /*#__PURE__*/function (_NetBase) {
- _inheritsLoose(NetPlayer, _NetBase);
- function NetPlayer() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _NetBase.call.apply(_NetBase, [this].concat(args)) || this;
- _this.evt = chsdk.get_new_event();
- _this._location = 0;
- _this._online = true;
- _this._ready = false;
- _this._score = 0;
- _this._rank = 0;
- _this._totalRank = 0;
- _this._ishost = true;
- _this._userData = void 0;
- _this._rankInfo = void 0;
- _this._canAI = false;
- _this._finsh_tag = false;
- return _this;
- }
- var _proto = NetPlayer.prototype;
- _proto.init = function init(pd) {
- var _pd$status;
- this._location = pd.location;
- this._online = (_pd$status = pd.status) != null ? _pd$status : true;
- this._ready = pd.teamReady;
- this._score = pd.score;
- this._rank = pd.rank;
- this._totalRank = pd.TotalRank;
- this._userData = pd.userData;
- this._userData.hid = Number.parseInt(pd.userData.hid);
- this._userData.loginTime = Number.parseInt(pd.userData.loginTime);
- this._userData.registerTime = Number.parseInt(pd.userData.registerTime);
- this._userData.userId = Number.parseInt(pd.userData.userId);
- this._rankInfo = pd.userRank;
- if (pd.gameData) this.initValue(pd.gameData);
- };
- _proto.set_level = function set_level(level, rank, score, totalRank) {
- this._rankInfo = level;
- this._rank = rank;
- this._totalRank = totalRank;
- this._score = score;
- };
- _proto.set_host = function set_host(isHost, ownHost) {
- this._ishost = isHost;
- this._canAI = this.isAI && ownHost;
- };
- _proto.change_online = function change_online(ol) {
- this._online = ol;
- this.evt._emit('online', this._online);
- };
- _proto.change_ready = function change_ready(ready) {
- this._ready = ready;
- this.evt._emit('ready', this._ready);
- }
- /**修改某个键的值*/;
- _proto.setValue = function setValue(key, data) {
- if (!this.isPermission) return;
- var old = _NetBase.prototype.getValue.call(this, key);
- if (old) {
- if (typeof old === "object") ;else if (data === old) {
- return;
- }
- }
- _NetBase.prototype.setValue.call(this, key, data);
- _NetBase.prototype.setValueDirty.call(this, key, data);
- this.evt._emit(key, data, old);
- }
- /**获取数据的值*/;
- _proto.getValue = function getValue(key) {
- return _NetBase.prototype.getValue.call(this, key);
- }
- //服务器发送过来的数据
- ;
- _proto.server_change = function server_change(data) {
- var _this2 = this;
- if (this.isPermission) return;
- Object.keys(data).forEach(function (key) {
- var old = _NetBase.prototype.getValue.call(_this2, key);
- _NetBase.prototype.setValue.call(_this2, key, data[key]);
- _this2.evt._emit(key, data[key], old);
- });
- };
- _proto.setFinish = function setFinish(rank) {
- this._rank = rank;
- this.evt._emit('finish', this._rank);
- };
- /**玩家完成游戏 不是自己或主机没有权限*/
- _proto.finishGame = function finishGame() {
- if (!this.isPermission) return;
- this._finsh_tag = true;
- };
- _proto.doFinishGame = function doFinishGame(f) {
- if (this._finsh_tag) f(this.Id);
- this._finsh_tag = false;
- };
- _proto.dispose = function dispose() {
- _NetBase.prototype.dispose.call(this);
- this.evt.clearAll();
- };
- _createClass(NetPlayer, [{
- key: "score",
- get: function get() {
- return this._score;
- }
- }, {
- key: "rank",
- get: function get() {
- return this._rank;
- }
- }, {
- key: "totalRank",
- get: function get() {
- return this._totalRank;
- }
- }, {
- key: "location",
- get: /**房间位置0开头*/
- function get() {
- return this._location;
- }
- }, {
- key: "gid",
- get: function get() {
- return this._userData.gid;
- }
- }, {
- key: "head",
- get: function get() {
- return this._userData.head;
- }
- }, {
- key: "hid",
- get: function get() {
- return this._userData.hid;
- }
- }, {
- key: "province",
- get: function get() {
- var _chsdk$provinceCode2N;
- return (_chsdk$provinceCode2N = chsdk.provinceCode2Name(this._userData.hid)) != null ? _chsdk$provinceCode2N : '其它';
- }
- }, {
- key: "ip",
- get: function get() {
- return this._userData.ip;
- }
- }, {
- key: "loginTime",
- get: function get() {
- return this._userData.loginTime;
- }
- }, {
- key: "nickName",
- get: function get() {
- return this._userData.nickName || '玩家' + this._userData.userId;
- }
- }, {
- key: "openId",
- get: function get() {
- return this._userData.openId;
- }
- }, {
- key: "option",
- get: function get() {
- return this._userData.option;
- }
- }, {
- key: "pf",
- get: function get() {
- return this._userData.pf;
- }
- }, {
- key: "userId",
- get: function get() {
- return this._userData.userId;
- }
- }, {
- key: "registerTime",
- get: function get() {
- return this._userData.registerTime;
- }
- }, {
- key: "isHost",
- get: /**是否是主机*/
- function get() {
- return this._ishost;
- }
- }, {
- key: "ready",
- get: /**是否准备*/
- function get() {
- return this._ready;
- }
- }, {
- key: "online",
- get: /**是否在线*/
- function get() {
- return this._online;
- }
- }, {
- key: "canMatch",
- get: /**是否能开启匹配*/
- function get() {
- return this.online && this.ready;
- }
- }, {
- key: "level",
- get: /**段位信息*/
- function get() {
- return this._rankInfo;
- }
- }, {
- key: "isOwn",
- get: /**是否是当前玩家自己 */
- function get() {
- return chsdk.get_uid() === this.userId;
- }
- /**是否是AI */
- }, {
- key: "isAI",
- get: function get() {
- return this._userData.userId < 8888;
- }
- }, {
- key: "canAI",
- get: /**是否有控制当前AI权限*/
- function get() {
- return this._canAI;
- }
- }, {
- key: "isPermission",
- get: /**是否有此玩家数据权限*/
- function get() {
- return this.isOwn || this._canAI;
- }
- }]);
- return NetPlayer;
- }(NetBase));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/NetRoom.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './NetBase.ts', './NetPlayer.ts'], function (exports) {
- var _inheritsLoose, _createClass, cclegacy, NetBase, NetPlayer;
- return {
- setters: [function (module) {
- _inheritsLoose = module.inheritsLoose;
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }, function (module) {
- NetBase = module.NetBase;
- }, function (module) {
- NetPlayer = module.NetPlayer;
- }],
- execute: function () {
- cclegacy._RF.push({}, "577dcgqDHFNgZms65V5Rprz", "NetRoom", undefined);
- /**网络房间*/
- var NetRoom = exports('NetRoom', /*#__PURE__*/function (_NetBase) {
- _inheritsLoose(NetRoom, _NetBase);
- //
- function NetRoom(roomData, playerData) {
- var _this;
- _this = _NetBase.call(this, roomData.roomId) || this;
- _this.evt = chsdk.get_new_event();
- _this._hostId = void 0;
- _this._status = true;
- _this._own_id = void 0;
- _this._players = new Map();
- //
- _this._waitSends_mode0 = [];
- _this._waitSends_mode1 = [];
- _this._waitSends_mode2 = [];
- _this._results = [];
- _this._chat_msg = null;
- _this._last_chat_time = 0;
- _this._status = roomData.status;
- _this._hostId = roomData.hostInfo;
- var ps = Object.keys(playerData).map(function (key) {
- return {
- key: key,
- data: playerData[key]
- };
- });
- for (var i = 0; i < ps.length; i++) _this.addPlayer(ps[i]);
- _this._players.forEach(function (v, _) {
- v.set_host(v.Id === _this._hostId, _this.isHost);
- });
- _this.initValue(roomData.gameData);
- return _this;
- }
- var _proto = NetRoom.prototype;
- _proto.addPlayer = function addPlayer(p) {
- var id = p.key;
- var pd = p.data;
- var player = this._players.get(id);
- if (!player) {
- player = new NetPlayer(id);
- this._players.set(id, player);
- }
- player.init(pd);
- if (player.isOwn) this._own_id = id;
- };
- _proto.updatePlayerStatus = function updatePlayerStatus(id, online) {
- var p = this.getPlayer(id);
- if (p) {
- p.change_online(online);
- var location = p.location;
- var nickName = p.nickName;
- this.evt._emit('r_online', id, online, location, nickName);
- }
- };
- _proto.changeHost = function changeHost(id) {
- var _this2 = this;
- this._hostId = id;
- this._players.forEach(function (v, _) {
- v.set_host(v.Id === _this2._hostId, _this2.isHost);
- });
- var p = this.getPlayer(this._hostId);
- this.evt._emit('r_host', id, p.location, p.nickName);
- }
- /**自己是否是主机*/;
- /**所有玩家*/
- _proto.getAllPlayer = function getAllPlayer() {
- return Array.from(this._players.values());
- }
- /**将玩家按 location 放到一个数组中,并自定义数组长度*/;
- _proto.getAllPlayersAtLocations = function getAllPlayersAtLocations(customLength) {
- var locationArray = Array(customLength).fill(null);
- this._players.forEach(function (player) {
- if (player.location >= 0 && player.location < customLength) locationArray[player.location] = player;
- });
- return locationArray;
- }
- /**中某个玩家的所有信息*/;
- _proto.getPlayer = function getPlayer(id) {
- return this._players.get(id);
- }
- /**获取除了某个id的所有玩家*/;
- _proto.getExPlayer = function getExPlayer(id) {
- return Array.from(this._players.values()).filter(function (player) {
- return player.Id != id;
- });
- }
- /**获在线或不在线的所有玩家*/;
- _proto.getOnlinePlayer = function getOnlinePlayer(isOnline) {
- return isOnline ? this.onlines : this.outlines;
- }
- /**是否有AI权限*/;
- _proto.canAiPlayer = function canAiPlayer(player) {
- if (!this._status) return false;
- if (!this.isHost) return false;
- if (!player || !player.isAI) return false;
- return true;
- }
- /**是否有AI权限Id,返回可以控制的player*/;
- _proto.canAiPlayerId = function canAiPlayerId(id) {
- if (!this._status) return null;
- if (!this.isHost) return null;
- var player = this._players.get(id);
- if (!player) return null;
- if (!player.isAI) return null;
- return player;
- }
- /**是否拥有权限(包括,自己和自己是主机时的ai)*/;
- _proto.hasPermission = function hasPermission(player) {
- return player.isOwn || this.canAiPlayer(player);
- }
- /**创建obj数据*/;
- _proto.creatObj = function creatObj(data) {
- var _NetBase$prototype$ge;
- if (!this._status) return;
- if (!this.isHost) return;
- var oid = (_NetBase$prototype$ge = _NetBase.prototype.getValue.call(this, 'oid')) != null ? _NetBase$prototype$ge : 0;
- oid++;
- var key = 'obj_' + oid;
- _NetBase.prototype.setValue.call(this, 'oid', oid);
- _NetBase.prototype.setValueDirty.call(this, 'oid', oid);
- _NetBase.prototype.setValue.call(this, key, data);
- _NetBase.prototype.setValueDirty.call(this, key, data);
- this.evt._emit('r_obj', key, data);
- return key;
- }
- /**删除obj数据*/;
- _proto.getObj = function getObj(key) {
- return _NetBase.prototype.getValue.call(this, key);
- }
- /**不建议经常更改obj */;
- _proto.changeObj = function changeObj(key, data) {
- if (!this.isHost) return;
- var old = _NetBase.prototype.getValue.call(this, key);
- if (old) {
- _NetBase.prototype.setValue.call(this, key, data);
- _NetBase.prototype.setValueDirty.call(this, key, data);
- this.evt._emit('r_obj', key, data, old);
- }
- }
- //
- ;
- _proto.deleteObj = function deleteObj(key) {
- if (!this.isHost) return;
- _NetBase.prototype.setValue.call(this, key, null);
- _NetBase.prototype.setValueDirty.call(this, key, null);
- }
- /**修改某个键的值*/;
- _proto.setValue = function setValue(key, data) {
- if (!this._status) return;
- if (!this.isHost) return; //不是主机没有权限
- var old = _NetBase.prototype.getValue.call(this, key);
- if (old) {
- if (typeof data === "object") ;else if (data === old) {
- return;
- }
- }
- _NetBase.prototype.setValue.call(this, key, data);
- _NetBase.prototype.setValueDirty.call(this, key, data);
- this.evt._emit(key, data, old);
- }
- /**获取数据的值*/;
- _proto.getValue = function getValue(key) {
- return _NetBase.prototype.getValue.call(this, key);
- };
- _proto.server_change = function server_change(data) {
- var _this3 = this;
- if (!this._status) return;
- if (this.isHost) return;
- Object.keys(data).forEach(function (key) {
- _this3.change(key, data[key]);
- });
- };
- _proto.change = function change(key, data) {
- var old = _NetBase.prototype.getValue.call(this, key);
- _NetBase.prototype.setValue.call(this, key, data);
- if (typeof data !== "object" && data === old) return;
- if (key === 'oid') {
- return;
- } else if (key.startsWith('obj_')) {
- this.evt._emit('r_obj', key, data, old);
- } else {
- this.evt._emit(key, data, old);
- }
- };
- _proto.closed = function closed(data) {
- this._status = false;
- this._results.length = 0;
- var ps = Object.keys(data).map(function (key) {
- return {
- key: key,
- data: data[key]
- };
- });
- for (var i = 0; i < ps.length; i++) {
- var _key = ps[i].key;
- var user = ps[i].data;
- user.Id = _key;
- var player = this.getPlayer(_key);
- player.set_level(user.Level, user.Rank, user.Score, user.TotalRank);
- user.UserData = {
- gid: player.gid,
- head: player.head,
- hid: player.hid,
- ip: player.ip,
- loginTime: player.loginTime,
- nickName: player.nickName,
- openId: player.openId,
- option: player.option,
- pf: player.pf,
- registerTime: player.registerTime,
- userId: player.userId,
- province: player.province
- };
- var elements = user.Elements;
- if (elements) {
- for (var _i = 0; _i < elements.length; _i++) {
- var _chsdk$provinceCode2N;
- var o = elements[_i];
- o.nickName = o.nickName || '玩家' + o.userId;
- o.hid = Number.parseInt(o.hid);
- o.loginTime = Number.parseInt(o.loginTime);
- o.registerTime = Number.parseInt(o.registerTime);
- o.userId = Number.parseInt(o.userId);
- o.province = (_chsdk$provinceCode2N = chsdk.provinceCode2Name(o.hid)) != null ? _chsdk$provinceCode2N : '其它';
- }
- }
- this._results.push(user);
- }
- if (this._results.length > 1) {
- this._results.sort(function (a, b) {
- if (a.Rank === 0 && b.Rank === 0) {
- return 0;
- } else if (a.Rank === 0) {
- return 1;
- } else if (b.Rank === 0) {
- return -1;
- } else {
- return a.Rank - b.Rank;
- }
- });
- }
- //
- this.evt._emit('r_closed');
- };
- _proto.finish = function finish(pid, rank) {
- var player = this.getPlayer(pid);
- if (!player) return;
- player.setFinish(rank);
- this.evt._emit('r_finish', pid, rank);
- }
- /**向房间所有玩家发消息*/;
- _proto.sendEvt = function sendEvt(key) {
- if (!this._status) return;
- for (var _len = arguments.length, data = new Array(_len > 1 ? _len - 1 : 0), _key2 = 1; _key2 < _len; _key2++) {
- data[_key2 - 1] = arguments[_key2];
- }
- this._waitSends_mode0.push({
- type: key,
- data: data
- });
- }
- /**向房间主机发消息*/;
- _proto.sendToHost = function sendToHost(key) {
- if (!this._status) return;
- for (var _len2 = arguments.length, data = new Array(_len2 > 1 ? _len2 - 1 : 0), _key3 = 1; _key3 < _len2; _key3++) {
- data[_key3 - 1] = arguments[_key3];
- }
- this._waitSends_mode1.push({
- type: key,
- data: data
- });
- }
- /**向房间其它玩家*/;
- _proto.sendToOther = function sendToOther(key) {
- if (!this._status) return;
- for (var _len3 = arguments.length, data = new Array(_len3 > 1 ? _len3 - 1 : 0), _key4 = 1; _key4 < _len3; _key4++) {
- data[_key4 - 1] = arguments[_key4];
- }
- this._waitSends_mode2.push({
- type: key,
- data: data
- });
- }
- /**处理发送事件*/;
- _proto.doSendMode = function doSendMode(f) {
- f(this._waitSends_mode0, this._waitSends_mode1, this._waitSends_mode2);
- this._waitSends_mode0.length = 0;
- this._waitSends_mode1.length = 0;
- this._waitSends_mode2.length = 0;
- };
- /**房间里聊天 ,成功返回true,发送频率过快返回false*/
- _proto.chat = function chat(msg) {
- var now = chsdk.date.now();
- if (now - this._last_chat_time < 1000) return false;
- this._last_chat_time = now;
- this._chat_msg = msg;
- return true;
- };
- _proto.onChat = function onChat(id, msg) {
- var p = this.getPlayer(id);
- this.evt._emit('r_chat', id, msg, p.location, p.nickName);
- };
- _proto.doSendChat = function doSendChat(f) {
- f(this._chat_msg);
- this._chat_msg = null;
- }
- //
- ;
- _proto._onEvt = function _onEvt(key, data) {
- var _ref;
- (_ref = this.evt)._emit.apply(_ref, [key].concat(data));
- }
- //
- ;
- _proto.dispose = function dispose() {
- _NetBase.prototype.dispose.call(this);
- this._players.forEach(function (v, _) {
- v.dispose();
- });
- this._players.clear();
- this._status = false;
- this.evt.clearAll();
- };
- _createClass(NetRoom, [{
- key: "HostId",
- get: /**游戏主机ID*/function get() {
- return this._hostId;
- }
- }, {
- key: "cloosed",
- get: /**游戏是否关闭*/function get() {
- return !this._status;
- }
- }, {
- key: "isHost",
- get: function get() {
- return this._own_id === this._hostId;
- }
- /**自己的所有信息*/
- }, {
- key: "own",
- get: function get() {
- return this._players.get(this._own_id);
- }
- /**其它玩家信息*/
- }, {
- key: "others",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return !player.isOwn;
- });
- }
- /**所有ai信息*/
- }, {
- key: "ais",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return player.isAI;
- });
- }
- /**所有玩家*/
- }, {
- key: "all",
- get: function get() {
- return this.getAllPlayer();
- }
- /**在线玩家信息*/
- }, {
- key: "onlines",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return player.online;
- });
- }
- /**不在线玩家信息*/
- }, {
- key: "outlines",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return !player.online;
- });
- }
- }, {
- key: "results",
- get:
- /**
- * 游戏结算数据
- *
- * @returns {Array} results - 包含游戏结算信息的数组。
- * 每个元素表示一个玩家的结算数据,结构如下:
- *
- * - Id: {string} 玩家唯一标识符
- * - AddScore: {number} 本局游戏中增加的星星数
- * - IsFinish: {boolean} 游戏是否已完成
- * - Rank: {number} 玩家在当前游戏中的排名
- * - Score: {number} 玩家在最后星星数
- * - TotalRank: {number} 玩家的总排名
- * - Level: {Object} 玩家当前等级的信息
- * - LowerRank: {number} 当前段位的等级
- * - Rank: {number} 段位
- * - Star: {number} 当前段位的等级的星级
- * - UserData: {Object} 玩家个人信息
- * - gid: {string} 游戏全局唯一标识符
- * - head: {string} 玩家头像的 URL
- * - hid: {number} 玩家省份id
- * - ip: {string} 玩家 IP 地址
- * - loginTime: {number} 玩家登录时间的时间戳
- * - nickName: {string} 玩家昵称
- * - openId: {string} 玩家在平台上的唯一标识符
- * - option: {string} 玩家选择的选项或设置
- * - pf: {string} 平台信息
- * - registerTime: {number} 玩家注册时间的时间戳
- * - userId: {number} 玩家在系统中的用户 ID
- * - province: {string} 玩家所在的省份
- * - Elements: {Array} 包含其他玩家的结算数据
- * - Rank: {number} 其他玩家的排名
- * - Level: {Object} 其他玩家的等级信息
- * - LowerRank: {number} 其他玩家当前段位的等级
- * - Rank: {number} 其他玩家的段位
- * - Star: {number} 其他玩家段位的等级的星级
- * - UserData: {Object} 其他玩家的个人信息(与上面的 UserData 结构相同)
- */
- function get() {
- return this._results;
- }
- /**获取自己本局获得星星*/
- }, {
- key: "own_results_addScore",
- get: function get() {
- var rs = this.results;
- if (!rs) return 0;
- for (var i = 0; i < rs.length; i++) {
- if (rs[i].Id === this._own_id) {
- return rs[i].AddScore;
- }
- }
- return 0;
- }
- }]);
- return NetRoom;
- }(NetBase));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/NetTeam.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './NetPlayer.ts'], function (exports) {
- var _createClass, cclegacy, NetPlayer;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }, function (module) {
- NetPlayer = module.NetPlayer;
- }],
- execute: function () {
- cclegacy._RF.push({}, "33caeCu1CZJPaCD2lrLn4Gv", "NetTeam", undefined);
- var C2S_MATCH = 'c2s_match';
- var C2S_MATCH_CANCEL = 'c2s_match_cancel';
- var C2S_READY = 'c2s_ready';
- var C2S_KICK_OUT = 'c2s_kick_out';
- /**网络队伍*/
- var NetTeam = exports('NetTeam', /*#__PURE__*/function () {
- function NetTeam(data, send) {
- /**队伍事件*/
- this.evt = chsdk.get_new_event();
- this._status = true;
- this._hostId = void 0;
- this._password = void 0;
- this._limit = void 0;
- this._id = void 0;
- this._inCollect = false;
- this._own_id = void 0;
- this._players = new Map();
- this._send = void 0;
- this._chat_msg = null;
- this._last_chat_time = 0;
- var team = data.teamData;
- var playerData = data.playerData;
- this._hostId = team.hostInfo;
- this._status = team.status;
- this._inCollect = team.inCollect;
- this._password = team.password;
- this._limit = team.limit;
- this._id = team.roomId;
- this._players.clear();
- var ps = Object.keys(playerData).map(function (key) {
- return {
- key: key,
- data: playerData[key]
- };
- });
- for (var i = 0; i < ps.length; i++) this.addPlayer(ps[i]);
- this._send = send;
- }
- /**主机开始匹配*/
- var _proto = NetTeam.prototype;
- _proto.match = function match() {
- if (!this.isHost) return;
- this._send(C2S_MATCH);
- }
- /**主机退出匹配*/;
- _proto.exit_match = function exit_match() {
- if (!this.isHost) return;
- this._send(C2S_MATCH_CANCEL);
- }
- /**主机踢出某个玩家出小队 */;
- _proto.kick_out = function kick_out(arg) {
- if (!this.isHost) return;
- if (typeof arg === 'string') {
- this._send(C2S_KICK_OUT, arg);
- } else if (typeof arg === 'number') {
- var playerToKick = this.all.find(function (player) {
- return player.location === arg;
- });
- if (playerToKick) this._send(C2S_KICK_OUT, playerToKick.Id); // 踢出找到的玩家
- }
- }
- /**主机踢出所有没有准备的玩家 */;
- _proto.kick_out_no_readys = function kick_out_no_readys() {
- if (!this.isHost) return;
- var list = this.notreadys;
- for (var i = 0; i < list.length; i++) this._send(C2S_KICK_OUT, list[i].Id);
- }
- /**主机踢出所有不在线玩家*/;
- _proto.kick_out_outlines = function kick_out_outlines() {
- if (!this.isHost) return;
- var list = this.outlines;
- for (var i = 0; i < list.length; i++) this._send(C2S_KICK_OUT, list[i].Id);
- }
- /**主机踢出所有不在线或没有准备的玩家*/;
- _proto.kick_out_badplayers = function kick_out_badplayers() {
- if (!this.isHost) return;
- var list = this.badplayers;
- for (var i = 0; i < list.length; i++) this._send(C2S_KICK_OUT, list[i].Id);
- }
- /**准备*/;
- _proto.ready = function ready() {
- this._send(C2S_READY);
- };
- _proto.addPlayer = function addPlayer(p, isevt) {
- if (isevt === void 0) {
- isevt = false;
- }
- var id = p.key;
- var pd = p.data;
- var player = this._players.get(id);
- if (!player) {
- player = new NetPlayer(id);
- this._players.set(id, player);
- }
- player.init(pd);
- player.set_host(player.Id === this._hostId);
- if (player.isOwn) this._own_id = id;
- if (isevt) this.evt._emit('t_entry', id, player.location, player.nickName);
- }
- /**玩家离开*/;
- _proto.removePlayer = function removePlayer(id) {
- var p = this._players.get(id);
- if (p) {
- var _location = p.location;
- var nickName = p.nickName;
- this._players["delete"](id);
- this.evt._emit('t_exit', id, _location, nickName);
- }
- }
- /**队伍解散*/;
- _proto.closed = function closed() {
- this.evt._emit('t_closed');
- };
- _proto.updatePlayerStatus = function updatePlayerStatus(id, online) {
- var p = this.getPlayer(id);
- if (p) {
- p.change_online(online);
- var _location2 = p.location;
- var nickName = p.nickName;
- this.evt._emit('t_online', id, online, _location2, nickName);
- }
- };
- _proto.updatePlayerReady = function updatePlayerReady(id, ready) {
- var p = this.getPlayer(id);
- if (p) {
- p.change_ready(ready);
- var _location3 = p.location;
- var nickName = p.nickName;
- this.evt._emit('t_ready', id, ready, _location3, nickName);
- }
- };
- _proto.match_start = function match_start() {
- this._inCollect = true;
- this.evt._emit('t_matchStart');
- };
- _proto.match_cancel = function match_cancel() {
- this._inCollect = false;
- this.evt._emit('t_matchCancel');
- };
- _proto.match_success = function match_success() {
- this._inCollect = false;
- this.evt._emit('t_matchSuccess');
- var ps = this.getAllPlayer();
- for (var i = 0; i < ps.length; i++) {
- ps[i].change_ready(false);
- }
- };
- _proto.not_ready = function not_ready() {
- this.evt._emit('t_no_ready');
- };
- _proto.changeHost = function changeHost(id) {
- var _this = this;
- this._hostId = id;
- this._players.forEach(function (v, _) {
- v.set_host(v.Id === _this._hostId);
- });
- var p = this.getPlayer(this._hostId);
- this.evt._emit('t_host', id, p.location, p.nickName);
- };
- /*队伍里聊天,成功返回true,发送频率过快返回false*/
- _proto.chat = function chat(msg) {
- var now = chsdk.date.now();
- if (now - this._last_chat_time < 1000) return false;
- this._last_chat_time = now;
- this._chat_msg = msg;
- return true;
- };
- _proto.onChat = function onChat(id, msg) {
- var p = this.getPlayer(id);
- this.evt._emit('t_chat', id, msg, p.location, p.nickName);
- };
- _proto.doSendChat = function doSendChat(f) {
- f(this._chat_msg);
- this._chat_msg = null;
- }
- /**自己是否是主机*/;
- /**某个玩家的所有信息*/
- _proto.getPlayer = function getPlayer(id) {
- return this._players.get(id);
- }
- /**所有玩家*/;
- _proto.getAllPlayer = function getAllPlayer() {
- return this.all;
- }
- /**将玩家按 location 放到一个数组中,并自定义数组长度*/;
- _proto.getAllPlayersAtLocations = function getAllPlayersAtLocations(customLength) {
- var locationArray = Array(customLength).fill(null);
- this._players.forEach(function (player) {
- if (player.location >= 0 && player.location < customLength) locationArray[player.location] = player;
- });
- return locationArray;
- }
- /**获取除了某个id的所有玩家*/;
- _proto.getExPlayer = function getExPlayer(id) {
- return Array.from(this._players.values()).filter(function (player) {
- return player.Id != id;
- });
- }
- /**获在线或不在线的所有玩家*/;
- _proto.getOnlinePlayer = function getOnlinePlayer(isOnline) {
- return isOnline ? this.onlines : this.outlines;
- }
- /**获准备或没有准备的所有玩家*/;
- _proto.getReadyPlayer = function getReadyPlayer(ready) {
- return ready ? this.readys : this.notreadys;
- };
- _proto.dispose = function dispose() {
- this._send = null;
- this._players.forEach(function (v, _) {
- v.dispose();
- });
- this._players.clear();
- };
- _createClass(NetTeam, [{
- key: "status",
- get: /**队伍是否能进*/function get() {
- return this._status;
- }
- }, {
- key: "HostId",
- get: /**队伍队长ID*/function get() {
- return this._hostId;
- }
- }, {
- key: "Password",
- get: /**队伍进入口令*/function get() {
- return this._password;
- }
- }, {
- key: "Limit",
- get: /**队伍上限*/function get() {
- return this._limit;
- }
- }, {
- key: "Id",
- get: /**队伍标识id*/function get() {
- return this._id;
- }
- }, {
- key: "inCollect",
- get: /**是否在匹配中*/function get() {
- return this._inCollect;
- }
- }, {
- key: "isHost",
- get: function get() {
- return this._own_id === this._hostId;
- }
- /**自己的所有信息*/
- }, {
- key: "own",
- get: function get() {
- return this._players.get(this._own_id);
- }
- /**所有玩家*/
- }, {
- key: "all",
- get: function get() {
- return Array.from(this._players.values());
- }
- /**其它玩家信息*/
- }, {
- key: "others",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return !player.isOwn;
- });
- }
- /**在线玩家信息*/
- }, {
- key: "onlines",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return player.online;
- });
- }
- /**不在线玩家信息*/
- }, {
- key: "outlines",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return !player.online;
- });
- }
- /**没有准备或不在线玩家*/
- }, {
- key: "badplayers",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return !player.ready || !player.online;
- });
- }
- /**准备好的玩家信息*/
- }, {
- key: "readys",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return player.ready;
- });
- }
- /**没有准备的玩家信息*/
- }, {
- key: "notreadys",
- get: function get() {
- return Array.from(this._players.values()).filter(function (player) {
- return !player.ready;
- });
- }
- }]);
- return NetTeam;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/PathUtil.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "599009CYiRPSbP+6MJkFWLY", "PathUtil", undefined);
- var PathUtil = exports('default', /*#__PURE__*/function () {
- function PathUtil() {}
- /**
- * 返回 Path 的扩展名
- * @param path 路径
- * @returns {string}
- */
- PathUtil.extname = function extname(path) {
- var temp = /(\.[^\.\/\?\\]*)(\?.*)?$/.exec(path);
- return temp ? temp[1] : '';
- }
- /**
- * 获取文件路径的文件名。
- * @param path 路径
- * @param extname 扩展名
- * @returns {string}
- */;
- PathUtil.basename = function basename(path, extname) {
- var index = path.indexOf("?");
- if (index > 0) path = path.substring(0, index);
- var reg = /(\/|\\)([^\/\\]+)$/g;
- var result = reg.exec(path.replace(/(\/|\\)$/, ""));
- if (!result) return path;
- var baseName = result[2];
- if (extname && path.substring(path.length - extname.length).toLowerCase() === extname.toLowerCase()) return baseName.substring(0, baseName.length - extname.length);
- return baseName;
- }
- /**
- * 获取文件路径的目录名
- * @param path 路径
- * @returns {string}
- */;
- PathUtil.dirname = function dirname(path) {
- var temp = /((.*)(\/|\\|\\\\))?(.*?\..*$)?/.exec(path);
- return temp ? temp[2] : '';
- };
- return PathUtil;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/PeriodData.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createForOfIteratorHelperLoose, cclegacy;
- return {
- setters: [function (module) {
- _createForOfIteratorHelperLoose = module.createForOfIteratorHelperLoose;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "6e040Hgcc1C2r4oXdDQnwvy", "PeriodData", undefined);
- var PeriodDataUpdate = exports('PeriodDataUpdate', /*#__PURE__*/function (PeriodDataUpdate) {
- PeriodDataUpdate[PeriodDataUpdate["none"] = 0] = "none";
- PeriodDataUpdate[PeriodDataUpdate["day"] = 1] = "day";
- PeriodDataUpdate[PeriodDataUpdate["week"] = 2] = "week";
- PeriodDataUpdate[PeriodDataUpdate["month"] = 3] = "month";
- return PeriodDataUpdate;
- }({}));
- /**周期数据
- * @param T 为一个枚举类型
- * @param update PeriodDataUpdate 更新周期
- * @param limt 限制值最大,最小
- * 调用check检测更新
- * @exampl
- 定义数据枚举 字段名和字段key需要一致
- export enum day_type{
- score ="score",
- level ="level",
- relive="relive",
- }
- 初始所有定义数据
- day_data = new PeriodData<day_type>(PeriodDataUpdate.day,
- Object.keys(day_type) as day_type[],
- new Map([
- [day_type.relive,{min:0,max:3}],//限制每日复活3次
- ])
- );
- day_data.get(day_type.score)...
- */
- var PeriodData = exports('default', /*#__PURE__*/function () {
- function PeriodData(update, limt) {
- var _this = this;
- this._data = new Map();
- this._data_Array = new Map();
- this._last = 0;
- this._update = void 0;
- this._update = update;
- if (!limt) return;
- //遍历所有键进行初始化
- limt.forEach(function (v, key) {
- var _v$min;
- _this._data.set(key, {
- v: (_v$min = v.min) != null ? _v$min : 0,
- min: v.min,
- max: v.max
- });
- }, this);
- }
- /**
- * 序列化(数据库存储)
- */
- var _proto = PeriodData.prototype;
- _proto.serialize = function serialize() {
- var obj = {};
- this._data.forEach(function (value, key) {
- obj[String(key)] = value.v;
- });
- var obj1 = {};
- this._data_Array.forEach(function (value, key) {
- obj1[String(key)] = value;
- });
- var data = {
- "last": this._last,
- "data": obj,
- "data_Array": obj1
- };
- return data;
- }
- /**
- * 反序列化
- */;
- _proto.unserialize = function unserialize(data) {
- var _data$last;
- if (!data) return;
- this._last = (_data$last = data.last) != null ? _data$last : 0;
- var obj = data.data;
- if (obj) {
- for (var _key in obj) {
- var value = obj[_key];
- this._get(_key).v = value;
- }
- }
- var obj1 = data.data_Array;
- if (obj1) {
- for (var _key2 in obj1) {
- var _value = obj1[_key2];
- this.set_Array(_key2, _value);
- }
- }
- };
- _proto._get = function _get(key) {
- var data = this._data.get(key);
- if (!data) {
- data = {
- v: 0,
- min: 0,
- max: null
- };
- this._data.set(key, data);
- }
- return data;
- };
- _proto._get_Array = function _get_Array(key) {
- var data = this._data_Array.get(key);
- console.log("_get_Array called with key: " + String(key) + "data:", data); // 输出存储的数据
- if (!data) {
- data = new Array(5).fill(false);
- this._data_Array.set(key, data);
- }
- return data;
- }
- /**如果有必要,重新设置数据的min,max*/;
- _proto.set = function set(key, value, min, max) {
- var d = this._get(key);
- d.v = value;
- d.min = min;
- d.max = max;
- }
- /**获取数据*/;
- _proto.get = function get(key) {
- return this._get(key).v;
- };
- _proto.set_Array = function set_Array(key, value) {
- this._data_Array.set(key, value);
- }
- /**获取数据*/;
- _proto.get_Array = function get_Array(key) {
- return this._get_Array(key);
- }
- /**有大最值的话,获取数据为剩余可用次数*/;
- _proto.get_available = function get_available(key) {
- var d = this._get(key);
- if (d.max) return d.max - d.v;
- return d.v;
- };
- _proto.isEnble = function isEnble(key) {
- var d = this._get(key);
- return d.v > 0;
- };
- _proto.enble = function enble(key) {
- this._get(key).v = 1;
- };
- _proto.disEnble = function disEnble(key) {
- this._get(key).v = 0;
- }
- /**增加数据的值*/;
- _proto.add = function add(key, n) {
- if (n === void 0) {
- n = 1;
- }
- return this.change(key, n);
- }
- /**减小数据的值*/;
- _proto.sub = function sub(key, n) {
- if (n === void 0) {
- n = 1;
- }
- return this.change(key, -n);
- }
- /**改变数据 n>0增加 小于0减少*/;
- _proto.change = function change(key, n) {
- var d = this._get(key);
- if (!d) return null;
- d.v += n;
- if (d.min && d.v < d.min) d.v = d.min;
- if (d.max && d.v > d.max) d.v = d.max;
- return d.v;
- }
- /**改变数据,比原本值大直接替换,没有改变返回null*/;
- _proto.change_big = function change_big(key, n) {
- var d = this._get(key);
- if (!d) return null;
- if (n > d.v) {
- d.v = n;
- if (d.min && d.v < d.min) d.v = d.min;
- if (d.max && d.v > d.max) d.v = d.max;
- return d.v;
- }
- return null;
- }
- /**改变数据,比原本值小直接替换,没有改变返回null*/;
- _proto.change_sm = function change_sm(key, n) {
- var d = this._get(key);
- if (!d) return null;
- if (n < d.v) {
- d.v = n;
- if (d.min && d.v < d.min) d.v = d.min;
- if (d.max && d.v > d.max) d.v = d.max;
- return d.v;
- }
- return null;
- }
- /**检测更新now当前时间戳(ms)*/;
- _proto.check = function check(now) {
- if (this._update == PeriodDataUpdate.none) return false;
- if (this._update == PeriodDataUpdate.day) {
- if (!this.isSameDate(now, this._last)) {
- this._last = now;
- this.reset();
- return true;
- }
- }
- if (this._update == PeriodDataUpdate.week) {
- if (!this.areDatesInSameWeek(now, this._last)) {
- this._last = now;
- this.reset();
- this._data_Array = new Map();
- return true;
- }
- }
- if (this._update == PeriodDataUpdate.month) {
- if (!this.areDatesInSameMonth(now, this._last)) {
- this._last = now;
- this.reset();
- return true;
- }
- }
- return false;
- };
- _proto.reset = function reset() {
- for (var _iterator = _createForOfIteratorHelperLoose(this._data.keys()), _step; !(_step = _iterator()).done;) {
- var _data$min;
- var _key3 = _step.value;
- var data = this._get(_key3);
- data.v = (_data$min = data.min) != null ? _data$min : 0;
- }
- for (var _iterator2 = _createForOfIteratorHelperLoose(this._data_Array.keys()), _step2; !(_step2 = _iterator2()).done;) {
- var _key4 = _step2.value;
- this._data_Array.set(_key4, new Array(5).fill(false));
- }
- }
- /**判定两个时间是否是同一天*/;
- _proto.isSameDate = function isSameDate(timestamp1, timestamp2) {
- var date1 = new Date(timestamp1);
- var date2 = new Date(timestamp2);
- return date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate();
- }
- /**判定两个时间是否是同一周*/;
- _proto.areDatesInSameWeek = function areDatesInSameWeek(date1, date2) {
- var startOfWeek1 = this.getStartOfWeek(new Date(date1));
- var startOfWeek2 = this.getStartOfWeek(new Date(date2));
- return startOfWeek1.getTime() === startOfWeek2.getTime();
- };
- _proto.getStartOfWeek = function getStartOfWeek(date) {
- var startOfWeek = new Date(date);
- var day = startOfWeek.getDay(); // 星期日是 0,星期一是 1,依此类推
- var diff = startOfWeek.getDate() - day; // 计算当前日期所在周的第一天
- startOfWeek.setDate(diff); // 设置为该周的第一天
- startOfWeek.setHours(0, 0, 0, 0); // 设置时间为 00:00:00
- return startOfWeek;
- };
- _proto.areDatesInSameMonth = function areDatesInSameMonth(date1, date2) {
- var d1 = new Date(date1);
- var d2 = new Date(date2);
- return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth();
- };
- return PeriodData;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/PrefabPool.ts", ['cc'], function (exports) {
- var cclegacy, Node, NodePool, instantiate;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- Node = module.Node;
- NodePool = module.NodePool;
- instantiate = module.instantiate;
- }],
- execute: function () {
- exports('default', get_new_prefab_pool);
- cclegacy._RF.push({}, "12f30kX+ltO4JZlGRue34gE", "PrefabPool", undefined);
- /** node对象池 */
- var PrefabPool = /*#__PURE__*/function () {
- function PrefabPool() {
- this._pools = new Map();
- this._node = void 0;
- if (this._node == null) {
- this._node = new Node();
- this._node.active = false;
- }
- }
- var _proto = PrefabPool.prototype;
- _proto.getPool = function getPool(path) {
- var pool = this._pools.get(path);
- if (pool == null) {
- pool = new NodePool();
- this._pools.set(path, pool);
- }
- return pool;
- };
- _proto.GetNode = function GetNode(p) {
- var pool = this.getPool(p.name);
- var node = pool.get();
- if (!node) {
- node = instantiate(p);
- node.name = p.name;
- }
- return node;
- };
- _proto.RecNode = function RecNode(node) {
- node.parent = this._node;
- this.getPool(node.name).put(node);
- };
- _proto.InitPool = function InitPool(p, n) {
- if (n === void 0) {
- n = 10;
- }
- var pool = this.getPool(p.name);
- for (var i = 0; i < n; i++) {
- var node = instantiate(p);
- node.name = p.name;
- node.parent = this._node;
- pool.put(node);
- }
- };
- _proto.Clear = function Clear() {
- if (!this._node) return;
- this._node.removeAllChildren();
- this._pools.forEach(function (v, k) {
- v.clear();
- });
- this._pools.clear();
- };
- _proto.getAllPoolNames = function getAllPoolNames() {
- return Object.keys(this._pools);
- };
- _proto.getPoolSize = function getPoolSize(poolName) {
- var pool = this._pools[poolName];
- if (pool) {
- return pool.size();
- }
- return 0;
- };
- return PrefabPool;
- }();
- function get_new_prefab_pool() {
- return new PrefabPool();
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ProjectileMathUtil.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "16ac3tSOM5FwpZe8CFKhU2G", "ProjectileMathUtil", undefined);
- /** 用于弧度转角度 */
- var rad2Deg = 180 / Math.PI;
- /** 用于角度转弧度 */
- var deg2Rad = Math.PI / 180;
- /**
- * 抛射运动的数学工具
- */
- var ProjectileMathUtil = exports('default', /*#__PURE__*/function () {
- function ProjectileMathUtil() {}
- /**
- * 计算耗时
- * @param x 水平位移
- * @param angle 初始角度
- * @param velocity 初始速度
- */
- ProjectileMathUtil.calculateTotalTime = function calculateTotalTime(x, angle, velocity) {
- // 初始角度(弧度制)
- var θ = angle * deg2Rad;
- // 时间
- // t = x / ( v * cos(θ) )
- var t = x / (velocity * Math.cos(θ));
- return t;
- }
- /**
- * 计算指定时刻的运动角度
- * @param angle 初始角度
- * @param velocity 初始速度
- * @param time 时间
- * @param gravity 重力加速度
- * @param returnInRadians 是否返回弧度制结果
- */;
- ProjectileMathUtil.calculateAngleAtMoment = function calculateAngleAtMoment(angle, velocity, time, gravity, returnInRadians) {
- if (returnInRadians === void 0) {
- returnInRadians = false;
- }
- // 重力加速度(垂直向下)
- var g = gravity; //
- // 初始角度(弧度制)
- var θ = angle * deg2Rad;
- // 水平瞬时速度
- // vx = v * cos(θ)
- var vx = velocity * Math.cos(θ);
- // 垂直瞬时速度
- // vy = v * sin(θ) - g * t
- var vy = velocity * Math.sin(θ) - g * time;
- // 该时刻的运动角度(弧度制)
- var θt = Math.atan(vy / vx);
- return returnInRadians ? θt : θt * rad2Deg;
- }
- /**
- * 计算指定时刻的位移距离
- * @param angle 初始角度
- * @param velocity 初始速度
- * @param gravity 重力加速度
- * @param time 时间点
- */;
- ProjectileMathUtil.calculateDisplacementAtMoment = function calculateDisplacementAtMoment(angle, velocity, gravity, time) {
- // 重力加速度(垂直向下)
- var g = gravity;
- // 初始角度(弧度制)
- var θ = angle * deg2Rad;
- // 水平位移
- // x = v * cos(θ) * t
- var x = velocity * Math.cos(θ) * time;
- // 垂直位移
- // y = v * sin(θ) * t - 0.5 * g * t^2
- var y = velocity * Math.sin(θ) * time - 0.5 * g * Math.pow(time, 2);
- return {
- x: x,
- y: y
- };
- }
- /**
- * 根据初始角度计算初始速度
- * @param x 水平距离
- * @param y 垂直距离
- * @param gravity 重力加速度
- * @param angle 初始角度(角度制)
- */;
- ProjectileMathUtil.calculateWithAngle = function calculateWithAngle(x, y, gravity, angle) {
- // 重力加速度(垂直向下)
- var g = Math.abs(gravity);
- // 初始角度(弧度制)
- var θ = angle * deg2Rad;
- // 速度公式
- // v = sqrt( ( x^2 * g ) / ( 2 * x * sin(θ) * cos(θ) - 2 * y * cos(θ)^2 ) )
- // 部分计算结果
- var p1 = 2 * x * Math.sin(θ) * Math.cos(θ) - 2 * y * Math.pow(Math.cos(θ), 2);
- // 负数没有平方根
- if (p1 < 0) {
- return NaN;
- }
- // 速度
- var v = Math.sqrt(g * Math.pow(x, 2) / p1);
- return v;
- }
- /**
- * 根据初始速度计算初始角度
- * @param x 水平距离
- * @param y 垂直距离
- * @param gravity 重力加速度
- * @param velocity 初始速度
- */;
- ProjectileMathUtil.calculateWithVelocity = function calculateWithVelocity(x, y, velocity, gravity) {
- // 重力加速度(垂直向下)
- var g = gravity;
- // 初始速度
- var v = velocity;
- // 角度公式
- // θ = atan( ( -v^2 ± sqrt( v^4 - g * ( g * x^2 + 2 * y * v^2 ) ) / ( -g * x ) ) )
- // 部分计算结果
- var p1 = Math.pow(v, 2);
- var p2 = Math.pow(v, 4) - g * (g * Math.pow(x, 2) + 2 * y * p1);
- // 负数没有平方根
- if (p2 < 0) {
- return {
- angle1: NaN,
- angle2: NaN
- };
- }
- // 部分计算结果
- var p3 = Math.sqrt(p2);
- // 角度(两个解)
- var θ1 = Math.atan((-p1 + p3) / (-g * x));
- var θ2 = Math.atan((-p1 - p3) / (-g * x));
- return {
- angle1: θ1 * rad2Deg,
- angle2: θ2 * rad2Deg
- };
- }
- /**
- * 根据最大高度计算速度和角度
- * @param x 水平距离
- * @param y 垂直距离
- * @param gravity 重力加速度
- * @param maxHeight 最大高度
- */;
- ProjectileMathUtil.calculateWithMaxHeight = function calculateWithMaxHeight(x, y, maxHeight, gravity) {
- // 重力加速度(垂直向下)
- var g = gravity;
- // 最大高度
- var h = maxHeight;
- // 最大高度不能小于 0,也不能够小于垂直距离
- if (h < 0 || h - y < 0) {
- return {
- angle: NaN,
- velocity: NaN,
- time: NaN
- };
- }
- // 部分计算结果
- var p1 = Math.sqrt(2 * g * h);
- var p2 = Math.sqrt(2 * g * (h - y));
- // 时间公式
- // t = ( -sqrt( 2 * g * h ) ± sqrt( 2 * g * ( h - y ) ) ) / -g
- var t1 = (-p1 + p2) / -g;
- var t2 = (-p1 - p2) / -g;
- // 始终使用较大的解
- var t = Math.max(t1, t2);
- // 角度公式
- // θ = atan( ( sqrt( 2 * g * h ) * t ) / x )
- var θ = Math.atan(p1 * t / x);
- // 速度公式
- // v = sqrt( 2 * g * h ) / sin(θ)
- var v = p1 / Math.sin(θ);
- return {
- angle: θ * rad2Deg,
- velocity: v,
- time: t
- };
- };
- return ProjectileMathUtil;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Queue.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "16900mmPzlPkZiuO57PxvRs", "Queue", undefined);
- var Queue = exports('default', /*#__PURE__*/function () {
- function Queue() {
- this.count = void 0;
- this.lowestCount = void 0;
- this.items = void 0;
- this.count = 0;
- this.lowestCount = 0;
- this.items = {};
- }
- /**加入队列*/
- var _proto = Queue.prototype;
- _proto.enqueue = function enqueue(item) {
- // 队列的末尾添加元素: 将队列的大小作为key
- this.items[this.count] = item;
- this.count++;
- }
- /**拿出队首*/;
- _proto.dequeue = function dequeue() {
- if (this.isEmpty()) {
- return undefined;
- }
- var result = this.items[this.lowestCount];
- // 删除队首元素
- delete this.items[this.lowestCount];
- // 队首元素自增
- this.lowestCount++;
- return result;
- }
- /**是否为空队列*/;
- _proto.isEmpty = function isEmpty() {
- return this.count - this.lowestCount === 0;
- }
- /**查看下一个出队元素 */;
- _proto.peek = function peek() {
- if (this.isEmpty()) {
- return undefined;
- }
- return this.items[this.lowestCount];
- }
- /**队列个数*/;
- _proto.size = function size() {
- return this.count - this.lowestCount;
- }
- /**清空队列*/;
- _proto.clear = function clear() {
- this.count = 0;
- this.lowestCount = 0;
- this.items = {};
- };
- _proto.toString = function toString() {
- if (this.isEmpty()) {
- return "";
- }
- var objString = "" + this.items[this.lowestCount];
- for (var i = this.lowestCount + 1; i < this.count; i++) {
- objString = objString + "," + this.items[i];
- }
- return objString;
- };
- return Queue;
- }());
- var Deque = exports('Deque', /*#__PURE__*/function () {
- function Deque() {
- this.items = void 0;
- this.lowestCount = void 0;
- this.count = void 0;
- this.items = {};
- this.lowestCount = 0;
- this.count = 0;
- }
- /**
- * 向队列的尾端添加元素
- * @param element
- * @returns size
- */
- var _proto2 = Deque.prototype;
- _proto2.addTail = function addTail(element) {
- this.items[this.count++] = element;
- return this.size();
- }
- /**
- * 向队列头部添加元素
- * @param element
- * @returns size
- */;
- _proto2.addHead = function addHead(element) {
- if (this.count === 0) {
- this.addTail(element);
- } else if (this.lowestCount > 0) {
- this.items[--this.lowestCount] = element;
- } else {
- for (var i = this.count; i > this.lowestCount; i--) {
- this.items[i] = this.items[i - 1];
- }
- this.count++;
- this.items[0] = element;
- }
- return this.size();
- }
- /**
- * 返回队列尾部的元素
- * @returns T
- */;
- _proto2.getTail = function getTail() {
- if (this.isEmpty()) return undefined;
- this.count--;
- var res = this.items[this.count];
- delete this.items[this.count];
- return res;
- }
- /**
- * 返回头部元素
- * @returns T
- */;
- _proto2.getHead = function getHead() {
- if (this.isEmpty()) return undefined;
- var res = this.items[this.lowestCount];
- delete this.items[this.lowestCount];
- this.lowestCount++;
- return res;
- }
- /**
- * 看一下队列首部的元素
- * @returns T
- */;
- _proto2.peekHead = function peekHead() {
- if (this.isEmpty()) return undefined;
- return this.items[this.lowestCount];
- }
- /**
- * 看一下队列尾部的元素
- * @return T
- */;
- _proto2.peekTail = function peekTail() {
- if (this.isEmpty()) return undefined;
- return this.items[this.count - 1];
- }
- /**
- * 返回元素的个数
- * @returns number
- */;
- _proto2.size = function size() {
- return this.count - this.lowestCount;
- }
- /**
- * 判断队列是否为空
- */;
- _proto2.isEmpty = function isEmpty() {
- return this.size() === 0;
- }
- /**
- * 清空队列
- */;
- _proto2.clear = function clear() {
- this.items = {};
- this.count = this.lowestCount = 0;
- };
- _proto2.toString = function toString() {
- if (this.isEmpty()) {
- return '';
- }
- var res = this.items[this.lowestCount].toString();
- for (var i = this.lowestCount + 1; i < this.count; i++) {
- res = res + ", " + this.items[i].toString();
- }
- return res;
- };
- return Deque;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Random.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports('default', get_new_random);
- cclegacy._RF.push({}, "0df919aG5RLDb2SUzCkvbif", "Random", undefined);
- /**设种一个随机种子保证随机结果一致
- * 后面需要可以引入 seedrandom 库
- */
- var Random = /*#__PURE__*/function () {
- /**随机种子*/
- function Random(seed) {
- this._seed = void 0;
- this._start_seed = void 0;
- this.set_seed(seed);
- }
- /**设置当前开始种子*/
- var _proto = Random.prototype;
- _proto.set_seed = function set_seed(seed) {
- this._seed = seed;
- this._start_seed = seed;
- };
- _proto._nextSeed = function _nextSeed() {
- this._seed = (this._seed * 9301 + 49297) % 233280;
- }
- /**0.0(含)-1.0(不含)*/;
- _proto._nextFloat = function _nextFloat() {
- this._nextSeed();
- return this._seed / 233280;
- }
- /**0(含)-max(不含) */;
- _proto._nextInt = function _nextInt(max) {
- max = Math.floor(max);
- this._nextSeed();
- return this._seed % max;
- }
- /**
- * 生成指定范围的随机浮点数
- * @param min 最小值(含)
- * @param max 最大值(不含)
- */;
- _proto["float"] = function float(min, max) {
- if (min === void 0) {
- min = 0;
- }
- if (max === void 0) {
- max = 1;
- }
- return this._nextFloat() * (max - min) + min;
- }
- /**
- * 生成指定范围的随机整数
- * @param min 最小值(含)
- * @param max 最大值(不含)
- * @returns
- */;
- _proto["int"] = function int(min, max) {
- if (min === void 0) {
- min = 0;
- }
- if (max === void 0) {
- max = 100;
- }
- return this._nextInt(max - min) + Math.ceil(min);
- }
- /** 生成随机整数 -1 或 1*/;
- _proto.dir = function dir() {
- return Math.floor(this["float"]() * 2) === 0 ? -1 : 1;
- }
- /**
- * 在指定数组中随机取出N个不重复的数据
- * @param resArr
- * @param ranNum
- * @returns {Array}
- */;
- _proto.getDiffValueFromArr = function getDiffValueFromArr(resArr, ranNum) {
- var arr = new Array();
- var result = new Array();
- if (!resArr || resArr.length <= 0 || ranNum <= 0) {
- return result;
- }
- for (var i = 0; i < resArr.length; i++) {
- arr.push(resArr[i]);
- }
- if (ranNum >= arr.length) return arr;
- ranNum = Math.min(ranNum, arr.length - 1);
- for (var _i = 0; _i < ranNum; _i++) {
- var ran = this["int"](0, arr.length - 1);
- result.push(arr.splice(ran, 1)[0]);
- }
- return result;
- }
- /**
- * 生成指定范围的随机整数
- * @param min 最小值
- * @param max 最大值
- * @param type 类型
- * @example
- //type=1 [min,max) 得到一个两数之间的随机整数,这个值不小于min(如果min不是整数的话,得到一个向上取整的 min),并且小于(但不等于)max
- //type=2 [min,max] 得到一个两数之间的随机整数,包括两个数在内,这个值比min大(如果min不是整数,那就不小于比min大的整数),但小于(但不等于)max
- //type=3 (min,max) 得到一个两数之间的随机整数
- */;
- _proto.int_type = function int_type(min, max, type) {
- min = Math.ceil(min);
- max = Math.floor(max);
- switch (type) {
- case 1:
- // [min,max) 得到一个两数之间的随机整数,这个值不小于min(如果min不是整数的话,得到一个向上取整的 min),并且小于(但不等于)max
- return Math.floor(this._nextFloat() * (max - min)) + min;
- case 2:
- // [min,max] 得到一个两数之间的随机整数,包括两个数在内,这个值比min大(如果min不是整数,那就不小于比min大的整数),但小于(但不等于)max
- return Math.floor(this._nextFloat() * (max - min + 1)) + min;
- case 3:
- // (min,max) 得到一个两数之间的随机整数
- return Math.floor(this._nextFloat() * (max - min - 1)) + min + 1;
- }
- return 0;
- };
- _createClass(Random, [{
- key: "seed",
- get: /**当前种子*/
- function get() {
- return this._seed;
- }
- /**原始种子*/
- }, {
- key: "start_seed",
- get: function get() {
- return this._start_seed;
- }
- }]);
- return Random;
- }();
- /**创建一个设定好种子的随机数实例*/
- function get_new_random(seed) {
- return new Random(seed);
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ResUtil.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _asyncToGenerator, _regeneratorRuntime, cclegacy, assetManager, resources, AssetManager, director, Texture2D, ImageAsset;
- return {
- setters: [function (module) {
- _asyncToGenerator = module.asyncToGenerator;
- _regeneratorRuntime = module.regeneratorRuntime;
- }, function (module) {
- cclegacy = module.cclegacy;
- assetManager = module.assetManager;
- resources = module.resources;
- AssetManager = module.AssetManager;
- director = module.director;
- Texture2D = module.Texture2D;
- ImageAsset = module.ImageAsset;
- }],
- execute: function () {
- exports('ResUtil', void 0);
- cclegacy._RF.push({}, "fdca4buPvxCtqd20MSvpC7T", "ResUtil", undefined);
- //export type Constructor<T extends Asset> = new () => T;
- var headImgExt = exports('headImgExt', ".head");
- var ResUtil;
- (function (_ResUtil) {
- function loadRemote(url, option) {
- return new Promise(function (resolve, reject) {
- assetManager.loadRemote(url, option, function (err, asset) {
- resolve && resolve(err ? null : asset);
- });
- });
- }
- _ResUtil.loadRemote = loadRemote;
- function loadBundle(bundleName) {
- return new Promise(function (resolve, reject) {
- assetManager.loadBundle(bundleName, function (err, bundle) {
- resolve && resolve(err ? null : bundle);
- });
- });
- }
- _ResUtil.loadBundle = loadBundle;
- function getBundle(bundleName) {
- if (null == bundleName || '' === bundleName) {
- return resources;
- } else {
- return assetManager.getBundle(bundleName);
- }
- }
- _ResUtil.getBundle = getBundle;
- function loadAsset(_x, _x2) {
- return _loadAsset.apply(this, arguments);
- }
- function _loadAsset() {
- _loadAsset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(path, bundle) {
- var bd, asset;
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) switch (_context.prev = _context.next) {
- case 0:
- if (!bundle) bundle = '';
- if (!(typeof bundle === 'string')) {
- _context.next = 9;
- break;
- }
- bd = getBundle(bundle);
- if (bd) {
- _context.next = 7;
- break;
- }
- _context.next = 6;
- return loadBundle(bundle);
- case 6:
- bd = _context.sent;
- case 7:
- _context.next = 10;
- break;
- case 9:
- if (bundle instanceof AssetManager.Bundle) {
- bd = bundle;
- }
- case 10:
- asset = bd.get(path);
- if (!(null != asset)) {
- _context.next = 13;
- break;
- }
- return _context.abrupt("return", Promise.resolve(asset));
- case 13:
- return _context.abrupt("return", new Promise(function (resolve, reject) {
- bd.load(path, function (err, asset) {
- resolve(err ? null : asset);
- });
- }));
- case 14:
- case "end":
- return _context.stop();
- }
- }, _callee);
- }));
- return _loadAsset.apply(this, arguments);
- }
- _ResUtil.loadAsset = loadAsset;
- function loadDir(_x3, _x4, _x5) {
- return _loadDir.apply(this, arguments);
- }
- function _loadDir() {
- _loadDir = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(path, bundle, progressCallback) {
- var bd;
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
- while (1) switch (_context2.prev = _context2.next) {
- case 0:
- if (!bundle) bundle = '';
- if (!(typeof bundle === 'string')) {
- _context2.next = 9;
- break;
- }
- bd = getBundle(bundle);
- if (bd) {
- _context2.next = 7;
- break;
- }
- _context2.next = 6;
- return loadBundle(bundle);
- case 6:
- bd = _context2.sent;
- case 7:
- _context2.next = 10;
- break;
- case 9:
- if (bundle instanceof AssetManager.Bundle) {
- bd = bundle;
- }
- case 10:
- return _context2.abrupt("return", new Promise(function (resolve, reject) {
- bd.loadDir(path, function (finished, total, item) {
- progressCallback == null || progressCallback(finished, total);
- }, function (err, assets) {
- resolve(err ? null : assets);
- });
- }));
- case 11:
- case "end":
- return _context2.stop();
- }
- }, _callee2);
- }));
- return _loadDir.apply(this, arguments);
- }
- _ResUtil.loadDir = loadDir;
- function loadAssets(_x6, _x7, _x8) {
- return _loadAssets.apply(this, arguments);
- }
- function _loadAssets() {
- _loadAssets = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(list, bundle, progressCallback) {
- var bd;
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
- while (1) switch (_context3.prev = _context3.next) {
- case 0:
- if (!bundle) bundle = '';
- if (!(typeof bundle === 'string')) {
- _context3.next = 9;
- break;
- }
- bd = getBundle(bundle);
- if (bd) {
- _context3.next = 7;
- break;
- }
- _context3.next = 6;
- return loadBundle(bundle);
- case 6:
- bd = _context3.sent;
- case 7:
- _context3.next = 10;
- break;
- case 9:
- if (bundle instanceof AssetManager.Bundle) {
- bd = bundle;
- }
- case 10:
- return _context3.abrupt("return", new Promise(function (resolve, reject) {
- bd.load(list, function (finished, total, item) {
- progressCallback == null || progressCallback(finished, total);
- }, function (err, data) {
- resolve(err ? null : data);
- });
- }));
- case 11:
- case "end":
- return _context3.stop();
- }
- }, _callee3);
- }));
- return _loadAssets.apply(this, arguments);
- }
- _ResUtil.loadAssets = loadAssets;
- function loadScene(_x9, _x10, _x11) {
- return _loadScene.apply(this, arguments);
- }
- function _loadScene() {
- _loadScene = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(scene_name, bundle, show) {
- var bd;
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
- while (1) switch (_context4.prev = _context4.next) {
- case 0:
- if (show === void 0) {
- show = false;
- }
- if (!bundle) bundle = '';
- if (!(typeof bundle === 'string')) {
- _context4.next = 10;
- break;
- }
- bd = getBundle(bundle);
- if (bd) {
- _context4.next = 8;
- break;
- }
- _context4.next = 7;
- return loadBundle(bundle);
- case 7:
- bd = _context4.sent;
- case 8:
- _context4.next = 11;
- break;
- case 10:
- if (bundle instanceof AssetManager.Bundle) {
- bd = bundle;
- }
- case 11:
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
- bd.loadScene(scene_name, function (err, asset) {
- resolve(err ? null : asset);
- if (show) director.loadScene(scene_name);
- });
- }));
- case 12:
- case "end":
- return _context4.stop();
- }
- }, _callee4);
- }));
- return _loadScene.apply(this, arguments);
- }
- _ResUtil.loadScene = loadScene;
- function releaseAll() {
- assetManager.releaseAll();
- }
- _ResUtil.releaseAll = releaseAll;
- function releaseAsset(asset) {
- assetManager.releaseAsset(asset);
- }
- _ResUtil.releaseAsset = releaseAsset;
- function release(path, bundle) {
- var bd;
- if (!bundle) bundle = '';
- if (typeof bundle === 'string') {
- bd = getBundle(bundle);
- } else if (bundle instanceof AssetManager.Bundle) {
- bd = bundle;
- }
- if (path && path != '') {
- var _bd;
- (_bd = bd) == null || _bd.release(path);
- } else {
- var _bd2;
- (_bd2 = bd) == null || _bd2.releaseAll();
- }
- }
- _ResUtil.release = release;
- function registerHeadImgLoader() {
- assetManager.downloader.register(headImgExt, function (content, options, onComplete) {
- onComplete(null, content);
- });
- assetManager.parser.register(headImgExt, downloadDomImage);
- assetManager.factory.register(headImgExt, createTexture);
- }
- _ResUtil.registerHeadImgLoader = registerHeadImgLoader;
- function createTexture(id, data, options, onComplete) {
- var out = null;
- var err = null;
- try {
- out = new Texture2D();
- var imageAsset = new ImageAsset(data);
- out.image = imageAsset;
- } catch (e) {
- err = e;
- }
- onComplete && onComplete(err, out);
- }
- function downloadDomImage(url, options, onComplete) {
- var img = new Image();
- if (window.location.protocol !== 'file:') {
- img.crossOrigin = 'anonymous';
- }
- function loadCallback() {
- img.removeEventListener('load', loadCallback);
- img.removeEventListener('error', errorCallback);
- if (onComplete) {
- onComplete(null, img);
- }
- }
- function errorCallback() {
- img.removeEventListener('load', loadCallback);
- img.removeEventListener('error', errorCallback);
- if (onComplete) {
- onComplete(new Error(url));
- }
- }
- img.addEventListener('load', loadCallback);
- img.addEventListener('error', errorCallback);
- img.src = url;
- return img;
- }
- })(ResUtil || (ResUtil = exports('ResUtil', {})));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/RewardFly.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _inheritsLoose, cclegacy, _decorator, UITransform, Node, Vec3, instantiate, Widget, v3, UIOpacity, tween, easing, Component;
- return {
- setters: [function (module) {
- _inheritsLoose = module.inheritsLoose;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- UITransform = module.UITransform;
- Node = module.Node;
- Vec3 = module.Vec3;
- instantiate = module.instantiate;
- Widget = module.Widget;
- v3 = module.v3;
- UIOpacity = module.UIOpacity;
- tween = module.tween;
- easing = module.easing;
- Component = module.Component;
- }],
- execute: function () {
- var _dec, _dec2, _class;
- cclegacy._RF.push({}, "9d999oa7ZtO/Jhnk1+iN63E", "RewardFly", undefined);
- var ccclass = _decorator.ccclass,
- requireComponent = _decorator.requireComponent;
- var RewardFly = exports('RewardFly', (_dec = ccclass('RewardFly'), _dec2 = requireComponent(UITransform), _dec(_class = _dec2(_class = /*#__PURE__*/function (_Component) {
- _inheritsLoose(RewardFly, _Component);
- function RewardFly() {
- return _Component.apply(this, arguments) || this;
- }
- var _proto = RewardFly.prototype;
- _proto.onLoad = function onLoad() {
- //this.node.on(Node.EventType.TOUCH_START, function (event: EventTouch) {
- //event.propagationStopped = true;
- //event.preventSwallow = true;
- //}, this, true);
- };
- _proto.onDisable = function onDisable() {
- this.node.destroyAllChildren();
- };
- _proto.convertToNodeSpaceAR = function convertToNodeSpaceAR(target) {
- if (target instanceof Node) {
- return this.node.getComponent(UITransform).convertToNodeSpaceAR(target.getComponent(UITransform).convertToWorldSpaceAR(Vec3.ZERO));
- }
- return this.node.getComponent(UITransform).convertToNodeSpaceAR(target);
- };
- _proto.add = function add(opts) {
- var _this = this;
- var startPos = this.convertToNodeSpaceAR(opts.start);
- var endPos = this.convertToNodeSpaceAR(opts.end);
- if (opts.endOffset) {
- endPos.add3f(opts.endOffset[0], opts.endOffset[1], 0);
- }
- var nodeCopy = null;
- if (opts.highlight) {
- if (opts.highlightOffset) {
- endPos.add3f(opts.highlightOffset[0], opts.highlightOffset[1], 0);
- }
- if (opts.highlightArea) {
- var _nodeCopy$getComponen;
- var endAreaPos = this.convertToNodeSpaceAR(opts.highlightArea);
- if (opts.highlightOffset) {
- endAreaPos.add3f(opts.highlightOffset[0], opts.highlightOffset[1], 0);
- }
- nodeCopy = instantiate(opts.highlightArea);
- (_nodeCopy$getComponen = nodeCopy.getComponent(Widget)) == null || _nodeCopy$getComponen.destroy();
- nodeCopy.setParent(this.node);
- nodeCopy.setPosition(endAreaPos);
- } else if (Node.isNode(opts.end)) {
- var _nodeCopy$getComponen2;
- nodeCopy = instantiate(opts.end);
- (_nodeCopy$getComponen2 = nodeCopy.getComponent(Widget)) == null || _nodeCopy$getComponen2.destroy();
- nodeCopy.setParent(this.node);
- nodeCopy.setPosition(endPos);
- }
- }
- var _loop = function _loop(index) {
- var aniNode = instantiate(opts.item);
- aniNode.setPosition(startPos);
- aniNode.setParent(_this.node);
- // 炸开位置
- var midPos = v3(startPos.x, startPos.y, 0);
- midPos.x += (Math.random() * 2 - 1) * (opts.startRange ? opts.startRange[0] : 100);
- midPos.y += (Math.random() * 2 - 1) * (opts.startRange ? opts.startRange[1] : 100);
- // 执行动画
- (aniNode.getComponent(UIOpacity) || aniNode.addComponent(UIOpacity)).opacity = 0;
- tween(aniNode).delay(index * 0.025).call(function () {
- aniNode.getComponent(UIOpacity).opacity = 200;
- tween(aniNode.getComponent(UIOpacity)).to(0.4, {
- opacity: 255
- }, {
- easing: easing.expoOut
- }).start();
- }).to(0.4, {
- position: midPos
- }, {
- easing: easing.expoOut
- }).call(function () {
- tween(aniNode.getComponent(UIOpacity)).delay(0.5).to(0.1, {
- opacity: 70
- }).start();
- }).to(0.6, {
- position: endPos
- }, {
- easing: easing.expoIn
- }).call(function () {
- if (index === 0) {
- // 结束节点缩放
- if (nodeCopy) {
- var scale = v3(nodeCopy.scale);
- tween(nodeCopy).to(0.1, {
- scale: v3(scale.x * 1.3, scale.y * 1.3)
- }).delay(0.025 * Math.max(opts.count, 4)).to(0.1, {
- scale: scale
- }).call(function () {
- // 结束节点透明销毁
- var uiOpacity = nodeCopy.getComponent(UIOpacity) || nodeCopy.addComponent(UIOpacity);
- tween(uiOpacity).to(0.1, {
- opacity: uiOpacity.opacity * 0.3
- }).call(function () {
- return nodeCopy.destroy();
- }).start();
- }).start();
- }
- opts.onBegin && opts.onBegin(nodeCopy);
- }
- opts.onContact && opts.onContact(nodeCopy);
- }).delay(0.01).call(function () {
- aniNode.destroy();
- if (index === opts.count - 1) {
- opts.onFinish && opts.onFinish(nodeCopy);
- }
- }).start();
- };
- for (var index = 0; index < opts.count; index++) {
- _loop(index);
- }
- };
- return RewardFly;
- }(Component)) || _class) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/SafeNumber.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports({
- get_new_safe_const_number: get_new_safe_const_number,
- get_new_safe_number: get_new_safe_number
- });
- cclegacy._RF.push({}, "7e0d8kg6FBL46wNVfNiK7eE", "SafeNumber", undefined);
- /**
- * 防内存调试变量数字类型
- */
- var SafeVarNumber = /*#__PURE__*/function () {
- function SafeVarNumber(num) {
- if (num === void 0) {
- num = 0;
- }
- this.cache = 0;
- this.scale = 2;
- this.map = {};
- this.idx = 0;
- this.value = num;
- }
- /**数值 */
- var _proto = SafeVarNumber.prototype;
- _proto.valueOf = function valueOf() {
- return this.value;
- };
- _proto.toString = function toString() {
- return this.value.toString();
- };
- _proto.clone = function clone() {
- return new SafeVarNumber(this.value);
- };
- _createClass(SafeVarNumber, [{
- key: "value",
- get: function get() {
- if (Math.abs(this.map[this.idx] * this.scale - this.cache) > 0.000001) {
- this.map[this.idx] = this.cache / this.scale;
- }
- return this.map[this.idx];
- },
- set: function set(num) {
- delete this.map[this.idx];
- this.idx = Math.floor(Math.random() * 256);
- this.map[this.idx] = num;
- this.scale = Math.floor(Math.random() * 2) + 2;
- this.cache = num * this.scale;
- }
- }]);
- return SafeVarNumber;
- }();
- /**
- * 防内存调试常量数字类型
- */
- var SafeConstNumber = /*#__PURE__*/function () {
- function SafeConstNumber(num) {
- if (num === void 0) {
- num = 0;
- }
- this.cache = 0;
- this.scale = 2;
- this.map = {};
- this.idx = 0;
- this.idx = Math.floor(Math.random() * 256);
- this.map[this.idx] = num;
- this.scale = Math.floor(Math.random() * 2) + 2;
- this.cache = num * this.scale;
- }
- /**数值 */
- var _proto2 = SafeConstNumber.prototype;
- _proto2.valueOf = function valueOf() {
- return this.value;
- };
- _proto2.toString = function toString() {
- return this.value.toString();
- };
- _proto2.clone = function clone() {
- return new SafeConstNumber(this.value);
- };
- _createClass(SafeConstNumber, [{
- key: "value",
- get: function get() {
- var num = this.map[this.idx];
- if (Math.abs(num * this.scale - this.cache) > 0.000001) {
- num = this.cache / this.scale;
- }
- delete this.map[this.idx];
- this.idx = Math.floor(Math.random() * 256);
- this.map[this.idx] = num;
- return this.map[this.idx];
- }
- }]);
- return SafeConstNumber;
- }();
- function get_new_safe_number(num) {
- return new SafeVarNumber(num);
- }
- function get_new_safe_const_number(num) {
- return new SafeConstNumber(num);
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/SceneDef.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "01aa7QePwpMF4PE+VsC8QVh", "SceneDef", undefined);
- var SceneDef = exports('SceneDef', function SceneDef() {});
- SceneDef.START = 'start';
- SceneDef.GAME = 'game';
- SceneDef.Hall = 'hall';
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Shake.ts", ['cc'], function (exports) {
- var Vec3, cclegacy;
- return {
- setters: [function (module) {
- Vec3 = module.Vec3;
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports('default', get_new_shake);
- cclegacy._RF.push({}, "88adahxArtIPKhtXnEB29+o", "Shake", undefined);
- var Shake = /*#__PURE__*/function () {
- function Shake(startPos) {
- if (startPos === void 0) {
- startPos = new Vec3(0, 0, 0);
- }
- this.intensity = void 0;
- this.duration = void 0;
- this.shakePos = new Vec3(0, 0, 0);
- this.startPos = startPos;
- this.duration = 0;
- this.intensity = 0;
- }
- /**改变初起点*/
- var _proto = Shake.prototype;
- _proto.setStartPos = function setStartPos(x, y) {
- this.startPos.x = x;
- this.startPos.y = y;
- }
- /**开始抖动
- * duration 时间
- * intensity 强度
- */;
- _proto.start = function start(duration, intensity) {
- if (duration === void 0) {
- duration = 0.3;
- }
- if (intensity === void 0) {
- intensity = 3.8;
- }
- this.duration = duration;
- this.intensity = intensity;
- }
- /**停止抖动*/;
- _proto.stop = function stop() {
- this.shakePos.x = this.startPos.x;
- this.shakePos.y = this.startPos.y;
- this.duration = 0;
- return this.shakePos;
- };
- _proto.getShakePos = function getShakePos() {
- return this.shakePos;
- };
- _proto.action = function action(dt) {
- if (this.duration > 0) {
- this.duration -= dt;
- if (this.duration <= 0) {
- return this.stop();
- } else {
- var randomX = Math.random() * this.intensity - this.intensity * 0.5;
- var randomY = Math.random() * this.intensity - this.intensity * 0.5;
- this.shakePos.x = this.startPos.x + randomX;
- this.shakePos.y = this.startPos.y + randomY;
- return this.shakePos;
- }
- }
- return null;
- };
- return Shake;
- }();
- function get_new_shake(startPos) {
- if (startPos === void 0) {
- startPos = new Vec3(0, 0, 0);
- }
- return new Shake(startPos);
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/sign.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "6d031yryKRLYaiOHaXKh4Av", "sign", undefined);
- var ch_sign = exports('default', /*#__PURE__*/function () {
- function ch_sign() {
- this._sign_data = new Set();
- this._max = 7;
- this._creat_date = 0;
- this._sign_count = 0;
- this._mode = 1;
- }
- ch_sign.getInstance = function getInstance() {
- if (!this._instance) this._instance = new ch_sign();
- return this._instance;
- };
- var _proto = ch_sign.prototype;
- _proto.getCreatDayCount = function getCreatDayCount() {
- if (this._creat_date == 0) {
- chsdk.log.warn("签到模块没有初始化");
- return 0;
- }
- return chsdk.date.getDiffDayNum(this._creat_date, chsdk.date.now()) + 1;
- }
- /**
- * 签到初始化
- * @param mode =1可以补签 =2不可补签
- * @param data 签到存档数据,可以为空为第一天
- * @param max_day 签到最大天数
- */;
- _proto.init = function init(mode, data, max_day) {
- if (max_day === void 0) {
- max_day = 7;
- }
- this._mode = mode;
- if (this._mode == 1) {
- if (data) {
- var _data$sign_list, _data$creat_date;
- data = data;
- var sign_list = (_data$sign_list = data.sign_list) != null ? _data$sign_list : [];
- var creat_date = (_data$creat_date = data.creat_date) != null ? _data$creat_date : chsdk.date.now();
- for (var i = 0; i < sign_list.length; i++) this._sign_data.add(sign_list[i]);
- this._sign_count = this._sign_data.size;
- this._creat_date = creat_date;
- } else {
- this._sign_count = 0;
- this._sign_data.clear();
- this._creat_date = chsdk.date.now();
- }
- } else {
- if (data) {
- var _data$sign_count, _data$last_date;
- data = data;
- this._sign_count = (_data$sign_count = data.sign_count) != null ? _data$sign_count : 0;
- this._creat_date = (_data$last_date = data.last_date) != null ? _data$last_date : 0;
- } else {
- this._sign_count = 0;
- this._creat_date = 0;
- }
- }
- this._max = max_day;
- }
- /**已签到的数据,用于存档*/;
- _proto.getSignData = function getSignData() {
- if (this._mode == 1) {
- return {
- sign_list: Array.from(this._sign_data.keys()),
- creat_date: this._creat_date
- };
- } else if (this._mode == 2) {
- return {
- sign_count: this._sign_count,
- last_date: this._creat_date
- };
- }
- }
- /** 返回某一天的状态
- * 0 等待签到
- * 1 已经签到
- * 2 失效等待补签
- * */;
- _proto.checkSigineState = function checkSigineState(day) {
- if (this._mode == 1) {
- if (day < 1 || day > this._max) return 0;
- if (this._sign_data.has(day)) return 1;
- var count = this.getCreatDayCount();
- if (count <= 0) return 0;
- if (day < count) return 2;
- } else if (this._mode == 2) {
- if (day <= this._sign_count) return 1;
- }
- return 0;
- }
- /**今天是否可以签到*/;
- _proto.checkSigin = function checkSigin() {
- if (this._mode == 1) {
- var count = this.getCreatDayCount();
- if (count <= 0 || count > this._max) return false;
- return !this._sign_data.has(count);
- } else if (this._mode == 2) {
- var _count = this._sign_count;
- if (_count >= this._max) return false;
- return !chsdk.date.isSameDate(this._creat_date, chsdk.date.now());
- }
- return false;
- }
- /**签到是否全部完成*/;
- _proto.checkSiginComplete = function checkSiginComplete() {
- var count = this._sign_count;
- return count >= this._max;
- }
- /**
- * 是否能补签
- * 不能返回0,
- * 可以补签返回可以补签的那一天*/;
- _proto.checkReSigin = function checkReSigin() {
- if (this._mode != 1) return 0;
- var count = this.getCreatDayCount() - 1;
- if (count <= 0) return 0;
- if (count > this._max) count = this._max;
- for (var i = 1; i <= count; i++) {
- if (!this._sign_data.has(i)) return i;
- }
- return 0;
- }
- /**签到
- * 失败返回 0
- * 成功返回签到当天
- */;
- _proto.signIn = function signIn() {
- if (!this.checkSigin()) {
- return 0;
- }
- if (this._mode == 1) {
- var day = this.getCreatDayCount();
- this._sign_data.add(day);
- this._sign_count = this._sign_data.size;
- return day;
- } else if (this._mode == 2) {
- this._sign_count++;
- this._creat_date = chsdk.date.now();
- return this._sign_count;
- }
- return 0;
- }
- /**补签
- * 失败返回 0
- * 成功返回补签那天
- */;
- _proto.reSignIn = function reSignIn() {
- if (this._mode != 1) return 0;
- var index = this.checkReSigin();
- if (index <= 0 || index > this._max) {
- return 0;
- }
- this._sign_data.add(index);
- this._sign_count = this._sign_data.size;
- return index;
- }
- //
- ;
- _createClass(ch_sign, [{
- key: "max_day",
- get: /**设定的签到天数*/
- function get() {
- return this._max;
- }
- }]);
- return ch_sign;
- }());
- ch_sign._instance = void 0;
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/SpineView.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _applyDecoratedDescriptor, _inheritsLoose, _initializerDefineProperty, _assertThisInitialized, cclegacy, _decorator, sp, Color, sys, Component;
- return {
- setters: [function (module) {
- _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
- _inheritsLoose = module.inheritsLoose;
- _initializerDefineProperty = module.initializerDefineProperty;
- _assertThisInitialized = module.assertThisInitialized;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- sp = module.sp;
- Color = module.Color;
- sys = module.sys;
- Component = module.Component;
- }],
- execute: function () {
- var _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2;
- cclegacy._RF.push({}, "ce889T62SpI8ot39/O0nFrT", "SpineView", undefined);
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- /**
- * spine动画表现管理
- * @author
- *
- */
- var SpineView = exports('default', (_dec = ccclass('SpineView'), _dec2 = property({
- displayName: '待机'
- }), _dec3 = property({
- type: sp.Skeleton,
- tooltip: '角色动画'
- }), _dec(_class = (_class2 = /*#__PURE__*/function (_Component) {
- _inheritsLoose(SpineView, _Component);
- function SpineView() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _this.skin = "default";
- _initializerDefineProperty(_this, "idle", _descriptor, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "spine", _descriptor2, _assertThisInitialized(_this));
- _this.cur = null;
- _this.OnComp = void 0;
- _this.resetColor = Color.WHITE;
- return _this;
- }
- var _proto = SpineView.prototype;
- _proto.onLoad = function onLoad() {
- //console.log("111111111111");
- //this.spine.enableBatch=false;
- if (sys.isNative) {
- //原生共享模式有bug
- this.spine.setAnimationCacheMode(sp.AnimationCacheMode.REALTIME);
- this.spine.clearTracks(); //清理所有播放队列的动画
- }
- //this.SetSkin(this.skin);
- };
- _proto.start = function start() {
- this.DoAnimation(this.idle, true);
- this.spine.setCompleteListener(function () {
- if (this.OnComp) this.OnComp();
- }.bind(this));
- };
- _proto.onBeforeRemove = function onBeforeRemove() {
- this.spine.setCompleteListener(null);
- };
- _proto.Dispos = function Dispos() {
- this.ResetColor();
- this.OnComp = null;
- //this.spine.setCompleteListener(null);
- };
- _proto.SetSkin = function SetSkin(skin) {
- this.spine.setSkin(skin);
- };
- _proto.DoAnimation = function DoAnimation(animation, loop, track, force) {
- if (loop === void 0) {
- loop = true;
- }
- if (track === void 0) {
- track = 0;
- }
- if (force === void 0) {
- force = false;
- }
- if (force) {
- this.spine.setAnimation(track, animation, loop);
- return;
- }
- if (this.cur == animation) return;
- this.spine.setAnimation(track, animation, loop);
- }
- /**设置是否暂停 */;
- _proto.SetPaused = function SetPaused(paused) {
- this.spine.paused = paused;
- }
- /**获取是否暂停 */;
- _proto.GetPaused = function GetPaused() {
- return this.spine.paused;
- };
- _proto.CheckPaused = function CheckPaused(paused) {
- if (this.spine.paused != paused) this.spine.paused = paused;
- }
- /** 闪色表现 Color.RED 0.1*/;
- _proto.Flash = function Flash(color, time) {
- var _this2 = this;
- if (this.spine.color != color) {
- this.spine.color = color;
- this.unscheduleAllCallbacks();
- this.scheduleOnce(function () {
- _this2.spine.color = _this2.resetColor;
- }, time);
- }
- };
- _proto.ChangeMagenta = function ChangeMagenta() {
- this.ChangeColor(Color.MAGENTA);
- };
- _proto.ChangeGreen = function ChangeGreen() {
- this.ChangeColor(Color.GREEN);
- };
- _proto.ChangeGray = function ChangeGray() {
- this.ChangeColor(Color.GRAY);
- };
- _proto.ChangeRed = function ChangeRed() {
- this.ChangeColor(Color.RED);
- };
- _proto.ChangeCyan = function ChangeCyan() {
- this.ChangeColor(Color.CYAN);
- };
- _proto.ChangeBlack = function ChangeBlack() {
- this.ChangeColor(Color.BLACK);
- };
- _proto.ChangeBule = function ChangeBule() {
- this.ChangeColor(Color.BLUE);
- };
- _proto.ChangeYellow = function ChangeYellow() {
- this.ChangeColor(Color.YELLOW);
- }
- //
- /** 变色表现 Color.RED 0.1*/;
- _proto.ChangeColor = function ChangeColor(color) {
- this.resetColor = color;
- if (this.spine.color != this.resetColor) {
- this.spine.color = this.resetColor;
- }
- };
- _proto.ResetColor = function ResetColor() {
- this.resetColor = Color.WHITE;
- if (this.spine.color != this.resetColor) {
- this.spine.color = this.resetColor;
- }
- }
- /**
- * 缩放动画播放速率
- * @override
- * @param scale 缩放倍率
- */;
- _proto.scaleTime = function scaleTime(scale) {
- if (scale > 0) this.spine.timeScale = scale;
- };
- _proto.getBone = function getBone(name) {
- var bone = this.spine.findBone(name);
- return bone;
- }
- /**
- * 换装
- * @param slotName 插槽名字
- * @param attachmentName 元素名字
- */;
- _proto.changeEquipment = function changeEquipment(slotName, attachmentName) {
- if (attachmentName === void 0) {
- attachmentName = null;
- }
- var slot = this.spine.findSlot(slotName);
- if (slot) {
- if (attachmentName) {
- var attachment = this.spine.getAttachment(slotName, attachmentName);
- slot.setAttachment(attachment);
- } else {
- slot.setAttachment(null);
- }
- }
- }
- /**换装
- * @param skinName 要替换的部件皮肤名称
- * @param slotName 要替换的部件的插槽名称
- * @param targetAttaName Spine中皮肤占位符的名字
- */;
- _proto.changeSlot = function changeSlot(skinName, slotName, targetAttaName) {
- //查找局部皮肤
- var skeletonData = this.spine.skeletonData.getRuntimeData();
- var targetSkin = skeletonData.findSkin(skinName);
- //查找局部皮肤下的插槽与附件
- var targetSkinSlotIndex = skeletonData.findSlotIndex(slotName);
- var atta = targetSkin.getAttachment(targetSkinSlotIndex, targetAttaName);
- //查找全身皮肤下的插槽
- var curSlot = this.spine.findSlot(slotName);
- //替换全身皮肤插槽的附件
- curSlot && curSlot.setAttachment(atta);
- };
- return SpineView;
- }(Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "idle", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return "";
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "spine", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- })), _class2)) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Start.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './ch.ts', './ui.ts', './ch_start_pack.ts', './ResUtil.ts', './ModuleDef.ts', './SceneDef.ts'], function (exports) {
- var _applyDecoratedDescriptor, _inheritsLoose, _initializerDefineProperty, _assertThisInitialized, _asyncToGenerator, _regeneratorRuntime, cclegacy, _decorator, ProgressBar, Prefab, game, ch, gui, ch_start_pack, ResUtil, ModuleDef, SceneDef;
- return {
- setters: [function (module) {
- _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
- _inheritsLoose = module.inheritsLoose;
- _initializerDefineProperty = module.initializerDefineProperty;
- _assertThisInitialized = module.assertThisInitialized;
- _asyncToGenerator = module.asyncToGenerator;
- _regeneratorRuntime = module.regeneratorRuntime;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- ProgressBar = module.ProgressBar;
- Prefab = module.Prefab;
- game = module.game;
- }, function (module) {
- ch = module.ch;
- }, function (module) {
- gui = module.gui;
- }, function (module) {
- ch_start_pack = module.ch_start_pack;
- }, function (module) {
- ResUtil = module.ResUtil;
- }, function (module) {
- ModuleDef = module.ModuleDef;
- }, function (module) {
- SceneDef = module.SceneDef;
- }],
- execute: function () {
- var _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2, _class3;
- cclegacy._RF.push({}, "66e163GxmdDp7kaguqDvTVl", "Start", undefined);
- // import TableLoadUtil from '../core/util/TableLoadUtil';
- // import { TableUtil } from '../module_extra/table_ts/TableUtil';
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- //预加载模块
- var _preloadBundles = [ModuleDef.BASIC, ModuleDef.EXTRA, ModuleDef.GAME];
- //预加载资源
- var _preloadRes = [
- // { bundle: ModuleDef.EXTRA, url: 'ui_loading/UI_Loading' },
- {
- bundle: ModuleDef.BASIC,
- url: 'ui_alert/UI_Alert'
- }, {
- bundle: ModuleDef.BASIC,
- url: 'ui_waiting/UI_Waiting'
- }, {
- bundle: ModuleDef.BASIC,
- url: 'ui_notify/UI_Notify'
- }
- // { bundle: ModuleDef.Link, url: 'ui/main/UI_Main' },
- ];
- var _totalNum = _preloadBundles.length + _preloadRes.length + 1;
- var Start = exports('Start', (_dec = ccclass('Start'), _dec2 = property(ProgressBar), _dec3 = property({
- type: Prefab,
- displayName: 'ui初始预制体'
- }), _dec(_class = (_class2 = (_class3 = /*#__PURE__*/function (_ch_start_pack) {
- _inheritsLoose(Start, _ch_start_pack);
- function Start() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _ch_start_pack.call.apply(_ch_start_pack, [this].concat(args)) || this;
- // @property(Label)
- // txtLoading: Label;
- // @property(Slider)
- // loadingSlider: Slider;
- _initializerDefineProperty(_this, "loadingBar", _descriptor, _assertThisInitialized(_this));
- _this._percent = '1';
- _this._numCurrentLoaded = 0;
- _initializerDefineProperty(_this, "ui_prefab", _descriptor2, _assertThisInitialized(_this));
- return _this;
- }
- var _proto = Start.prototype;
- _proto.onLoad = function onLoad() {
- Start.packId = this.pid;
- };
- _proto.start = /*#__PURE__*/function () {
- var _start = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) switch (_context.prev = _context.next) {
- case 0:
- console.log('Start');
- gui.init(this.ui_prefab);
- game.frameRate = 61;
- // if (this.pid == 1) {
- // // seeg.onLoginRet(
- // // async (ret: { openid: string; white: boolean }) => {
- // // console.log(ret);
- // // await this.try_init(3);
- // // this.preloadBundle(0);
- // // }
- // // //(ret: { userId: number; openId: string; isTest: boolean; abTest: number }) => {
- // // //console.log(ret);
- // // //}
- // // )
- // // seeg.init({ gid: this.gid, loggerLevel: this.log, old: false });
- // } else {
- // await this.try_init(3);
- // this.preloadBundle(0);
- // }
- _context.next = 5;
- return this.try_init(3);
- case 5:
- this.preloadBundle(0);
- case 6:
- case "end":
- return _context.stop();
- }
- }, _callee, this);
- }));
- function start() {
- return _start.apply(this, arguments);
- }
- return start;
- }();
- _proto.onResLoaded = function onResLoaded() {
- this._numCurrentLoaded++;
- console.log(this._numCurrentLoaded);
- // this._percent = ~~(this._numCurrentLoaded / _totalNum * 100) + '%';
- };
- _proto.preloadBundle = /*#__PURE__*/function () {
- var _preloadBundle = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(idx) {
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
- while (1) switch (_context2.prev = _context2.next) {
- case 0:
- _context2.next = 2;
- return ResUtil.loadBundle(_preloadBundles[idx]);
- case 2:
- ch.log.info('module:<' + _preloadBundles[idx] + '>loaded.');
- idx++;
- this.onResLoaded();
- if (idx < _preloadBundles.length) {
- this.preloadBundle(idx);
- } else {
- this.preloadRes(0);
- }
- case 6:
- case "end":
- return _context2.stop();
- }
- }, _callee2, this);
- }));
- function preloadBundle(_x) {
- return _preloadBundle.apply(this, arguments);
- }
- return preloadBundle;
- }();
- _proto.preloadRes = /*#__PURE__*/function () {
- var _preloadRes2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(idx) {
- var res;
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
- while (1) switch (_context3.prev = _context3.next) {
- case 0:
- res = _preloadRes[idx];
- _context3.next = 3;
- return ResUtil.loadAsset(res.url, res.bundle);
- case 3:
- idx++;
- this.onResLoaded();
- if (idx < _preloadRes.length) {
- this.preloadRes(idx);
- } else {
- this.onPreloadingComplete();
- }
- case 6:
- case "end":
- return _context3.stop();
- }
- }, _callee3, this);
- }));
- function preloadRes(_x2) {
- return _preloadRes2.apply(this, arguments);
- }
- return preloadRes;
- }();
- _proto.onPreloadingComplete = /*#__PURE__*/function () {
- var _onPreloadingComplete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
- while (1) switch (_context4.prev = _context4.next) {
- case 0:
- _context4.next = 2;
- return ResUtil.loadScene(SceneDef.Hall, ModuleDef.GAME, true);
- case 2:
- this.onResLoaded();
- case 3:
- case "end":
- return _context4.stop();
- }
- }, _callee4, this);
- }));
- function onPreloadingComplete() {
- return _onPreloadingComplete.apply(this, arguments);
- }
- return onPreloadingComplete;
- }();
- _proto.update = function update(deltaTime) {
- if (this._percent) {
- // this.txtLoading.string = 'Loading...' + this._percent;
- var sc = this._numCurrentLoaded / _totalNum;
- if (sc >= 1) {
- this.loadingBar.progress = sc;
- } else {
- this.loadingBar.progress = this._numCurrentLoaded / _totalNum;
- }
- }
- // else {
- // let idx = Math.floor(game.totalTime / 1000) % 3;
- // this.txtLoading.string = _loadingText[idx];
- // }
- };
- return Start;
- }(ch_start_pack), _class3.packId = void 0, _class3), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "loadingBar", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: null
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "ui_prefab", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: null
- })), _class2)) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/State.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports('default', get_new_state);
- cclegacy._RF.push({}, "d9db0FDjAhNuLA9MVTSVAgv", "State", undefined);
- /*enum states{
- Read = 1, //0001
- Write = 2, //0010
- Create = 4,//0100
- Delete = 8 //1000
- }/**状态类型不算合并的不超过32种
- export enum StateType {
- Unmatched = 1<<1,//无敌
- Swoon = 1<<2,//晕眩
- }*/
- /**状态对像*/
- var State = /*#__PURE__*/function () {
- function State() {
- this._state = 0;
- }
- var _proto = State.prototype;
- //无状态
- _proto.Init = function Init() {
- this._state = 0;
- }
- /**是否满足传入的状态*/;
- _proto.Meet = function Meet(state) {
- return State.Has(this._state, state);
- }
- /**传入的状态是组合型时只要满足其一 */;
- _proto.MeetAny = function MeetAny(state) {
- var a = this._state & state;
- if (a === state) return true;
- if (a == 0) return false;
- return State.Has(state, a);
- }
- /**是否满足所有传入的状态*/;
- _proto.MeetAll = function MeetAll() {
- var result = 0;
- for (var i = 0; i < arguments.length; i++) {
- result |= i < 0 || arguments.length <= i ? undefined : arguments[i];
- }
- return this.Meet(State.CombieState(result));
- }
- /**是否满足其中传入的状态*/;
- _proto.MeetAnyOne = function MeetAnyOne() {
- for (var i = 0; i < arguments.length; i++) {
- if (this.Meet(i < 0 || arguments.length <= i ? undefined : arguments[i])) return true;
- }
- return false;
- }
- /**加入状态*/;
- _proto.Add = function Add(state) {
- this._state |= state;
- }
- /**删除状态*/;
- _proto.Delete = function Delete(state) {
- if (!this.Meet(state)) return;
- this._state ^= state;
- }
- /**转成状态*/;
- State.ToState = function ToState(Id) {
- return 1 << Id;
- }
- /**合并状态*/;
- State.CombieState = function CombieState() {
- var result = 0;
- for (var i = 0; i < arguments.length; i++) {
- result |= i < 0 || arguments.length <= i ? undefined : arguments[i];
- }
- return result;
- };
- State.Has = function Has(statss, state) {
- return (statss & state) === state;
- };
- return State;
- }();
- function get_new_state() {
- return new State();
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/StringUtil.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "77722BYjyNHJpJ4DuMACErZ", "StringUtil", undefined);
- var StringUtil = exports('StringUtil', /*#__PURE__*/function () {
- function StringUtil() {}
- /**小数转成保留几位小数的字符串*/
- StringUtil.ToFixed = function ToFixed(s, count) {
- return s.toFixed(count).toString();
- }
- /**秒转成 00:00时间格式*/;
- StringUtil.ToTimeString = function ToTimeString(s) {
- s = Math.floor(s);
- var m = Math.floor(s / 60);
- s = s - m * 60;
- var mm = m.toString();
- if (mm.length <= 1) {
- mm = "0".concat(mm);
- }
- if (s < 10) {
- return mm + ":" + "0".concat(s.toString());
- }
- return mm + ":" + s;
- }
- /**秒*/;
- StringUtil.ToSce = function ToSce(s, u) {
- if (u === void 0) {
- u = "s";
- }
- s = Math.floor(s);
- return "" + s + u;
- }
- /**货币值转字符 */;
- StringUtil.ToMoneyString = function ToMoneyString(n) {
- if (n > 1000000) {
- var m = Math.floor(n * 0.000001);
- n -= m * 1000000;
- if (n > 1000) {
- return m + "M" + Math.floor(n * 0.001) + "K";
- }
- return m + "M";
- } else if (n > 1000) {
- var _m = Math.floor(n * 0.001);
- n -= _m * 1000;
- if (n > 100) {
- n = Math.floor(n * 0.01);
- return _m + "K" + n;
- }
- return _m + "K";
- }
- return n.toString();
- }
- /**毫秒转秒显示*/;
- StringUtil.MS2S = function MS2S(ms) {
- return (ms * 0.001).toFixed(1);
- }
- /**
- * 去掉前后空格
- * @param str
- * @returns {string}
- */;
- var _proto = StringUtil.prototype;
- _proto.trimSpace = function trimSpace(str) {
- return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
- }
- /**
- * 获取字符串长度,中文为2
- * @param str
- */;
- _proto.getStringLength = function getStringLength(str) {
- var strArr = str.split("");
- var length = 0;
- for (var i = 0; i < strArr.length; i++) {
- var s = strArr[i];
- if (this.isChinese(s)) {
- length += 2;
- } else {
- length += 1;
- }
- }
- return length;
- }
- /**
- * 判断一个字符串是否包含中文
- * @param str
- * @returns {boolean}
- */;
- _proto.isChinese = function isChinese(str) {
- var reg = /^.*[\u4E00-\u9FA5]+.*$/;
- return reg.test(str);
- }
- /**
- * 格式化字符串 "{0},{1}.format("text0","text1")
- */;
- _proto.format = function format(val) {
- for (var i = 0, len = arguments.length <= 1 ? 0 : arguments.length - 1; i < len; i++) {
- var reg = new RegExp("({)" + i + "(})", "g");
- val = val.replace(reg, i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1]);
- }
- return val;
- };
- return StringUtil;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/TableLoadUtil.ts", ['cc'], function (exports) {
- var cclegacy, assetManager, JsonAsset;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- assetManager = module.assetManager;
- JsonAsset = module.JsonAsset;
- }],
- execute: function () {
- cclegacy._RF.push({}, "0d2abQaWYVLPptXiFU69SYv", "TableLoadUtil", undefined);
- var TableLoadUtil = exports('default', /*#__PURE__*/function () {
- function TableLoadUtil() {}
- TableLoadUtil.preloadAll = function preloadAll(bundleName, path, callback, util_cb) {
- var _this = this;
- assetManager.loadBundle(bundleName, function (err, bundle) {
- if (err) {
- console.log(err);
- return;
- }
- bundle.loadDir(path, JsonAsset, function (err, assets) {
- if (err) {
- console.log(err);
- return;
- }
- for (var i = 0; i < assets.length; i++) {
- util_cb == null || util_cb(assets[i].name, assets[i].json);
- }
- callback(assets);
- }.bind(_this));
- });
- };
- return TableLoadUtil;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/TimeJobCenter.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports('default', get_new_job);
- cclegacy._RF.push({}, "29a956DSGFLW6G8399hAoz8", "TimeJobCenter", undefined);
- /**任务*/
- var TimeTask = function TimeTask(tid, callback, destTime, delay, count) {
- this.tid = void 0;
- this.destTime = void 0;
- //延时执行时间
- this.callback = void 0;
- //执行方法
- this.count = void 0;
- //执行次数
- this.delay = void 0;
- //间隔
- this.doDelete = false;
- this.tid = tid;
- this.callback = callback;
- this.destTime = destTime;
- this.delay = delay;
- this.count = count;
- };
- /**时间单位*/
- var TimeUnit = exports('TimeUnit', /*#__PURE__*/function (TimeUnit) {
- TimeUnit[TimeUnit["Millisecond"] = 0] = "Millisecond";
- TimeUnit[TimeUnit["Second"] = 1] = "Second";
- TimeUnit[TimeUnit["Hour"] = 2] = "Hour";
- TimeUnit[TimeUnit["Day"] = 3] = "Day";
- return TimeUnit;
- }({}));
- /**
- * 时间定时任务
- * 更好管理某一模块层级的时间任务,暂停,取消等
- */
- var TimeJobCenter = /*#__PURE__*/function () {
- function TimeJobCenter() {
- this.tid = 0;
- this.tempList = new Array();
- this.taskList = new Array();
- this.nowTime = 0;
- //
- this._index = void 0;
- this._count = void 0;
- this._tt = void 0;
- }
- var _proto = TimeJobCenter.prototype;
- _proto.Dispose = function Dispose() {
- this.taskList.length = 0;
- this.tempList.length = 0;
- this.nowTime = 0;
- };
- _proto.getTid = function getTid() {
- //安全代码以防过了
- if (this.tid == Number.MAX_VALUE) {
- var id = 0;
- while (true) {
- var used = false;
- for (var index = 0; index < this.taskList.length; index++) {
- if (this.taskList[index].tid == id) {
- used = true;
- break;
- }
- }
- if (!used) {
- break;
- } else {
- id++;
- }
- }
- return id;
- } else {
- this.tid += 1;
- return this.tid;
- }
- }
- /**延迟(ms)*/;
- _proto.delay = function delay(ms) {
- var _this = this;
- return new Promise(function (resolve) {
- return _this.AddTimeTask(resolve, ms, 1, TimeUnit.Millisecond);
- });
- }
- /**延迟(s)*/;
- _proto.delay_second = function delay_second(ms) {
- var _this2 = this;
- return new Promise(function (resolve) {
- return _this2.AddTimeTask(resolve, ms, 1, TimeUnit.Second);
- });
- }
- /**
- * 增加时间任务
- * @param callback 执行方法
- * @param delay 延迟时间
- * @param count 次数
- * @param timeUnit 时间单位 默认为 秒 TimeUnit.Second
- * @returns 时间任务id
- */;
- _proto.AddTimeTask = function AddTimeTask(callback, delay, count, timeUnit) {
- if (count === void 0) {
- count = 1;
- }
- if (timeUnit === void 0) {
- timeUnit = TimeUnit.Second;
- }
- var tid = this.getTid();
- this.tempList.push(this.CreatNewTimeTask(tid, callback, delay, count, timeUnit)); //增加一个任务到缓存
- return tid;
- }
- //
- ;
- _proto.CreatNewTimeTask = function CreatNewTimeTask(tid, callback, delay, count, timeUnit) {
- if (count === void 0) {
- count = 1;
- }
- if (timeUnit === void 0) {
- timeUnit = TimeUnit.Second;
- }
- if (timeUnit != TimeUnit.Second) {
- //如果单位不是秒,就全换算成秒做为单位
- switch (timeUnit) {
- case TimeUnit.Millisecond:
- delay *= 0.001;
- break;
- case TimeUnit.Hour:
- delay *= 360;
- break;
- case TimeUnit.Day:
- delay *= 360 * 24;
- break;
- default:
- console.error("Add Task TimeUnit Type Error...");
- break;
- }
- }
- return new TimeTask(tid, callback, this.nowTime + delay, delay, count);
- }
- /**
- * 删除一个时间任务
- * @param tid 时间任务id
- * @returns 是否删除成功
- */;
- _proto.DeleteTimeTask = function DeleteTimeTask(tid) {
- var exist = false;
- var tt;
- for (var i = 0; i < this.tempList.length; i++) {
- tt = this.tempList[i];
- if (tt.tid == tid) {
- this.tempList[i].doDelete = true;
- exist = true;
- break;
- }
- }
- if (!exist) {
- for (var _i = 0; _i < this.taskList.length; _i++) {
- tt = this.taskList[_i];
- if (tt.tid == tid) {
- this.taskList[_i].doDelete = true;
- exist = true;
- break;
- }
- }
- }
- return exist;
- };
- //运行调用
- _proto.Run = function Run(dt) {
- this.nowTime += dt;
- this._count = this.tempList.length;
- if (this._count > 0) {
- for (this._index = 0; this._index < this._count; this._index++) {
- if (this.tempList[this._index].doDelete) continue;
- this.taskList.push(this.tempList[this._index]);
- }
- this.tempList.length = 0;
- }
- this._count = this.taskList.length;
- if (this._count > 0) {
- for (this._index = 0; this._index < this._count; this._index++) {
- this._tt = this.taskList[this._index];
- if (this.nowTime < this._tt.destTime) continue;
- if (this._tt.doDelete) continue;
- this._tt.callback();
- if (this._tt.count == 1) {
- this._tt.doDelete = true;
- } else if (this._tt.count > 0) {
- this._tt.count--;
- this._tt.destTime += this._tt.delay; //下次执行时间
- } else {
- this._tt.destTime += this._tt.delay;
- }
- }
- }
- this.taskList = this.taskList.filter(function (task) {
- return !task.doDelete;
- }); //把标记为删除的真正删除
- }
- //
- ;
- return TimeJobCenter;
- }();
- function get_new_job() {
- return new TimeJobCenter();
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Timer.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports('default', get_new_timer);
- cclegacy._RF.push({}, "890248SdzRIsa6dPHIO+Qxy", "Timer", undefined);
- var Timer = /*#__PURE__*/function () {
- function Timer(step) {
- if (step === void 0) {
- step = 0;
- }
- this._elapsedTime = 0;
- this._step = -1;
- this.step = step;
- }
- /**
- * 序列化(数据库存储)
- */
- var _proto = Timer.prototype;
- _proto.serialize = function serialize() {
- var data = {
- "step": this._step,
- "elapsed": this._elapsedTime
- };
- return data;
- }
- /**
- * 反序列化
- */;
- _proto.unserialize = function unserialize(data) {
- if (!data) return;
- this._step = data.step;
- this._elapsedTime = data.elapsed;
- };
- _proto.update = function update(dt) {
- if (this.step <= 0) return false;
- this._elapsedTime += dt;
- if (this._elapsedTime >= this._step) {
- this._elapsedTime -= this._step;
- return true;
- }
- return false;
- };
- _proto.reset = function reset() {
- this._elapsedTime = 0;
- };
- _proto.stop = function stop() {
- this._elapsedTime = 0;
- this.step = -1;
- };
- _createClass(Timer, [{
- key: "elapsedTime",
- get: function get() {
- return this._elapsedTime;
- }
- }, {
- key: "step",
- get: /** 触发间隔时间(秒) */
- function get() {
- return this._step;
- },
- set: function set(step) {
- this._step = step; // 每次修改时间
- this._elapsedTime = 0; // 逝去时间
- }
- }, {
- key: "coundown",
- get: function get() {
- return this._step - this._elapsedTime;
- }
- }, {
- key: "progress",
- get: function get() {
- return this._elapsedTime / this._step;
- }
- }]);
- return Timer;
- }();
- function get_new_timer(step) {
- return new Timer(step);
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Toast.ts", ['cc'], function (exports) {
- var cclegacy, ImageAsset, UIOpacity, tween, Label, UITransform, v3, Node, Layers, view, BlockInputEvents, Sprite, Texture2D, SpriteFrame, color;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- ImageAsset = module.ImageAsset;
- UIOpacity = module.UIOpacity;
- tween = module.tween;
- Label = module.Label;
- UITransform = module.UITransform;
- v3 = module.v3;
- Node = module.Node;
- Layers = module.Layers;
- view = module.view;
- BlockInputEvents = module.BlockInputEvents;
- Sprite = module.Sprite;
- Texture2D = module.Texture2D;
- SpriteFrame = module.SpriteFrame;
- color = module.color;
- }],
- execute: function () {
- cclegacy._RF.push({}, "0cfc340yupKhKm9JAtrMkIE", "Toast", undefined);
- /**
- * 位置
- */
- var Gravity = exports('Gravity', /*#__PURE__*/function (Gravity) {
- Gravity[Gravity["BOTTOM"] = 0] = "BOTTOM";
- return Gravity;
- }({}));
- var imageObj = new Image();
- imageObj.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACAQMAAABIeJ9nAAAAA1BMVEX///+nxBvIAAAACklEQVQI12MAAgAABAABINItbwAAAABJRU5ErkJggg==";
- var imageAsset = new ImageAsset(imageObj);
- /*
- Toast.makeText(gui.getLayerNode(5),"可笑可笑1").show();
- */
- var Toast = exports('Toast', /*#__PURE__*/function () {
- function Toast(root) {
- this._bgNode = null;
- this._textNode = null;
- this._node = null;
- this._text = '';
- this._time = 0;
- this._textSize = 26;
- this._gravity = Gravity.BOTTOM;
- this._node = this.getPNode(root);
- this._bgNode = new Node();
- this._bgNode.layer = Layers.Enum.UI_2D;
- this._bgNode.addComponent(BlockInputEvents);
- var sprite = this._bgNode.addComponent(Sprite);
- sprite.type = Sprite.Type.SLICED;
- var textureObj = new Texture2D();
- textureObj.image = imageAsset;
- var sf = new SpriteFrame();
- sf.texture = textureObj;
- sprite.spriteFrame = sf;
- sprite.color = color(128, 128, 128, 255);
- this._bgNode.addComponent(UIOpacity);
- this._bgNode.active = false;
- this._textNode = new Node('Text');
- this._textNode.layer = Layers.Enum.UI_2D;
- var uiTransform = this._textNode.addComponent(UITransform);
- uiTransform.width = this._node.getComponent(UITransform).width;
- var label = this._textNode.addComponent(Label);
- label.horizontalAlign = Label.HorizontalAlign.CENTER;
- label.verticalAlign = Label.VerticalAlign.CENTER;
- this._textSize = 26;
- this._textNode.parent = this._bgNode;
- this._bgNode.parent = this._node;
- }
- /**
- * 生成吐司
- * @param node
- * @param text
- * @param time
- * @returns
- */
- Toast.makeText = function makeText(parent, text, time) {
- if (time === void 0) {
- time = Toast.LENGTH_SHORT;
- }
- var toast = new Toast(parent);
- toast.setText(text);
- toast.setTime(time);
- return toast;
- }
- /**
- * 显示吐司
- */;
- var _proto = Toast.prototype;
- _proto.show = function show() {
- var _this = this;
- this.setFontSize(this._textSize);
- this.setOverFlow();
- this._bgNode.active = true;
- var uiOpacity = this._bgNode.getComponent(UIOpacity);
- tween(uiOpacity).delay(this._time).to(0.3, {
- opacity: 0
- }).call(function () {
- _this._bgNode.destroy();
- }).start();
- }
- /**
- * 设置文字
- * @param text 文字
- * @returns
- */;
- _proto.setText = function setText(text) {
- this._text = text;
- var label = this._textNode.getComponent(Label);
- label.string = this._text;
- return this;
- }
- /**
- * 设置文字大小
- * @param textSize 文字大小
- * @returns
- */;
- _proto.setFontSize = function setFontSize(textSize) {
- this._textSize = textSize;
- var label = this._textNode.getComponent(Label);
- label.fontSize = this._textSize;
- return this;
- }
- /**
- * 设置时间
- * @param time 时间
- * @returns
- */;
- _proto.setTime = function setTime(time) {
- this._time = time;
- return this;
- }
- /**
- * 设置位置
- * @param gravity 位置
- * @returns
- */;
- _proto.setGravity = function setGravity(gravity) {
- this._gravity = gravity;
- return this;
- };
- _proto.setPosition = function setPosition() {
- var uiTransform = this._node.getComponent(UITransform);
- var bgUITransform = this._bgNode.getComponent(UITransform);
- if (Gravity.BOTTOM === this._gravity) {
- var y = bgUITransform.height / 2;
- this._bgNode.position = v3(0, y, 0);
- }
- };
- _proto.setOverFlow = function setOverFlow() {
- var maxLength = this._node.getComponent(UITransform).width / 2;
- var label = this._textNode.getComponent(Label);
- var fontLength = this._text.length * label.fontSize;
- var uiTransform = this._textNode.getComponent(UITransform);
- if (fontLength > maxLength) {
- uiTransform.width = maxLength;
- label.overflow = Label.Overflow.RESIZE_HEIGHT;
- } else {
- uiTransform.width = fontLength;
- label.overflow = Label.Overflow.NONE;
- }
- var bgUITransform = this._bgNode.getComponent(UITransform);
- bgUITransform.width = uiTransform.width + label.fontSize * 4;
- bgUITransform.height = uiTransform.height;
- this.setPosition();
- };
- _proto.getPNode = function getPNode(root) {
- if (null == Toast.pNode || !Toast.pNode.isValid) {
- Toast.pNode = new Node('Toast');
- var transform = Toast.pNode.addComponent(UITransform);
- Toast.pNode.layer = Layers.Enum.UI_2D;
- root.addChild(Toast.pNode);
- Toast.pNode.setSiblingIndex(root.children.length);
- var size = view.getVisibleSize();
- transform.contentSize = size;
- transform.width = size.width;
- transform.height = size.height;
- }
- return Toast.pNode;
- };
- return Toast;
- }());
- Toast.LENGTH_SHORT = 1;
- // 短时间吐司
- Toast.LENGTH_LONG = 3.5;
- // 长时间吐司
- Toast.pNode = null;
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ui_base.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _inheritsLoose, _createClass, cclegacy, _decorator, Button, assetManager, Node, find, EventHandler, Toggle, ToggleContainer, Component, isValid;
- return {
- setters: [function (module) {
- _inheritsLoose = module.inheritsLoose;
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- Button = module.Button;
- assetManager = module.assetManager;
- Node = module.Node;
- find = module.find;
- EventHandler = module.EventHandler;
- Toggle = module.Toggle;
- ToggleContainer = module.ToggleContainer;
- Component = module.Component;
- isValid = module.isValid;
- }],
- execute: function () {
- var _dec, _class;
- cclegacy._RF.push({}, "a34ebvwnv5E2LG2J8RHwXU2", "ui_base", undefined);
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- /***
- * @en internal class, used for handling node event.
- * @zh 内部类,用于节点事件监听
- *
- * */
- var __NodeEventAgent__ = (_dec = ccclass('tgxNodeEventAgent'), _dec(_class = /*#__PURE__*/function (_Component) {
- _inheritsLoose(__NodeEventAgent__, _Component);
- function __NodeEventAgent__() {
- return _Component.apply(this, arguments) || this;
- }
- var _proto = __NodeEventAgent__.prototype;
- /***
- * @en recieve button click event and deliver them to the real handlers.
- * @zh 接受按钮事件,并转发给真正的处理函数
- * */
- _proto.onButtonClicked = function onButtonClicked(evt, customEventData) {
- var btn = evt.target.getComponent(Button);
- var clickEvents = btn.clickEvents;
- for (var i = 0; i < clickEvents.length; ++i) {
- var h = clickEvents[i];
- if (h.customEventData == customEventData) {
- var cb = h['$cb$'];
- var target = h['$target$'];
- var args = h['$args$'];
- cb.apply(target, [btn, args]);
- }
- }
- }
- /***
- * @en recieve toggle event and deliver them to the real handlers.
- * @zh 接受Toggle事件,并转发给真正的处理函数
- * */;
- _proto.onToggleEvent = function onToggleEvent(toggle, customEventData) {
- var checkEvents = toggle.checkEvents;
- //if (toggle['_toggleContainer']) {
- // checkEvents = toggle['_toggleContainer'].checkEvents;
- //}
- for (var i = 0; i < checkEvents.length; ++i) {
- var h = checkEvents[i];
- if (h.customEventData == customEventData) {
- var cb = h['$cb$'];
- var target = h['$target$'];
- var args = h['$args$'];
- cb.apply(target, [toggle, args]);
- }
- }
- };
- return __NodeEventAgent__;
- }(Component)) || _class);
- var _id = 0;
- var ui_base = exports('default', /*#__PURE__*/function () {
- /***
- * @en hide and destroy all ui panel.
- * @zh 隐藏并销毁所有UI面板
- * */
- ui_base.closeAll = function closeAll() {
- while (this._uis.length) {
- this._uis[0].close();
- }
- this._clss.clear();
- }
- //
- ;
- ui_base.closeAndReleaseAll = function closeAndReleaseAll() {
- while (this._uis.length) {
- this._uis[0].closeAndRelease();
- }
- this._clss.clear();
- }
- //update all ui, called by UI.
- ;
- ui_base.updateAll = function updateAll(dt) {
- for (var i = 0; i < this._uis.length; ++i) {
- var ctrl = this._uis[i];
- if (ctrl.node && isValid(ctrl.node)) {
- this._uis[i].onUpdate(dt);
- }
- }
- };
- ui_base._addCls = function _addCls(cls) {
- if (!cls) return;
- this._clss.add(cls);
- };
- ui_base._removeCls = function _removeCls(cls) {
- if (!cls) return;
- this._clss["delete"](cls);
- };
- ui_base._hasCls = function _hasCls(cls) {
- return this._clss.has(cls);
- };
- var _proto2 = ui_base.prototype;
- _proto2.getLayout = function getLayout() {
- return this._layout;
- };
- function ui_base(bundle, prefab, layer, layoutCls) {
- this._id = 0;
- this._bundle = void 0;
- this._prefab = void 0;
- this._layer = void 0;
- this._layout = void 0;
- this._cls = void 0;
- this.node = void 0;
- this._destroyed = false;
- this._resolve_close = null;
- this._cls = null;
- this._bundle = bundle;
- this._prefab = prefab;
- this._layer = layer;
- this._layout = layoutCls;
- this._id = _id++;
- }
- //setup this ui,called by UIMgr.
- _proto2._setup = function _setup(cls, node) {
- ui_base._uis.push(this);
- this._cls = cls;
- ui_base._addCls(this._cls);
- this.node = node;
- if (this._layout) this._layout = this.node.getComponent(this._layout);
- //notify sub class to handle something.
- //节点创建完毕,调用子类的处理函数。
- for (var _len = arguments.length, data = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
- data[_key - 2] = arguments[_key];
- }
- this.onCreated.apply(this, data);
- //check whether it has been destroyed, if has, hide it.
- //检查是否为已销毁,如果已销毁,则走销毁流程
- if (this._destroyed) this.close();
- }
- /**
- * @en hide and destroy this ui panel.
- * @zh 隐藏并销毁此UI面板
- * */;
- _proto2.close = function close() {
- var _this$_resolve_close;
- (_this$_resolve_close = this._resolve_close) == null || _this$_resolve_close.call(this);
- this._resolve_close = null;
- this._destroyed = true;
- if (!this.node) return;
- this.node.removeFromParent();
- for (var i = 0; i < ui_base._uis.length; ++i) {
- if (ui_base._uis[i] == this) {
- ui_base._uis.splice(i, 1);
- break;
- }
- }
- this.onDispose();
- this.node.destroy();
- this.node = null;
- ui_base._removeCls(this._cls);
- this._cls = null;
- };
- _proto2.closeAndRelease = function closeAndRelease() {
- var _assetManager$getBund;
- this.close();
- (_assetManager$getBund = assetManager.getBundle(this._bundle)) == null || _assetManager$getBund.release(this._prefab);
- };
- /**等待此ui关闭*/
- _proto2.wait_close = function wait_close() {
- var _this = this;
- if (this._resolve_close) return;
- return new Promise(function (resolve) {
- _this._resolve_close = resolve;
- });
- }
- /**
- * @en add button event handler
- * @zh 添加按钮事件
- * @param relativeNodePath to indicate a button node, can pass `string`|`Node`|`Button` here.
- * @param cb will be called when event emits. method format:(btn:Button,args:any)=>void
- * @param target the `this` argument of `cb`
- * */;
- _proto2.onButtonEvent = function onButtonEvent(relativeNodePath, cb, target, args) {
- var buttonNode = null;
- if (relativeNodePath instanceof Node) {
- buttonNode = relativeNodePath;
- } else if (relativeNodePath instanceof Button) {
- buttonNode = relativeNodePath.node;
- } else {
- buttonNode = find(relativeNodePath, this.node);
- }
- if (!buttonNode) {
- return null;
- }
- //添加转发器
- var agent = this.node.getComponent(__NodeEventAgent__);
- if (!agent) {
- agent = this.node.addComponent(__NodeEventAgent__);
- }
- var btn = buttonNode.getComponent(Button);
- var clickEvents = btn.clickEvents;
- var handler = new EventHandler();
- handler.target = this.node;
- handler.component = 'tgxNodeEventAgent';
- handler.handler = 'onButtonClicked';
- handler.customEventData = '' + _id++;
- //附加额外信息 供事件转发使用
- handler['$cb$'] = cb;
- handler['$target$'] = target;
- handler['$args$'] = args;
- clickEvents.push(handler);
- btn.clickEvents = clickEvents;
- }
- /**
- * @en remove button event handler
- * @zh 移除按钮事件
- * @param relativeNodePath to indicate a button node, can pass `string`|`Node`|`Button` here.
- * @param cb will be called when event emits.
- * @param target the `this` argument of `cb`
- * */;
- _proto2.offButtonEvent = function offButtonEvent(relativeNodePath, cb, target) {
- var buttonNode = null;
- if (relativeNodePath instanceof Node) {
- buttonNode = relativeNodePath;
- } else if (relativeNodePath instanceof Button) {
- buttonNode = relativeNodePath.node;
- } else {
- buttonNode = find(relativeNodePath, this.node);
- }
- if (!buttonNode) {
- return;
- }
- var agent = this.node.getComponent(__NodeEventAgent__);
- if (!agent) {
- return;
- }
- var btn = buttonNode.getComponent(Button);
- if (!btn) {
- return;
- }
- var clickEvents = btn.clickEvents;
- for (var i = 0; i < clickEvents.length; ++i) {
- var h = clickEvents[i];
- if (h['$cb$'] == cb && h['$target$'] == target) {
- clickEvents.splice(i, 1);
- btn.clickEvents = clickEvents;
- break;
- }
- }
- }
- /**
- * @en add toggle event handler
- * @zh 添加Toggle事件
- * @param relativeNodePath to indicate a button node, can pass `string`|`Node`|`Button` here.
- * @param cb will be called when event emits. method format:(btn:Toggle,args:any)=>void
- * @param target the `this` argument of `cb`
- */;
- _proto2.onToggleEvent = function onToggleEvent(relativeNodePath, cb, target, args) {
- var buttonNode = null;
- if (relativeNodePath instanceof Node) {
- buttonNode = relativeNodePath;
- } else if (relativeNodePath instanceof Toggle) {
- buttonNode = relativeNodePath.node;
- } else if (relativeNodePath instanceof ToggleContainer) {
- buttonNode = relativeNodePath.node;
- } else {
- buttonNode = find(relativeNodePath, this.node);
- }
- if (!buttonNode) {
- return null;
- }
- //添加转发器
- var agent = this.node.getComponent(__NodeEventAgent__);
- if (!agent) agent = this.node.addComponent(__NodeEventAgent__);
- var btn = buttonNode.getComponent(Toggle);
- if (!btn) btn = buttonNode.getComponent(ToggleContainer);
- var checkEvents = btn.checkEvents;
- var handler = new EventHandler();
- handler.target = this.node;
- handler.component = 'tgxNodeEventAgent';
- handler.handler = 'onToggleEvent';
- handler.customEventData = '' + _id++;
- //附加额外信息 供事件转发使用
- handler['$cb$'] = cb;
- handler['$target$'] = target;
- handler['$args$'] = args;
- checkEvents.push(handler);
- btn.checkEvents = checkEvents;
- }
- /**
- * @en remove toggle event handler
- * @zh 移除Toggle事件
- * @param relativeNodePath to indicate a button node, can pass `string`|`Node`|`Button` here.
- * @param cb will be called when event emits. method format:(btn:Toggle,args:any)=>void
- * @param target the `this` argument of `cb`
- * */;
- _proto2.offToggleEvent = function offToggleEvent(relativeNodePath, cb, target) {
- var buttonNode = null;
- if (relativeNodePath instanceof Node) {
- buttonNode = relativeNodePath;
- } else if (relativeNodePath instanceof Toggle) {
- buttonNode = relativeNodePath.node;
- } else if (relativeNodePath instanceof ToggleContainer) {
- buttonNode = relativeNodePath.node;
- } else {
- buttonNode = find(relativeNodePath, this.node);
- }
- if (!buttonNode) {
- return null;
- }
- //添加转发器
- var agent = this.node.getComponent(__NodeEventAgent__);
- if (!agent) {
- return;
- }
- var btn = buttonNode.getComponent(Toggle);
- if (!btn) {
- btn = buttonNode.getComponent(ToggleContainer);
- }
- var checkEvents = btn.checkEvents;
- for (var i = 0; i < checkEvents.length; ++i) {
- var h = checkEvents[i];
- if (h['$cb$'] == cb && h['$target$'] == target) {
- checkEvents.splice(i, 1);
- btn.checkEvents = checkEvents;
- break;
- }
- }
- }
- //子类的所有操作,需要在这个函数之后。
- ;
- _proto2.onCreated = function onCreated() {}
- //当界面销毁时调用
- ;
- _proto2.onDispose = function onDispose() {}
- //
- ;
- _proto2.onUpdate = function onUpdate(dt) {};
- _createClass(ui_base, [{
- key: "id",
- get:
- /***
- * @en the instance id to indicate an unique ui panel.
- * @zh 实例ID,用于标记一个唯一面板实例
- * */
- function get() {
- return this._id;
- }
- /***
- * @en url of the prefab used by this ui panel.
- * @zh 本UI使用prefab路径
- * */
- }, {
- key: "prefab",
- get: function get() {
- return this._prefab;
- }
- }, {
- key: "bundle",
- get: function get() {
- return this._bundle;
- }
- /***
- * @en layer of this ui panel.
- * @zh 本UI所在的UI层级
- * */
- }, {
- key: "layer",
- get: function get() {
- return this._layer;
- }
- /***
- * @en layout of this ui panel.
- * @zh 本UI组件
- * */
- }, {
- key: "layout",
- get: function get() {
- return this._layout;
- }
- }]);
- return ui_base;
- }());
- ui_base._clss = new Set();
- ui_base._uis = [];
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ui_ResolutionAutoFit.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _inheritsLoose, cclegacy, _decorator, screen, view, ResolutionPolicy, size, Component;
- return {
- setters: [function (module) {
- _inheritsLoose = module.inheritsLoose;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- screen = module.screen;
- view = module.view;
- ResolutionPolicy = module.ResolutionPolicy;
- size = module.size;
- Component = module.Component;
- }],
- execute: function () {
- var _dec, _class;
- cclegacy._RF.push({}, "c7d72SJqEtIhpLiAo3HdgLR", "ui_ResolutionAutoFit", undefined);
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- var CHECK_INTERVAL = 0.1;
- var ResolutionAutoFit = exports('ResolutionAutoFit', (_dec = ccclass('ch.ResolutionAutoFit'), _dec(_class = /*#__PURE__*/function (_Component) {
- _inheritsLoose(ResolutionAutoFit, _Component);
- function ResolutionAutoFit() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _this._oldSize = size();
- _this.lastCheckTime = 0;
- return _this;
- }
- var _proto = ResolutionAutoFit.prototype;
- _proto.start = function start() {
- this.adjustResolutionPolicy();
- };
- _proto.update = function update(deltaTime) {
- this.lastCheckTime += deltaTime;
- if (this.lastCheckTime < CHECK_INTERVAL) {
- return;
- }
- this.lastCheckTime = 0;
- this.adjustResolutionPolicy();
- };
- _proto.adjustResolutionPolicy = function adjustResolutionPolicy() {
- var winSize = screen.windowSize;
- if (!this._oldSize.equals(winSize)) {
- var ratio = winSize.width / winSize.height;
- var drs = view.getDesignResolutionSize();
- var drsRatio = drs.width / drs.height;
- if (ratio > drsRatio) {
- //wider than desgin. fixed height
- view.setResolutionPolicy(ResolutionPolicy.FIXED_HEIGHT);
- } else {
- //
- view.setResolutionPolicy(ResolutionPolicy.FIXED_WIDTH);
- }
- this._oldSize.set(winSize);
- }
- };
- return ResolutionAutoFit;
- }(Component)) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/ui.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc', './ui_base.ts', './ui_ResolutionAutoFit.ts'], function (exports) {
- var _inheritsLoose, _asyncToGenerator, _regeneratorRuntime, cclegacy, _decorator, Component, tween, v3, UIOpacity, Tween, Vec3, UITransform, Node, Widget, error, instantiate, director, assetManager, ui_base, ResolutionAutoFit;
- return {
- setters: [function (module) {
- _inheritsLoose = module.inheritsLoose;
- _asyncToGenerator = module.asyncToGenerator;
- _regeneratorRuntime = module.regeneratorRuntime;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- Component = module.Component;
- tween = module.tween;
- v3 = module.v3;
- UIOpacity = module.UIOpacity;
- Tween = module.Tween;
- Vec3 = module.Vec3;
- UITransform = module.UITransform;
- Node = module.Node;
- Widget = module.Widget;
- error = module.error;
- instantiate = module.instantiate;
- director = module.director;
- assetManager = module.assetManager;
- }, function (module) {
- ui_base = module.default;
- exports('ui_base', module.default);
- }, function (module) {
- ResolutionAutoFit = module.ResolutionAutoFit;
- }],
- execute: function () {
- var _dec, _class;
- cclegacy._RF.push({}, "81e48wxjGBMPp2rQOJDljTG", "ui", undefined);
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- var ui_updater = (_dec = ccclass('ui_updater'), _dec(_class = /*#__PURE__*/function (_Component) {
- _inheritsLoose(ui_updater, _Component);
- function ui_updater() {
- return _Component.apply(this, arguments) || this;
- }
- var _proto = ui_updater.prototype;
- _proto.update = function update(dt) {
- ui_base.updateAll(dt);
- };
- return ui_updater;
- }(Component)) || _class);
- var GameUILayers = exports('GameUILayers', /*#__PURE__*/function (GameUILayers) {
- GameUILayers[GameUILayers["GAME"] = 0] = "GAME";
- GameUILayers[GameUILayers["JOY_STICK"] = 1] = "JOY_STICK";
- GameUILayers[GameUILayers["HUD"] = 2] = "HUD";
- GameUILayers[GameUILayers["POPUP"] = 3] = "POPUP";
- GameUILayers[GameUILayers["ALERT"] = 4] = "ALERT";
- GameUILayers[GameUILayers["NOTICE"] = 5] = "NOTICE";
- GameUILayers[GameUILayers["LOADING"] = 6] = "LOADING";
- GameUILayers[GameUILayers["OVERLAY"] = 7] = "OVERLAY";
- return GameUILayers;
- }({}));
- /**ui管理模块*/
- var ui = /*#__PURE__*/function () {
- function ui() {
- this._uiCanvas = void 0;
- this._uiRoot = void 0;
- this._clss_loading = new Set();
- }
- ui.getInstance = function getInstance() {
- if (!this._instance) this._instance = new ui();
- return this._instance;
- };
- var _proto2 = ui.prototype;
- _proto2.delay = function delay(ms) {
- return new Promise(function (resolve) {
- return setTimeout(resolve, ms);
- });
- };
- _proto2.delay_second = function delay_second(s) {
- return new Promise(function (resolve) {
- return setTimeout(resolve, s * 1000);
- });
- };
- _proto2.progressBar_anim = function progressBar_anim(bar, progress, duration) {
- if (duration === void 0) {
- duration = 0.2;
- }
- if (bar.progress >= progress) {
- bar.progress = progress;
- return;
- } else {
- return new Promise(function (resolve) {
- return tween(bar).to(duration, {
- progress: progress
- }).call(function () {
- resolve();
- }).start();
- });
- }
- };
- _proto2.fillRange_anim = function fillRange_anim(sp, progress, duration, limt) {
- if (duration === void 0) {
- duration = 0.2;
- }
- if (limt === void 0) {
- limt = 0;
- }
- if (limt > 0 && sp.fillRange >= progress && limt < 0 && sp.fillRange <= progress) {
- sp.fillRange = progress;
- return;
- } else {
- return new Promise(function (resolve) {
- return tween(sp).to(duration, {
- fillRange: progress
- }).call(function () {
- resolve();
- }).start();
- });
- }
- };
- _proto2.scale_anim = function scale_anim(node, duration, start, end) {
- if (duration === void 0) {
- duration = 0.2;
- }
- if (start === void 0) {
- start = 0.5;
- }
- if (end === void 0) {
- end = 1;
- }
- node.setScale(start, start, 1);
- return new Promise(function (resolve) {
- return tween(node).to(duration, {
- scale: v3(end, end, 1)
- }).call(function () {
- resolve();
- }).start();
- });
- };
- _proto2.scale_elasticOut_anim = function scale_elasticOut_anim(node, duration, start, end) {
- if (duration === void 0) {
- duration = 0.2;
- }
- if (start === void 0) {
- start = 0.5;
- }
- if (end === void 0) {
- end = 1;
- }
- node.setScale(start, start, 1);
- return new Promise(function (resolve) {
- return tween(node).to(duration, {
- scale: v3(end, end, 1)
- }, {
- easing: 'elasticOut'
- }).call(function () {
- resolve();
- }).start();
- });
- };
- _proto2.fade_anim = function fade_anim(node, duration, startOpacity, targetOpacity) {
- var _node$getComponent;
- if (duration === void 0) {
- duration = 0.2;
- }
- if (startOpacity === void 0) {
- startOpacity = 0;
- }
- if (targetOpacity === void 0) {
- targetOpacity = 255;
- }
- var opacity = (_node$getComponent = node.getComponent(UIOpacity)) != null ? _node$getComponent : node.addComponent(UIOpacity);
- opacity.opacity = startOpacity;
- return new Promise(function (resolve) {
- tween(opacity).to(duration, {
- opacity: targetOpacity
- }).call(function () {
- resolve();
- }).start();
- });
- };
- _proto2.shake_anim = function shake_anim(node, duration, intensity, shakeCount) {
- if (duration === void 0) {
- duration = 0.2;
- }
- if (intensity === void 0) {
- intensity = 5;
- }
- if (shakeCount === void 0) {
- shakeCount = 7;
- }
- return new Promise(function (resolve) {
- var originalPosition = node.position.clone(); // 保存原始位置
- var shakeDuration = duration / (shakeCount * 2); // 每次抖动的持续时间
- var shakeTween = tween(node);
- for (var i = 0; i < shakeCount; i++) {
- var offsetX = i % 2 === 0 ? intensity : -intensity; // 交替偏移
- shakeTween.to(shakeDuration, {
- position: v3(originalPosition.x + offsetX, originalPosition.y, originalPosition.z)
- }).to(shakeDuration, {
- position: originalPosition
- }); // 回到原位
- }
- shakeTween.call(function () {
- resolve();
- }).start(); // 开始抖动动画
- });
- };
- _proto2.rotate_shake_anim = function rotate_shake_anim(node, duration, intensity, shakeCount) {
- if (duration === void 0) {
- duration = 0.3;
- }
- if (intensity === void 0) {
- intensity = 5;
- }
- if (shakeCount === void 0) {
- shakeCount = 5;
- }
- return new Promise(function (resolve) {
- var originalAngle = node.angle; // 保存原始角度
- var shakeDuration = duration / (shakeCount * 2); // 每次晃动的持续时间
- var shakeTween = tween(node);
- for (var i = 0; i < shakeCount; i++) {
- var offsetAngle = i % 2 === 0 ? intensity : -intensity; // 交替旋转
- shakeTween.to(shakeDuration, {
- angle: originalAngle + offsetAngle
- }).to(shakeDuration, {
- angle: originalAngle
- }); // 回到原位
- }
- shakeTween.call(function () {
- resolve();
- }).start(); // 开始角度晃动动画
- });
- };
- _proto2.scale_shake_anim = function scale_shake_anim(node, duration, intensity, shakeCount, reset) {
- if (duration === void 0) {
- duration = 0.3;
- }
- if (intensity === void 0) {
- intensity = 0.1;
- }
- if (shakeCount === void 0) {
- shakeCount = 10;
- }
- if (reset === void 0) {
- reset = null;
- }
- if (reset) {
- Tween.stopAllByTarget(node);
- node.setScale(reset, reset, reset);
- }
- return new Promise(function (resolve) {
- var originalScale = node.scale.clone(); // 保存原始缩放
- var shakeDuration = duration / (shakeCount * 2); // 每次震动的持续时间
- var shakeTween = tween(node);
- for (var i = 0; i < shakeCount; i++) {
- var offsetScale = i % 2 === 0 ? intensity : -intensity; // 交替缩放
- shakeTween.to(shakeDuration, {
- scale: v3(originalScale.x + offsetScale, originalScale.y + offsetScale, originalScale.z)
- }).to(shakeDuration, {
- scale: originalScale
- }); // 回到原位
- }
- shakeTween.call(function () {
- resolve();
- }).start(); // 开始缩放震动动画
- });
- };
- _proto2.opacity_shake_anim = function opacity_shake_anim(node, duration, intensity, shakeCount) {
- var _node$getComponent2;
- if (duration === void 0) {
- duration = 0.8;
- }
- if (intensity === void 0) {
- intensity = 80;
- }
- if (shakeCount === void 0) {
- shakeCount = 5;
- }
- var opacity = (_node$getComponent2 = node.getComponent(UIOpacity)) != null ? _node$getComponent2 : node.addComponent(UIOpacity);
- var originalOpacity = opacity.opacity;
- var shakeDuration = duration / (shakeCount * 2);
- return new Promise(function (resolve) {
- var shakeTween = tween(opacity);
- for (var i = 0; i < shakeCount; i++) {
- var offsetOpacity = i % 2 === 0 ? intensity : -intensity;
- shakeTween.to(shakeDuration, {
- opacity: Math.min(Math.max(originalOpacity + offsetOpacity, 0), 255)
- }).to(shakeDuration, {
- opacity: originalOpacity
- });
- }
- shakeTween.call(function () {
- resolve();
- }).start(); // 开始透明度震动动画
- });
- }
- /**处理弹跳动画*/;
- _proto2.bounce_anim = function bounce_anim(node, height, duration) {
- if (height === void 0) {
- height = 100;
- }
- if (duration === void 0) {
- duration = 0.5;
- }
- return new Promise(function (resolve) {
- tween(node).to(duration, {
- position: node.position.clone().add(new Vec3(0, height, 0))
- }, {
- easing: 'bounceOut'
- }) // 向上弹跳
- .to(duration, {
- position: node.position
- }, {
- easing: 'bounceIn'
- }) // 回到原位
- .call(function () {
- resolve();
- }) //完成动画
- .start(); //开始动画
- });
- }
- /**
- * 奖励物飞行动画
- * @param node 奖励物节点
- * @param startPos 起始爆开点
- * @param targetPos 最终目标点
- * @param explosionDistance 爆开距离
- * @param explosionDuration 爆开时间
- * @param stayDuration 停留时间
- * @param moveDuration 移动到目标的时间
- * @returns
- */;
- _proto2.reward_fly_anim = function reward_fly_anim(node, startPos, targetPos, explosionDistance, explosionDuration, stayDuration, moveDuration) {
- if (explosionDistance === void 0) {
- explosionDistance = 100;
- }
- if (explosionDuration === void 0) {
- explosionDuration = 0.3;
- }
- if (stayDuration === void 0) {
- stayDuration = 0.5;
- }
- if (moveDuration === void 0) {
- moveDuration = 0.3;
- }
- node.setPosition(startPos);
- return new Promise(function (resolve) {
- //随机方向
- var randomDirection = new Vec3(Math.random() * 2 - 1, Math.random() * 2 - 1, 0).normalize();
- var explosionEndPos = startPos.add(randomDirection.multiplyScalar(explosionDistance)); // 爆炸效果的位置
- tween(node).to(explosionDuration, {
- worldPosition: explosionEndPos
- }) // 爆炸动画
- .delay(stayDuration) //停留时间
- .to(moveDuration, {
- worldPosition: targetPos
- }, {
- easing: 'cubicIn'
- }).call(function () {
- resolve();
- }).start();
- });
- };
- _proto2.createFullScreenNode = function createFullScreenNode() {
- var canvas = this._uiCanvas.getComponent(UITransform);
- var node = new Node();
- node.layer = this._uiCanvas.layer;
- var uiTransform = node.addComponent(UITransform);
- uiTransform.width = canvas.width;
- uiTransform.height = canvas.height;
- var widget = node.addComponent(Widget);
- widget.isAlignBottom = true;
- widget.isAlignTop = true;
- widget.isAlignLeft = true;
- widget.isAlignRight = true;
- widget.left = 0;
- widget.right = 0;
- widget.top = 0;
- widget.bottom = 0;
- return node;
- };
- _proto2.getLayers = function getLayers() {
- return Object.values(GameUILayers).filter(function (value) {
- return typeof value === 'number';
- });
- }
- /**
- * @en init,`don't call more than once`.
- * @zh 初始化UIMgr,`不要多次调用`
- * */;
- _proto2.init = function init(uiCanvas) {
- if (this._uiCanvas) return;
- if (!uiCanvas) throw error('uiCanvas must be a Node or Prefab');
- if (uiCanvas instanceof Node) {
- this._uiCanvas = uiCanvas;
- } else {
- this._uiCanvas = instantiate(uiCanvas);
- director.getScene().addChild(this._uiCanvas);
- }
- this._uiCanvas.name = '__ui_canvas__';
- director.addPersistRootNode(this._uiCanvas);
- if (!this._uiCanvas.getComponent(ui_updater)) {
- this._uiCanvas.addComponent(ui_updater);
- }
- var canvas = this._uiCanvas.getComponent(UITransform);
- this._uiCanvas.addComponent(ResolutionAutoFit);
- this._uiRoot = this.createFullScreenNode();
- this._uiRoot.name = 'root';
- canvas.node.addChild(this._uiRoot);
- var layers = this.getLayers();
- //create layers
- for (var i = 0; i < layers.length; ++i) {
- var layerNode = this.createFullScreenNode();
- layerNode.name = 'layer_' + GameUILayers[layers[i]];
- this._uiRoot.addChild(layerNode);
- }
- }
- /**获取层级节点*/;
- _proto2.getLayerNode = function getLayerNode(layerIndex) {
- return this._uiRoot.children[layerIndex] || this._uiRoot;
- }
- /**关闭所有界面*/;
- _proto2.closeAll = function closeAll() {
- ui_base.closeAll();
- }
- /**关闭和释放所有界面 */;
- _proto2.closeAndReleaseAll = function closeAndReleaseAll() {
- ui_base.closeAndReleaseAll();
- }
- /**关闭某个界面*/;
- _proto2.close = function close(uiCls) {
- var _this$get;
- (_this$get = this.get(uiCls)) == null || _this$get.close();
- }
- /**获取界面*/;
- _proto2.get = function get(uiCls) {
- var all = ui_base._uis;
- for (var i = 0; i < all.length; ++i) {
- var c = all[i];
- if (c instanceof uiCls) {
- return c;
- }
- }
- return null;
- }
- /**某个界面是否显示中*/;
- _proto2.isShowing = function isShowing(uiCls) {
- return ui_base._hasCls(uiCls);
- };
- /**是否有正在加载中的界面*/
- _proto2.isLoading = function isLoading(uiCls) {
- if (!uiCls) return this._clss_loading.size > 0;
- return this._clss_loading.has(uiCls);
- }
- /***
- * @en show ui by the given parameters.
- * @zh 显示UI
- * @param uiCls the class, must inherits from the class `UIController`.
- * @returns the instance of `uiCls`
- * */;
- _proto2.show = /*#__PURE__*/
- function () {
- var _show = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(uiCls) {
- var _ui,
- bundleName,
- bundle,
- _len,
- data,
- _key,
- loadedBundle,
- _args = arguments;
- return _regeneratorRuntime().wrap(function _callee$(_context) {
- while (1) switch (_context.prev = _context.next) {
- case 0:
- if (!this.isLoading(uiCls)) {
- _context.next = 2;
- break;
- }
- return _context.abrupt("return", null);
- case 2:
- if (!this.isShowing(uiCls)) {
- _context.next = 4;
- break;
- }
- return _context.abrupt("return", null);
- case 4:
- _ui = new uiCls();
- this._clss_loading.add(uiCls);
- bundleName = _ui.bundle;
- if (!bundleName) {
- _context.next = 31;
- break;
- }
- bundle = assetManager.getBundle(bundleName);
- for (_len = _args.length, data = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- data[_key - 1] = _args[_key];
- }
- if (bundle) {
- _context.next = 26;
- break;
- }
- _context.prev = 11;
- _context.next = 14;
- return this.loadBundleAsync(bundleName);
- case 14:
- loadedBundle = _context.sent;
- _context.next = 17;
- return this._create.apply(this, [loadedBundle, _ui, uiCls].concat(data));
- case 17:
- return _context.abrupt("return", _context.sent);
- case 20:
- _context.prev = 20;
- _context.t0 = _context["catch"](11);
- console.error(_context.t0);
- this._clss_loading["delete"](uiCls);
- case 24:
- _context.next = 29;
- break;
- case 26:
- _context.next = 28;
- return this._create.apply(this, [bundle, _ui, uiCls].concat(data));
- case 28:
- return _context.abrupt("return", _context.sent);
- case 29:
- _context.next = 34;
- break;
- case 31:
- this._clss_loading["delete"](uiCls);
- console.error("ui no bundle name");
- return _context.abrupt("return", null);
- case 34:
- case "end":
- return _context.stop();
- }
- }, _callee, this, [[11, 20]]);
- }));
- function show(_x) {
- return _show.apply(this, arguments);
- }
- return show;
- }();
- _proto2._create = /*#__PURE__*/function () {
- var _create2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(bundle, _ui2, uiCls) {
- var _ref,
- _data,
- node,
- parent,
- _len2,
- p,
- _key2,
- _args2 = arguments;
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
- while (1) switch (_context2.prev = _context2.next) {
- case 0:
- _context2.prev = 0;
- _context2.next = 3;
- return this.loadPrefabAsync(bundle, _ui2.prefab);
- case 3:
- _data = _context2.sent;
- node = instantiate(_data);
- parent = this.getLayerNode(_ui2.layer);
- parent.addChild(node);
- for (_len2 = _args2.length, p = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
- p[_key2 - 3] = _args2[_key2];
- }
- (_ref = _ui2)._setup.apply(_ref, [uiCls, node].concat(p));
- this._clss_loading["delete"](uiCls);
- return _context2.abrupt("return", _ui2);
- case 13:
- _context2.prev = 13;
- _context2.t0 = _context2["catch"](0);
- console.error(_context2.t0);
- this._clss_loading["delete"](uiCls);
- return _context2.abrupt("return");
- case 18:
- case "end":
- return _context2.stop();
- }
- }, _callee2, this, [[0, 13]]);
- }));
- function _create(_x2, _x3, _x4) {
- return _create2.apply(this, arguments);
- }
- return _create;
- }();
- _proto2.loadBundleAsync = function loadBundleAsync(bundleName) {
- return new Promise(function (resolve, reject) {
- assetManager.loadBundle(bundleName, null, function (err, loadedBundle) {
- if (err) {
- reject(err);
- } else {
- resolve(loadedBundle);
- }
- });
- });
- };
- _proto2.loadPrefabAsync = function loadPrefabAsync(bundle, prefabName) {
- return new Promise(function (resolve, reject) {
- bundle.load(prefabName, function (err, data) {
- if (err) {
- reject(err);
- } else {
- resolve(data);
- }
- });
- });
- };
- return ui;
- }();
- ui._instance = void 0;
- var gui = exports('gui', ui.getInstance());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/UISpineMovie.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _applyDecoratedDescriptor, _inheritsLoose, _initializerDefineProperty, _assertThisInitialized, cclegacy, _decorator, CCString, sp, Color, Component;
- return {
- setters: [function (module) {
- _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
- _inheritsLoose = module.inheritsLoose;
- _initializerDefineProperty = module.initializerDefineProperty;
- _assertThisInitialized = module.assertThisInitialized;
- }, function (module) {
- cclegacy = module.cclegacy;
- _decorator = module._decorator;
- CCString = module.CCString;
- sp = module.sp;
- Color = module.Color;
- Component = module.Component;
- }],
- execute: function () {
- var _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2;
- cclegacy._RF.push({}, "4ce979zctxD67dYVnpW4Mn+", "UISpineMovie", undefined);
- var ccclass = _decorator.ccclass,
- property = _decorator.property;
- /**
- * spine动画表现管理
- * @author
- */
- var UISpineMovie = exports('default', (_dec = ccclass('UISpineMovie'), _dec2 = property({
- type: [CCString],
- displayName: '动画列表'
- }), _dec3 = property({
- type: sp.Skeleton,
- tooltip: '角色动画'
- }), _dec(_class = (_class2 = /*#__PURE__*/function (_Component) {
- _inheritsLoose(UISpineMovie, _Component);
- function UISpineMovie() {
- var _this;
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- _this = _Component.call.apply(_Component, [this].concat(args)) || this;
- _initializerDefineProperty(_this, "animat_names", _descriptor, _assertThisInitialized(_this));
- _initializerDefineProperty(_this, "spine", _descriptor2, _assertThisInitialized(_this));
- _this.cur = null;
- _this.index = 0;
- return _this;
- }
- var _proto = UISpineMovie.prototype;
- _proto.onLoad = function onLoad() {};
- _proto.start = function start() {
- //this.spine.clearTracks()
- /*this.spine.setStartListener(function(){
- console.log("动画开始")
- }.bind(this));*/
- /* this.spine.setEventListener(((trackEntry:any, event:any) => {
- //var animationName = trackEntry.animation ? trackEntry.animation.name : "";
- //console.log("[track %s][animation %s] event: %s, %s, %s, %s", trackEntry.trackIndex, animationName, event.data.name, event.intValue, event.floatValue, event.stringValue);
- this.unit.DoEvent(event.data.name);
- }) as any);*/
- //
- //let duration = this.spine.getCurrent(0).animation.duration;
- //let frames = Math.ceil(frameRate * duration);
- //let secondsPerFrame = 1 / frameRate;
- //`总帧数 ${this.frames}`;
- //this.spine.setCompleteListener(trackEntry => {
- //});
- if (this.animat_names.length > 0) {
- this.index = 0;
- if (this.index == this.animat_names.length - 1) {
- this.DoAnimation(this.animat_names[this.index], true);
- } else {
- this.DoAnimation(this.animat_names[this.index], false);
- }
- this.spine.setCompleteListener(function () {
- this.index++;
- if (this.index < this.animat_names.length) {
- if (this.index == this.animat_names.length - 1) {
- this.DoAnimation(this.animat_names[this.index], true);
- } else {
- this.DoAnimation(this.animat_names[this.index], false);
- }
- } else {
- this.spine.setCompleteListener(null);
- }
- }.bind(this));
- }
- };
- _proto.SetSkin = function SetSkin(skin) {
- this.spine.setSkin(skin);
- };
- _proto.DoAnimation = function DoAnimation(animation, loop, track, force) {
- if (loop === void 0) {
- loop = true;
- }
- if (track === void 0) {
- track = 0;
- }
- if (force === void 0) {
- force = false;
- }
- if (force) {
- this.spine.setAnimation(track, animation, loop);
- return;
- }
- if (this.cur == animation) return;
- this.spine.setAnimation(track, animation, loop);
- }
- /**设置是否暂停 */;
- _proto.SetPaused = function SetPaused(paused) {
- this.spine.paused = paused;
- }
- /**获取是否暂停 */;
- _proto.GetPaused = function GetPaused() {
- return this.spine.paused;
- };
- _proto.CheckPaused = function CheckPaused(paused) {
- if (this.spine.paused != paused) this.spine.paused = paused;
- }
- /** 闪色表现 Color.RED 0.1*/;
- _proto.Flash = function Flash(color, time, reColor) {
- var _this2 = this;
- if (reColor === void 0) {
- reColor = Color.WHITE;
- }
- if (this.spine.color != color) {
- this.spine.color = color;
- this.unscheduleAllCallbacks();
- this.scheduleOnce(function () {
- _this2.spine.color = reColor;
- }, time);
- }
- }
- /**
- * 缩放动画播放速率
- * @override
- * @param scale 缩放倍率
- */;
- _proto.scaleTime = function scaleTime(scale) {
- if (scale > 0) this.spine.timeScale = scale;
- };
- _proto.getBone = function getBone(name) {
- var bone = this.spine.findBone(name);
- return bone;
- };
- return UISpineMovie;
- }(Component), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "animat_names", [_dec2], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return [];
- }
- }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "spine", [_dec3], {
- configurable: true,
- enumerable: true,
- writable: true,
- initializer: function initializer() {
- return null;
- }
- })), _class2)) || _class));
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/UrlUtil.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "27d07mMayFBBZrBncxUySIT", "UrlUtil", undefined);
- var UrlUtil = exports('default', /*#__PURE__*/function () {
- function UrlUtil() {}
- /**
- * 获取URL参数(字符串)
- * @param url 地址
- * @returns {string}
- */
- UrlUtil.getParamString = function getParamString(url) {
- var _window$location;
- url = url || ((_window$location = window.location) == null ? void 0 : _window$location.href);
- if (url != void 0) {
- var index = url.indexOf('?');
- if (index != -1) {
- return url.substring(index + 1);
- }
- }
- return null;
- }
- /**
- * 获取URL参数
- * @param url 地址
- * @returns {JSON}
- */;
- UrlUtil.getParam = function getParam(url) {
- var param = {};
- var paramString = this.getParamString(url);
- if (paramString) {
- paramString.split("&").forEach(function (value) {
- var values = value.split("=");
- if (values.length == 2) {
- param[values[0]] = values[1];
- }
- });
- }
- return param;
- }
- /**
- * 根据key获取URL参数
- * @param key key
- * @param url 地址
- * @returns {string}
- */;
- UrlUtil.getParamValue = function getParamValue(key, url) {
- var paramString = this.getParamString(url);
- if (paramString) {
- var values = paramString.match("(^|&)" + key + "=([^&]*)(&|$)");
- if (values) {
- return values[2];
- }
- }
- return null;
- };
- return UrlUtil;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Utils.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "7ea66r0AApIFbjuTFjXJIWh", "Utils", undefined);
- var Utils = exports('Utils', /*#__PURE__*/function () {
- function Utils() {}
- /**
- * 随机数 (包含min,不包含max)
- * @param min
- * @param max
- * @param isInt
- * @return {*}
- */
- Utils.getRandom = function getRandom(min, max, isInt) {
- if (min === void 0) {
- min = 0;
- }
- if (max === void 0) {
- max = 1;
- }
- if (isInt === void 0) {
- isInt = false;
- }
- if (min == null) min = 0;
- if (max == null) max = 1;
- if (isInt == null) isInt = false;
- if (min === max) return min;
- var value = min + Math.random() * (max - min);
- if (isInt) {
- value = Math.floor(value);
- }
- return value;
- }
- /**
- * 随机整数-包含最大值,最小值
- * @param min
- * @param max
- * @return {*}
- */;
- Utils.getRandomIntInclusive = function getRandomIntInclusive(min, max) {
- min = Math.ceil(min);
- max = Math.floor(max);
- if (min == max) return min;
- return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive
- }
- /**
- * 随机整数-不包含最大值,最小值
- * @param min
- * @param max
- * @return {*}
- */;
- Utils.getRandomInt = function getRandomInt(min, max) {
- min = Math.ceil(min);
- max = Math.ceil(max);
- return Math.floor(Math.random() * (max - min)) + min;
- }
- /** */;
- Utils.getRandomNumberInRange = function getRandomNumberInRange(min, max) {
- return Math.random() * (max - min) + min;
- }
- /**生成随机整数 -1 或 1*/;
- Utils.getRandomDir = function getRandomDir() {
- return Math.floor(Math.random() * 2) === 0 ? -1 : 1; //
- }
- /**
- * 在指定数组中随机取出N个不重复的数据
- * @param resArr
- * @param ranNum
- * @returns {Array}
- */;
- Utils.getRandomDiffValueFromArr = function getRandomDiffValueFromArr(resArr, ranNum) {
- var arr = new Array();
- var result = new Array();
- if (!resArr || resArr.length <= 0 || ranNum <= 0) {
- return result;
- }
- for (var i = 0; i < resArr.length; i++) {
- arr.push(resArr[i]);
- }
- if (ranNum >= arr.length) {
- return arr;
- }
- ranNum = Math.min(ranNum, arr.length - 1);
- for (var _i = 0; _i < ranNum; _i++) {
- var ran = Utils.getRandomIntInclusive(0, arr.length - 1); // Math.floor(Math.random() * arr.length);
- result.push(arr.splice(ran, 1)[0]);
- }
- return result;
- }
- /**
- * 随机一个字符串
- * @param length
- * @returns
- */;
- Utils.randomStr = function randomStr(length) {
- var result = '';
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
- var charactersLength = characters.length;
- for (var i = 0; i < length; i++) {
- result += characters.charAt(Math.floor(Math.random() * charactersLength));
- }
- return result;
- }
- /**
- * 时间转换 毫秒=》2019-03-28 19:55:34
- * @param milliseconds
- * @return {string}
- */;
- Utils.time2str = function time2str(milliseconds) {
- var time = new Date();
- time.setTime(milliseconds);
- var year = time.getFullYear();
- var hours = time.getHours();
- var min = time.getMinutes();
- var sec = time.getSeconds();
- var month = time.getMonth() + 1;
- var date = time.getDate();
- return year + "-" + month + "-" + date + " " + (hours > 9 ? hours : "0" + hours) + ":" + (min > 9 ? min : "0" + min) + ":" + (sec > 9 ? sec : "0" + sec);
- }
- /**
- * 将毫秒转换为时间格式 00:00:00
- * @param delay
- * @param detail
- * @return
- */;
- Utils.second2time = function second2time(delay, detail) {
- if (detail === void 0) {
- detail = 2;
- }
- // if (detail == undefined) detail = 2;
- //天
- var d = Math.floor(delay / 86400000);
- delay = delay % 86400000;
- // 小时
- var h = Math.floor(delay / 3600000);
- delay = delay % 3600000;
- // 分钟
- var m = Math.floor(delay / 60000);
- delay = delay % 60000;
- // 秒
- var s = Math.floor(delay / 1000);
- delay = delay % 1000;
- // 毫秒
- var ml = delay;
- var result = "";
- if (d > 0 && detail > 0) {
- result += (d > 9 ? d : "0" + d) + ":"; // "天";
- detail--;
- }
- if (h > 0 && detail > 0) {
- result += (h > 9 ? h : "0" + h) + ":"; // "小时";
- detail--;
- }
- if (m > 0 && detail > 0) {
- result += (m > 9 ? m : "0" + m) + ":"; // "分钟";
- detail--;
- }
- if (detail > 0) {
- result += s > 9 ? s : "0" + s; // "秒";
- detail--;
- }
- if (ml > 0 && detail > 0) {
- detail--;
- }
- return result;
- };
- Utils.formatMilliseconds = function formatMilliseconds(milliseconds) {
- var seconds = Math.floor(milliseconds / 1000 % 60);
- var minutes = Math.floor(milliseconds / (1000 * 60) % 60);
- var hours = Math.floor(milliseconds / (1000 * 60 * 60) % 24);
- //const formattedSeconds = seconds < 10 ? "0" + seconds : seconds;
- //const formattedMinutes = minutes < 10 ? "0" + minutes : minutes;
- //const formattedHours = hours < 10 ? "0" + hours : hours;
- //`${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
- return hours.toString().padStart(2, "0") + ":" + minutes.toString().padStart(2, "0") + ":" + seconds.toString().padStart(2, "0");
- }
- /**
- * 取小数位
- * @param decimal 小数
- * @param places 位数
- * @return {number}
- */;
- Utils.getDecimal = function getDecimal(decimal, places) {
- var round = Math.pow(10, places);
- return Math.round(decimal * round) / round;
- }
- /**
- * 本年第几周
- * @param timestamp 毫秒
- * @returns
- */;
- Utils.getYearWeek = function getYearWeek(timestamp) {
- // let nowDate: Date = new Date(date);
- // let firstDay: Date = new Date(date);
- // firstDay.setMonth(0);//设置1月
- // firstDay.setDate(1);//设置1号
- // let diffDays = Math.ceil((nowDate.valueOf() - firstDay.valueOf())/(24*60*60*1000));
- // return Math.ceil((diffDays + (firstDay.getDay() + 1 - 1)) / 7);
- var currentDate = new Date(timestamp);
- var year = new Date(currentDate.getFullYear(), 0, 1);
- var days = Math.floor((currentDate.valueOf() - year.valueOf()) / (24 * 60 * 60 * 1000));
- var week = Math.ceil((currentDate.getDay() + 1 + days) / 7);
- return week;
- }
- /**
- * 是否是同一天
- * @param timeStampA
- * @param timeStampB
- * @return {boolean}
- */;
- Utils.isSameDay = function isSameDay(timeStampA, timeStampB) {
- var dateA = new Date(timeStampA);
- dateA.setHours(0, 0, 0, 0);
- var dateB = new Date(timeStampB);
- dateB.setHours(0, 0, 0, 0);
- return dateA.getTime() == dateB.getTime() ? true : false;
- }
- //
- ;
- Utils.checkAndAdd = function checkAndAdd(map, k, v) {
- if (map.has(k)) {
- map.set(k, map.get(k) + v);
- } else {
- map.set(k, v);
- }
- }
- //
- /**
- * 随机权重下标
- * @param weights 权重数组
- */;
- Utils.randomWeights = function randomWeights(weights) {
- // 总权重值
- var totalWeight = weights.reduce(function (a, b) {
- return a + b;
- }, 0);
- // 随机的权重值
- var randomWeight = this.getRandom(0, totalWeight);
- for (var index = 0, weight = 0; index < weights.length; index++) {
- weight += weights[index];
- if (weight >= randomWeight) {
- return index;
- }
- }
- return -1;
- }
- /**
- * 随机数组下标
- * @param array 数组
- */;
- Utils.randomArray = function randomArray(array, weights) {
- if (!weights) {
- var index = this.getRandom(0, array.length, true);
- return index;
- }
- return this.randomWeights(weights.slice(0, array.length));
- };
- return Utils;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/Wait.ts", ['cc'], function (exports) {
- var cclegacy;
- return {
- setters: [function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- exports('default', get_new_wait);
- cclegacy._RF.push({}, "5f7efxwnidOU6yhMrPMB9m6", "Wait", undefined);
- var Wait = /*#__PURE__*/function () {
- function Wait() {
- this._resolve = null;
- }
- var _proto = Wait.prototype;
- _proto.wait = function wait() {
- var _this = this;
- return new Promise(function (resolve) {
- return _this._resolve = resolve;
- });
- };
- _proto.resolve = function resolve(value) {
- if (this._resolve) {
- this._resolve(value);
- this.dispose();
- }
- };
- _proto.dispose = function dispose() {
- this._resolve = null;
- };
- return Wait;
- }();
- function get_new_wait() {
- return new Wait();
- }
- cclegacy._RF.pop();
- }
- };
- });
- System.register("chunks:///_virtual/WsClient.ts", ['./rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
- var _createClass, cclegacy;
- return {
- setters: [function (module) {
- _createClass = module.createClass;
- }, function (module) {
- cclegacy = module.cclegacy;
- }],
- execute: function () {
- cclegacy._RF.push({}, "d14186TLCpDIa2nmf/PWkp9", "WsClient", undefined);
- /**web scoket 客户端*/
- var WsClient = exports('WsClient', /*#__PURE__*/function () {
- var _proto = WsClient.prototype;
- _proto.onConnected = function onConnected(evt) {};
- _proto.onError = function onError(err) {};
- _proto.onClosing = function onClosing() {};
- _proto.onClosed = function onClosed(event) {};
- _proto.onMessage = function onMessage(msg) {};
- function WsClient(url, ca, autoConnect) {
- //
- this._ws = null;
- /** 连接地址*/
- this._url = null;
- /**证书*/
- this._ca = void 0;
- this._ca = ca;
- this._url = url;
- if (autoConnect) this.connect();
- }
- /**连接成功时的回调 */
- _proto._onConnected = function _onConnected(evt) {
- this.onConnected(evt);
- }
- /**收到消息时的回调 */;
- _proto._onMessage = function _onMessage(msg) {
- this.onMessage(msg);
- }
- /** 错误处理回调 */;
- _proto._onError = function _onError(err) {
- this.onError(err);
- }
- /**连接关闭时的回调 */;
- _proto._onClosed = function _onClosed(event) {
- this.onClosed(event);
- }
- /**
- * 获取当前连接状态
- * @returns 是否处于活动状态
- */;
- /**手动连接*/
- _proto.connect = function connect() {
- if (this.isConnecting) return false;
- if (this.isActive) return false;
- var url = this._url;
- if (!url) return false;
- try {
- //eslint-disable-next-line @typescript-eslint/ban-ts-comment
- //@ts-ignore
- //eslint-disable-next-line @typescript-eslint/no-unsafe-call
- var ws = this._ca && url.startsWith('wss://') ? new WebSocket(url, {}, this._ca) : new WebSocket(url);
- ws.binaryType = 'arraybuffer';
- ws.onmessage = this._onMessage.bind(this);
- ws.onopen = this._onConnected.bind(this);
- ws.onerror = this._onError.bind(this);
- ws.onclose = this._onClosed.bind(this);
- this._ws = ws;
- } catch (error) {
- this._onError(error instanceof Error ? error.message : 'Unknown error');
- }
- return true;
- }
- /**
- * 主动关闭WebSocket连接
- */;
- _proto.close = function close(code, reason) {
- if (this.isClosed || this.isClosing) return;
- this.onClosing();
- this._ws.close(code, reason);
- }
- /**
- * 发送数据
- * @param data 指定格式数据
- */;
- _proto.send = function send(data) {
- this._ws.send(data);
- };
- _createClass(WsClient, [{
- key: "ws",
- get: /** WebSocket对象*/function get() {
- return this._ws;
- }
- }, {
- key: "isActive",
- get: function get() {
- var _this$_ws;
- return ((_this$_ws = this._ws) == null ? void 0 : _this$_ws.readyState) === WebSocket.OPEN;
- }
- /**
- * 检查是否正在连接
- * @returns 是否正在连接
- */
- }, {
- key: "isConnecting",
- get: function get() {
- var _this$_ws2;
- return ((_this$_ws2 = this._ws) == null ? void 0 : _this$_ws2.readyState) === WebSocket.CONNECTING;
- }
- /**
- *是否正在关闭
- */
- }, {
- key: "isClosing",
- get: function get() {
- var _this$_ws3;
- return ((_this$_ws3 = this._ws) == null ? void 0 : _this$_ws3.readyState) === WebSocket.CLOSING;
- }
- /**是否已经关闭 */
- }, {
- key: "isClosed",
- get: function get() {
- var _this$_ws4;
- return ((_this$_ws4 = this._ws) == null ? void 0 : _this$_ws4.readyState) === WebSocket.CLOSED;
- }
- }]);
- return WsClient;
- }());
- cclegacy._RF.pop();
- }
- };
- });
- (function(r) {
- r('virtual:///prerequisite-imports/main', 'chunks:///_virtual/main');
- })(function(mid, cid) {
- System.register(mid, [cid], function (_export, _context) {
- return {
- setters: [function(_m) {
- var _exportObj = {};
- for (var _key in _m) {
- if (_key !== "default" && _key !== "__esModule") _exportObj[_key] = _m[_key];
- }
-
- _export(_exportObj);
- }],
- execute: function () { }
- };
- });
- });
|