猫史档案馆


NomenSql系列与EasyCoding系列合集

用户:萌新大佬萌新大佬查看:2 回复:3 评论:2 创建时间:2023-05-18T18:13:31


NomenFileSystem@1.7.0

https://shequ.codemao.cn/community/540876

【神岛首个多表格便携式轻量级协同管理器】NomenSQLite:

1.2.0:https://shequ.codemao.cn/wiki/forum/540732
1.0.0:https://shequ.codemao.cn/community/539617

其它NomenSQL系列:

【萌新向:妈妈再也不用担心我不会写SQL辣】https://shequ.codemao.cn/community/539624
【 NomenSQLitePro1.0:表格字段自动更新 - 为开发者提供的便捷调试工具】https://shequ.codemao.cn/community/539869
【 NomenPostgre-Base:神岛首个PG数据库动态多表格轻量级便携式管理器】https://shequ.codemao.cn/community/539700

EasyCoding系列(未发帖):

EasyController

/**
 * EasyController 是由萌新大佬开发的一款便于管理文件,代码的便捷工具
 * 此工具完全开源,免费试用,共所有人学习与参考
 * 建议单独设立文件使用,并首个require
 * @author 萌新大佬 <https://box3.codemao.cn/u/mxdlorzorz>
 * @version 1.0.0
 */

//init

const assetTypes ={
    'js':'代码',
    'image':'图片',
    'lut':'滤镜',
    'snow':'雪花纹样',
    'mesh':'模型',
    'sound':'音乐/音效',
    'directory':'文件夹',
};
!function init(){
    console.clear();
    console.log('EasyController加载中...');
    console.log(`检测到EasyController存储位置:[${__dirname||'.'}/${__filename}]`);
    console.log('[EasyController]整理文件中...');
    console.log('[EasyController]文件:');
    /**
     * @param {Box3AssetListEntry[]} asts
     */
    function dir(asts,deep){
        for(const ast of asts){
            var log='';
            for(let i=1;i<=deep;i++)log+='····';
            console.log(`${log}[${assetTypes[ast.type]}]${ast.path.split('/').pop()}`);
            if(ast.type==Box3AssetType.DIRECTORY)dir(resources.ls(ast.path),deep+1);
        }
    }
    dir(resources.ls('.'),1);
}();

//tools
function getFileName(){
    try{
        throw Error();
    }catch(err){
        return err.stack.split('\n').
        find(x=>x.includes('eval')).slice(13).split(':')[0];
    }
}
function getLine(){
    try{
        throw Error();
    }catch(err){
        return err.stack.split('\n').
        find(x=>x.includes('eval')).slice(13).split(':')[1];
    }
}

//logger

class Logger{
    /**
     * 为每个文件建立独立对话框
     * @param {boolean?} showLine 是否显示输出的行数,默认为false
     * @param {boolean?} showTime 是否显示输出的时间,默认为false
     */
    constructor(showLine,showTime){
        this.filename=getFileName();
        this.showLine=showLine||false;
        this.showTime=showTime||false;
        this.log(`[logger] ${this.filename}logger加载完毕`);
    }
    get preLog(){
        var log='';
        var d=new Date();
        if(this.showTime)log+=`[${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}]`;
        log+='['+this.filename;
        if(this.showLine)log+=':'+getLine();
        return log+']';
    }
    log(...args){
        return console.log(this.preLog,...args);
    }
    warn(...args){
        return console.warn(this.preLog,...args);
    }
    error(...args){
        return console.error(this.preLog,...args);
    }
    clear(){
        console.clear();
        console.log(`clear at ${this.preLog}`);
    }
}

//exports

module.exports={    
    Logger,
}

EasyDialog

/**
 * EasyDialog 是由萌新大佬开发的一款便捷建立对话框的工具
 * 此工具完全开源,免费试用,共所有人学习与参考
 * @author 萌新大佬 <https://box3.codemao.cn/u/mxdlorzorz>
 * @version 1.0.0
 */

//enumerations
const TYPES={
    NUMBER: "number",
    STRING: "string",
    OBJECT: "object",
    FUNCTION: "function",
    
}

/**
 * 重复询问,直到选择“×”或者回调函数返回null
 * 此功能强制选择对话框
 * @param {Box喵layerEntity} entity 产生对话的实体
 * @param {Box3SelectDialogParams} configs 对话的参数,type强制select
 * @param {selectCallback} callback 回调函数
 */
async function reask(entity,configs,callback){
    configs.type=Box3DialogType.SELECT;
    while(true){
        let res=await entity.player.dialog(configs);
        if(!res||res==null)break;
        let cb=callback(res.index,res.value);
        if(cb===null)break;
        else configs.content=cb||configs.content;
    }
}

/**
 * 滚动字幕功能
 * 此功能不强制对话类型
 * 为了确保此功能正常运行,会在滚动前清除实体的所有对话框
 * 特殊字符可能会导致输出混乱
 * @param {Box喵layerEntity} entity 产生对话的实体
 * @param {number} interval 两次滚动的间隔(ms)
 * @param {Box3DialogParams} configs 对话的参数
 * @param {boolean?} delay 如果为true,则除最后一次对话外均为text对话框,默认为false
 * 特殊处理:如果delay为true,则除最后一次对话外hasArrow强制为false
 * @returns {Box3DialogResponse} 返回最终对话框的结果

 */
async function rollPlay(entity,interval,configs,delay){
    delay=delay||false;
    let {content,hasArrow,type}=configs;
    configs.content='';
    if(delay)Object.assign(configs,{hasArrow:false,type:Box3DialogType.TEXT});
    entity.player.cancelDialogs();
    for(let i=0;i<content.length-1;i++){
        configs.content+=content[i];
        entity.player.dialog(configs);
        await sleep(interval);
        entity.player.cancelDialogs();
    }
    Object.assign(configs,{content,hasArrow,type});
    return await entity.player.dialog(configs);
}

//callbacks

/**
 * 选择对话框的回调函数
 * @callback selectCallback
 * @param {number} index
 * @param {string} value
 * @returns {string|null|undefined}
 * string    : 下次对话的content
 * null      : 如果返回null则退出循环询问
 * undefined : 什么也不做
 */

//exports
module.exports={
    //enumerations
    TYPES,
    //functions
    rollPlay,
    reask,
}

目前所有EasyCoding项目均有本人开发,期待更多人的建议与加入

Box3-Tools仓库(github)

github.com/helloyork/Box3-Tools

 


回复

上一页1 页 / 共 1下一页
yee089yee089

qpzc

点赞0


评论


萌新大佬萌新大佬

ddd

点赞0


评论


NomenNomen

喵d

点赞0


评论