@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
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 1996-2025 NAO
|
|
4
|
+
Copyright (c) 2015-2025 WWA Wing Team
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
|
14
|
+
all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# WWALoader
|
|
2
|
+
WWA( http://wwajp.com )のマップデータを解析した結果をJavaScriptのオブジェクトとして返すプログラムです。
|
|
3
|
+
|
|
4
|
+
ブラウザ, Node.js で動作します。
|
|
5
|
+
|
|
6
|
+
## 重要なお知らせ
|
|
7
|
+
WWALoader は、他のnpm パッケージから依存されることを前提に開発されています。
|
|
8
|
+
|
|
9
|
+
WWALoader 単体では、ブラウザ間の実装差異を埋めるような構成にはなっていません。(例: IE11には対応していない `Promise` を利用するなど)
|
|
10
|
+
|
|
11
|
+
最終的なアプリケーション側で、必ずpolyfillの付加など適切な措置を行ってください。
|
|
12
|
+
|
|
13
|
+
## ライセンス
|
|
14
|
+
- MIT License (Expat)。詳しくは「LICENSE」ファイルを参照。
|
|
15
|
+
|
|
16
|
+
### 同梱物のライセンスについて
|
|
17
|
+
テスト用にスタンダードマップのデータ「wwamap.dat」を同梱していますが、このファイルの著作権の取り扱いについてはキャラバンサークル
|
|
18
|
+
( http://wwajp.com )で定める通りとします。
|
|
19
|
+
|
|
20
|
+
## とりあえず触りたい人へ
|
|
21
|
+
- 新しめの node.js (原則、最新LTS) をお手元にご用意ください.
|
|
22
|
+
- `npm run build` で 成果物が `./lib` 下に生成されます. 型定義ファイルも生成されます.
|
|
23
|
+
- `npm start` もしくは `npm run start:browser` でテスト用のマップデータをブラウザから読み込む動作確認ができます。 8080番ポートでテスト用のサーバが立ち上がりますので、 http://localhost:8080/ などで確認してください。
|
|
24
|
+
- `npm run start:node` で Node.js で動作させる場合の動作確認ができます。
|
|
25
|
+
|
|
26
|
+
## ディレクトリ構成
|
|
27
|
+
- `./src` ディレクトリにソースコードがあります。
|
|
28
|
+
- `./src/___debug-resources___` 下は、動作確認用のソースコードがあります。これらのコードは成果物には含まれません。
|
|
29
|
+
- 成果物は、 `./lib` (CommonJS), `./module` (ES Module) 下のディレクトリのファイル群です。
|
|
30
|
+
|
|
31
|
+
## その他
|
|
32
|
+
不具合を発見された場合は、issuesかPull Requestまで。Githubのアカウントを持っていない場合はバグ報告板( http://jbbs.shitaraba.net/netgame/14732/ )まで。
|
|
33
|
+
|
|
34
|
+
WWA Wing - https://wwawing.com
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decompressMapData = decompressMapData;
|
|
4
|
+
const MEM_BLOCK = 65000;
|
|
5
|
+
const EXT_LAST_PADDING = 3;
|
|
6
|
+
function decompressMapData(srcData) {
|
|
7
|
+
let destData = new Uint8Array(srcData.length);
|
|
8
|
+
let srcCounter, destCounter;
|
|
9
|
+
for (srcCounter = 0, destCounter = 0; srcCounter < srcData.length; srcCounter++) {
|
|
10
|
+
if (srcData[srcCounter] === 0 &&
|
|
11
|
+
srcData[srcCounter + 1] === 0 &&
|
|
12
|
+
srcData[srcCounter + 2] === 0) {
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
destData[destCounter++] = srcData[srcCounter];
|
|
16
|
+
if (srcData[srcCounter] === srcData[srcCounter + 1]) {
|
|
17
|
+
const maxim = srcData[srcCounter + 2];
|
|
18
|
+
for (let i = 0; i < maxim; i++) {
|
|
19
|
+
destData[destCounter++] = srcData[srcCounter];
|
|
20
|
+
}
|
|
21
|
+
srcCounter += 2;
|
|
22
|
+
}
|
|
23
|
+
if (destCounter + 255 >= destData.length) {
|
|
24
|
+
var newDestData = new Uint8Array(destData.length + MEM_BLOCK);
|
|
25
|
+
newDestData.set(destData);
|
|
26
|
+
destData = newDestData;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
console.log("EXTRACT DATA = " + destCounter + " " + srcCounter);
|
|
30
|
+
return { byteMapData: destData, byteMapLength: destCounter, compressedEndPosition: srcCounter + EXT_LAST_PADDING };
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkMapDataBroken(mapData: Uint8Array, dataLength: number): void;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkMapDataBroken = checkMapDataBroken;
|
|
4
|
+
const util_1 = require("../../infra/util");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
function calculateCorrectCheckSum(mapData) {
|
|
7
|
+
return mapData[constants_1.BytePosition.CHECK] + mapData[constants_1.BytePosition.CHECK + 1] * 0x100;
|
|
8
|
+
}
|
|
9
|
+
function calculateByteSum(mapData, dataLength) {
|
|
10
|
+
let sum = 0;
|
|
11
|
+
if (mapData[constants_1.BytePosition.VERSION] >= 29) {
|
|
12
|
+
for (let i = 2; i < dataLength; i++) {
|
|
13
|
+
sum += (0, util_1.signedByte)(mapData[i]) * (i % 8 + 1);
|
|
14
|
+
}
|
|
15
|
+
sum = (sum % 0x10000) & 0xffff;
|
|
16
|
+
}
|
|
17
|
+
return sum;
|
|
18
|
+
}
|
|
19
|
+
function checkMapDataBroken(mapData, dataLength) {
|
|
20
|
+
const correctCheckSum = calculateCorrectCheckSum(mapData);
|
|
21
|
+
const sum = calculateByteSum(mapData, dataLength);
|
|
22
|
+
if (correctCheckSum !== sum) {
|
|
23
|
+
throw new Error("マップデータが壊れているようです。\n チェックサムの値は" +
|
|
24
|
+
correctCheckSum +
|
|
25
|
+
"ですが、" +
|
|
26
|
+
"実際の和は" +
|
|
27
|
+
sum +
|
|
28
|
+
"でした。");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare enum BytePosition {
|
|
2
|
+
CHECK = 0,
|
|
3
|
+
VERSION = 2,
|
|
4
|
+
OLD_MAP_COUNT = 3,
|
|
5
|
+
OLD_OBJ_COUNT = 4,
|
|
6
|
+
OLD_PLAYER_X = 5,
|
|
7
|
+
OLD_PLAYER_Y = 6,
|
|
8
|
+
STATUS_ENERGY = 10,
|
|
9
|
+
STATUS_STRENGTH = 12,
|
|
10
|
+
STATUS_DEFENCE = 14,
|
|
11
|
+
STATUS_GOLD = 16,
|
|
12
|
+
OLD_GAMEOVER_X = 18,
|
|
13
|
+
OLD_GAMEOVER_Y = 19,
|
|
14
|
+
OLD_ITEMBOX_TOP = 20,
|
|
15
|
+
STATUS_ENERGY_MAX = 32,
|
|
16
|
+
MAP_COUNT = 34,
|
|
17
|
+
OBJ_COUNT = 36,
|
|
18
|
+
PLAYER_X = 38,
|
|
19
|
+
PLAYER_Y = 40,
|
|
20
|
+
GAMEOVER_X = 42,
|
|
21
|
+
GAMEOVER_Y = 44,
|
|
22
|
+
MAP_SIZE = 46,
|
|
23
|
+
MESSAGE_NUM = 48,
|
|
24
|
+
ITEMBOX_TOP = 60,
|
|
25
|
+
MAPDATA_TOP = 90,
|
|
26
|
+
OLD_MAPDATA_TOP = 100
|
|
27
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BytePosition = void 0;
|
|
4
|
+
var BytePosition;
|
|
5
|
+
(function (BytePosition) {
|
|
6
|
+
BytePosition[BytePosition["CHECK"] = 0] = "CHECK";
|
|
7
|
+
BytePosition[BytePosition["VERSION"] = 2] = "VERSION";
|
|
8
|
+
BytePosition[BytePosition["OLD_MAP_COUNT"] = 3] = "OLD_MAP_COUNT";
|
|
9
|
+
BytePosition[BytePosition["OLD_OBJ_COUNT"] = 4] = "OLD_OBJ_COUNT";
|
|
10
|
+
BytePosition[BytePosition["OLD_PLAYER_X"] = 5] = "OLD_PLAYER_X";
|
|
11
|
+
BytePosition[BytePosition["OLD_PLAYER_Y"] = 6] = "OLD_PLAYER_Y";
|
|
12
|
+
BytePosition[BytePosition["STATUS_ENERGY"] = 10] = "STATUS_ENERGY";
|
|
13
|
+
BytePosition[BytePosition["STATUS_STRENGTH"] = 12] = "STATUS_STRENGTH";
|
|
14
|
+
BytePosition[BytePosition["STATUS_DEFENCE"] = 14] = "STATUS_DEFENCE";
|
|
15
|
+
BytePosition[BytePosition["STATUS_GOLD"] = 16] = "STATUS_GOLD";
|
|
16
|
+
BytePosition[BytePosition["OLD_GAMEOVER_X"] = 18] = "OLD_GAMEOVER_X";
|
|
17
|
+
BytePosition[BytePosition["OLD_GAMEOVER_Y"] = 19] = "OLD_GAMEOVER_Y";
|
|
18
|
+
BytePosition[BytePosition["OLD_ITEMBOX_TOP"] = 20] = "OLD_ITEMBOX_TOP";
|
|
19
|
+
BytePosition[BytePosition["STATUS_ENERGY_MAX"] = 32] = "STATUS_ENERGY_MAX";
|
|
20
|
+
BytePosition[BytePosition["MAP_COUNT"] = 34] = "MAP_COUNT";
|
|
21
|
+
BytePosition[BytePosition["OBJ_COUNT"] = 36] = "OBJ_COUNT";
|
|
22
|
+
BytePosition[BytePosition["PLAYER_X"] = 38] = "PLAYER_X";
|
|
23
|
+
BytePosition[BytePosition["PLAYER_Y"] = 40] = "PLAYER_Y";
|
|
24
|
+
BytePosition[BytePosition["GAMEOVER_X"] = 42] = "GAMEOVER_X";
|
|
25
|
+
BytePosition[BytePosition["GAMEOVER_Y"] = 44] = "GAMEOVER_Y";
|
|
26
|
+
BytePosition[BytePosition["MAP_SIZE"] = 46] = "MAP_SIZE";
|
|
27
|
+
BytePosition[BytePosition["MESSAGE_NUM"] = 48] = "MESSAGE_NUM";
|
|
28
|
+
BytePosition[BytePosition["ITEMBOX_TOP"] = 60] = "ITEMBOX_TOP";
|
|
29
|
+
BytePosition[BytePosition["MAPDATA_TOP"] = 90] = "MAPDATA_TOP";
|
|
30
|
+
BytePosition[BytePosition["OLD_MAPDATA_TOP"] = 100] = "OLD_MAPDATA_TOP";
|
|
31
|
+
})(BytePosition || (exports.BytePosition = BytePosition = {}));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { WWAData } from "@wwawing/common-interface";
|
|
2
|
+
import { WWALoaderEventEmitter } from "../../infra";
|
|
3
|
+
export declare class WWADataExtractor {
|
|
4
|
+
private byteMapData;
|
|
5
|
+
private eventEmitter;
|
|
6
|
+
private wwaData;
|
|
7
|
+
private currentPosition;
|
|
8
|
+
constructor(byteMapData: Uint8Array, byteMapLength: number, eventEmitter: WWALoaderEventEmitter);
|
|
9
|
+
extractAllData(): WWAData;
|
|
10
|
+
private _convertAttributeV2toV3;
|
|
11
|
+
private _get1ByteNumber;
|
|
12
|
+
private _get2BytesNumber;
|
|
13
|
+
private _extractInitialParameters;
|
|
14
|
+
private _extractInitialItemData;
|
|
15
|
+
private _getFieldDataFromBits;
|
|
16
|
+
private _getPartsDataFromBits;
|
|
17
|
+
private _replaceAllRandomObjects;
|
|
18
|
+
private emitProgress;
|
|
19
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WWADataExtractor = void 0;
|
|
4
|
+
const util_1 = require("../../infra/util");
|
|
5
|
+
const checksum_1 = require("./checksum");
|
|
6
|
+
const constants_1 = require("./constants");
|
|
7
|
+
const infra_1 = require("../../infra");
|
|
8
|
+
class WWADataExtractor {
|
|
9
|
+
constructor(byteMapData, byteMapLength, eventEmitter) {
|
|
10
|
+
this.byteMapData = byteMapData;
|
|
11
|
+
this.eventEmitter = eventEmitter;
|
|
12
|
+
(0, checksum_1.checkMapDataBroken)(byteMapData, byteMapLength);
|
|
13
|
+
this.wwaData = (0, infra_1.createDefaultWWAData)();
|
|
14
|
+
}
|
|
15
|
+
extractAllData() {
|
|
16
|
+
var mapAttrMax, objAttrMax;
|
|
17
|
+
this.wwaData.version = this.byteMapData[constants_1.BytePosition.VERSION];
|
|
18
|
+
this._extractInitialParameters();
|
|
19
|
+
if (this.wwaData.version >= 29) {
|
|
20
|
+
this.currentPosition = constants_1.BytePosition.MAPDATA_TOP;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.currentPosition = constants_1.BytePosition.OLD_MAPDATA_TOP;
|
|
24
|
+
}
|
|
25
|
+
this.wwaData.map = this._getFieldDataFromBits(infra_1.PartsType.MAP, this.wwaData.mapPartsMax).concat();
|
|
26
|
+
this.wwaData.mapObject = this._getFieldDataFromBits(infra_1.PartsType.OBJECT, this.wwaData.objPartsMax).concat();
|
|
27
|
+
mapAttrMax = this.wwaData.version > 29 ? infra_1.WWAConsts.MAP_ATR_MAX : infra_1.WWAConsts.OLD_MAP_ATR_MAX;
|
|
28
|
+
objAttrMax = this.wwaData.version > 29 ? infra_1.WWAConsts.OBJ_ATR_MAX : infra_1.WWAConsts.OLD_OBJ_ATR_MAX;
|
|
29
|
+
this.wwaData.mapAttribute = this._getPartsDataFromBits(infra_1.PartsType.MAP, this.wwaData.mapPartsMax, mapAttrMax).concat();
|
|
30
|
+
this.wwaData.objectAttribute = this._getPartsDataFromBits(infra_1.PartsType.OBJECT, this.wwaData.objPartsMax, objAttrMax).concat();
|
|
31
|
+
if (this.wwaData.version <= 29) {
|
|
32
|
+
this._convertAttributeV2toV3(infra_1.PartsType.MAP);
|
|
33
|
+
this._convertAttributeV2toV3(infra_1.PartsType.OBJECT);
|
|
34
|
+
}
|
|
35
|
+
this._replaceAllRandomObjects();
|
|
36
|
+
return this.wwaData;
|
|
37
|
+
}
|
|
38
|
+
_convertAttributeV2toV3(partsType) {
|
|
39
|
+
var partsMax;
|
|
40
|
+
var attributeArray;
|
|
41
|
+
var localGateIndex;
|
|
42
|
+
if (partsType == infra_1.PartsType.MAP) {
|
|
43
|
+
partsMax = this.wwaData.mapPartsMax;
|
|
44
|
+
attributeArray = this.wwaData.mapAttribute;
|
|
45
|
+
localGateIndex = infra_1.WWAConsts.MAP_LOCALGATE;
|
|
46
|
+
}
|
|
47
|
+
else if (partsType == infra_1.PartsType.OBJECT) {
|
|
48
|
+
partsMax = this.wwaData.objPartsMax;
|
|
49
|
+
attributeArray = this.wwaData.objectAttribute;
|
|
50
|
+
localGateIndex = infra_1.WWAConsts.OBJECT_LOCALGATE;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error("謎のパーツ種別が指定されました");
|
|
54
|
+
}
|
|
55
|
+
for (var j = 0; j < partsMax; j++) {
|
|
56
|
+
for (var i = 9; i >= 0; i--) {
|
|
57
|
+
var dataChara = attributeArray[j][20 + i * 2] & 0xff;
|
|
58
|
+
var dataMode = attributeArray[j][20 + i * 2] >> 8;
|
|
59
|
+
var x = attributeArray[j][20 + i * 2 + 1] & 0xff;
|
|
60
|
+
var y = attributeArray[j][20 + i * 2 + 1] >> 8;
|
|
61
|
+
if (x === 250) {
|
|
62
|
+
x = 9000;
|
|
63
|
+
}
|
|
64
|
+
else if (x > 100) {
|
|
65
|
+
x += 10000 - 160;
|
|
66
|
+
}
|
|
67
|
+
if (y === 250) {
|
|
68
|
+
y = 9000;
|
|
69
|
+
}
|
|
70
|
+
else if (y > 100) {
|
|
71
|
+
y += 10000 - 160;
|
|
72
|
+
}
|
|
73
|
+
attributeArray[j][20 + i * 4] = dataChara;
|
|
74
|
+
attributeArray[j][20 + i * 4 + 3] = dataMode;
|
|
75
|
+
attributeArray[j][20 + i * 4 + 1] = x;
|
|
76
|
+
attributeArray[j][20 + i * 4 + 2] = y;
|
|
77
|
+
}
|
|
78
|
+
if (attributeArray[j][infra_1.WWAConsts.ATR_TYPE] === localGateIndex) {
|
|
79
|
+
if (attributeArray[j][infra_1.WWAConsts.ATR_JUMP_X] > 100) {
|
|
80
|
+
attributeArray[j][infra_1.WWAConsts.ATR_JUMP_X] += 10000 - 160;
|
|
81
|
+
}
|
|
82
|
+
if (attributeArray[j][infra_1.WWAConsts.ATR_JUMP_Y] > 100) {
|
|
83
|
+
attributeArray[j][infra_1.WWAConsts.ATR_JUMP_Y] += 10000 - 160;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
_get1ByteNumber(index) {
|
|
89
|
+
return this.byteMapData[index];
|
|
90
|
+
}
|
|
91
|
+
_get2BytesNumber(index) {
|
|
92
|
+
return this.byteMapData[index] + this.byteMapData[index + 1] * 0x100;
|
|
93
|
+
}
|
|
94
|
+
_extractInitialParameters() {
|
|
95
|
+
if (this.wwaData.version > 29) {
|
|
96
|
+
this.wwaData.gameoverX = this._get2BytesNumber(constants_1.BytePosition.GAMEOVER_X);
|
|
97
|
+
this.wwaData.gameoverY = this._get2BytesNumber(constants_1.BytePosition.GAMEOVER_Y);
|
|
98
|
+
this.wwaData.playerX = this._get2BytesNumber(constants_1.BytePosition.PLAYER_X);
|
|
99
|
+
this.wwaData.playerY = this._get2BytesNumber(constants_1.BytePosition.PLAYER_Y);
|
|
100
|
+
this.wwaData.mapPartsMax = this._get2BytesNumber(constants_1.BytePosition.MAP_COUNT);
|
|
101
|
+
this.wwaData.objPartsMax = this._get2BytesNumber(constants_1.BytePosition.OBJ_COUNT);
|
|
102
|
+
this.wwaData.isOldMap = false;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this.wwaData.gameoverX = this._get1ByteNumber(constants_1.BytePosition.OLD_GAMEOVER_X);
|
|
106
|
+
this.wwaData.gameoverY = this._get1ByteNumber(constants_1.BytePosition.OLD_GAMEOVER_Y);
|
|
107
|
+
this.wwaData.playerX = this._get1ByteNumber(constants_1.BytePosition.OLD_PLAYER_X);
|
|
108
|
+
this.wwaData.playerY = this._get1ByteNumber(constants_1.BytePosition.OLD_PLAYER_Y);
|
|
109
|
+
this.wwaData.mapPartsMax = this._get1ByteNumber(constants_1.BytePosition.OLD_MAP_COUNT);
|
|
110
|
+
this.wwaData.objPartsMax = this._get1ByteNumber(constants_1.BytePosition.OLD_OBJ_COUNT);
|
|
111
|
+
this.wwaData.isOldMap = true;
|
|
112
|
+
}
|
|
113
|
+
this.wwaData.statusEnergyMax = this._get2BytesNumber(constants_1.BytePosition.STATUS_ENERGY_MAX);
|
|
114
|
+
this.wwaData.statusEnergy = this._get2BytesNumber(constants_1.BytePosition.STATUS_ENERGY);
|
|
115
|
+
this.wwaData.statusStrength = this._get2BytesNumber(constants_1.BytePosition.STATUS_STRENGTH);
|
|
116
|
+
this.wwaData.statusDefence = this._get2BytesNumber(constants_1.BytePosition.STATUS_DEFENCE);
|
|
117
|
+
this.wwaData.statusGold = this._get2BytesNumber(constants_1.BytePosition.STATUS_GOLD);
|
|
118
|
+
this._extractInitialItemData();
|
|
119
|
+
this.wwaData.mapWidth = this._get2BytesNumber(constants_1.BytePosition.MAP_SIZE);
|
|
120
|
+
this.wwaData.messageNum = this._get2BytesNumber(constants_1.BytePosition.MESSAGE_NUM);
|
|
121
|
+
if (this.wwaData.version < 28)
|
|
122
|
+
this.wwaData.mapWidth = 71;
|
|
123
|
+
else if (this.wwaData.version <= 29)
|
|
124
|
+
this.wwaData.mapWidth = 101;
|
|
125
|
+
}
|
|
126
|
+
_extractInitialItemData() {
|
|
127
|
+
const topIdx = this.wwaData.version > 29 ? constants_1.BytePosition.ITEMBOX_TOP : constants_1.BytePosition.OLD_ITEMBOX_TOP;
|
|
128
|
+
this.wwaData.itemBox = new Array(infra_1.WWAConsts.ITEMBOX_SIZE);
|
|
129
|
+
for (let i = 0; i < infra_1.WWAConsts.ITEMBOX_SIZE; i++) {
|
|
130
|
+
this.wwaData.itemBox[i] = this._get1ByteNumber(topIdx + i);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
_getFieldDataFromBits(partsType, partsMax) {
|
|
134
|
+
var x, y;
|
|
135
|
+
var fieldArray;
|
|
136
|
+
fieldArray = (0, util_1.new2DArray)(this.wwaData.mapWidth, this.wwaData.mapWidth);
|
|
137
|
+
for (x = 0; x < this.wwaData.mapWidth; x++) {
|
|
138
|
+
for (y = 0; y < this.wwaData.mapWidth; y++) {
|
|
139
|
+
if (this.wwaData.version > 29) {
|
|
140
|
+
fieldArray[x][y] = this._get2BytesNumber(this.currentPosition);
|
|
141
|
+
this.currentPosition += 2;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
fieldArray[x][y] = this._get1ByteNumber(this.currentPosition);
|
|
145
|
+
this.currentPosition += 1;
|
|
146
|
+
}
|
|
147
|
+
if ((x * this.wwaData.mapWidth + y) % 200 === 0) {
|
|
148
|
+
this.emitProgress(x * this.wwaData.mapWidth + y, this.wwaData.mapWidth * this.wwaData.mapWidth, partsType === infra_1.PartsType.MAP ? infra_1.LoadStage.MAP_LOAD : infra_1.LoadStage.OBJ_LOAD);
|
|
149
|
+
}
|
|
150
|
+
if (fieldArray[x][y] >= partsMax) {
|
|
151
|
+
fieldArray[x][y] = 0;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
this.emitProgress(this.wwaData.mapWidth * this.wwaData.mapWidth, this.wwaData.mapWidth * this.wwaData.mapWidth, partsType === infra_1.PartsType.MAP ? infra_1.LoadStage.MAP_LOAD : infra_1.LoadStage.OBJ_LOAD);
|
|
156
|
+
return fieldArray;
|
|
157
|
+
}
|
|
158
|
+
_getPartsDataFromBits(partsType, partsMax, attrMax) {
|
|
159
|
+
var i, j;
|
|
160
|
+
var partsData;
|
|
161
|
+
partsData = (0, util_1.new2DArray)(partsMax, attrMax);
|
|
162
|
+
for (i = 0; i < partsMax; i++) {
|
|
163
|
+
for (j = 0; j < attrMax; j++) {
|
|
164
|
+
if ((i * this.wwaData.mapWidth + j) % 200 === 0) {
|
|
165
|
+
this.emitProgress(i * attrMax + j, partsMax * attrMax, partsType === infra_1.PartsType.MAP ? infra_1.LoadStage.MAP_ATTR : infra_1.LoadStage.OBJ_ATTR);
|
|
166
|
+
}
|
|
167
|
+
if (j === infra_1.WWAConsts.ATR_CROP1 || j === infra_1.WWAConsts.ATR_CROP2) {
|
|
168
|
+
partsData[i][j] = 0;
|
|
169
|
+
this.currentPosition += 2;
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
partsData[i][j] = this._get2BytesNumber(this.currentPosition);
|
|
173
|
+
this.currentPosition += 2;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
this.emitProgress(partsMax * attrMax, partsMax * attrMax, partsType === infra_1.PartsType.MAP ? infra_1.LoadStage.MAP_ATTR : infra_1.LoadStage.OBJ_ATTR);
|
|
177
|
+
return partsData;
|
|
178
|
+
}
|
|
179
|
+
_replaceAllRandomObjects() {
|
|
180
|
+
this.emitProgress(this.wwaData.mapWidth * this.wwaData.mapWidth, this.wwaData.mapWidth * this.wwaData.mapWidth, infra_1.LoadStage.RAND_PARTS);
|
|
181
|
+
}
|
|
182
|
+
emitProgress(current, total, stage) {
|
|
183
|
+
this.eventEmitter.dispatch("progress", { current, total, stage });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
exports.WWADataExtractor = WWADataExtractor;
|
|
@@ -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,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WWALoader = void 0;
|
|
4
|
+
const extractor_1 = require("./extractor");
|
|
5
|
+
const decompressor_1 = require("./decompressor");
|
|
6
|
+
const text_loader_1 = require("./text-loader");
|
|
7
|
+
const map_data_client_1 = require("./map-data-client");
|
|
8
|
+
const createMapDataClient = (fileName) => {
|
|
9
|
+
if (typeof window !== "undefined") {
|
|
10
|
+
return new map_data_client_1.BrowserMapDataClient(fileName);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
return new map_data_client_1.NodeLocalMapDataClient(fileName);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
class WWALoader {
|
|
17
|
+
constructor(fileName, eventEmitter) {
|
|
18
|
+
this.fileName = fileName;
|
|
19
|
+
this.eventEmitter = eventEmitter;
|
|
20
|
+
}
|
|
21
|
+
async requestAndLoadMapData() {
|
|
22
|
+
const client = createMapDataClient(this.fileName);
|
|
23
|
+
try {
|
|
24
|
+
const responseBuffer = await client.request();
|
|
25
|
+
if (!responseBuffer) {
|
|
26
|
+
this.eventEmitter.dispatch("error", { name: "マップデータ取得に失敗しました", message: "mapdata is empty" });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const wwaData = this.loadMapData(responseBuffer);
|
|
30
|
+
this.eventEmitter.dispatch("mapData", wwaData);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const name = error.name || "";
|
|
34
|
+
const message = error.message || "";
|
|
35
|
+
this.eventEmitter.dispatch("error", { name, message });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
loadMapData(data) {
|
|
39
|
+
try {
|
|
40
|
+
const compressedByteMapData = new Uint8Array(data);
|
|
41
|
+
const { byteMapData, byteMapLength, compressedEndPosition } = (0, decompressor_1.decompressMapData)(compressedByteMapData);
|
|
42
|
+
const wwaData = new extractor_1.WWADataExtractor(byteMapData, byteMapLength, this.eventEmitter).extractAllData();
|
|
43
|
+
return new text_loader_1.TextLoader(wwaData, compressedByteMapData, compressedEndPosition, this.eventEmitter).load();
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
throw e;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.WWALoader = WWALoader;
|
|
@@ -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,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BrowserMapDataClient = void 0;
|
|
4
|
+
const BaseMapDataClient_1 = require("./BaseMapDataClient");
|
|
5
|
+
class BrowserMapDataClient extends BaseMapDataClient_1.BaseMapDataClient {
|
|
6
|
+
constructor(uri) {
|
|
7
|
+
super();
|
|
8
|
+
this.uri = uri;
|
|
9
|
+
}
|
|
10
|
+
static async fetch(uri) {
|
|
11
|
+
try {
|
|
12
|
+
return await fetch(uri);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw new Error(`マップデータ 「${uri}」の読み込みに失敗しました。
|
|
16
|
+
通信環境の良いところで再度お試しください。
|
|
17
|
+
ローカルテストの場合は、ブラウザが対応していない可能性があります。`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
static handleError(uri, response) {
|
|
21
|
+
const statusCodeMessage = `HTTPステータスコードは ${response.status} です。`;
|
|
22
|
+
switch (response.status) {
|
|
23
|
+
case 200:
|
|
24
|
+
case 304:
|
|
25
|
+
return;
|
|
26
|
+
case 403:
|
|
27
|
+
throw new Error(`マップデータ「${uri}」を読み取る権限がないようです。
|
|
28
|
+
管理者の方へ: マップデータのパーミッションを確認してください。
|
|
29
|
+
${statusCodeMessage}`);
|
|
30
|
+
case 404:
|
|
31
|
+
throw new Error(`マップデータ「${uri}」が見つかりませんでした。
|
|
32
|
+
${statusCodeMessage}`);
|
|
33
|
+
default:
|
|
34
|
+
throw new Error(`マップデータ「${uri}」の読み込みに失敗しました。
|
|
35
|
+
${statusCodeMessage}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async request() {
|
|
39
|
+
const response = await BrowserMapDataClient.fetch(this.uri);
|
|
40
|
+
BrowserMapDataClient.handleError(this.uri, response);
|
|
41
|
+
const buffer = await response.arrayBuffer();
|
|
42
|
+
return buffer;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.BrowserMapDataClient = BrowserMapDataClient;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NodeLocalMapDataClient = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const BaseMapDataClient_1 = require("./BaseMapDataClient");
|
|
9
|
+
class NodeLocalMapDataClient extends BaseMapDataClient_1.BaseMapDataClient {
|
|
10
|
+
constructor(fileName) {
|
|
11
|
+
super();
|
|
12
|
+
this.fileName = fileName;
|
|
13
|
+
}
|
|
14
|
+
async request() {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
fs_1.default.readFile(this.fileName, (error, data) => {
|
|
17
|
+
if (error) {
|
|
18
|
+
reject(error);
|
|
19
|
+
}
|
|
20
|
+
resolve(data.buffer);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
}
|
|
26
|
+
exports.NodeLocalMapDataClient = NodeLocalMapDataClient;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeLocalMapDataClient = exports.BrowserMapDataClient = exports.BaseMapDataClient = void 0;
|
|
4
|
+
const BaseMapDataClient_1 = require("./BaseMapDataClient");
|
|
5
|
+
Object.defineProperty(exports, "BaseMapDataClient", { enumerable: true, get: function () { return BaseMapDataClient_1.BaseMapDataClient; } });
|
|
6
|
+
const BrowserMapDataClient_1 = require("./BrowserMapDataClient");
|
|
7
|
+
Object.defineProperty(exports, "BrowserMapDataClient", { enumerable: true, get: function () { return BrowserMapDataClient_1.BrowserMapDataClient; } });
|
|
8
|
+
const NodeLocalMapDataClient_1 = require("./NodeLocalMapDataClient");
|
|
9
|
+
Object.defineProperty(exports, "NodeLocalMapDataClient", { enumerable: true, get: function () { return NodeLocalMapDataClient_1.NodeLocalMapDataClient; } });
|
|
@@ -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
|
+
}
|