-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Prototype template. remplace $proto with the root name e.g Item | ||
|
||
use crate::{NoParent, Prototype, PrototypeBase, get_lua}; | ||
use mlua::Table; | ||
use std::ops::Deref; | ||
|
||
use super::*; | ||
|
||
/// $protoPrototype is | ||
#[derive(Clone, Debug)] | ||
pub struct $protoPrototype { | ||
pub base: $parent, | ||
pub id: $protoPrototypeID, | ||
} | ||
|
||
impl Prototype for $protoPrototype { | ||
type Parent = $parent; | ||
type ID = $protoPrototypeID; | ||
const NAME: &'static str = ; | ||
|
||
fn from_lua(table: &Table) -> mlua::Result<Self> { | ||
let base = $parent::from_lua(table)?; | ||
Ok(Self { | ||
id: Self::ID::new(&base.name), | ||
base, | ||
}) | ||
} | ||
|
||
fn id(&self) -> Self::ID { | ||
self.id | ||
} | ||
|
||
fn parent(&self) -> Option<&Self::Parent> { | ||
Some(&self.base) | ||
} | ||
} | ||
|
||
impl Deref for $protoPrototype { | ||
type Target = $parent; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.base | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#[derive(Debug, Clone, egui_inspect::Inspect)] | ||
pub struct PrototypeBase { | ||
pub name: String, | ||
pub order: String, | ||
pub label: String, | ||
} | ||
|
||
impl crate::Prototype for PrototypeBase { | ||
type Parent = crate::NoParent; | ||
type ID = (); | ||
const NAME: &'static str = "base"; | ||
|
||
fn from_lua(table: &mlua::Table) -> mlua::Result<Self> { | ||
use crate::get_lua; | ||
Ok(Self { | ||
name: get_lua(table, "name")?, | ||
order: get_lua(table, "order").unwrap_or(String::new()), | ||
label: get_lua(table, "label")?, | ||
}) | ||
} | ||
|
||
fn id(&self) -> Self::ID {} | ||
|
||
fn parent(&self) -> &Self::Parent { | ||
&crate::NoParent | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters