use crate::config::GenerationConfig;
use crate::model::geometry::{GridPoint, WorldPoint};
use crate::model::room::RoomType;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GenerationRequest {
pub seed: Option<u64>,
pub config: GenerationConfig,
pub constraints: Vec<Constraint>,
pub runtime_context: Option<RuntimeContext>,
pub trace_id: Option<String>,
}
impl GenerationRequest {
pub fn new(config: GenerationConfig) -> Self {
Self {
seed: None,
config,
constraints: Vec::new(),
runtime_context: None,
trace_id: None,
}
}
pub fn with_seed(mut self, seed: u64) -> Self {
self.seed = Some(seed);
self
}
pub fn with_trace_id(mut self, trace_id: String) -> Self {
self.trace_id = Some(trace_id);
self
}
pub fn with_constraints(mut self, constraints: Vec<Constraint>) -> Self {
self.constraints = constraints;
self
}
pub fn with_runtime_context(mut self, ctx: RuntimeContext) -> Self {
self.runtime_context = Some(ctx);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct RuntimeContext {
pub focus_position: Option<WorldPoint>,
pub interest_radius: Option<f32>,
pub requested_chunks: Vec<ChunkId>,
pub caller_tag: Option<String>,
}
pub use super::ChunkId;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Constraint {
Anchor(AnchorConstraint),
ExclusionZone(ExclusionZoneConstraint),
Template(TemplateConstraint),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct AnchorConstraint {
pub label: String,
pub room_id: Option<String>,
pub room_type: Option<RoomType>,
pub target_grid_pos: Option<GridPoint>,
}
impl AnchorConstraint {
pub fn new(label: impl Into<String>) -> Self {
Self {
label: label.into(),
room_id: None,
room_type: None,
target_grid_pos: None,
}
}
pub fn with_room_id(mut self, id: impl Into<String>) -> Self {
self.room_id = Some(id.into());
self
}
pub fn with_room_type(mut self, t: RoomType) -> Self {
self.room_type = Some(t);
self
}
pub fn with_target_grid_pos(mut self, pos: GridPoint) -> Self {
self.target_grid_pos = Some(pos);
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ExclusionZoneConstraint {
pub label: String,
pub min: GridPoint,
pub max: GridPoint,
pub exclude_rooms: bool,
pub exclude_spawns: bool,
}
impl ExclusionZoneConstraint {
pub fn new(label: impl Into<String>, min: GridPoint, max: GridPoint) -> Self {
Self {
label: label.into(),
min,
max,
exclude_rooms: false,
exclude_spawns: true,
}
}
pub fn with_exclude_rooms(mut self, v: bool) -> Self {
self.exclude_rooms = v;
self
}
pub fn with_exclude_spawns(mut self, v: bool) -> Self {
self.exclude_spawns = v;
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TemplateConstraint {
pub room_id: Option<String>,
pub room_type: Option<RoomType>,
pub template_ref: String,
}
impl TemplateConstraint {
pub fn new(template_ref: impl Into<String>) -> Self {
Self {
room_id: None,
room_type: None,
template_ref: template_ref.into(),
}
}
pub fn with_room_id(mut self, id: impl Into<String>) -> Self {
self.room_id = Some(id.into());
self
}
pub fn with_room_type(mut self, t: RoomType) -> Self {
self.room_type = Some(t);
self
}
}