12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import { _decorator, assetManager, Component, ImageAsset, instantiate, Node, Prefab, resources, SpriteFrame, Texture2D } from 'cc';
- import { config } from './config';
- import { main } from './main';
- import { car_item_data, edit_game_config_data, model_item_data, userData } from './data';
- import { game } from './game/game';
- import { Util } from './util';
- const { ccclass, property } = _decorator;
- @ccclass('tools')
- export class tools {
- public static levels:string[] = []
- public static tpl_list:model_item_data[] = []
- public static game_config:edit_game_config_data = null
- public static all_car_list:car_item_data[] =[]
- public static init(n:Node){
- tools.parent = n
- }
- public static playGame(){
- resources.load(config.PREFAB.game,(err,prefab:Prefab)=>{
- let node = instantiate(prefab)
- node.parent = tools.parent
- node.getComponent(game).show()
- })
- }
- public static parent:Node = null;
- public static getBoxRandom(type:number){
- for (let index = 0; index < tools.game_config.box_list.length; index++) {
- const element = tools.game_config.box_list[index];
- if(element.type==type){
- return element
- }
- }
- }
- public static isBox(type:number){
- if(type<=5||type>=9){
- return true
- }
- return false
- }
- public static randomCoin(){
- return Util.getRandomInt(tools.game_config.scores.min,tools.game_config.scores.max)
- }
- public static loadRemoteImg(url:string,call,tag:number=-1){
- if(url.length<=0){
- return null;
- }
- assetManager.loadRemote<ImageAsset>(url, (err, imageAsset2)=>{
- if (!err && imageAsset2) {
- const texture = new Texture2D();
- texture.image = imageAsset2;
- let spFrame2 = new SpriteFrame();
- spFrame2.texture = texture;
- spFrame2.addRef()
- call({"url":url,"sf":spFrame2,"tag":tag})
- }
- });
- }
- }
|