diff --git a/.env b/.env new file mode 100644 index 00000000..1cfbf5d4 --- /dev/null +++ b/.env @@ -0,0 +1,9 @@ + +# Log level (0 = none, 1 = info, 2 = verbose) +LOG_LEVEL=1 + +# Tileset optimization +TILESET_OPTIMIZATION=false +# Tileset optimization quality (0.0 - 1.0) +TILESET_OPTIMIZATION_QUALITY_MIN=0.9 +TILESET_OPTIMIZATION_QUALITY_MAX=1.0 diff --git a/package-lock.json b/package-lock.json index d962b891..e4b31629 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,9 +14,10 @@ "devDependencies": { "@types/node": "^18.15.11", "@workadventure/iframe-api-typings": "^1.17.1", + "dotenv": "^16.3.1", "typescript": "^4.9.5", "vite": "^4.3.9", - "wa-map-optimizer-vite": "^1.1.17" + "wa-map-optimizer-vite": "^1.1.18" } }, "node_modules/@16bits/nes.css": { @@ -2222,6 +2223,18 @@ "resolved": "https://registry.npmjs.org/dlv/-/dlv-1.1.3.tgz", "integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==" }, + "node_modules/dotenv": { + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" + } + }, "node_modules/download": { "version": "6.2.5", "resolved": "https://registry.npmjs.org/download/-/download-6.2.5.tgz", @@ -5052,9 +5065,9 @@ } }, "node_modules/wa-map-optimizer-vite": { - "version": "1.1.17", - "resolved": "https://registry.npmjs.org/wa-map-optimizer-vite/-/wa-map-optimizer-vite-1.1.17.tgz", - "integrity": "sha512-t63/9O21MhmJSD322cG+0tVHV/p7jmYMGgYRTQllT+TjSQF8gffyk+/6DlL96znpCNy2E68aCTZvPng6NYcQ+Q==", + "version": "1.1.18", + "resolved": "https://registry.npmjs.org/wa-map-optimizer-vite/-/wa-map-optimizer-vite-1.1.18.tgz", + "integrity": "sha512-myPvlvVGAcktFJEoZDBTTuUZHMtG4z9DTkJq5Vr2RtldHdFB7KdqZquWuzAAbJRdIep20y+R2YWejlI8jx23tQ==", "dev": true, "dependencies": { "@workadventure/tiled-map-type-guard": "^2.1.1", @@ -6848,6 +6861,12 @@ "resolved": "https://registry.npmjs.org/dlv/-/dlv-1.1.3.tgz", "integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==" }, + "dotenv": { + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", + "dev": true + }, "download": { "version": "6.2.5", "resolved": "https://registry.npmjs.org/download/-/download-6.2.5.tgz", @@ -8867,9 +8886,9 @@ } }, "wa-map-optimizer-vite": { - "version": "1.1.17", - "resolved": "https://registry.npmjs.org/wa-map-optimizer-vite/-/wa-map-optimizer-vite-1.1.17.tgz", - "integrity": "sha512-t63/9O21MhmJSD322cG+0tVHV/p7jmYMGgYRTQllT+TjSQF8gffyk+/6DlL96znpCNy2E68aCTZvPng6NYcQ+Q==", + "version": "1.1.18", + "resolved": "https://registry.npmjs.org/wa-map-optimizer-vite/-/wa-map-optimizer-vite-1.1.18.tgz", + "integrity": "sha512-myPvlvVGAcktFJEoZDBTTuUZHMtG4z9DTkJq5Vr2RtldHdFB7KdqZquWuzAAbJRdIep20y+R2YWejlI8jx23tQ==", "dev": true, "requires": { "@workadventure/tiled-map-type-guard": "^2.1.1", diff --git a/package.json b/package.json index cd210d01..876d1190 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "workadventure-map-starter-kit", - "version": "3.3.6", + "version": "3.3.7", "license": "MIT", "scripts": { "dev": "vite", @@ -11,9 +11,10 @@ "devDependencies": { "@types/node": "^18.15.11", "@workadventure/iframe-api-typings": "^1.17.1", + "dotenv": "^16.3.1", "typescript": "^4.9.5", "vite": "^4.3.9", - "wa-map-optimizer-vite": "^1.1.17" + "wa-map-optimizer-vite": "^1.1.18" }, "dependencies": { "@workadventure/scripting-api-extra": "^1.4.8" diff --git a/vite.config.ts b/vite.config.ts index 1f52edfa..e7ca7774 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,26 @@ +import 'dotenv/config'; import { defineConfig } from "vite"; -import { getMaps, getMapsOptimizers, getMapsScripts } from "wa-map-optimizer-vite"; +import { getMaps, getMapsOptimizers, getMapsScripts, LogLevel, OptimizeOptions } from "wa-map-optimizer-vite"; const maps = getMaps(); +let optimizerOptions: OptimizeOptions = { + logs: process.env.LOG_LEVEL && process.env.LOG_LEVEL in LogLevel ? LogLevel[process.env.LOG_LEVEL] : LogLevel.NORMAL, +}; + +if (process.env.TILESET_OPTIMIZATION && process.env.TILESET_OPTIMIZATION === "true") { + const qualityMin = process.env.TILESET_OPTIMIZATION_QUALITY_MIN ? parseInt(process.env.TILESET_OPTIMIZATION_QUALITY_MIN) : 0.9; + const qualityMax = process.env.TILESET_OPTIMIZATION_QUALITY_MAX ? parseInt(process.env.TILESET_OPTIMIZATION_QUALITY_MAX) : 1; + + optimizerOptions.output = { + tileset: { + compress: { + quality: [qualityMin, qualityMax], + } + } + } +} + export default defineConfig({ base: "./", build: { @@ -13,7 +31,7 @@ export default defineConfig({ }, }, }, - plugins: [...getMapsOptimizers(maps)], + plugins: [...getMapsOptimizers(maps, optimizerOptions)], server: { host: "localhost", headers: {