backspace 0.1.0

Game engine.
Documentation
// Copyright 2024-2025 Gabriel Bjørnager Jensen.
//
// This file is part of Backspace.
//
// Backspace is free software: you can redistribute
// it and/or modify it under the terms of the GNU
// Affero General Public License as published by
// the Free Software Foundation, either version 3
// of the License, or (at your option) any later
// version.
//
// Backspace is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; with-
// out even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Affero General Public License for more details.
//
// You should have received a copy of the GNU Af-
// fero General Public License along with Back-
// space. If not, see
// <https://www.gnu.org/licenses/>.

use crate::engine::Engine;

/// An [`Engine`] builder.
#[derive(Clone, Debug)]
pub struct EngineBuilder {
	/// The application identifier.
	app_id: Option<Box<str>>,

	/// The application name.
	app_name: Option<Box<str>>,
}

impl EngineBuilder {
	/// Constructs a new engine builder.
	#[inline]
	#[must_use]
	pub(super) const fn new() -> Self {
		Self {
			app_id:   None,
			app_name: None,
		}
	}

	/// Specifies the application identifier.
	#[inline]
	#[must_use]
	pub fn with_app_id(mut self, app_id: &str) -> Self {
		self.app_id = Some(app_id.into());
		self
	}

	/// Specifies the application name.
	#[inline]
	#[must_use]
	pub fn with_app_name(mut self, app_name: &str) -> Self {
		self.app_name = Some(app_name.into());
		self
	}

	/// Builds the engine.
	///
	/// # Panics
	///
	/// All fields must be specified before building.
	/// If only a subset of fields are specified, this method will panic.
	#[inline]
	#[must_use]
	pub fn build(self) -> Engine {
		let app_id = self
			.app_id
			.expect("cannot construct engine without application identifier");

		let app_name = self
			.app_name
			.expect("cannot construct engine without application name");

		Engine {
			app_id,
			app_name,

			graphics: Default::default(),
		}
	}
}

impl Default for EngineBuilder {
	/// Equivalent to <code>[Engine]::[builder](Engine::builder)</code>.
	#[inline]
	fn default() -> Self {
		Self::new()
	}
}