tools.ts 2.0 KB

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