27 lines
543 B
Rust
27 lines
543 B
Rust
use std::cell::RefCell;
|
|
use std::rc::Rc;
|
|
use skunk2d::{Image, Vec2};
|
|
use crate::unit::Unit;
|
|
|
|
pub struct UnitKind {
|
|
pub sprite: Rc<Image>,
|
|
pub name: String
|
|
}
|
|
|
|
impl UnitKind {
|
|
pub fn new(name: &str) -> Rc<Self> {
|
|
UnitKind {
|
|
sprite: Image::load(format!("assets/units/{}.gif", name).as_str()),
|
|
name: name.into()
|
|
}.into()
|
|
}
|
|
|
|
pub fn spawn(self: Rc<Self>, pos: Vec2<i32>) -> Rc<RefCell<Unit>> {
|
|
RefCell::new(Unit {
|
|
kind: self,
|
|
pos
|
|
}).into()
|
|
}
|
|
}
|
|
|