From 0a9dc80583f9ad767d639682cbbc440e563b2b36 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Tue, 30 Jul 2024 23:43:47 +0300 Subject: [PATCH] Initial commit --- .gitignore | 16 +++++++ Cargo.toml | 18 +++++++ LICENSE | 9 ++++ README.md | 11 +++++ crates/parser/Cargo.toml | 9 ++++ crates/parser/src/lib.rs | 3 ++ crates/parser/src/stmt.rs | 8 ++++ crates/parser/src/stmt/bgload.rs | 9 ++++ crates/parser/src/stmt/setimg.rs | 9 ++++ crates/parser/src/types.rs | 21 ++++++++ flake.lock | 82 ++++++++++++++++++++++++++++++++ flake.nix | 41 ++++++++++++++++ src/main.rs | 3 ++ 13 files changed, 239 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 crates/parser/Cargo.toml create mode 100644 crates/parser/src/lib.rs create mode 100644 crates/parser/src/stmt.rs create mode 100644 crates/parser/src/stmt/bgload.rs create mode 100644 crates/parser/src/stmt/setimg.rs create mode 100644 crates/parser/src/types.rs create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3ca43ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +# ---> Rust +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..6352c62 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "saja" +version = "0.1.0" +edition = "2021" + +[workspace] +members = [ + "crates/parser", +] +resolver = "2" + +[workspace.dependencies] +compact_str = "0.8.0" + +saja-parser = { path = "crates/parser", version = "0.1.0" } + +[dependencies] + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..99c1f34 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2024 VienDesu + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..dd0ba47 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# saja + +VNDS engine implementation. + +# Architecture + +`saja` consist of two parts: + +1. `saja-parser` - parser of the vnds scripts format +2. `saja-project` - library for loading VNDS games as complete projects + diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml new file mode 100644 index 0000000..f294562 --- /dev/null +++ b/crates/parser/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "saja-parser" +version = "0.1.0" +edition = "2021" + +[dependencies] +chumsky = "0.9.3" +compact_str.workspace = true + diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs new file mode 100644 index 0000000..193b77e --- /dev/null +++ b/crates/parser/src/lib.rs @@ -0,0 +1,3 @@ +pub mod stmt; + +pub mod types; diff --git a/crates/parser/src/stmt.rs b/crates/parser/src/stmt.rs new file mode 100644 index 0000000..3501b38 --- /dev/null +++ b/crates/parser/src/stmt.rs @@ -0,0 +1,8 @@ +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub enum Stmt { + BgLoad(bgload::BgLoad), + SetImg(setimg::SetImg), +} + +pub mod bgload; +pub mod setimg; diff --git a/crates/parser/src/stmt/bgload.rs b/crates/parser/src/stmt/bgload.rs new file mode 100644 index 0000000..57ab218 --- /dev/null +++ b/crates/parser/src/stmt/bgload.rs @@ -0,0 +1,9 @@ +use compact_str::CompactString; + +use crate::types::Fadetime; + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct BgLoad { + pub file: CompactString, + pub fadetime: Option, +} diff --git a/crates/parser/src/stmt/setimg.rs b/crates/parser/src/stmt/setimg.rs new file mode 100644 index 0000000..f87f71c --- /dev/null +++ b/crates/parser/src/stmt/setimg.rs @@ -0,0 +1,9 @@ +use compact_str::CompactString; + +use crate::types::Position; + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] +pub struct SetImg { + pub file: CompactString, + pub position: Position, +} diff --git a/crates/parser/src/types.rs b/crates/parser/src/types.rs new file mode 100644 index 0000000..e641518 --- /dev/null +++ b/crates/parser/src/types.rs @@ -0,0 +1,21 @@ +use std::num::NonZeroU16; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[repr(transparent)] +pub struct Fadetime(pub NonZeroU16); + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[repr(transparent)] +pub struct Coord(pub i16); + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub struct Position(pub Coord, pub Coord); + +impl Position { + pub const fn offset(self, Offset(dx, dy): Offset) -> Self { + Self(Coord(self.0 .0 + dx.0), Coord(self.1 .0 + dy.0)) + } +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub struct Offset(pub Coord, pub Coord); diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c2e7d49 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1722185531, + "narHash": "sha256-veKR07psFoJjINLC8RK4DiLniGGMgF3QMlS4tb74S6k=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "52ec9ac3b12395ad677e8b62106f0b98c1f8569d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1722305989, + "narHash": "sha256-ljiuTGSFuEtudqFqp/5Wr1OuEsVCjur/F2CmlNujSjc=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "38c2f156fca1868c8be7195ddac150522752f6ab", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..906104f --- /dev/null +++ b/flake.nix @@ -0,0 +1,41 @@ +{ + description = "Saja"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + nixpkgs, + flake-utils, + rust-overlay, + ... + }: + flake-utils.lib.eachDefaultSystem(system: + let + overlays = [(import rust-overlay)]; + pkgs = import nixpkgs { inherit system overlays; }; + + rust = rec { + package = pkgs.rust-bin.stable.latest.default; + devPackage = package.override { + extensions = [ "rust-src" "rust-analyzer" ]; + }; + }; + in + { + devShells.default = pkgs.mkShell { + shellHook = '' + export PS1="(saja) $PS1" + ''; + buildInputs = [ rust.devPackage ]; + }; + } + ); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}