jbcore
# ==命名空间 jb==
### ==jb.allConfig==
游戏中用到的配置都放到这里 配置类型设定在 config.d.ts 中
### ==jb.ald==
```javascript
function init(useAld: boolean = false): void;
```
```javascript
/**
*
* @param name 事件名称 string 描述用户的动作名称,不超过255个字符,支持特殊字符
* @param action action 参数 string 动作的参数,不超过255个字符,支持特殊字符但不包括(英文逗号 , 英文冒号 : 点 .)
* @param value value 参数值 string 动作的参数值,不超过255个字符,支持特殊字符但不包括(英文逗号 , 英文冒号 : 点 .)
* }
*/
function sendEvent(name: string, opts?: any): void;
```
```javascript
/**
*
* @param stageId 关卡ID String 1 , 2 , 3 , 1.1 , 1.2 , 1.3 格式 最多支持 32 个字符 必传
* @param stageName 关卡名称 String 最多支持 32 个字符 必传
* @param userId 用户ID String 最多支持 32 个字符 可选
*/
function startStage(stageId: string, stageName: string, userId: string): void ;
```
```javascript
function runmingStage(stageId: string, stageName: string, userId: string, event: string,
itemName: string, itemId?: string, desc?: string, itemCount?: number, itemMoney?: number): void ;
```
```javascript
function endStage(stageId: string, stageName: string, userId: string, event: string, desc: string): void ;
```
### ***==jb.interfaces==***
```javascript
/**
*启动参数
*
* @export
* @interface ILaunchOption
*/
export interface ILaunchOption {
scene: string,
query: { [id: string]: any },
shareTicket: string,
referrerInfo: any,
}
/**
* 空方法别名
*/
export type IFunctionNull = () => void;
/**
*
*需要自己控制update的类要继承这个
* @export
* @interface IServerTimer
*/
export interface IServerTimer {
timeUpdate(dt: number): void;
}
/**
*对象池管理接口
*
* @export
* @interface INodePool
*/
export interface INodePool {
clear(): void;
}
/**
*
*确认框信息接口
* @export
* @interface IConfirmParmas
*/
export interface IConfirmParmas {
str: string
sure: IFunctionNull,
cancel: IFunctionNull
}
/**
*用户信息接口
*
* @export
* @interface IUserInfo
*/
export interface IUserInfo {
nickName: string,
avatarUrl: string,
gender?: string,
language?: string,
city?: string,
province?: string,
country?: string,
auth: boolean,
}
/**
*
*游戏设置界面数据接口
* @export
* @interface ISetting
*/
export interface ISetting {
}
```
### ***==jb.time==***
```javascript
export class Group implements interfaces.IServerTimer{
/**
*
*是否在运行
* @readonly
* @type {boolean}
* @memberof Group
*/
get isRunning(): boolean;
/**
*
*暂停计时
* @memberof Group
*/
pause(): void ;
/**
*
*恢复计时
* @memberof Group
*/
resume(): void ;
/**
* 添加
* @param target
*/
add(target: interfaces.IServerTimer): boolean ;
/**
* 清理对象
* @param target
*/
remove(target: interfaces.IServerTimer): boolean ;
/**
* 清理
*/
clear(): void ;
/**
*
*添加重复计时
* @param {number} [interval=0] 每次计时时间 (秒)
* @param {interfaces.IFunctionNull} callback 计时回调
* @param {boolean} [immediate=false] 是否一开始就执行一次
* @param {number} [repeatTimes=0] 执行次数 0就是无限 大于0实际次数
* @return {*} {interfaces.IServerTimer}
* @memberof Group
*/
addRepeatTime(interval: number = 0,
callback: interfaces.IFunctionNull,
immediate: boolean = false, repeatTimes: number = 0): interfaces.IServerTimer ;
}
export class SchedulePerSecond {
public init(): void ;
/**
*添加
*
* @param {*} target 目标
* @param {number} duration 每局时间(秒)
* @param {number} runningTime 已经运行时间(秒)
* @param {() => void} [callback=null] 每局回调
* @param {(times: number) => void} [perCall] 每秒回调
* @memberof SchedulePerSecond
*/
public add(target: any, duration: number, runningTime: number,
callback: () => void = null, perCall?: (times: number) => void): void ;
/**
*获取
*
* @param {*} target
* @return {*} {Schedule}
* @memberof SchedulePerSecond
*/
public get(target: any): Schedule ;
/**
*删除
*
* @param {*} target
* @return {*} {boolean}
* @memberof SchedulePerSecond
*/
public remove(target: any): boolean ;
}
export class Schedule {
/**
*运行时间
*
* @type {number}
* @memberof Schedule
*/
public runningTime: number;
}
```
### ***==jb.funcs==***
```javascript
/**
* 获取当天是今天的第几天
*/
function getYearDay(): number;
/**
* 获取当天还有几秒钟
*/
function getTodayRemainSecond(): number;
/**
* 获取当天已经用了多少秒
*/
function getTodayPassSecond(): number;
/**
*
* @param duration 体眠 毫秒
*/
function sleep(duration: number): Promise<number>;
/**
*
*时间转成二位格式
* @export
* @param {number} time 转入的值
* @return {*} {string} eg 3->03 10->10
*//
function timeSecondFormat(time: number): string ;
/**
*
*时间格式
* @export
* @param {number} time 时间戳
* @param {string} [split=":"] 连接符
* @return {*} {string} 12:12:12
*//
function timeToString(time: number, split: string = ":"): string ;
/**
* 转换成格式
* @param time 时间戳
* @param format 格式 h:m:s h-m-s
* @param isMillSecond 传入的时间单位是否是毫秒
*/
function timeFormat(time: number, format: string = "m:s", isMillSecond: boolean = false): string;
/**
*保留小数点后面几位
*
* @param {number} v
* @param {number} [size=1] 小数位数
* @return {*} {string}
*//
function toFixed(v: number, size: number = 1): string;
/**
*数值格式转换
*
* @export
* @param {number} value
* @return {*} {string} 1000-> 1K 1000000->1M
*///
function numberFormat(value: number): string;
/**
* 呼吸动画
* @param node
* @param duration 时间
* @param append 扩展系数
* @param times 次数 0 : 循环
*/
function breath(node: cc.Node, duration: number, append: number, times: number = 0, startScale: number = 1):void;
/**
* 比较版本号
* @param a
* @param b 1.2.3 > 1.2.2
*/
function compareVersion(a: string, b: string): boolean;
/**
* 获取文字ASICC码长度(中文二个
* @param str
*//
function charSize(str: string): number;
/**
* 旋转结点
* @param node 结点对象
* @param duration 转一圈需要的时间
* @param times 转圈次数 0:无限
*/
function rotation(node: cc.Node, duration: number, times: number = 0): void;
```
### ***==jb.mvc==***
```javascript
/**
* 数据模型基类,游戏中用到的所有模型内 都要继续该类
*/
abstract class BaseModel extends Publish {
/**
* 请求服务器
* @param {*} action 接口名
* @param {*} opts 参数 {}
*/
request(action: string, req: any = {}, event?: string);
/**
* 回调响应 子类重写
* @param {*} action 接口名
* @param {*} res 服务器响应数据
* @param {*} event
*/
abstract responseHandler(action: string, req: any, res: any, event?: string): void;
/**
* 所有模块都已经注册后
*/
abstract afterAllModelRegister(): void;
}
abstract class BaseMediator<T extends BaseComponent> extends Publish {
update(dt: number): void { };
/**
*
*逻辑帧
* @param {number} dt
* @memberof BaseMediator
*/
timeUpdate(dt: number): void {};
/**
* view 预制体准备好了
*/
abstract onViewReady(): void;
/**
* 订阅全局事件消息回调
* @param event 消息名称
* @param param 消息参数
*/
protected abstract onMessage(event: string, ...param: any[]): void;
/**
* UI 事件
* @param {*} event
* @param {...any} param
*/
protected abstract onGUI(event: string, ...param: any[]): void;
/**
* 订阅事件 全局事件
* @param {*} eventList 事件列表
*/
protected subscribeMessages(eventList: string[]): void ;
/**
* 订阅UI事件
* @param eventList
*/
protected subscriGUIEvents(eventList: string[], debug: boolean = false): void ;
}
abstract class BaseComponent extends cc.Component {
/**
* 选中与否
*/
set selected(value: boolean);
/**
* 注册ui事件响应对象
* @param node 对象
* @param dis 有效点击划动距离
*/
protected registerTouch(node: cc.Node, dis: number = 10): void;
}
```
### ***==jb.view==***
```javascript
/**
* 界面显示方式
*/
export const ViewMode = cc.Enum({
ALONE: 1, //独占
SHARE: 2 //共享
});
/**
* 界面类型
*/
export const ViewType = cc.Enum({
MODULE: 0,
UI: 1,
PANEL: 2,
ALERT: 3
});
export const TweenType = cc.Enum({
NONE: 1,
SCALE: 2,
DROP: 3
});
```
### ***==jb.viewImp==***
```javascript
let viewImp = {
/**
* 注册界面配置
* @param name 界面名字
* @param prefabName 预制体名字 或是预制体
* @param scriptName 脚本
* @param MediatorCLS 控制器
* @param viewType 显示类型
* @param viewMode 显示模式
*/
registerView(name: string,
prefabName: string | cc.Asset,
scriptName: string,
mediatorClass: any = null,
viewType: number = ViewType.PANEL,
viewMode: number = ViewMode.ALONE,
tweenType: number = TweenType.SCALE): void;
/**
* 異步顯示
* @param url
* @param isDir
* @param target
* @param zIndex
* @param viewType
* @param viewMode
* @param reset
*/
showViewAsync(url: string, isDir: boolean, target: string, zIndex: number = 0,
viewType: number = ViewType.PANEL, viewMode: number = ViewMode.ALONE, reset: boolean = false): Promise<cc.Node>;
/**
* 显示对象同步
* @param {*} target 注册时用到的名字 或者一个显示实例
* @param {*} zIndex
* @param {*} viewType 显示方式
* @param {*} viewMode 显示模式
*/
showView(target: string | cc.Node, zIndex: number = 0,
viewType: number = ViewType.PANEL, viewMode: number = ViewMode.ALONE, reset: boolean = false): cc.Node ;
/**
* 删除面板
* @param {*} node 面板对象
*/
removeView(node: cc.Node):void;
}
export class BaseScene extends mvc.BaseComponent {
start():void;
}
```
### ***==jb.BaseScene==***
```javascript
declare class BaseScene extends mvc.BaseComponent {
constructor(name: String);
start() :void;
}
```
### ***==jb.module==***
```javascript
class ModuleStack extends jb.funcs.Signaleton{
/**
* 显示对象
* @param {*} name 注册用到的名字
* @param {*} keepPath 是否保存回退路径
*/
show(name: string, keepPath: boolean = true): void;
/**
* 回到上一个界面
*/
back(moduleName: string = null): void;
/**
* 清除记录
*/
clean(): void;
}
}
```
### ***==jb.sound==***
```javascript
/**
* 是否播放音效
*/
export let enableEffect: boolean = true;
/**
* 是否播放背景音乐
*/
export let enableMusic: boolean = true;
export function registerSound(type: platform.Type, sound: ISound): void ;
/**
* 初始化声音管理类
* @param type 平台标记
*/
export function init(type: platform.Type): void ;
export function getUrlToAudioClip(url: string, callback: (clip: cc.AudioClip) => void) ;
export function loadMusic(url: string, callback: () => void): void ;
export function prepareMusic(target: string, isloop: boolean = false, isRemote: boolean = true, autoplay: boolean = false) ;
export function playMusic(target: string | cc.AudioClip, isloop: boolean = false): void ;
export function pauseMusic(): void ;
export function resumeMusic(): void ;
export function stopMusic(): void ;
export function playEffect(target: string | cc.AudioClip, isloop: boolean = false, node: cc.Node = null): void ;
function stopEffect(target: string, node: cc.Node = null): boolean ;
function setVolumn(vol: number): void ;
export function setRemoteUrl(url: string): void ;
```
### ***==jb.platform==***
```javascript
declare function registerPlatform(name: string, cls: any): void ;
declare let enableVibrate : boolean;
declare function init(name: string): void ;
declare function showLoading(title:string):void;
declare function hideLoading():void;
declare function loginSdkResponse(res: any): void ;
/**
* 联上网
*/
declare function online(): void ;
/**
* 网络断开
*/
declare function offline(): void ;
//-------------------------------------- proxy -----
declare function shareGame(shareTicket: string/*,online : any*/,
query: { [id: string]: string }, title: string, imageUrl: string, desc: string = "award") ;
declare function setUserCloudStorage(obj: any) ;
declare function setUserScore(score: number, suc: () => void): void ;
declare function setWXOpenId(id: string): void ;
/**
* 显示微信排行榜
*/
declare function showWXRankList(suc: () => void): void ;
declare function hideWXRankList(): void ;
declare function vibrateShort(duration: number = 10): void ;
/**
* 使手机发生较长时间的振动(400 ms)
*/
declare function vibrateLong(): void ;
declare function getLaunchOption(): interfaces.ILaunchOption ;
/**
* 是否开放banner广告
*/
declare let bannerEnabled: boolean;
declare function showBanner(type: string, width?: number): void ;
declare function hideBannger(): void;
declare function hasVideo(): boolean ;
/**
* 是否开放插屏广告
*/
declare let interEnabled: boolean;
declare function showInteAd(type: string, success: () => void = null, fail: () => void = null): void;
declare function wdithDivideHeight(): number ;
//
declare function isLargeScreen(): boolean ;
declare function isMiddleScreen(): boolean ;
declare function isSmallScreen(): boolean ;
declare function bannerEnabelScreen(): boolean;
declare function showGameClub():void;
declare function hideGameClub():void;
declare function shareToFriend(action:string,success:(res:any)=>void,fail:()=>void):void;
declare function showAwardVideo(shareTicket:string,success:()=>void,fail:(code:any)=>void):void;
declare function getSetting(always:boolean=false):Promise<any>;
declare function requestSubscribeMessage(id:string):Promise<any>;
declare function getUserInfoAnyTouch():Promise<any>;
declare function updateApp(callback:()=>void):void;
declare function run():void;
declare function get<T>(prop:string):T;
```
### ***==jb.poolManager==***
```javascript
/**
*生成对像池
*
* @param {...string[]} parmas 对象Tag 列表
* @memberof PoolManager
*/
init(...parmas: string[]): void {
parmas.forEach((tag: string) => {
this.poolMap.set(tag, new cc.NodePool());
})
}
/**
*
*将数据放入对象池
* @param {string} tag
* @param {cc.Node} node 对象
* @param {({ prototype: cc.Component } | string)} [poolHandlerComp] 回收对象可控制的脚本
* @memberof PoolManager
*/
put(tag: string, node: cc.Node, poolHandlerComp?: { prototype: cc.Component } | string) {
if (!this.poolMap.has(tag)) this.poolMap.set(tag, new cc.NodePool(poolHandlerComp));
node.stopAllActions();
this.poolMap.get(tag).put(node);
// console.log("put back " + tag + " size = " + this.poolMap.get(tag).size());
}
/**
*
* 获取对象池里的数据
* @param {string} tag
* @param {(...parmas: any[]) => cc.Node} initFun 如果对象池没有 初始方法
* @param {...any[]} parmas 初始参数
* @return {*} {cc.Node}
* @memberof PoolManager
*/
get(tag: string, initFun: (...parmas: any[]) => cc.Node, ...parmas: any[]): cc.Node {
let node: cc.Node = null;
if (this.poolMap.has(tag)) {
node = this.poolMap.get(tag).get(...parmas);
}
if (!node && initFun) {
// console.log("can not find " + tag);
node = initFun(...parmas);
}
return node;
}
/**
*清除对象池
*
* @param {string} [tag]
* @memberof PoolManager
*/
clear(tag?: string): void {
if (tag) {
let pool: cc.NodePool = this.poolMap.get(tag);
if (pool) {
pool.clear();
}
} else {
this.poolMap.forEach((pool: cc.NodePool) => {
pool.clear();
});
}
}
```