@wwawing/loader 0.0.0-exe-chousa.based-on.3.12.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +34 -0
- package/lib/core/decompressor/index.d.ts +6 -0
- package/lib/core/decompressor/index.js +31 -0
- package/lib/core/extractor/checksum.d.ts +1 -0
- package/lib/core/extractor/checksum.js +30 -0
- package/lib/core/extractor/constants.d.ts +27 -0
- package/lib/core/extractor/constants.js +31 -0
- package/lib/core/extractor/index.d.ts +19 -0
- package/lib/core/extractor/index.js +186 -0
- package/lib/core/index.d.ts +8 -0
- package/lib/core/index.js +50 -0
- package/lib/core/map-data-client/BaseMapDataClient.d.ts +4 -0
- package/lib/core/map-data-client/BaseMapDataClient.js +7 -0
- package/lib/core/map-data-client/BrowserMapDataClient.d.ts +8 -0
- package/lib/core/map-data-client/BrowserMapDataClient.js +45 -0
- package/lib/core/map-data-client/NodeLocalMapDataClient.d.ts +6 -0
- package/lib/core/map-data-client/NodeLocalMapDataClient.js +26 -0
- package/lib/core/map-data-client/index.d.ts +4 -0
- package/lib/core/map-data-client/index.js +9 -0
- package/lib/core/text-loader/index.d.ts +13 -0
- package/lib/core/text-loader/index.js +147 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +20 -0
- package/lib/infra/index.d.ts +98 -0
- package/lib/infra/index.js +174 -0
- package/lib/infra/util.d.ts +2 -0
- package/lib/infra/util.js +16 -0
- package/module/core/decompressor/index.d.ts +6 -0
- package/module/core/decompressor/index.js +28 -0
- package/module/core/extractor/checksum.d.ts +1 -0
- package/module/core/extractor/checksum.js +27 -0
- package/module/core/extractor/constants.d.ts +27 -0
- package/module/core/extractor/constants.js +28 -0
- package/module/core/extractor/index.d.ts +19 -0
- package/module/core/extractor/index.js +182 -0
- package/module/core/index.d.ts +8 -0
- package/module/core/index.js +46 -0
- package/module/core/map-data-client/BaseMapDataClient.d.ts +4 -0
- package/module/core/map-data-client/BaseMapDataClient.js +3 -0
- package/module/core/map-data-client/BrowserMapDataClient.d.ts +8 -0
- package/module/core/map-data-client/BrowserMapDataClient.js +41 -0
- package/module/core/map-data-client/NodeLocalMapDataClient.d.ts +6 -0
- package/module/core/map-data-client/NodeLocalMapDataClient.js +19 -0
- package/module/core/map-data-client/index.d.ts +4 -0
- package/module/core/map-data-client/index.js +4 -0
- package/module/core/text-loader/index.d.ts +13 -0
- package/module/core/text-loader/index.js +143 -0
- package/module/index.d.ts +2 -0
- package/module/index.js +2 -0
- package/module/infra/index.d.ts +98 -0
- package/module/infra/index.js +167 -0
- package/module/infra/util.d.ts +2 -0
- package/module/infra/util.js +11 -0
- package/package.json +73 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { new2DArray } from "../../infra/util";
|
|
2
|
+
import { checkMapDataBroken } from "./checksum";
|
|
3
|
+
import { BytePosition } from "./constants";
|
|
4
|
+
import { WWAConsts, PartsType, LoadStage, createDefaultWWAData } from "../../infra";
|
|
5
|
+
export class WWADataExtractor {
|
|
6
|
+
constructor(byteMapData, byteMapLength, eventEmitter) {
|
|
7
|
+
this.byteMapData = byteMapData;
|
|
8
|
+
this.eventEmitter = eventEmitter;
|
|
9
|
+
checkMapDataBroken(byteMapData, byteMapLength);
|
|
10
|
+
this.wwaData = createDefaultWWAData();
|
|
11
|
+
}
|
|
12
|
+
extractAllData() {
|
|
13
|
+
var mapAttrMax, objAttrMax;
|
|
14
|
+
this.wwaData.version = this.byteMapData[BytePosition.VERSION];
|
|
15
|
+
this._extractInitialParameters();
|
|
16
|
+
if (this.wwaData.version >= 29) {
|
|
17
|
+
this.currentPosition = BytePosition.MAPDATA_TOP;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.currentPosition = BytePosition.OLD_MAPDATA_TOP;
|
|
21
|
+
}
|
|
22
|
+
this.wwaData.map = this._getFieldDataFromBits(PartsType.MAP, this.wwaData.mapPartsMax).concat();
|
|
23
|
+
this.wwaData.mapObject = this._getFieldDataFromBits(PartsType.OBJECT, this.wwaData.objPartsMax).concat();
|
|
24
|
+
mapAttrMax = this.wwaData.version > 29 ? WWAConsts.MAP_ATR_MAX : WWAConsts.OLD_MAP_ATR_MAX;
|
|
25
|
+
objAttrMax = this.wwaData.version > 29 ? WWAConsts.OBJ_ATR_MAX : WWAConsts.OLD_OBJ_ATR_MAX;
|
|
26
|
+
this.wwaData.mapAttribute = this._getPartsDataFromBits(PartsType.MAP, this.wwaData.mapPartsMax, mapAttrMax).concat();
|
|
27
|
+
this.wwaData.objectAttribute = this._getPartsDataFromBits(PartsType.OBJECT, this.wwaData.objPartsMax, objAttrMax).concat();
|
|
28
|
+
if (this.wwaData.version <= 29) {
|
|
29
|
+
this._convertAttributeV2toV3(PartsType.MAP);
|
|
30
|
+
this._convertAttributeV2toV3(PartsType.OBJECT);
|
|
31
|
+
}
|
|
32
|
+
this._replaceAllRandomObjects();
|
|
33
|
+
return this.wwaData;
|
|
34
|
+
}
|
|
35
|
+
_convertAttributeV2toV3(partsType) {
|
|
36
|
+
var partsMax;
|
|
37
|
+
var attributeArray;
|
|
38
|
+
var localGateIndex;
|
|
39
|
+
if (partsType == PartsType.MAP) {
|
|
40
|
+
partsMax = this.wwaData.mapPartsMax;
|
|
41
|
+
attributeArray = this.wwaData.mapAttribute;
|
|
42
|
+
localGateIndex = WWAConsts.MAP_LOCALGATE;
|
|
43
|
+
}
|
|
44
|
+
else if (partsType == PartsType.OBJECT) {
|
|
45
|
+
partsMax = this.wwaData.objPartsMax;
|
|
46
|
+
attributeArray = this.wwaData.objectAttribute;
|
|
47
|
+
localGateIndex = WWAConsts.OBJECT_LOCALGATE;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new Error("謎のパーツ種別が指定されました");
|
|
51
|
+
}
|
|
52
|
+
for (var j = 0; j < partsMax; j++) {
|
|
53
|
+
for (var i = 9; i >= 0; i--) {
|
|
54
|
+
var dataChara = attributeArray[j][20 + i * 2] & 0xff;
|
|
55
|
+
var dataMode = attributeArray[j][20 + i * 2] >> 8;
|
|
56
|
+
var x = attributeArray[j][20 + i * 2 + 1] & 0xff;
|
|
57
|
+
var y = attributeArray[j][20 + i * 2 + 1] >> 8;
|
|
58
|
+
if (x === 250) {
|
|
59
|
+
x = 9000;
|
|
60
|
+
}
|
|
61
|
+
else if (x > 100) {
|
|
62
|
+
x += 10000 - 160;
|
|
63
|
+
}
|
|
64
|
+
if (y === 250) {
|
|
65
|
+
y = 9000;
|
|
66
|
+
}
|
|
67
|
+
else if (y > 100) {
|
|
68
|
+
y += 10000 - 160;
|
|
69
|
+
}
|
|
70
|
+
attributeArray[j][20 + i * 4] = dataChara;
|
|
71
|
+
attributeArray[j][20 + i * 4 + 3] = dataMode;
|
|
72
|
+
attributeArray[j][20 + i * 4 + 1] = x;
|
|
73
|
+
attributeArray[j][20 + i * 4 + 2] = y;
|
|
74
|
+
}
|
|
75
|
+
if (attributeArray[j][WWAConsts.ATR_TYPE] === localGateIndex) {
|
|
76
|
+
if (attributeArray[j][WWAConsts.ATR_JUMP_X] > 100) {
|
|
77
|
+
attributeArray[j][WWAConsts.ATR_JUMP_X] += 10000 - 160;
|
|
78
|
+
}
|
|
79
|
+
if (attributeArray[j][WWAConsts.ATR_JUMP_Y] > 100) {
|
|
80
|
+
attributeArray[j][WWAConsts.ATR_JUMP_Y] += 10000 - 160;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
_get1ByteNumber(index) {
|
|
86
|
+
return this.byteMapData[index];
|
|
87
|
+
}
|
|
88
|
+
_get2BytesNumber(index) {
|
|
89
|
+
return this.byteMapData[index] + this.byteMapData[index + 1] * 0x100;
|
|
90
|
+
}
|
|
91
|
+
_extractInitialParameters() {
|
|
92
|
+
if (this.wwaData.version > 29) {
|
|
93
|
+
this.wwaData.gameoverX = this._get2BytesNumber(BytePosition.GAMEOVER_X);
|
|
94
|
+
this.wwaData.gameoverY = this._get2BytesNumber(BytePosition.GAMEOVER_Y);
|
|
95
|
+
this.wwaData.playerX = this._get2BytesNumber(BytePosition.PLAYER_X);
|
|
96
|
+
this.wwaData.playerY = this._get2BytesNumber(BytePosition.PLAYER_Y);
|
|
97
|
+
this.wwaData.mapPartsMax = this._get2BytesNumber(BytePosition.MAP_COUNT);
|
|
98
|
+
this.wwaData.objPartsMax = this._get2BytesNumber(BytePosition.OBJ_COUNT);
|
|
99
|
+
this.wwaData.isOldMap = false;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
this.wwaData.gameoverX = this._get1ByteNumber(BytePosition.OLD_GAMEOVER_X);
|
|
103
|
+
this.wwaData.gameoverY = this._get1ByteNumber(BytePosition.OLD_GAMEOVER_Y);
|
|
104
|
+
this.wwaData.playerX = this._get1ByteNumber(BytePosition.OLD_PLAYER_X);
|
|
105
|
+
this.wwaData.playerY = this._get1ByteNumber(BytePosition.OLD_PLAYER_Y);
|
|
106
|
+
this.wwaData.mapPartsMax = this._get1ByteNumber(BytePosition.OLD_MAP_COUNT);
|
|
107
|
+
this.wwaData.objPartsMax = this._get1ByteNumber(BytePosition.OLD_OBJ_COUNT);
|
|
108
|
+
this.wwaData.isOldMap = true;
|
|
109
|
+
}
|
|
110
|
+
this.wwaData.statusEnergyMax = this._get2BytesNumber(BytePosition.STATUS_ENERGY_MAX);
|
|
111
|
+
this.wwaData.statusEnergy = this._get2BytesNumber(BytePosition.STATUS_ENERGY);
|
|
112
|
+
this.wwaData.statusStrength = this._get2BytesNumber(BytePosition.STATUS_STRENGTH);
|
|
113
|
+
this.wwaData.statusDefence = this._get2BytesNumber(BytePosition.STATUS_DEFENCE);
|
|
114
|
+
this.wwaData.statusGold = this._get2BytesNumber(BytePosition.STATUS_GOLD);
|
|
115
|
+
this._extractInitialItemData();
|
|
116
|
+
this.wwaData.mapWidth = this._get2BytesNumber(BytePosition.MAP_SIZE);
|
|
117
|
+
this.wwaData.messageNum = this._get2BytesNumber(BytePosition.MESSAGE_NUM);
|
|
118
|
+
if (this.wwaData.version < 28)
|
|
119
|
+
this.wwaData.mapWidth = 71;
|
|
120
|
+
else if (this.wwaData.version <= 29)
|
|
121
|
+
this.wwaData.mapWidth = 101;
|
|
122
|
+
}
|
|
123
|
+
_extractInitialItemData() {
|
|
124
|
+
const topIdx = this.wwaData.version > 29 ? BytePosition.ITEMBOX_TOP : BytePosition.OLD_ITEMBOX_TOP;
|
|
125
|
+
this.wwaData.itemBox = new Array(WWAConsts.ITEMBOX_SIZE);
|
|
126
|
+
for (let i = 0; i < WWAConsts.ITEMBOX_SIZE; i++) {
|
|
127
|
+
this.wwaData.itemBox[i] = this._get1ByteNumber(topIdx + i);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
_getFieldDataFromBits(partsType, partsMax) {
|
|
131
|
+
var x, y;
|
|
132
|
+
var fieldArray;
|
|
133
|
+
fieldArray = new2DArray(this.wwaData.mapWidth, this.wwaData.mapWidth);
|
|
134
|
+
for (x = 0; x < this.wwaData.mapWidth; x++) {
|
|
135
|
+
for (y = 0; y < this.wwaData.mapWidth; y++) {
|
|
136
|
+
if (this.wwaData.version > 29) {
|
|
137
|
+
fieldArray[x][y] = this._get2BytesNumber(this.currentPosition);
|
|
138
|
+
this.currentPosition += 2;
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
fieldArray[x][y] = this._get1ByteNumber(this.currentPosition);
|
|
142
|
+
this.currentPosition += 1;
|
|
143
|
+
}
|
|
144
|
+
if ((x * this.wwaData.mapWidth + y) % 200 === 0) {
|
|
145
|
+
this.emitProgress(x * this.wwaData.mapWidth + y, this.wwaData.mapWidth * this.wwaData.mapWidth, partsType === PartsType.MAP ? LoadStage.MAP_LOAD : LoadStage.OBJ_LOAD);
|
|
146
|
+
}
|
|
147
|
+
if (fieldArray[x][y] >= partsMax) {
|
|
148
|
+
fieldArray[x][y] = 0;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
this.emitProgress(this.wwaData.mapWidth * this.wwaData.mapWidth, this.wwaData.mapWidth * this.wwaData.mapWidth, partsType === PartsType.MAP ? LoadStage.MAP_LOAD : LoadStage.OBJ_LOAD);
|
|
153
|
+
return fieldArray;
|
|
154
|
+
}
|
|
155
|
+
_getPartsDataFromBits(partsType, partsMax, attrMax) {
|
|
156
|
+
var i, j;
|
|
157
|
+
var partsData;
|
|
158
|
+
partsData = new2DArray(partsMax, attrMax);
|
|
159
|
+
for (i = 0; i < partsMax; i++) {
|
|
160
|
+
for (j = 0; j < attrMax; j++) {
|
|
161
|
+
if ((i * this.wwaData.mapWidth + j) % 200 === 0) {
|
|
162
|
+
this.emitProgress(i * attrMax + j, partsMax * attrMax, partsType === PartsType.MAP ? LoadStage.MAP_ATTR : LoadStage.OBJ_ATTR);
|
|
163
|
+
}
|
|
164
|
+
if (j === WWAConsts.ATR_CROP1 || j === WWAConsts.ATR_CROP2) {
|
|
165
|
+
partsData[i][j] = 0;
|
|
166
|
+
this.currentPosition += 2;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
partsData[i][j] = this._get2BytesNumber(this.currentPosition);
|
|
170
|
+
this.currentPosition += 2;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
this.emitProgress(partsMax * attrMax, partsMax * attrMax, partsType === PartsType.MAP ? LoadStage.MAP_ATTR : LoadStage.OBJ_ATTR);
|
|
174
|
+
return partsData;
|
|
175
|
+
}
|
|
176
|
+
_replaceAllRandomObjects() {
|
|
177
|
+
this.emitProgress(this.wwaData.mapWidth * this.wwaData.mapWidth, this.wwaData.mapWidth * this.wwaData.mapWidth, LoadStage.RAND_PARTS);
|
|
178
|
+
}
|
|
179
|
+
emitProgress(current, total, stage) {
|
|
180
|
+
this.eventEmitter.dispatch("progress", { current, total, stage });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WWALoaderEventEmitter } from "../infra";
|
|
2
|
+
export declare class WWALoader {
|
|
3
|
+
private fileName;
|
|
4
|
+
private eventEmitter;
|
|
5
|
+
constructor(fileName: string, eventEmitter: WWALoaderEventEmitter);
|
|
6
|
+
requestAndLoadMapData(): Promise<void>;
|
|
7
|
+
private loadMapData;
|
|
8
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { WWADataExtractor } from "./extractor";
|
|
2
|
+
import { decompressMapData } from "./decompressor";
|
|
3
|
+
import { TextLoader } from "./text-loader";
|
|
4
|
+
import { BrowserMapDataClient, NodeLocalMapDataClient } from "./map-data-client";
|
|
5
|
+
const createMapDataClient = (fileName) => {
|
|
6
|
+
if (typeof window !== "undefined") {
|
|
7
|
+
return new BrowserMapDataClient(fileName);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return new NodeLocalMapDataClient(fileName);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export class WWALoader {
|
|
14
|
+
constructor(fileName, eventEmitter) {
|
|
15
|
+
this.fileName = fileName;
|
|
16
|
+
this.eventEmitter = eventEmitter;
|
|
17
|
+
}
|
|
18
|
+
async requestAndLoadMapData() {
|
|
19
|
+
const client = createMapDataClient(this.fileName);
|
|
20
|
+
try {
|
|
21
|
+
const responseBuffer = await client.request();
|
|
22
|
+
if (!responseBuffer) {
|
|
23
|
+
this.eventEmitter.dispatch("error", { name: "マップデータ取得に失敗しました", message: "mapdata is empty" });
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const wwaData = this.loadMapData(responseBuffer);
|
|
27
|
+
this.eventEmitter.dispatch("mapData", wwaData);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const name = error.name || "";
|
|
31
|
+
const message = error.message || "";
|
|
32
|
+
this.eventEmitter.dispatch("error", { name, message });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
loadMapData(data) {
|
|
36
|
+
try {
|
|
37
|
+
const compressedByteMapData = new Uint8Array(data);
|
|
38
|
+
const { byteMapData, byteMapLength, compressedEndPosition } = decompressMapData(compressedByteMapData);
|
|
39
|
+
const wwaData = new WWADataExtractor(byteMapData, byteMapLength, this.eventEmitter).extractAllData();
|
|
40
|
+
return new TextLoader(wwaData, compressedByteMapData, compressedEndPosition, this.eventEmitter).load();
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseMapDataClient } from "./BaseMapDataClient";
|
|
2
|
+
export declare class BrowserMapDataClient extends BaseMapDataClient {
|
|
3
|
+
private uri;
|
|
4
|
+
constructor(uri: string);
|
|
5
|
+
private static fetch;
|
|
6
|
+
private static handleError;
|
|
7
|
+
request(): Promise<ArrayBufferLike>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { BaseMapDataClient } from "./BaseMapDataClient";
|
|
2
|
+
export class BrowserMapDataClient extends BaseMapDataClient {
|
|
3
|
+
constructor(uri) {
|
|
4
|
+
super();
|
|
5
|
+
this.uri = uri;
|
|
6
|
+
}
|
|
7
|
+
static async fetch(uri) {
|
|
8
|
+
try {
|
|
9
|
+
return await fetch(uri);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
throw new Error(`マップデータ 「${uri}」の読み込みに失敗しました。
|
|
13
|
+
通信環境の良いところで再度お試しください。
|
|
14
|
+
ローカルテストの場合は、ブラウザが対応していない可能性があります。`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
static handleError(uri, response) {
|
|
18
|
+
const statusCodeMessage = `HTTPステータスコードは ${response.status} です。`;
|
|
19
|
+
switch (response.status) {
|
|
20
|
+
case 200:
|
|
21
|
+
case 304:
|
|
22
|
+
return;
|
|
23
|
+
case 403:
|
|
24
|
+
throw new Error(`マップデータ「${uri}」を読み取る権限がないようです。
|
|
25
|
+
管理者の方へ: マップデータのパーミッションを確認してください。
|
|
26
|
+
${statusCodeMessage}`);
|
|
27
|
+
case 404:
|
|
28
|
+
throw new Error(`マップデータ「${uri}」が見つかりませんでした。
|
|
29
|
+
${statusCodeMessage}`);
|
|
30
|
+
default:
|
|
31
|
+
throw new Error(`マップデータ「${uri}」の読み込みに失敗しました。
|
|
32
|
+
${statusCodeMessage}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async request() {
|
|
36
|
+
const response = await BrowserMapDataClient.fetch(this.uri);
|
|
37
|
+
BrowserMapDataClient.handleError(this.uri, response);
|
|
38
|
+
const buffer = await response.arrayBuffer();
|
|
39
|
+
return buffer;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { BaseMapDataClient } from "./BaseMapDataClient";
|
|
3
|
+
export class NodeLocalMapDataClient extends BaseMapDataClient {
|
|
4
|
+
constructor(fileName) {
|
|
5
|
+
super();
|
|
6
|
+
this.fileName = fileName;
|
|
7
|
+
}
|
|
8
|
+
async request() {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
fs.readFile(this.fileName, (error, data) => {
|
|
11
|
+
if (error) {
|
|
12
|
+
reject(error);
|
|
13
|
+
}
|
|
14
|
+
resolve(data.buffer);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
;
|
|
19
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WWALoaderEventEmitter } from "../../infra";
|
|
2
|
+
import { WWAData } from "@wwawing/common-interface";
|
|
3
|
+
export declare class TextLoader {
|
|
4
|
+
private wwaData;
|
|
5
|
+
private compressedMapData;
|
|
6
|
+
private startPosition;
|
|
7
|
+
private eventEmitter;
|
|
8
|
+
readonly OLDVER_MESSAGE_MAX: number;
|
|
9
|
+
private currentPos;
|
|
10
|
+
constructor(wwaData: WWAData, compressedMapData: Uint8Array, startPosition: number, eventEmitter: WWALoaderEventEmitter);
|
|
11
|
+
load(): WWAData;
|
|
12
|
+
private getMessageFromData;
|
|
13
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { LoadStage, WWAConsts } from "../../infra";
|
|
2
|
+
export class TextLoader {
|
|
3
|
+
constructor(wwaData, compressedMapData, startPosition, eventEmitter) {
|
|
4
|
+
this.wwaData = wwaData;
|
|
5
|
+
this.compressedMapData = compressedMapData;
|
|
6
|
+
this.startPosition = startPosition;
|
|
7
|
+
this.eventEmitter = eventEmitter;
|
|
8
|
+
this.OLDVER_MESSAGE_MAX = 400;
|
|
9
|
+
}
|
|
10
|
+
load() {
|
|
11
|
+
const wwaData = this.wwaData;
|
|
12
|
+
this.currentPos = this.startPosition;
|
|
13
|
+
if (wwaData.version >= 30) {
|
|
14
|
+
wwaData.worldPassword = this.getMessageFromData();
|
|
15
|
+
}
|
|
16
|
+
if (wwaData.version <= 29) {
|
|
17
|
+
wwaData.messageNum = this.OLDVER_MESSAGE_MAX;
|
|
18
|
+
}
|
|
19
|
+
wwaData.message = new Array(wwaData.messageNum);
|
|
20
|
+
for (let i = 0; i < wwaData.message.length; i++) {
|
|
21
|
+
wwaData.message[i] = this.getMessageFromData();
|
|
22
|
+
if (i % 200 === 0) {
|
|
23
|
+
this.eventEmitter.dispatch("progress", {
|
|
24
|
+
current: i,
|
|
25
|
+
total: wwaData.message.length,
|
|
26
|
+
stage: LoadStage.MESSAGE
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
while (wwaData.messageNum < 10) {
|
|
31
|
+
wwaData.message.push("");
|
|
32
|
+
wwaData.messageNum++;
|
|
33
|
+
}
|
|
34
|
+
this.eventEmitter.dispatch("progress", {
|
|
35
|
+
current: wwaData.message.length,
|
|
36
|
+
total: wwaData.message.length,
|
|
37
|
+
stage: LoadStage.MESSAGE
|
|
38
|
+
});
|
|
39
|
+
wwaData.worldName = this.getMessageFromData();
|
|
40
|
+
if (wwaData.version <= 29) {
|
|
41
|
+
wwaData.worldPassword = this.getMessageFromData();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.getMessageFromData();
|
|
45
|
+
}
|
|
46
|
+
if (wwaData.worldPassword === "") {
|
|
47
|
+
wwaData.worldPassNumber = 0;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (wwaData.version >= 29) {
|
|
51
|
+
wwaData.worldPassNumber =
|
|
52
|
+
(parseInt(wwaData.worldPassword) / 10 - 1197) / 17 - 2357;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
wwaData.worldPassNumber = parseInt(wwaData.worldPassword);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
wwaData.charCGName = this.getMessageFromData();
|
|
59
|
+
wwaData.mapCGName = this.getMessageFromData();
|
|
60
|
+
wwaData.systemMessage = new Array(WWAConsts.SYSTEM_MESSAGE_NUM);
|
|
61
|
+
for (let i = 0; i < WWAConsts.SYSTEM_MESSAGE_NUM; i++) {
|
|
62
|
+
if (wwaData.version >= 30) {
|
|
63
|
+
wwaData.systemMessage[i] = this.getMessageFromData();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
wwaData.systemMessage[i] = "";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
wwaData.yesnoImgPosX = WWAConsts.IMGPOS_DEFAULT_YESNO_X;
|
|
70
|
+
wwaData.yesnoImgPosY = WWAConsts.IMGPOS_DEFAULT_YESNO_Y;
|
|
71
|
+
wwaData.playerImgPosX = WWAConsts.IMGPOS_DEFAULT_PLAYER_X;
|
|
72
|
+
wwaData.playerImgPosY = WWAConsts.IMGPOS_DEFAULT_PLAYER_Y;
|
|
73
|
+
wwaData.clickableItemSignImgPosX = WWAConsts.IMGPOS_DEFAULT_CLICKABLE_ITEM_SIGN_X;
|
|
74
|
+
wwaData.clickableItemSignImgPosY = WWAConsts.IMGPOS_DEFAULT_CLICKABLE_ITEM_SIGN_Y;
|
|
75
|
+
wwaData.disableSaveFlag = WWAConsts.DEFAULT_DISABLE_SAVE;
|
|
76
|
+
wwaData.isOldMap = WWAConsts.DEFAULT_OLDMAP;
|
|
77
|
+
wwaData.isOldMove = wwaData.version < 31;
|
|
78
|
+
wwaData.objectNoCollapseDefaultFlag = WWAConsts.DEFAULT_OBJECT_NO_COLLAPSE;
|
|
79
|
+
wwaData.delPlayerFlag = false;
|
|
80
|
+
wwaData.bgm = 0;
|
|
81
|
+
wwaData.effectCoords = [];
|
|
82
|
+
wwaData.effectWaits = 0;
|
|
83
|
+
wwaData.imgStatusEnergyX = WWAConsts.IMGPOS_DEFAULT_STATUS_X + WWAConsts.IMGRELPOS_ENERGY_ICON_X;
|
|
84
|
+
wwaData.imgStatusEnergyY = WWAConsts.IMGPOS_DEFAULT_STATUS_Y;
|
|
85
|
+
wwaData.imgStatusStrengthX = WWAConsts.IMGPOS_DEFAULT_STATUS_X + WWAConsts.IMGRELPOS_STRENGTH_ICON_X;
|
|
86
|
+
wwaData.imgStatusStrengthY = WWAConsts.IMGPOS_DEFAULT_STATUS_Y;
|
|
87
|
+
wwaData.imgStatusDefenceX = WWAConsts.IMGPOS_DEFAULT_STATUS_X + WWAConsts.IMGRELPOS_DEFENCE_ICON_X;
|
|
88
|
+
wwaData.imgStatusDefenceY = WWAConsts.IMGPOS_DEFAULT_STATUS_Y;
|
|
89
|
+
wwaData.imgStatusGoldX = WWAConsts.IMGPOS_DEFAULT_STATUS_X + WWAConsts.IMGRELPOS_GOLD_ICON_X;
|
|
90
|
+
wwaData.imgStatusGoldY = WWAConsts.IMGPOS_DEFAULT_STATUS_Y;
|
|
91
|
+
wwaData.imgWideCellX = WWAConsts.IMGPOS_DEFAULT_WIDE_CELL_X;
|
|
92
|
+
wwaData.imgWideCellY = WWAConsts.IMGPOS_DEFAULT_WIDE_CELL_Y;
|
|
93
|
+
wwaData.imgItemboxX = WWAConsts.IMGPOS_DEFAULT_ITEMBOX_X;
|
|
94
|
+
wwaData.imgItemboxY = WWAConsts.IMGPOS_DEFAULT_ITEMBOX_Y;
|
|
95
|
+
wwaData.imgFrameX = WWAConsts.IMGPOS_DEFAULT_FRAME_X;
|
|
96
|
+
wwaData.imgFrameY = WWAConsts.IMGPOS_DEFAULT_FRAME_Y;
|
|
97
|
+
wwaData.imgBattleEffectX = WWAConsts.IMGPOS_DEFAULT_BATTLE_EFFECT_X;
|
|
98
|
+
wwaData.imgBattleEffectY = WWAConsts.IMGPOS_DEFAULT_BATTLE_EFFECT_Y;
|
|
99
|
+
wwaData.imgClickX = 0;
|
|
100
|
+
wwaData.imgClickY = 0;
|
|
101
|
+
wwaData.frameColorR = WWAConsts.DEFAULT_FRAME_COLOR_R;
|
|
102
|
+
wwaData.frameColorG = WWAConsts.DEFAULT_FRAME_COLOR_G;
|
|
103
|
+
wwaData.frameColorB = WWAConsts.DEFAULT_FRAME_COLOR_B;
|
|
104
|
+
wwaData.frameOutColorR = WWAConsts.DEFAULT_FRAMEOUT_COLOR_R;
|
|
105
|
+
wwaData.frameOutColorG = WWAConsts.DEFAULT_FRAMEOUT_COLOR_G;
|
|
106
|
+
wwaData.frameOutColorB = WWAConsts.DEFAULT_FRAMEOUT_COLOR_B;
|
|
107
|
+
wwaData.fontColorR = WWAConsts.DEFAULT_STR_COLOR_R;
|
|
108
|
+
wwaData.fontColorG = WWAConsts.DEFAULT_STR_COLOR_G;
|
|
109
|
+
wwaData.fontColorB = WWAConsts.DEFAULT_STR_COLOR_B;
|
|
110
|
+
wwaData.statusColorR = WWAConsts.DEFAULT_STATUS_COLOR_R;
|
|
111
|
+
wwaData.statusColorG = WWAConsts.DEFAULT_STATUS_COLOR_G;
|
|
112
|
+
wwaData.statusColorB = WWAConsts.DEFAULT_STATUS_COLOR_B;
|
|
113
|
+
wwaData.moves = WWAConsts.DEFAULT_MOVES;
|
|
114
|
+
wwaData.gameSpeedIndex = WWAConsts.DEFAULT_SPEED_INDEX;
|
|
115
|
+
wwaData.permitChangeGameSpeed = true;
|
|
116
|
+
wwaData.userVar = new Array(WWAConsts.USER_VAR_NUM);
|
|
117
|
+
for (let i = 0; i < WWAConsts.USER_VAR_NUM; i++) {
|
|
118
|
+
wwaData.userVar[i] = 0;
|
|
119
|
+
}
|
|
120
|
+
wwaData.playTime = 0;
|
|
121
|
+
wwaData.isVisibleStatusEnergy = true;
|
|
122
|
+
wwaData.isVisibleStatusStrength = true;
|
|
123
|
+
wwaData.isVisibleStatusDefence = true;
|
|
124
|
+
wwaData.isVisibleStatusGold = true;
|
|
125
|
+
wwaData.gameOverPolicy = "default";
|
|
126
|
+
wwaData.bgmDelayDurationMs = 0;
|
|
127
|
+
return wwaData;
|
|
128
|
+
}
|
|
129
|
+
getMessageFromData() {
|
|
130
|
+
let str = "";
|
|
131
|
+
let i = 0;
|
|
132
|
+
for (i = 0; i < 1500; i++) {
|
|
133
|
+
if (this.compressedMapData[this.currentPos + i * 2] == 0 &&
|
|
134
|
+
this.compressedMapData[this.currentPos + i * 2 + 1] == 0) {
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
str += String.fromCharCode((this.compressedMapData[this.currentPos + i * 2 + 1] << 8) +
|
|
138
|
+
this.compressedMapData[this.currentPos + i * 2]);
|
|
139
|
+
}
|
|
140
|
+
this.currentPos += i * 2 + 2;
|
|
141
|
+
return str;
|
|
142
|
+
}
|
|
143
|
+
}
|
package/module/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { WWAData } from "@wwawing/common-interface";
|
|
2
|
+
import { IEventEmitter } from "@wwawing/event-emitter";
|
|
3
|
+
export declare class WWAConsts {
|
|
4
|
+
static ITEMBOX_SIZE: number;
|
|
5
|
+
static MAP_ATR_MAX: number;
|
|
6
|
+
static OBJ_ATR_MAX: number;
|
|
7
|
+
static OLD_MAP_ATR_MAX: number;
|
|
8
|
+
static OLD_OBJ_ATR_MAX: number;
|
|
9
|
+
static ATR_CROP1: number;
|
|
10
|
+
static ATR_CROP2: number;
|
|
11
|
+
static ATR_TYPE: number;
|
|
12
|
+
static ATR_JUMP_X: number;
|
|
13
|
+
static ATR_JUMP_Y: number;
|
|
14
|
+
static MAP_LOCALGATE: number;
|
|
15
|
+
static OBJECT_LOCALGATE: number;
|
|
16
|
+
static SYSTEM_MESSAGE_NUM: number;
|
|
17
|
+
static IMGPOS_DEFAULT_YESNO_X: number;
|
|
18
|
+
static IMGPOS_DEFAULT_YESNO_Y: number;
|
|
19
|
+
static IMGPOS_DEFAULT_PLAYER_X: number;
|
|
20
|
+
static IMGPOS_DEFAULT_PLAYER_Y: number;
|
|
21
|
+
static IMGPOS_DEFAULT_CLICKABLE_ITEM_SIGN_X: number;
|
|
22
|
+
static IMGPOS_DEFAULT_CLICKABLE_ITEM_SIGN_Y: number;
|
|
23
|
+
static IMGPOS_DEFAULT_STATUS_X: number;
|
|
24
|
+
static IMGPOS_DEFAULT_STATUS_Y: number;
|
|
25
|
+
static IMGRELPOS_ENERGY_ICON_X: number;
|
|
26
|
+
static IMGRELPOS_STRENGTH_ICON_X: number;
|
|
27
|
+
static IMGRELPOS_DEFENCE_ICON_X: number;
|
|
28
|
+
static IMGRELPOS_GOLD_ICON_X: number;
|
|
29
|
+
static IMGPOS_DEFAULT_WIDE_CELL_X: number;
|
|
30
|
+
static IMGPOS_DEFAULT_WIDE_CELL_Y: number;
|
|
31
|
+
static IMGPOS_DEFAULT_ITEMBOX_X: number;
|
|
32
|
+
static IMGPOS_DEFAULT_ITEMBOX_Y: number;
|
|
33
|
+
static IMGPOS_DEFAULT_FRAME_X: number;
|
|
34
|
+
static IMGPOS_DEFAULT_FRAME_Y: number;
|
|
35
|
+
static IMGPOS_DEFAULT_BATTLE_EFFECT_X: number;
|
|
36
|
+
static IMGPOS_DEFAULT_BATTLE_EFFECT_Y: number;
|
|
37
|
+
static DEFAULT_DISABLE_SAVE: boolean;
|
|
38
|
+
static DEFAULT_OLDMAP: boolean;
|
|
39
|
+
static DEFAULT_OBJECT_NO_COLLAPSE: boolean;
|
|
40
|
+
static DEFAULT_FRAME_COLOR_R: number;
|
|
41
|
+
static DEFAULT_FRAME_COLOR_G: number;
|
|
42
|
+
static DEFAULT_FRAME_COLOR_B: number;
|
|
43
|
+
static DEFAULT_FRAMEOUT_COLOR_R: number;
|
|
44
|
+
static DEFAULT_FRAMEOUT_COLOR_G: number;
|
|
45
|
+
static DEFAULT_FRAMEOUT_COLOR_B: number;
|
|
46
|
+
static DEFAULT_STR_COLOR_R: number;
|
|
47
|
+
static DEFAULT_STR_COLOR_G: number;
|
|
48
|
+
static DEFAULT_STR_COLOR_B: number;
|
|
49
|
+
static DEFAULT_STATUS_COLOR_R: number;
|
|
50
|
+
static DEFAULT_STATUS_COLOR_G: number;
|
|
51
|
+
static DEFAULT_STATUS_COLOR_B: number;
|
|
52
|
+
static DEFAULT_MOVES: number;
|
|
53
|
+
static DEFAULT_SPEED_INDEX: number;
|
|
54
|
+
static USER_VAR_NUM: number;
|
|
55
|
+
}
|
|
56
|
+
export declare class LoaderError implements Error {
|
|
57
|
+
name: string;
|
|
58
|
+
message: string;
|
|
59
|
+
}
|
|
60
|
+
export declare class LoaderProgress {
|
|
61
|
+
current: number;
|
|
62
|
+
total: number;
|
|
63
|
+
stage: LoadStage;
|
|
64
|
+
}
|
|
65
|
+
export declare enum PartsType {
|
|
66
|
+
MAP = 1,
|
|
67
|
+
OBJECT = 0
|
|
68
|
+
}
|
|
69
|
+
export declare enum LoadStage {
|
|
70
|
+
INIT = 0,
|
|
71
|
+
MAP_LOAD = 1,
|
|
72
|
+
OBJ_LOAD = 2,
|
|
73
|
+
MAP_ATTR = 3,
|
|
74
|
+
OBJ_ATTR = 4,
|
|
75
|
+
RAND_PARTS = 5,
|
|
76
|
+
MESSAGE = 6
|
|
77
|
+
}
|
|
78
|
+
export declare function createDefaultWWAData(): WWAData;
|
|
79
|
+
export interface Progress {
|
|
80
|
+
current: number;
|
|
81
|
+
total: number;
|
|
82
|
+
stage: LoadStage;
|
|
83
|
+
}
|
|
84
|
+
export interface LoaderError {
|
|
85
|
+
name: string;
|
|
86
|
+
message: string;
|
|
87
|
+
}
|
|
88
|
+
export interface WWALoaderEventEmitter extends IEventEmitter {
|
|
89
|
+
dispatch(eventName: "mapData", data: WWAData): void;
|
|
90
|
+
dispatch(eventName: "progress", data: Progress): void;
|
|
91
|
+
dispatch(eventName: "error", data: LoaderError): void;
|
|
92
|
+
addListener(eventName: "mapData", callback: (data: WWAData) => any): (data: WWAData) => any;
|
|
93
|
+
addListener(eventName: "progress", callback: (data: Progress) => any): (data: Progress) => any;
|
|
94
|
+
addListener(eventName: "error", callback: (data: LoaderError) => any): (data: LoaderError) => any;
|
|
95
|
+
removeListener(eventName: "mapData", callback: (...arg: any[]) => any): void;
|
|
96
|
+
removeListener(eventName: "progress", callback: (...arg: any[]) => any): void;
|
|
97
|
+
removeListener(eventName: "error", callback: (...arg: any[]) => any): void;
|
|
98
|
+
}
|