Skip to content

Commit

Permalink
put base & template in own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Jun 30, 2024
1 parent cfd95da commit ef3ac8f
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 74 deletions.
44 changes: 44 additions & 0 deletions prototypes/src/prototypes/_template.rs
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
}
}
27 changes: 27 additions & 0 deletions prototypes/src/prototypes/base.rs
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
}
}
77 changes: 3 additions & 74 deletions prototypes/src/prototypes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Find template in _template.rs
crate::gen_prototypes!(
mod item: ItemID = ItemPrototype,
mod building: BuildingPrototypeID = BuildingPrototype,
Expand All @@ -13,77 +14,5 @@ crate::gen_prototypes!(
mod freightstation: FreightStationPrototypeID = FreightStationPrototype,
);

/** Prototype template. remplace $proto with the root name e.g Item
```rs
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
}
}
```
*/

#[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
}
}
mod base;
pub use base::*;

0 comments on commit ef3ac8f

Please sign in to comment.