tools.ts 2.3 KB

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