117 lines
3.0 KiB
JavaScript
117 lines
3.0 KiB
JavaScript
// ================================================================
|
|
//
|
|
// 桥接 属性快捷接口
|
|
//
|
|
// ================================================================
|
|
|
|
// 导出
|
|
module.exports = {
|
|
|
|
// 是不是千分比
|
|
isPermillage: function( _key ) {
|
|
|
|
let type = game.configs.attr_data.data_type[_key];
|
|
if( !nx.dt.numGood( type ) ) {
|
|
nx.error( "无效属性:", _key );
|
|
return false;
|
|
}
|
|
|
|
return type == 2;
|
|
},
|
|
|
|
// 设置属性UI组
|
|
// _node子节点: icon key val
|
|
// _data: [key,val]
|
|
setAttribute: function( _node, _data, _add = true ) {
|
|
|
|
let key = _data[0];
|
|
if( nx.dt.strEmpty( key ) ) {
|
|
nx.error( "无效属性设置!" );
|
|
return;
|
|
}
|
|
|
|
let id = game.configs.attr_data.data_key_to_id[key];
|
|
if( !nx.dt.numPositive( id, false ) ) {
|
|
nx.error( "无效属性:", key );
|
|
return false;
|
|
}
|
|
|
|
// 图标
|
|
if( nx.gui.find( _node, "icon" ) ) {
|
|
let icon = _data[2] ? cc.path.join( "coms/images", "ico_w" + key ) : cc.path.join( "coms/images", "ico_" + key ) ;
|
|
nx.gui.setSpriteFrame( _node, "icon", icon );
|
|
}
|
|
|
|
// 属性名
|
|
let name = game.configs.attr_data.data_id_to_name[id];
|
|
nx.gui.setString( _node, "key", nx.text.getKey( name ) );
|
|
|
|
// 数值
|
|
let val = _data[1] || 0;
|
|
let mk = ( _add && val >= 0 ) ? "+" : "";
|
|
if( this.isPermillage( key ) ) {
|
|
val = ( val / 10 ) + "%";
|
|
}
|
|
nx.gui.setString( _node, "val", mk + val );
|
|
},
|
|
|
|
// 规范属性数据
|
|
fmtAttribute: function( _key, _val ) {
|
|
|
|
let id = game.configs.attr_data.data_key_to_id[_key];
|
|
if( !nx.dt.numPositive( id, false ) ) {
|
|
nx.error( "无效属性:", _key );
|
|
return null;
|
|
}
|
|
|
|
// 数值
|
|
let val = _val || 0;
|
|
let mk = ( val >= 0 ) ? "+" : "";
|
|
if( this.isPermillage( _key ) ) {
|
|
val = ( val / 10 ) + "%";
|
|
}
|
|
|
|
return {
|
|
key: _key,
|
|
val: mk + val,
|
|
icon: "ico_" + _key,
|
|
name: game.configs.attr_data.data_id_to_name[id],
|
|
}
|
|
},
|
|
|
|
// 字符串化属性列表
|
|
strAttributes: function( _attrs ) {
|
|
|
|
if( nx.dt.arrEmpty( _attrs ) ) {
|
|
return "";
|
|
}
|
|
|
|
let str = "";
|
|
let push = function( _data, _last ) {
|
|
|
|
if( nx.dt.objEmpty( _data ) ) {
|
|
return;
|
|
}
|
|
|
|
let txt = nx.text.format(
|
|
"SingleAttributeDesc",
|
|
nx.text.getKey( _data.name ),
|
|
_data.val );
|
|
|
|
if( !_last ) {
|
|
txt += "\t";
|
|
}
|
|
|
|
str += txt;
|
|
};
|
|
|
|
for( let i = 0; i < _attrs.length; ++i ) {
|
|
let attr = _attrs[i];
|
|
let info = this.fmtAttribute( attr[0], attr[1] );
|
|
push( info, ( i == ( _attrs.length - 1 ) ) );
|
|
}
|
|
|
|
return str;
|
|
},
|
|
|
|
} |