From 98edefff2e18bcdf300bddb35402a79efb8cf246 Mon Sep 17 00:00:00 2001 From: yellows111 Date: Tue, 5 Dec 2023 18:40:46 +0000 Subject: [PATCH] A compatibility update. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No, this isn't a late 'Fool's joke, I was just having fun and now I can target pure ES6/ES2015 if I wanted to. …except Chakra ('Edge <= 44), that thing never implemented `TextDecoder`/`TextEncoder` for some reason. We'll never know why... I'm researching what makes over-bright happen... give me time! --- README.md | 52 ++++++++++++++++++------- gltf-exporter.js | 2 +- icon.js | 30 +++++++++++---- index.htm | 98 +++++++++++++++++++++++++++++++----------------- 4 files changed, 124 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 04b5fce..7c49c0f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,20 @@ # icondumper2 (working title) A JavaScript library (sorta) to read PS2 icons, and their related formats. -## What it supports +## What is a "PS2 icon"? +A set of vertices with may or may not include a texture while defining colours for those vertices. + +## Why? +Current implementations had some issues with rendering some icons. These were mostly: +* Not rendering any color for texture type 3. +* Failing to decompress some specific RLE-compressed icons. (types above 8) +* Requires writing/reading a specific format for successful output of data. + +As of writing, there was no exporter that exists for the format that exhibited one of these problems. + +**icondumper2** is the result of me trying to avoid these problems. + +## What it supports: * EMS Memory Adapter export files (.psu) * PS3 virtual memory card export files (.psv) * SharkPort export files (.sps) @@ -9,30 +22,41 @@ A JavaScript library (sorta) to read PS2 icons, and their related formats. * PS2 icons (.ico, .icn) * PS2D format (icon.sys) -## What can it do -* Allow any file in a PSU's or SPS/XPS's virtual filesystem to be dumped. +## What can it do: +* Allow any file in a supported virtual filesystem (such as those from export files) to be read. * Warn of invalid icon.sys display names. -* Read and parse an EMS MA export file. -* Export the icon model, with all seperate shapes included to a JavaScript Object. -* Node.js compatible (CommonJS) exporting while still being compatible with other JavaScript implementations. -* Convert a 128x128x16 BGR5A1 bitmap to a RGB5A1 format. +* Export the icon model, with all seperate shapes included as a JavaScript Object. +* CommonJS (that includes node!) module exporting while still being compatible with other JavaScript implementations. +* Convert a 128x128x16 BGR5A1 bitmap to a standard RGB5A1 format. * Convert an icon or a set of icons to glTF 2, with textures saved as PNG. -## What it doesn't do -* (Re)build save files. -* Modify the original input files. -* Use any Node.js-exclusive features. +## What it doesn't do: +* Create, manipulate or otherwise taint save files. +* Modify any original input files. +* Use any implementation-specific features. -## Client compatibility -(todo: write this) +## Client compatibility: +The library requires use of `const`, `let` and `class` declarations. + +Any JavaScript implementation should work if they support all three of these declarations. + +### Tested clients: +* Chrome (or Blink-based browser) 49 (or higher) - HTML reference client +* Firefox (or Gecko-based browser) 45 (or higher) - HTML reference client +* Node.js 13 (or higher) - Example client and glTF 2 exporter. ## Why "icondumper2"? Because it replaced what *was* left of icondumper (1). -## Included files +## Included files: | File | Description | | ---------------- | ----------------------------------------- | | icon.js | The library itself. | | index.js | Node.js example client. | | gltf-exporter.js | Node.js client to export icons to glTF 2. | | index.htm | HTML reference client. | + +## Included example files: +| Directory | Description | Formats | +| ------------ | ----------------------------------------- | -------- | +| /example_001 | A tetrahedron with all 3 base colors set. | PSU, SPS | \ No newline at end of file diff --git a/gltf-exporter.js b/gltf-exporter.js index a48dcce..2794f5f 100644 --- a/gltf-exporter.js +++ b/gltf-exporter.js @@ -249,7 +249,7 @@ function loadAndConvertIcon(inputData, attemptedFilename = "-") { if (inputData.hasOwnProperty("numberOfShapes") === false) { throw "Expected a icondumper2 Intermediate Model Format object."; } - const filename = encodeURIComponent(attemptedFilename).replaceAll(/\%[0-9A-F]{2,2}/g, "").replaceAll(".", "_"); + const filename = encodeURIComponent(attemptedFilename).replace(/\%[0-9A-F]{2,2}/g, "").replace(/\./g, "_"); const glTF_output = imf2gltf(inputData, filename); for (let index = 0; index < (inputData.numberOfShapes); index++) { (require("fs")).writeFileSync(`${filename}_${index}.gltf`, new TextEncoder().encode(JSON.stringify(glTF_output.objects[index]))); diff --git a/icon.js b/icon.js index a7f5882..e65fbb8 100644 --- a/icon.js +++ b/icon.js @@ -1,21 +1,22 @@ //todo: Make this a module/mjs file. C6 compatibility can stay, if needed. //LOOKING FOR: LZARI implementation (for MAX), description of CBS compression (node zlib doesn't tackle it, even with RC4'ing the data) -ICONJS_DEBUG = false; -ICONJS_STRICT = true; +var ICONJS_DEBUG = false; +var ICONJS_STRICT = true; /** * The current version of the library. * @constant {string} * @default */ -const ICONJS_VERSION = "0.6.1"; +const ICONJS_VERSION = "0.6.1+u1"; /** * Extension of DataView to add shortcuts for datatypes that I use often. * @augments DataView * @constructor * @param {ArrayBuffer} buffer ArrayBuffer to base DataView from. - * @returns {Object.} + * @returns {Object.} [u16le, f16le, u32le, f32le] + * @returns {Object.>} [t64le] * @access protected */ class yellowDataReader extends DataView { @@ -40,9 +41,16 @@ class yellowDataReader extends DataView { */ f32le(i){return super.getFloat32(i, 1)}; /** 64-bit Timestamp structure, Little Endian. + * Time returned is set for JST (UTC+09:00) instead of UTC. * Time returned is going to be offseted for JST (GMT+09:00). * @param {number} i Indice offset. * @returns {Object.} + * @property {number} seconds - Seconds. + * @property {number} minutes - Minutes. + * @property {number} hours - Hours. + * @property {number} day - Day. + * @property {number} month - Month. + * @property {number} year - Year. */ t64le(i){return { seconds: super.getUint8(i+1), @@ -78,7 +86,7 @@ function setDebug(value) { * Select if invalid characters in titles should be replaced with either spaces or nulls * @param {boolean} value - true: with nulls, false: with spaces * @default true - * @deprecated unlikely to ever need this? + * @deprecated Hasn't been needed for a while. Dropping support by ESM transition. * @public */ function setStrictness(value) { @@ -182,7 +190,7 @@ function convertBGR5A1toRGB5A1(bgrData) { * @access protected */ function stringScrubber(dirty) { - return dirty.replaceAll("\x00","").substring(0, (dirty.indexOf("\x00") === -1) ? dirty.length : dirty.indexOf("\x00")); + return dirty.replace(/\0/g, "").substring(0, (dirty.indexOf("\x00") === -1) ? dirty.length : dirty.indexOf("\x00")); } /** @@ -627,9 +635,9 @@ function readSharkXPortSxpsFile(input) { } /** - * Define (module.)exports with all public functions + * Define (module.)exports with all public functions. * @exports icondumper2/icon - */ + */ // start c6js exports = { readers: {readIconFile, readPS2D, readEmsPsuFile, readPsvFile, readSharkXPortSxpsFile}, helpers: {uncompressTexture, convertBGR5A1toRGB5A1}, @@ -640,3 +648,9 @@ exports = { if(typeof module !== "undefined") { module.exports = exports; } +//end c6js +//start esm +/*export { + readIconFile, readPS2D, readEmsPsuFile, readPsvFile, readSharkXPortSxpsFile, uncompressTexture, convertBGR5A1toRGB5A1, setDebug, ICONJS_VERSION +};*/ +//end esm \ No newline at end of file diff --git a/index.htm b/index.htm index e128d94..8ee1da9 100644 --- a/index.htm +++ b/index.htm @@ -20,6 +20,13 @@ input[type="file"] {line-height: 2em;} #version {text-shadow: 1px 1px 2px black;} a {color: #ccc;} + .inputbox { + display: inline-grid; + margin-right: 0.25em; + border: 1px gray solid; + padding: 0.175em 0.25em 0 0.25em; + margin-bottom: 4px; + }