Update compression lib.

This commit is contained in:
2025-08-07 21:02:19 +02:00
parent 908bfd2900
commit 397a80a1d0
4 changed files with 30 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import { useEffect, useRef } from "react"
import { Hammer } from "./classes/Hammer";
import pako from "pako";
function App() {
@@ -57,17 +58,20 @@ function App() {
};
try {
let reader = new FileReader();
reader.readAsText(files[0], "UTF-8");
reader.readAsArrayBuffer(files[0]);
reader.onload = (evt) => {
if (evt.target) {
const data = JSON.parse(evt.target.result as string);
// @ts-expect-error
const uncompressed_data = pako.inflate(evt.target.result, {to: "string"});
console.log(uncompressed_data)
const data = JSON.parse(uncompressed_data as string);
if (hammerRef.current) {
const tl = new Image();
tl.src = data.tilesheet;
tl.onload = () => {
if (hammerRef.current) {
hammerRef.current.setTileSheet(tl);
hammerRef.current.tileMap = data.map;
hammerRef.current.heditor.tileMap = data.map;
}
};

View File

@@ -7,7 +7,7 @@ import { EventsManager } from "./EventManager";
import { HammerConsole } from "./HammerConsole";
import { HammerLoader } from "./HammerLoader";
import { Tile } from "./Tile";
import pako from "pako";
export class Hammer {
canvas: HTMLCanvasElement | null = null;
@@ -72,7 +72,8 @@ export class Hammer {
if (this.tilesheet == null) return this.hconsole.push("Tilesheet not exist !", "ERROR");
const tilesheet_string = ImageToString(this.tilesheet);
if (tilesheet_string)
DownloadTextFile(JSON.stringify({ tilesheet: tilesheet_string, map: this.heditor.tileMap }), "my_map.tmpx");
// @ts-expect-error
DownloadTextFile(pako.deflate(JSON.stringify({ tilesheet: tilesheet_string, map: this.heditor.tileMap })), "my_map.tmpx");
else
return this.hconsole.push("An error has occurred !", "ERROR");
}
@@ -120,8 +121,6 @@ export class Hammer {
}
async setTileSheet(img: HTMLImageElement) {
// ? Save le tilesheet
this.tilesheet = img;
// ? desactiver le bouton pour add des ts
if (this.helements.elements.button_set_tilesheet)
@@ -132,6 +131,9 @@ export class Hammer {
// ? Reset l'ancien ts
this.resetTiles();
// ? Save le tilesheet
this.tilesheet = img;
// ? Recup le nombre
const tilesMax = Math.floor(img.width / 16) * Math.floor(img.height / 16);
this.hloader.loadingMax = tilesMax;