Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsuk1ko committed Aug 3, 2023
0 parents commit 6d77161
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish

on:
push:
branches:
- "!*"
tags:
- "v*"

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup wasm-pack
uses: jetli/wasm-pack-action@v0.4.0
- name: Build
run: ./build.sh
- name: Publish
uses: JS-DevTools/npm-publish@v2
with:
token: ${{ secrets.NPM_TOKEN }}
package: ./pkg
access: public
- name: Release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: ${{ secrets.BOT_TOKEN }}
prerelease: false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
/Cargo.lock
21 changes: 21 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "unity-js-tools"
version = "1.0.0"
edition = "2021"
authors = ["神代綺凛 <i@loli.best>"]
license = "MIT"
description = "Tools for arkntools/unity-js"
repository = "https://github.com/arkntools/unity-js-tools"

[profile.release]
lto = true
opt-level = 3
codegen-units = 1

[lib]
crate-type = ["cdylib"]

[dependencies]
astc-decode = "0.3.1"
lz4_flex = "0.11.1"
wasm-bindgen = "0.2.87"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 神代綺凛

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# unity-js-tools

[![NPM version](https://img.shields.io/npm/v/@arkntools/unity-js-tools?style=flat-square)](https://www.npmjs.com/package/@arkntools/unity-js-tools)

一些给 [unity-js](https://github.com/arkntools/unity-js) 用的工具方法,从 rust 编译为 wasm
1 change: 1 addition & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wasm-pack build --release --target nodejs --scope arkntools
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
wasm-pack build --release --target nodejs --scope arkntools
33 changes: 33 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use astc_decode::{astc_decode, Footprint};
use lz4_flex::decompress;
use wasm_bindgen::prelude::*;

#[wasm_bindgen(js_name = decodeAstc)]
pub fn decode_astc(
data: &[u8],
width: u32,
height: u32,
block_width: u32,
block_height: u32,
) -> Result<Vec<u8>, JsError> {
let footprint = Footprint::new(block_width, block_height);
let mut result: Vec<u8> = vec![0; (width * height * 4) as usize];

let astc_result = astc_decode(data, width, height, footprint, |x, y, v4| {
let y = height - y - 1;
let ri = ((y * width + x) * 4) as usize;
for (i, v) in v4.iter().enumerate() {
result[ri + i] = *v;
}
});

match astc_result {
Ok(()) => Ok(result),
Err(e) => Err(JsError::new(&e.to_string())),
}
}

#[wasm_bindgen(js_name = decompressLz4)]
pub fn decompress_lz4(data: &[u8], size: usize) -> Result<Vec<u8>, JsError> {
decompress(data, size).map_err(|e| JsError::new(&e.to_string()))
}

0 comments on commit 6d77161

Please sign in to comment.