aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
l---------.github/CODE_OF_CONDUCT.md1
-rw-r--r--clients/www/package.json3
-rw-r--r--clients/www/src-tauri/Cargo.toml1
-rw-r--r--libs/zora-rs/Cargo.toml5
l---------libs/zora-rs/LICENSE1
-rw-r--r--libs/zora-rs/README.md12
-rw-r--r--libs/zora-rs/src/enums.rs89
-rw-r--r--libs/zora-rs/src/lib.rs77
-rw-r--r--libs/zora-rs/tests/web.rs3
-rw-r--r--package.json2
-rw-r--r--pnpm-lock.yaml6
-rw-r--r--pnpm-workspace.yaml2
12 files changed, 171 insertions, 31 deletions
diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md
deleted file mode 120000
index dc1dc0c..0000000
--- a/.github/CODE_OF_CONDUCT.md
+++ /dev/null
@@ -1 +0,0 @@
-/dev/null \ No newline at end of file
diff --git a/clients/www/package.json b/clients/www/package.json
index a45dfb6..7ef49c3 100644
--- a/clients/www/package.json
+++ b/clients/www/package.json
@@ -13,6 +13,9 @@
"lint": "prettier --check . && eslint .",
"format": "prettier --write ."
},
+ "dependencies": {
+ "zora-rs": "workspace:*"
+ },
"devDependencies": {
"@skeletonlabs/skeleton": "2.9.0",
"@skeletonlabs/tw-plugin": "0.3.1",
diff --git a/clients/www/src-tauri/Cargo.toml b/clients/www/src-tauri/Cargo.toml
index 5f6ddab..bdb35e7 100644
--- a/clients/www/src-tauri/Cargo.toml
+++ b/clients/www/src-tauri/Cargo.toml
@@ -20,6 +20,7 @@ serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.6.1", features = [] }
specta = "1.0.5"
tauri-specta = { version = "1.0.2", features = ["javascript", "typescript"] }
+zora-rs = { path = "../../../libs/zora-rs" }
[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
diff --git a/libs/zora-rs/Cargo.toml b/libs/zora-rs/Cargo.toml
index c11df29..5535a13 100644
--- a/libs/zora-rs/Cargo.toml
+++ b/libs/zora-rs/Cargo.toml
@@ -13,12 +13,15 @@ crate-type = ["cdylib", "rlib"]
[features]
default = ["console_error_panic_hook"]
+
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
-specta = { version = "1.0.5", features = ["typescript"] }
+
+[target.'cfg(target_family = "wasm")'.dependencies]
wasm-bindgen = "0.2.84"
+
# The `console_error_panic_hook` crate provides better debugging of panics by
# logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
diff --git a/libs/zora-rs/LICENSE b/libs/zora-rs/LICENSE
new file mode 120000
index 0000000..30cff74
--- /dev/null
+++ b/libs/zora-rs/LICENSE
@@ -0,0 +1 @@
+../../LICENSE \ No newline at end of file
diff --git a/libs/zora-rs/README.md b/libs/zora-rs/README.md
index e69de29..bce0ffe 100644
--- a/libs/zora-rs/README.md
+++ b/libs/zora-rs/README.md
@@ -0,0 +1,12 @@
+# zora-rs
+
+`zora-rs` is a Rust implementation of The Legend of Zelda Oracle of Ages and Oracle of Seasons password system.
+It is heavily inspired by the C# implementation [zora-sharp](https://github.com/kabili207/zora-sharp).
+
+## Usage
+
+TODO
+
+## License
+
+MIT
diff --git a/libs/zora-rs/src/enums.rs b/libs/zora-rs/src/enums.rs
index a16718b..62cb8ac 100644
--- a/libs/zora-rs/src/enums.rs
+++ b/libs/zora-rs/src/enums.rs
@@ -1,33 +1,84 @@
-use serde::{Serialize, Deserialize};
-use specta::Type;
-mod utils;
+use serde::{Deserialize, Serialize};
+#[cfg(target_family = "wasm")]
+use wasm_bindgen::prelude::*;
/// The region of the game.
-#[derive(Debug, Clone, Type, Serialize, Deserialize)]
+///
+/// Currently only the US version is supported, though the EU version will probably work too.
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Region {
- US,
- EU,
- JP,
+ US,
+ // EU,
+ // JP,
}
/// Which game
-#[derive(Debug, Clone, Type, Serialize, Deserialize)]
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Game {
- Ages,
- Seasons,
+ Ages,
+ Seasons,
}
-#[derive(Debug, Clone, Type, Serialize, Deserialize)]
+/// The choice of animal companion
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Animal {
- Ricky = 0x0b,
- Dimitri = 0x0c,
- Moosh = 0x0d,
+ Ricky = 0x0b,
+ Dimitri = 0x0c,
+ Moosh = 0x0d,
}
-#[derive(Debug, Clone, Type, Serialize, Deserialize)]
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub enum RupeesGiven {
+ /// One Rupee
+ One = 0,
+ /// Ten Rupees
+ Ten = 2,
+ /// Fifty Rupees
+ Fifty = 5,
+ // 150 Rupees
+ OneFifty = 8,
+}
+
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub enum SleepMethod {
+ Sing = 0,
+ Play = 10,
+}
+
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub enum Child {
- None,
- Curious,
- Shy,
- Hyperactive
+ None,
+ Curious,
+ Shy,
+ Hyperactive,
+}
+
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub enum AnimalChoice {
+ None = 0,
+ Ricky = 0x0b,
+ Dimitri = 0x0c,
+ Moosh = 0x0d,
+}
+
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[repr(C)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub enum ChildQuestion {
+ NoEgg = 0,
+ YesChicken = 4,
} \ No newline at end of file
diff --git a/libs/zora-rs/src/lib.rs b/libs/zora-rs/src/lib.rs
index 239f3af..8a06dd5 100644
--- a/libs/zora-rs/src/lib.rs
+++ b/libs/zora-rs/src/lib.rs
@@ -1,13 +1,76 @@
-mod utils;
+use std::fmt;
+use serde::{Deserialize, Serialize};
+#[cfg(target_family = "wasm")]
use wasm_bindgen::prelude::*;
-#[wasm_bindgen]
-extern "C" {
- fn alert(s: &str);
+use enums::*;
+
+/// Enumerations for the various choices in the games.
+pub mod enums;
+
+/// The structure that holds the save information.
+///
+/// This is the main struct that is used to hold all the information about the save.
+/// This is used to serialize and deserialize the save data to and from a file.
+///
+/// # Example
+///
+/// ```rust
+/// use zora_rs::Save;
+///
+/// let save = Save {
+/// region: Region::US,
+/// game: Game::OcarinaOfTime,
+/// animal: Animal::Pony,
+/// rupees_given: RupeesGiven::No,
+/// sleep_method: SleepMethod::No,
+/// child: Child::No,
+/// animal_choice: AnimalChoice::No,
+/// child_question: ChildQuestion::No,
+/// hero: "Link".to_string(),
+/// child_name: "Child".to_string(),
+/// is_linked: false,
+/// is_hero_quest: false,
+/// };
+/// ```
+#[cfg_attr(target_family = "wasm", wasm_bindgen)]
+#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
+pub struct Save {
+ region: Region,
+ game: Game,
+ animal: Animal,
+ rupees_given: RupeesGiven,
+ sleep_method: SleepMethod,
+ child: Child,
+ animal_choice: AnimalChoice,
+ child_question: ChildQuestion,
+ hero: String,
+ child_name: String,
+ is_linked: bool,
+ is_hero_quest: bool,
}
-#[wasm_bindgen]
-pub fn greet() {
- alert("Hello, zora-rs!");
+impl Save {
+ pub fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "")
+ }
}
+
+/// The cipher used by the non-Japanese versions of the game.
+/// "EN" is a misnomer, as it is used by all non-Japanese versions of the game.
+///
+/// Stolen (with love) from https://github.com/kabili207/zora-sharp/blob/master/src/Secret.cs#L53
+pub static EN_CIPHER: [u8; 48] = [
+ 21, 35, 46, 4, 13, 63, 26, 16, 58, 47, 30, 32, 15, 62, 54, 55, 9, 41, 59, 49, 2, 22, 61, 56,
+ 40, 19, 52, 50, 1, 11, 10, 53, 14, 27, 18, 44, 33, 45, 37, 48, 25, 42, 6, 57, 60, 23, 51, 24,
+];
+
+/// The cipher used by the Japanese version of the game.
+///
+/// Stolen (lovingly :)) from https://github.com/kabili207/zora-sharp/blob/master/src/Secret.cs#L45
+pub static JP_CIPHER: [u8; 48] = [
+ 0x31, 0x09, 0x29, 0x3b, 0x18, 0x3c, 0x17, 0x33, 0x35, 0x01, 0x0b, 0x0a, 0x30, 0x21, 0x2d, 0x25,
+ 0x20, 0x3a, 0x2f, 0x1e, 0x39, 0x19, 0x2a, 0x06, 0x04, 0x15, 0x23, 0x2e, 0x32, 0x28, 0x13, 0x34,
+ 0x10, 0x0d, 0x3f, 0x1a, 0x37, 0x0f, 0x3e, 0x36, 0x38, 0x02, 0x16, 0x3d, 0x2c, 0x0e, 0x1b, 0x12,
+];
diff --git a/libs/zora-rs/tests/web.rs b/libs/zora-rs/tests/web.rs
index de5c1da..9bed16c 100644
--- a/libs/zora-rs/tests/web.rs
+++ b/libs/zora-rs/tests/web.rs
@@ -1,9 +1,10 @@
//! Test suite for the Web and headless browsers.
-#![cfg(target_arch = "wasm32")]
+#![cfg(target_family = "wasm")]
extern crate wasm_bindgen_test;
use wasm_bindgen_test::*;
+use zora_rs::*;
wasm_bindgen_test_configure!(run_in_browser);
diff --git a/package.json b/package.json
index d63ec53..e3d3eed 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "zorascript",
"scripts": {
"build-wasm": "wasm-pack build ./libs/zora-rs",
- "build-tauri": "tauri build"
+ "build-tauri": "env TAURI=true tauri build"
},
"keywords": [],
"author": "Matt Strapp <matt@mattstrapp.net>",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a8fc82c..cc5e749 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -31,6 +31,10 @@ importers:
version: 0.12.1
clients/www:
+ dependencies:
+ zora-rs:
+ specifier: workspace:*
+ version: link:../../libs/zora-rs/pkg
devDependencies:
'@skeletonlabs/skeleton':
specifier: 2.9.0
@@ -108,6 +112,8 @@ importers:
specifier: 0.2.1
version: 0.2.1(vite@5.2.8)
+ libs/zora-rs/pkg: {}
+
packages:
/@aashutoshrathi/word-wrap@1.2.6:
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index daa543c..3946dc5 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -1,3 +1,3 @@
packages:
- "clients/*"
- - "libs/*" \ No newline at end of file
+ - "libs/**/*" \ No newline at end of file