tools.ts 2.3 KB

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