feat: Basic structs

- Added Account struct
- Added Config struct
- Added empty Map struct
- Added Quest struct
This commit is contained in:
Alexey 2025-11-28 14:06:12 +03:00
commit 4e3c137f8b
8 changed files with 441 additions and 0 deletions

275
Cargo.lock generated Normal file
View file

@ -0,0 +1,275 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anstream"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
[[package]]
name = "anstyle-parse"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]]
name = "clap"
version = "4.5.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9e340e012a1bf4935f5282ed1436d1489548e8f72308207ea5df0e23d2d03f8"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.53"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d76b5d13eaa18c901fd2f7fca939fefe3a0727a953561fefdf3b2922b8569d00"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_lex"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "hashbrown"
version = "0.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"
[[package]]
name = "indexmap"
version = "2.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ad4bb2b565bca0645f4d68c5c9af97fba094e9791da685bf83cb5f3ce74acf2"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "proc-macro2"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a338cc41d27e6cc6dce6cefc13a0729dfbb81c262b1f519331575dd80ef3067f"
dependencies = [
"proc-macro2",
]
[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_spanned"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e24345aa0fe688594e73770a5f6d1b216508b4f93484c0026d521acd30134392"
dependencies = [
"serde_core",
]
[[package]]
name = "squad-quest"
version = "0.1.0"
dependencies = [
"clap",
"serde",
"toml",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.111"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "390cc9a294ab71bdb1aa2e99d13be9c753cd2d7bd6560c77118597410c4d2e87"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "toml"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0dc8b1fb61449e27716ec0e1bdf0f6b8f3e8f6b05391e8497b8b6d7804ea6d8"
dependencies = [
"indexmap",
"serde_core",
"serde_spanned",
"toml_datetime",
"toml_parser",
"toml_writer",
"winnow",
]
[[package]]
name = "toml_datetime"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533"
dependencies = [
"serde_core",
]
[[package]]
name = "toml_parser"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e"
dependencies = [
"winnow",
]
[[package]]
name = "toml_writer"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8b2b54733674ad286d16267dcfc7a71ed5c776e4ac7aa3c3e2561f7c637bf2"
[[package]]
name = "unicode-ident"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link",
]
[[package]]
name = "winnow"
version = "0.7.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"

View file

@ -4,3 +4,6 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
clap = "4.5.53"
serde = { version = "1.0.228", features = ["derive"] }
toml = "0.9.8"

10
cfg/config.toml Normal file
View file

@ -0,0 +1,10 @@
# Default config
# Path to quests folder relative to config
quests_path = "./quests"
# Path to accounts folder relative to config
accounts_path = "./accounts"
# Path to map .toml file relative to config
map = "./map.toml"

24
src/account/mod.rs Normal file
View file

@ -0,0 +1,24 @@
//! Module for handling user accounts
use serde::{ Serialize, Deserialize };
fn default_id() -> String {
"none".to_string()
}
/// User account struct, which can be (de-)serialized from/into TOML
#[derive(Serialize, Deserialize)]
pub struct Account {
/// User id, specific to used service
#[serde(default = "default_id")]
pub id: String,
/// User balance,
#[serde(default)]
pub balance: u32,
/// Id of room node where user is located
#[serde(default)]
pub location: u16
}

55
src/config/mod.rs Normal file
View file

@ -0,0 +1,55 @@
//! Module for handling configuration
use std::path::PathBuf;
use serde::Deserialize;
/// Struct for containing paths to other (de-)serializable things
#[derive(Deserialize)]
pub struct Config {
/// Path to serialized [quests][`crate::quest::Quest`] folder
#[serde(default)]
pub quests_path: PathBuf,
/// Path to serialized [accounts][`crate::account::Account`] folder
#[serde(default)]
pub accounts_path: PathBuf,
/// Path to serialized [map][`crate::map::Map`] file
#[serde(default)]
pub map: PathBuf
}
impl Default for Config {
fn default() -> Self {
Config {
quests_path: "quests".into(),
accounts_path: "accounts".into(),
map: "map.toml".into()
}
}
}
impl Config {
/// Deserialize config from TOML
pub fn load(path: PathBuf) -> Self {
match std::fs::read_to_string(path) {
Ok(string) => {
match toml::from_str::<Config>(&string) {
Ok(conf) => {
println!("Successfully loaded config");
conf
},
Err(error) => {
eprintln!("Error on parsing config: {error}");
Config::default()
}
}
},
Err(error) => {
eprintln!("Error on reading config path: {error}");
Config::default()
}
}
}
}

View file

@ -0,0 +1,8 @@
//! This crate allows to build primitive RPG-like system for community events.
#![warn(missing_docs)]
pub mod account;
pub mod config;
pub mod map;
pub mod quest;

4
src/map/mod.rs Normal file
View file

@ -0,0 +1,4 @@
//! Module for handling map, which is a graph of rooms
#![allow(dead_code)]
struct Map;

62
src/quest/mod.rs Normal file
View file

@ -0,0 +1,62 @@
//! Module for handling text-based quests and user answers
use serde::{ Serialize, Deserialize };
/// Difficulty of the quest
#[derive(Serialize, Deserialize)]
pub enum QuestDifficulty {
/// Easy quest
Easy,
/// Normal quest
Normal,
/// Hard quest
Hard,
/// Special case of hard quests. Also is a default value for enum
Secret
}
impl Default for QuestDifficulty {
fn default() -> Self {
QuestDifficulty::Secret
}
}
fn default_name() -> String {
"Slay the dragon".to_string()
}
fn default_description() -> String {
"Just do it in any way".to_string()
}
fn default_answer() -> String {
"Attachment should show that the dragon was slain".to_string()
}
/// Quest struct
#[derive(Serialize, Deserialize)]
pub struct Quest {
/// Quest identifier
#[serde(default)]
pub id: u16,
/// Difficulty of this quest
#[serde(default)]
pub difficulty: QuestDifficulty,
/// Reward for the quest
#[serde(default)]
pub reward: u32,
/// Visible quest name
#[serde(default = "default_name")]
pub name: String,
/// Visible quest description
#[serde(default = "default_description")]
pub description: String,
/// Quest answer, available for admins
#[serde(default = "default_answer")]
pub answer: String,
}