Initial commit
This commit is contained in:
commit
f1ac2e85dd
13 changed files with 1459 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/target
|
||||
1267
Cargo.lock
generated
Normal file
1267
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "itemse"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.45.1", features = ["full"] }
|
||||
warp = "0.3.7"
|
||||
13
src/db/item.rs
Normal file
13
src/db/item.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
use crate::item::{ItemID, ItemType};
|
||||
|
||||
use super::ItemseDB;
|
||||
|
||||
impl ItemseDB<ItemID> for ItemType {
|
||||
fn get_from_db(id: &ItemID) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn save(&self) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
13
src/db/location.rs
Normal file
13
src/db/location.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
use crate::location::{Location, LocationID};
|
||||
|
||||
use super::ItemseDB;
|
||||
|
||||
impl ItemseDB<LocationID> for Location {
|
||||
fn get_from_db(id: &LocationID) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn save(&self) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
25
src/db/mod.rs
Normal file
25
src/db/mod.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
mod item;
|
||||
mod location;
|
||||
mod tag;
|
||||
|
||||
pub static DATABASE: Arc<Mutex>
|
||||
|
||||
pub trait ItemseDB<ID> {
|
||||
fn get_from_db(id: &ID) -> Self;
|
||||
fn save(&self);
|
||||
}
|
||||
|
||||
pub trait ItemseID<Object> {
|
||||
fn get(&self) -> Object;
|
||||
}
|
||||
|
||||
impl<ID, Object> ItemseID<Object> for ID
|
||||
where
|
||||
Object: ItemseDB<ID>,
|
||||
{
|
||||
fn get(&self) -> Object {
|
||||
Object::get_from_db(self)
|
||||
}
|
||||
}
|
||||
13
src/db/tag.rs
Normal file
13
src/db/tag.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
use crate::tag::{Tag, TagID};
|
||||
|
||||
use super::ItemseDB;
|
||||
|
||||
impl ItemseDB<TagID> for Tag {
|
||||
fn get_from_db(id: &TagID) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn save(&self) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
8
src/item/ident.rs
Normal file
8
src/item/ident.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#[derive(Clone)]
|
||||
pub struct ItemID {}
|
||||
|
||||
impl ItemID {
|
||||
pub fn new() -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
38
src/item/mod.rs
Normal file
38
src/item/mod.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
mod ident;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub use ident::ItemID;
|
||||
|
||||
use crate::{
|
||||
location::LocationID,
|
||||
tag::{TagID, TagVal},
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ItemStack {
|
||||
id: ItemID,
|
||||
item_type: ItemType,
|
||||
home: LocationID,
|
||||
amount: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ItemType {
|
||||
parent: Option<ItemID>,
|
||||
id: ItemID,
|
||||
name: String,
|
||||
description: String,
|
||||
properties: HashMap<TagID, TagVal>,
|
||||
}
|
||||
|
||||
impl ItemType {
|
||||
pub fn child(&self, name: String, desc: String) -> ItemType {
|
||||
ItemType {
|
||||
parent: Some(self.id.clone()),
|
||||
id: ItemID::new(),
|
||||
name,
|
||||
description: desc,
|
||||
properties: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/location/ident.rs
Normal file
8
src/location/ident.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#[derive(Clone)]
|
||||
pub struct LocationID {}
|
||||
|
||||
impl LocationID {
|
||||
pub fn new() -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
39
src/location/mod.rs
Normal file
39
src/location/mod.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
pub use ident::LocationID;
|
||||
|
||||
use crate::item::ItemStack;
|
||||
|
||||
mod ident;
|
||||
|
||||
pub struct Location {
|
||||
pub parent: Option<LocationID>,
|
||||
pub id: LocationID,
|
||||
pub name: String,
|
||||
pub item: Option<ItemStack>,
|
||||
}
|
||||
|
||||
impl Location {
|
||||
pub fn child(&self, name: String) -> Location {
|
||||
Location {
|
||||
parent: Some(self.id.clone()),
|
||||
id: LocationID::new(),
|
||||
name,
|
||||
item: None,
|
||||
}
|
||||
}
|
||||
pub fn has_item(&self) -> bool {
|
||||
self.item.is_some()
|
||||
}
|
||||
pub fn take(&mut self) -> Option<ItemStack> {
|
||||
let item = self.item.take();
|
||||
self.save();
|
||||
item
|
||||
}
|
||||
pub fn put(&mut self, item: ItemStack) -> Result<(), ItemStack> {
|
||||
let prev = self.item.take();
|
||||
self.item = Some(item);
|
||||
if let Some(prev) = prev {
|
||||
return Err(prev);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
8
src/main.rs
Normal file
8
src/main.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
pub mod db;
|
||||
pub mod item;
|
||||
pub mod location;
|
||||
pub mod tag;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
18
src/tag/mod.rs
Normal file
18
src/tag/mod.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use crate::item::ItemID;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct TagID {}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Tag {
|
||||
id: TagID,
|
||||
default_value: TagVal,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum TagVal {
|
||||
Str(String),
|
||||
Int(i64),
|
||||
Num(f64),
|
||||
Item(ItemID),
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue