Skip to content

Commit 8ba0a6a

Browse files
author
ozelot379
committed
- Restruct code
- Optimized conversion popup - Reimplement weather convert
1 parent 56d9639 commit 8ba0a6a

71 files changed

Lines changed: 2402 additions & 2004 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [1.10.0]
4+
- Restruct code
5+
- Optimized conversion popup
6+
- Reimplement weather convert
7+
38
## [1.9.0]
49
- Allow select folder on browser gui
510

‎README.md‎

Lines changed: 62 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It supports currently the follow Minecraft versions:
99

1010
Currently it supports blocks, items, entities, paintings, particles and map icons textures
1111

12-
Supported formats are mcpack archives, zip archives or directories
12+
Supported formats are zip archives or folders
1313

1414
This library is inspired by the no longer continued [PCTexture2PE](https://github.com/rodrigojxd/PCTexture2PE)
1515

@@ -41,7 +41,7 @@ ConvertMinecraftJavaTextureToBedrock -i input/java_texture_pack.zip -o output/be
4141
|---------------|-------------------------------|
4242
| -i (Required) | Input folder or archive path |
4343
| -o (Required) | Output folder or archive path |
44-
| -l | Verbose log (Default `true`) |
44+
| -l | Show log (Default `true`) |
4545

4646
## Direct in your code
4747
Add it as a dependency to your `package.json`
@@ -52,33 +52,80 @@ yarn add @ozelot379/convert-minecraft-java-texture-to-bedrock
5252

5353
Import it in your code, if you use webpack
5454
```javascript
55-
import ConvertMinecraftJavaTextureToBedrock from "@ozelot379/convert-minecraft-java-texture-to-bedrock";
55+
import ConvertMinecraftJavaTextureToBedrock, {ConsoleLog, Input, LocalFileInputEntry, LocalFileOutput} from "@ozelot379/convert-minecraft-java-texture-to-bedrock";
5656
```
5757
or require it if you use native NodeJs
5858
```javascript
59-
const ConvertMinecraftJavaTextureToBedrock = require("@ozelot379/convert-minecraft-java-texture-to-bedrock").default;
59+
const {default: ConvertMinecraftJavaTextureToBedrock, ConsoleLog, Input, LocalFileInputEntry, LocalFileOutput} = require("@ozelot379/convert-minecraft-java-texture-to-bedrock");
6060
```
6161

6262
You can now convert your texture packs in an `async function`
6363
```javascript
64-
let outputPath;
64+
let output;
6565
try {
66-
outputPath = await ConvertMinecraftJavaTextureToBedrock(input, output/*, "options"*/);
66+
output = await new ConvertMinecraftJavaTextureToBedrock(input, output, log).convert();
6767
} catch (err) {
6868

6969
}
7070
```
71-
or handle the `Promise` direct
71+
or self handle the `Promise`
7272
```javascript
73-
ConvertMinecraftJavaTextureToBedrock(input, output/*, "options"*/).then((outputPath) => {}).catch((err) => {});
73+
new ConvertMinecraftJavaTextureToBedrock(input, output, log).convert().then((output) => {}).catch((err) => {});
7474
```
7575

76-
| Parameter | Description |
77-
|---------------------|------------------------------------------------|
78-
| input (Required) | - Folder or archive path (`string`)<br>- Archive (`Buffer`)<br>- `Array` with archive (`Buffer`) and filename (`string`) |
79-
| output (Required) | - Folder or archive path (`string`)<br>- Archive (`Buffer`) |
80-
| options.verbose | Verbose log (Default `true`) |
81-
| options.logCallback | Custom log callback (Default is `console.log`) |
76+
### Input
77+
| Import | Description |
78+
|-----------------|-------------|
79+
| `Input` | The input consists on one input entry (Common) |
80+
| `ArrayInput` | The input consists on multiple input entries (For instance a selected folder with multiple `FileInputEntry`) |
81+
| `AbstractInput` | Base input |
82+
83+
### Input entry
84+
| Import | For type |
85+
|-------------------------|--------------------|
86+
| `BufferInputEntry` | <ul><li>`ArrayBuffer`</li><li>`Blob`</li><li>`Buffer`</li><li>`Uint8Array`</li></ul> |
87+
| `FileInputEntry` | `File` |
88+
| `LocalFileInputEntry` | Local file |
89+
| `LocalFolderInputEntry` | Local folder |
90+
| `AbstractInputEntry` | Base input entry |
91+
92+
### Output
93+
| Import | For type |
94+
|---------------------|---------------|
95+
| `ArrayBufferOutput` | `ArrayBuffer` |
96+
| `BlobOutput` | `Blob` |
97+
| `BufferOutput` | `Buffer` |
98+
| `FileBlobOutput` | `File` |
99+
| `LocalFileOutput` | Local file |
100+
| `LocalFolderOutput` | Local folder |
101+
| `Uint8ArrayOutput` | `Uint8Array` |
102+
| `AbstractOutput` | Base output |
103+
104+
### Log
105+
| Import | Description |
106+
|---------------|----------------|
107+
| `ConsoleLog` | Log to console |
108+
| `SlientLog` | Disable log |
109+
| `AbstractLog` | Base log |
110+
111+
### Example
112+
```javascript
113+
import ConvertMinecraftJavaTextureToBedrock, {ConsoleLog, Input, LocalFileInputEntry, LocalFileOutput} from "@ozelot379/convert-minecraft-java-texture-to-bedrock";
114+
115+
(async () => {
116+
let output;
117+
118+
try {
119+
output = await new ConvertMinecraftJavaTextureToBedrock(new Input(new LocalFileInputEntry("input/java_texture_pack.zip")), new LocalFileOutput("output/bedrock_texture_pack.mcpack"), new ConsoleLog()).convert();
120+
} catch (err) {
121+
console.log(err);
122+
123+
return;
124+
}
125+
126+
console.log(`Output: ${output}`);
127+
})();
128+
```
82129

83130
## Known issues
84131
- Convert horse textures is very tricky and may buggy
@@ -90,7 +137,7 @@ ConvertMinecraftJavaTextureToBedrock(input, output/*, "options"*/).then((outputP
90137
You can create the `bedrock_uuid_header` and `bedrock_uuid_module` files in your input, to keep the same uuid on repeating conversions - otherwise, random uuids are generated each time and you need to reselect the texture pack again in the game
91138

92139
## Custom textures
93-
You can put custom textures in a `bedrock_textures` directory in your input
140+
You can put custom textures in a `bedrock_textures` folder in your input
94141

95142
For instance for textures, that can not be converted or are not converted correctly
96143

‎package.json‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@ozelot379/convert-minecraft-java-texture-to-bedrock",
33
"productName": "ConvertMinecraftJavaTextureToBedrock",
4-
"version": "1.9.0",
4+
"version": "1.10.0",
55
"description": "Convert Minecraft Java texture packs to Minecraft Bedrock texture packs",
66
"keywords": [
77
"Minecraft",
@@ -26,7 +26,6 @@
2626
"css-loader": "^3.2.0",
2727
"favicons-webpack-plugin": "^1.0.1",
2828
"file-saver": "https://github.com/eligrey/FileSaver.js",
29-
"file-to-array-buffer": "^1.0.0",
3029
"fs-extra": "^8.1.0",
3130
"gh-pages": "^2.1.1",
3231
"html-webpack-plugin": "^3.2.0",
@@ -60,7 +59,7 @@
6059
"build:dev": "webpack --mode=development",
6160
"cli": "node dist/cli.js",
6261
"debug": "yarn build:dev && yarn cli",
63-
"prepublishOnly": "yarn build && yarn publishGhpages",
64-
"publishGhpages": "gh-pages -d ./dist/webapp"
62+
"prepublishOnly": "yarn build && yarn publishGhPages",
63+
"publishGhPages": "gh-pages -d ./dist/webapp"
6564
}
6665
}

‎src/cli.js‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
import ConvertMinecraftJavaTextureToBedrock from "./index";
2-
import PACKAGE from "../package";
1+
import ConvertMinecraftJavaTextureToBedrock, {
2+
ConsoleLog,
3+
Input,
4+
LocalFileInputEntry,
5+
LocalFileOutput,
6+
LocalFolderInputEntry,
7+
LocalFolderOutput,
8+
SilentLog
9+
} from ".";
10+
import fs from "fs-extra";
11+
import PACKAGE from "./../package";
312
import yargs from "yargs";
413

514
(async () => {
@@ -8,19 +17,19 @@ import yargs from "yargs";
817
i: {
918
alias: "input",
1019
demand: true,
11-
describe: "Input folder or archive path",
20+
describe: "Input folder or zip path",
1221
type: "string"
1322
},
1423
o: {
1524
alias: "output",
1625
demand: true,
17-
describe: "Output folder or archive path",
26+
describe: "Output folder or zip path",
1827
type: "string"
1928
},
2029
l: {
21-
alias: "verbose",
30+
alias: "log",
2231
default: true,
23-
describe: "Verbose log",
32+
describe: "Log",
2433
type: "boolean"
2534
}
2635
})
@@ -29,9 +38,11 @@ import yargs from "yargs";
2938
.argv;
3039

3140
try {
32-
await ConvertMinecraftJavaTextureToBedrock(argv.input, argv.output, {
33-
verbose: argv.verbose
34-
});
41+
return new ConvertMinecraftJavaTextureToBedrock(
42+
new Input(fs.statSync(argv.input).isDirectory() ? new LocalFolderInputEntry(argv.input) : new LocalFileInputEntry(argv.input)),
43+
(argv.output.includes(".") ? new LocalFileOutput(argv.output) : new LocalFolderOutput(argv.output)),
44+
(argv.log ? new ConsoleLog() : new SilentLog())
45+
).convert();
3546
} catch (err) {
3647
console.error(err.message);
3748

‎src/converter/AbstractConverter.js‎

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,63 @@
1-
import AbstractOutput from "../output/AbstractOutput";
1+
import {AbstractInput} from "./../input"
2+
import {AbstractLog} from "./../log";
3+
import {AbstractOutput} from "./../output";
24
import Jimp from "jimp";
3-
import Log from "../log/Log";
45

56
/**
67
* Class AbstractConverter
78
*
89
* @abstract
910
*/
1011
class AbstractConverter {
12+
1113
/**
1214
* AbstractConverter constructor
1315
*
14-
* @param {AbstractOutput} output
1516
* @param {mixed[]} data
16-
* @param {Log} log
1717
*
1818
* @throws {Error}
1919
*/
20-
constructor(output, data = [], log) {
20+
constructor(data = this.constructor.DATA) {
2121
if (this.constructor === AbstractConverter) {
2222
throw new Error("Can't instantiate abstract class!");
2323
}
2424

25+
/**
26+
* @type {AbstractInput}
27+
*
28+
* @protected
29+
*/
30+
this.input;
2531
/**
2632
* @type {AbstractOutput}
2733
*
2834
* @protected
2935
*/
30-
this.output = output;
36+
this.output;
3137
/**
32-
* @type {mixed[]}
38+
* @type {AbstractLog}
3339
*
3440
* @protected
3541
*/
36-
this.data = data;
42+
this.log;
3743
/**
38-
* @type {Log}
44+
* @type {mixed[]}
3945
*
4046
* @protected
4147
*/
48+
this.data = data;
49+
}
50+
51+
/**
52+
* @param {AbstractInput} input
53+
* @param {AbstractOutput} output
54+
* @param {AbstractLog} log
55+
*
56+
* @returns Promise<>
57+
*/
58+
async _init(input, output, log) {
59+
this.input = input;
60+
this.output = output;
4261
this.log = log;
4362
}
4463

@@ -69,28 +88,39 @@ class AbstractConverter {
6988
}
7089

7190
/**
72-
* @returns {Promise<Function<AbstractConverter>[]>}
91+
* @returns {AsyncIterableIterator<*>}
7392
*
7493
* @throws {Error}
7594
*
95+
* @protected
96+
*/
97+
async* getData() {
98+
for (const date of this.data) {
99+
yield date;
100+
}
101+
}
102+
103+
/**
104+
* @returns {mixed[]}
105+
*
106+
* @protected
107+
*
76108
* @abstract
77109
*/
78-
async convert() {
110+
static get DATA() {
79111

80112
}
81113

82114
/**
83-
* @returns {AsyncIterableIterator<*>}
115+
* @returns {Promise<Function<AbstractConverter>[]>}
84116
*
85117
* @throws {Error}
86118
*
87119
* @abstract
88-
*
89-
* @protected
90120
*/
91-
async* getData() {
121+
async convert() {
92122

93123
}
94124
}
95125

96-
export default AbstractConverter;
126+
export {AbstractConverter};

‎src/converter/AtlasConverter.js‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import AbstractConverter from "./AbstractConverter";
2-
import DeleteConverter from "./DeleteConverter";
1+
import {AbstractConverter} from "./AbstractConverter";
2+
import {DeleteConverter} from "./DeleteConverter";
33
import Jimp from "jimp";
44

55
/**
@@ -38,22 +38,18 @@ class AtlasConverter extends AbstractConverter {
3838
}
3939
}
4040

41-
return [[DeleteConverter, to_delete]];
41+
return [new DeleteConverter(to_delete)];
4242
}
4343

4444
/**
4545
* @inheritDoc
4646
*/
47-
async* getData() {
48-
const data = [
47+
static get DATA() {
48+
return [
4949
["textures/items/clock_", 63, "textures/items/watch_atlas.png"],
5050
["textures/items/compass_", 31, "textures/items/compass_atlas.png"]
5151
];
52-
53-
for (const date of data) {
54-
yield date;
55-
}
5652
}
5753
}
5854

59-
export default AtlasConverter;
55+
export {AtlasConverter};

‎src/converter/BannerPatternConverter.js‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import AbstractConverter from "./AbstractConverter";
1+
import {AbstractConverter} from "./AbstractConverter";
22

33
/**
44
* Class BannerPatternConverter
@@ -49,8 +49,8 @@ class BannerPatternConverter extends AbstractConverter {
4949
/**
5050
* @inheritDoc
5151
*/
52-
async* getData() {
53-
const data = [
52+
static get DATA() {
53+
return [
5454
["textures/entity/banner_base.png", [
5555
// https://www.planetminecraft.com/banner/pillager-banner-199281/
5656
// Colors from original bedrock texture
@@ -64,11 +64,7 @@ class BannerPatternConverter extends AbstractConverter {
6464
["textures/entity/banner/border.png", [0, 0, 0]]
6565
], "textures/entity/banner/banner_pattern_illager.png"]
6666
];
67-
68-
for (const date of data) {
69-
yield date;
70-
}
7167
}
7268
}
7369

74-
export default BannerPatternConverter;
70+
export {BannerPatternConverter};

0 commit comments

Comments
 (0)