tools.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { _decorator, assetManager, Component, ImageAsset, instantiate, Node, Prefab, resources, SpriteFrame, sys, Texture2D } from 'cc';
  2. import { config } from './config';
  3. import { main } from './main';
  4. import { car_item_data, edit_game_config_data, model_item_data, rankData, sysConfig, userData } from './data';
  5. import { game } from './game/game';
  6. import { Util } from './util';
  7. import { http } from './http';
  8. import { SdkUtil } from './sdkUtil';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('tools')
  11. export class tools {
  12. public static levels:string[] = []
  13. public static tpl_list:model_item_data[] = []
  14. public static game_config:edit_game_config_data = null
  15. public static sys_config:sysConfig = null
  16. public static mine_rank_data:rankData = null
  17. public static all_car_list:car_item_data[] =[]
  18. public static all_car_page_list = []
  19. public static init(n:Node){
  20. tools.parent = n
  21. }
  22. public static playGame(call_back){
  23. resources.load(config.PREFAB.game,(err,prefab:Prefab)=>{
  24. let node = instantiate(prefab)
  25. node.parent = tools.parent
  26. node.getComponent(game).show(call_back)
  27. })
  28. }
  29. public static parent:Node = null;
  30. public static getBoxRandom(type:number){
  31. for (let index = 0; index < tools.game_config.box_list.length; index++) {
  32. const element = tools.game_config.box_list[index];
  33. if(element.type==type){
  34. return element
  35. }
  36. }
  37. }
  38. public static isBox(type:number){
  39. if(type<=5||type>=9){
  40. return true
  41. }
  42. return false
  43. }
  44. public static randomCoin(){
  45. return Util.getRandomInt(tools.game_config.scores.min,tools.game_config.scores.max)
  46. }
  47. public static loadRemoteImg(url:string,call,tag:number=-1){
  48. if(url==undefined) { return null }
  49. if(url.length<=0){ return null }
  50. assetManager.loadRemote<ImageAsset>(url, (err, imageAsset2)=>{
  51. if (!err && imageAsset2) {
  52. const texture = new Texture2D();
  53. texture.image = imageAsset2;
  54. let spFrame2 = new SpriteFrame();
  55. spFrame2.texture = texture;
  56. spFrame2.addRef()
  57. if(call) {
  58. call({"url":url,"sf":spFrame2,"tag":tag})
  59. }
  60. }
  61. });
  62. }
  63. }