Skip to content

Commit 3d46662

Browse files
committed
Add web save editor
1 parent 77c5bb3 commit 3d46662

20 files changed

Lines changed: 4125 additions & 1 deletion

.github/workflows/pages.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [master]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: pages
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Setup Rust
24+
uses: dtolnay/rust-toolchain@stable
25+
26+
- name: Install wasm-pack
27+
run: cargo install wasm-pack
28+
29+
- name: Build WASM
30+
run: wasm-pack build --target web --out-dir ../web/src/wasm
31+
working-directory: uesave-wasm
32+
33+
- name: Setup Node
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: 22
37+
cache: npm
38+
cache-dependency-path: web/package-lock.json
39+
40+
- name: Install dependencies
41+
run: npm ci
42+
working-directory: web
43+
44+
- name: Build
45+
run: npm run build
46+
working-directory: web
47+
env:
48+
BASE_PATH: /${{ github.event.repository.name }}
49+
50+
- name: Upload artifact
51+
uses: actions/upload-pages-artifact@v3
52+
with:
53+
path: web/dist
54+
55+
deploy:
56+
needs: build
57+
runs-on: ubuntu-latest
58+
environment:
59+
name: github-pages
60+
url: ${{ steps.deployment.outputs.page_url }}
61+
steps:
62+
- name: Deploy to GitHub Pages
63+
id: deployment
64+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
/target
2+
/web/src/lib/licenses.json
3+
/web/dist
4+
node_modules

Cargo.lock

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = ["uesave", "uesave_cli"]
3+
members = ["uesave", "uesave_cli", "uesave-wasm"]
44

55
[workspace.package]
66
version = "0.6.2"

about.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
accepted = [
2+
"Apache-2.0",
3+
"MIT",
4+
"BSD-2-Clause",
5+
"BSD-3-Clause",
6+
"ISC",
7+
"Zlib",
8+
"CC0-1.0",
9+
"Unlicense",
10+
"Unicode-DFS-2016",
11+
]

uesave-wasm/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "uesave-wasm"
3+
version.workspace = true
4+
edition.workspace = true
5+
authors.workspace = true
6+
repository.workspace = true
7+
homepage.workspace = true
8+
description.workspace = true
9+
keywords.workspace = true
10+
license.workspace = true
11+
12+
[lib]
13+
crate-type = ["cdylib", "rlib"]
14+
15+
[dependencies]
16+
uesave = { path = "../uesave" }
17+
wasm-bindgen = "0.2"
18+
serde_json = "1.0"
19+
console_error_panic_hook = "0.1"

uesave-wasm/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::io::Cursor;
2+
3+
use uesave::{Save, SaveReader};
4+
use wasm_bindgen::prelude::*;
5+
6+
#[wasm_bindgen(start)]
7+
pub fn init() {
8+
console_error_panic_hook::set_once();
9+
}
10+
11+
#[wasm_bindgen]
12+
pub fn sav_to_json(data: &[u8]) -> Result<String, JsValue> {
13+
let save = SaveReader::new()
14+
.error_to_raw(true)
15+
.read(Cursor::new(data))
16+
.map_err(|e| JsValue::from_str(&format!("{e}")))?;
17+
18+
serde_json::to_string_pretty(&save).map_err(|e| JsValue::from_str(&format!("{e}")))
19+
}
20+
21+
#[wasm_bindgen]
22+
pub fn json_to_sav(json: &str) -> Result<Vec<u8>, JsValue> {
23+
let save: Save = serde_json::from_str(json).map_err(|e| JsValue::from_str(&format!("{e}")))?;
24+
25+
let mut buffer = Vec::new();
26+
save.write(&mut buffer)
27+
.map_err(|e| JsValue::from_str(&format!("{e}")))?;
28+
29+
Ok(buffer)
30+
}

web/index.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta name="description" content="Unreal Engine .sav editor" />
7+
<meta name="theme-color" content="#4d9a4d" />
8+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
9+
<link rel="canonical" href="https://trumank.github.io/uesave" />
10+
11+
<!-- Open Graph -->
12+
<meta property="og:title" content="uesave editor" />
13+
<meta property="og:description" content="Unreal Engine .sav editor" />
14+
<meta property="og:type" content="website" />
15+
<meta property="og:url" content="https://trumank.github.io/uesave" />
16+
17+
<title>uesave editor</title>
18+
<style>
19+
* {
20+
box-sizing: border-box;
21+
}
22+
html, body, #app {
23+
margin: 0;
24+
height: 100vh;
25+
}
26+
body {
27+
font-family: system-ui, -apple-system, sans-serif;
28+
background: #fff;
29+
color: #1e1e1e;
30+
}
31+
</style>
32+
</head>
33+
<body>
34+
<div id="app"></div>
35+
<script type="module" src="/src/main.ts"></script>
36+
</body>
37+
</html>

0 commit comments

Comments
 (0)