12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import { _decorator, assetManager, Component, ImageAsset, instantiate, Label, Node, Prefab, resources, SpriteFrame, sys, Texture2D } from 'cc';
- import { config } from './config';
- import { car_item_data, edit_game_config_data, model_item_data, rankData, sysConfig, 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 sys_config:sysConfig = null
- public static mine_rank_data:rankData = null
- public static all_car_list:car_item_data[] =[]
- public static all_car_page_list = []
- public static init(n:Node){
- tools.parent = n
- }
- public static playGame(call_back){
- resources.load(config.PREFAB.game,(err,prefab:Prefab)=>{
- let node = instantiate(prefab)
- node.parent = tools.parent
- node.getComponent(game).show(call_back)
- })
- }
- 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==undefined) { return null }
- 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()
- if(call) {
- call({"url":url,"sf":spFrame2,"tag":tag})
- }
- }
- });
- }
- public static labelCutString(node:Node, str:string, length:number, is_text_center:boolean = true) {
- let lab_component = node.getComponent(Label)
- if(lab_component==null) { return }
- if(str.length>length) {
- lab_component.string = str.substring(0,length) + '...'
- lab_component.horizontalAlign = Label.HorizontalAlign.LEFT
- } else {
- lab_component.string = str
- if(is_text_center) {
- lab_component.horizontalAlign = Label.HorizontalAlign.CENTER
- }
- }
- }
- public static substring(string:string, length:number):string {
- if(string.length>length) {
- string = string.substring(0,length)
- }
- return string
- }
-
- }
|