From 820dc5bf4cf0b9f78586392a3535a627c6b37070 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 9 Jun 2023 11:07:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=B5=84=E6=BA=90=E5=88=86?= =?UTF-8?q?=E7=A6=BB=EF=BC=8C=E7=94=9F=E6=88=90=E5=8F=AF=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierignore | 3 +- mota.config.ts | 4 +- script/resource.ts | 77 ++++++++++++++++++++++++++----- script/template/.h5data | Bin 0 -> 22 bytes script/template/data.js | 26 +++++++++++ script/template/lz-string.min.js | 1 + script/template/main.js | 40 ++++++++++++++++ src/core/loader/load.ts | 31 +------------ src/initPlugin.ts | 2 - 9 files changed, 139 insertions(+), 45 deletions(-) create mode 100644 script/template/.h5data create mode 100644 script/template/data.js create mode 100644 script/template/lz-string.min.js create mode 100644 script/template/main.js diff --git a/.prettierignore b/.prettierignore index 2ae4e4c..264740c 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,4 +4,5 @@ story.md public/project/floors/*.js public/project/items.js public/project/floors/*.js -public/project/maps.js \ No newline at end of file +public/project/maps.js +script/**/*.js \ No newline at end of file diff --git a/mota.config.ts b/mota.config.ts index defa94e..fdfa1a1 100644 --- a/mota.config.ts +++ b/mota.config.ts @@ -2,6 +2,7 @@ interface MotaConfig { name: string; /** 资源分组打包信息 */ resourceZip?: string[][]; + resourceName?: string; } function defineConfig(config: MotaConfig): MotaConfig { @@ -10,5 +11,6 @@ function defineConfig(config: MotaConfig): MotaConfig { export default defineConfig({ // 这里修改塔的name,请保持与全塔属性的完全相同,否则发布之后可能无法进行游玩 - name: 'HumanBreak' + name: 'HumanBreak', + resourceName: 'HumanBreakRes' }); diff --git a/script/resource.ts b/script/resource.ts index b01eef9..6c5e3c2 100644 --- a/script/resource.ts +++ b/script/resource.ts @@ -2,6 +2,7 @@ import fs from 'fs-extra'; import { uniqueSymbol } from './utils.js'; import { basename, extname, resolve } from 'path'; import { dirname } from 'path'; +import motaConfig from '../mota.config.js'; type ResorceType = | 'bgms' @@ -13,17 +14,8 @@ type ResorceType = | 'animates' | 'fonts'; -const compress: ResorceType[] = [ - 'sounds', - 'animates', - 'autotiles', - 'images', - 'materials', - 'tilesets' -]; - const SYMBOL = uniqueSymbol(); -const MAX_SIZE = 100 * (1 << 20); +const MAX_SIZE = 100 * (1 << 20) - 20 * (1 << 10); const baseDir = './dist'; let totalSize = 0; @@ -160,6 +152,9 @@ async function doSplit(compress: boolean) { ) ); + // 生成可发布结构 + await generatePublishStructure(dir, index); + if (Object.values(dirInfo).every(v => v.length === 0)) return; else return split(index + 1); }; @@ -175,7 +170,7 @@ async function rewriteMain(sourceIndex: Record) { .replace(/this\.USE_RESOURCE\s*\=\s*false/, 'this.USE_RESOURCE = true') .replace( /this\.RESOURCE_URL\s*\=\s*'.*'/, - "this.RESOURCE_URL = '/games/HumanBreakRes'" + `this.RESOURCE_URL = '/games/${motaConfig.resourceName}'` ) .replace( /this\.RESOURCE_SYMBOL\s*\=\s*'.*'/, @@ -187,3 +182,63 @@ async function rewriteMain(sourceIndex: Record) { ); await fs.writeFile('./dist/main.js', res, 'utf-8'); } + +async function generatePublishStructure(dir: string, index: number) { + await fs.mkdir(resolve(dir, 'libs')); + await fs.mkdir(resolve(dir, 'libs/thirdparty')); + await fs.mkdir(resolve(dir, 'project')); + await Promise.all( + [ + 'autotiles', + 'images', + 'materials', + 'animates', + 'fonts', + 'floors', + 'tilesets', + 'sounds', + 'bgms' + ].map(v => fs.mkdir(resolve(dir, 'project', v))) + ); + + await fs.writeFile( + resolve(dir, 'project/icons.js'), + `var icons_4665ee12_3a1f_44a4_bea3_0fccba634dc1 = +{ + "autotile": { + + } +}`, + 'utf-8' + ); + await fs.writeFile( + resolve(dir, 'project/floors/none.js'), + '"none"', + 'utf-8' + ); + await fs.writeFile(resolve(dir, 'libs/none.js'), '"none"', 'utf-8'); + + await fs.copyFile( + './script/template/main.js', + resolve(dir, 'project/main.js') + ); + const data = await fs.readFile('./script/template/data.js', 'utf-8'); + await fs.writeFile( + resolve(dir, 'project/data.js'), + data.replace('@name', `${motaConfig.resourceName}${index}`) + ); + + await fs.copyFile( + './script/template/lz-string.min.js', + resolve(dir, 'libs/thirdparty/lz-string.min.js') + ); + + await Promise.all( + ['animates', 'images', 'materials', 'sounds', 'tilesets'].map(v => { + fs.copyFile( + './script/template/.h5data', + resolve(dir, `project/${v}/${v}.h5data`) + ); + }) + ); +} diff --git a/script/template/.h5data b/script/template/.h5data new file mode 100644 index 0000000000000000000000000000000000000000..15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7 GIT binary patch literal 22 NcmWIWW@Tf*000g10H*)| literal 0 HcmV?d00001 diff --git a/script/template/data.js b/script/template/data.js new file mode 100644 index 0000000..cfb2c0f --- /dev/null +++ b/script/template/data.js @@ -0,0 +1,26 @@ +var data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d = +{ + "main": { + "floorIds": ["none"], + "floorPartitions": [], + "images": [], + "tilesets": [], + "animates": [], + "bgms": [], + "sounds": [], + "fonts": [], + "nameMap": {}, + "levelChoose": [], + "equipName": [], + "styles": {}, + "splitImages": [] + }, + "firstData": { + "title": "@name", + "name": "@name", + "version": "v0.1", + "hero": {} + }, + "values": {}, + "flags": {} +} diff --git a/script/template/lz-string.min.js b/script/template/lz-string.min.js new file mode 100644 index 0000000..b2088b1 --- /dev/null +++ b/script/template/lz-string.min.js @@ -0,0 +1 @@ +var LZString=function(){function o(o,r){if(!t[o]){t[o]={};for(var n=0;ne;e++){var s=r.charCodeAt(e);n[2*e]=s>>>8,n[2*e+1]=s%256}return n},decompressFromUint8Array:function(o){if(null===o||void 0===o)return i.decompress(o);for(var n=new Array(o.length/2),e=0,t=n.length;t>e;e++)n[e]=256*o[2*e]+o[2*e+1];var s=[];return n.forEach(function(o){s.push(r(o))}),i.decompress(s.join(""))},compressToEncodedURIComponent:function(o){return null==o?"":i._compress(o,6,function(o){return e.charAt(o)})},decompressFromEncodedURIComponent:function(r){return null==r?"":""==r?null:(r=r.replace(/ /g,"+"),i._decompress(r.length,32,function(n){return o(e,r.charAt(n))}))},compress:function(o){return i._compress(o,16,function(o){return r(o)})},_compress:function(o,r,n){if(null==o)return"";var e,t,i,s={},p={},u="",c="",a="",l=2,f=3,h=2,d=[],m=0,v=0;for(i=0;ie;e++)m<<=1,v==r-1?(v=0,d.push(n(m)),m=0):v++;for(t=a.charCodeAt(0),e=0;8>e;e++)m=m<<1|1&t,v==r-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}else{for(t=1,e=0;h>e;e++)m=m<<1|t,v==r-1?(v=0,d.push(n(m)),m=0):v++,t=0;for(t=a.charCodeAt(0),e=0;16>e;e++)m=m<<1|1&t,v==r-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}l--,0==l&&(l=Math.pow(2,h),h++),delete p[a]}else for(t=s[a],e=0;h>e;e++)m=m<<1|1&t,v==r-1?(v=0,d.push(n(m)),m=0):v++,t>>=1;l--,0==l&&(l=Math.pow(2,h),h++),s[c]=f++,a=String(u)}if(""!==a){if(Object.prototype.hasOwnProperty.call(p,a)){if(a.charCodeAt(0)<256){for(e=0;h>e;e++)m<<=1,v==r-1?(v=0,d.push(n(m)),m=0):v++;for(t=a.charCodeAt(0),e=0;8>e;e++)m=m<<1|1&t,v==r-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}else{for(t=1,e=0;h>e;e++)m=m<<1|t,v==r-1?(v=0,d.push(n(m)),m=0):v++,t=0;for(t=a.charCodeAt(0),e=0;16>e;e++)m=m<<1|1&t,v==r-1?(v=0,d.push(n(m)),m=0):v++,t>>=1}l--,0==l&&(l=Math.pow(2,h),h++),delete p[a]}else for(t=s[a],e=0;h>e;e++)m=m<<1|1&t,v==r-1?(v=0,d.push(n(m)),m=0):v++,t>>=1;l--,0==l&&(l=Math.pow(2,h),h++)}for(t=2,e=0;h>e;e++)m=m<<1|1&t,v==r-1?(v=0,d.push(n(m)),m=0):v++,t>>=1;for(;;){if(m<<=1,v==r-1){d.push(n(m));break}v++}return d.join("")},decompress:function(o){return null==o?"":""==o?null:i._decompress(o.length,32768,function(r){return o.charCodeAt(r)})},_decompress:function(o,n,e){var t,i,s,p,u,c,a,l,f=[],h=4,d=4,m=3,v="",w=[],A={val:e(0),position:n,index:1};for(i=0;3>i;i+=1)f[i]=i;for(p=0,c=Math.pow(2,2),a=1;a!=c;)u=A.val&A.position,A.position>>=1,0==A.position&&(A.position=n,A.val=e(A.index++)),p|=(u>0?1:0)*a,a<<=1;switch(t=p){case 0:for(p=0,c=Math.pow(2,8),a=1;a!=c;)u=A.val&A.position,A.position>>=1,0==A.position&&(A.position=n,A.val=e(A.index++)),p|=(u>0?1:0)*a,a<<=1;l=r(p);break;case 1:for(p=0,c=Math.pow(2,16),a=1;a!=c;)u=A.val&A.position,A.position>>=1,0==A.position&&(A.position=n,A.val=e(A.index++)),p|=(u>0?1:0)*a,a<<=1;l=r(p);break;case 2:return""}for(f[3]=l,s=l,w.push(l);;){if(A.index>o)return"";for(p=0,c=Math.pow(2,m),a=1;a!=c;)u=A.val&A.position,A.position>>=1,0==A.position&&(A.position=n,A.val=e(A.index++)),p|=(u>0?1:0)*a,a<<=1;switch(l=p){case 0:for(p=0,c=Math.pow(2,8),a=1;a!=c;)u=A.val&A.position,A.position>>=1,0==A.position&&(A.position=n,A.val=e(A.index++)),p|=(u>0?1:0)*a,a<<=1;f[d++]=r(p),l=d-1,h--;break;case 1:for(p=0,c=Math.pow(2,16),a=1;a!=c;)u=A.val&A.position,A.position>>=1,0==A.position&&(A.position=n,A.val=e(A.index++)),p|=(u>0?1:0)*a,a<<=1;f[d++]=r(p),l=d-1,h--;break;case 2:return w.join("")}if(0==h&&(h=Math.pow(2,m),m++),f[l])v=f[l];else{if(l!==d)return null;v=s+s.charAt(0)}w.push(v),f[d++]=s+v.charAt(0),h--,s=v,0==h&&(h=Math.pow(2,m),m++)}}};return i}();"function"==typeof define&&define.amd?define(function(){return LZString}):"undefined"!=typeof module&&null!=module&&(module.exports=LZString); \ No newline at end of file diff --git a/script/template/main.js b/script/template/main.js new file mode 100644 index 0000000..47280b5 --- /dev/null +++ b/script/template/main.js @@ -0,0 +1,40 @@ +function main() { + //------------------------ 用户修改内容 ------------------------// + + this.version = 'v0.1'; // 游戏版本号;如果更改了游戏内容建议修改此version以免造成缓存问题。 + + this.useCompress = false; // 是否使用压缩文件 + // 当你即将发布你的塔时,请使用“JS代码压缩工具”将所有js代码进行压缩,然后将这里的useCompress改为true。 + // 请注意,只有useCompress是false时才会读取floors目录下的文件,为true时会直接读取libs目录下的floors.min.js文件。 + // 如果要进行剧本的修改请务必将其改成false + + this.bgmRemote = false; // 是否采用远程BGM + this.bgmRemoteRoot = 'https://h5mota.com/music/'; // 远程BGM的根目录 + + this.isCompetition = false; // 是否是比赛模式 + + this.savePages = 1000; // 存档页数,每页可存5个;默认为1000页5000个存档 + this.criticalUseLoop = 1; // 循环临界的分界 + + //------------------------ 用户修改内容 END ------------------------// + + this.dom = {}; + this.mode = 'play'; + this.loadList = ['none']; + this.pureData = ['data']; + this.materials = []; + + this.statusBar = { + image: {}, + icons: {} + }; + this.floors = {}; + this.canvas = {}; + + this.__VERSION__ = 'v0.1'; + this.__VERSION_CODE__ = 1000; +} + +main.prototype.loadMod = function () {}; + +main.prototype.init = function () {}; diff --git a/src/core/loader/load.ts b/src/core/loader/load.ts index ad99c16..6342cee 100644 --- a/src/core/loader/load.ts +++ b/src/core/loader/load.ts @@ -1,30 +1 @@ -import axios, { AxiosRequestConfig } from 'axios'; - -class LoadTask { - loaded: boolean = false; - promise?: Promise; - url: string; - config?: AxiosRequestConfig; - - constructor(url: string, config?: AxiosRequestConfig) { - this.url = url; - this.config = config; - } - - load() { - if (this.promise) return this.promise; - - return (this.promise = axios.get(this.url, this.config)); - } - - static list: Promise[] = []; - static push(...tasks: LoadTask[]) { - this.list.push(...tasks.map(v => v.load())); - } - - static onEnd(): Promise { - return Promise.all(LoadTask.list) as Promise; - } -} - -export default function load() {} +export function readyAllResource() {} diff --git a/src/initPlugin.ts b/src/initPlugin.ts index 695dba0..7236ef6 100644 --- a/src/initPlugin.ts +++ b/src/initPlugin.ts @@ -18,7 +18,6 @@ import completion, { floors } from './plugin/completion'; import path from './plugin/fx/path'; import gameCanvas from './plugin/fx/gameCanvas'; import noise from './plugin/fx/noise'; -import load from './core/loader/load'; function forward() { const toForward: any[] = [ @@ -61,7 +60,6 @@ function forward() { } console.log('插件转发完成!'); - load(); Object.values(floors).forEach((v, i) => { const from = core.floorIds.indexOf(v[0]);