use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Machine {
pub name: String,
pub source_file: Option<String>,
pub rom_of: Option<String>,
pub clone_of: Option<String>,
pub is_bios: Option<bool>,
pub is_device: Option<bool>,
pub runnable: Option<bool>,
pub is_mechanical: Option<bool>,
pub sample_of: Option<String>,
pub description: Option<String>,
pub year: Option<String>,
pub manufacturer: Option<String>,
pub bios_sets: Vec<BiosSet>,
pub roms: Vec<Rom>,
pub device_refs: Vec<DeviceRef>,
pub software_list: Vec<Software>,
pub samples: Vec<Sample>,
pub driver_status: Option<String>,
pub languages: Vec<String>,
pub players: Option<String>,
pub series: Option<String>,
pub category: Option<String>,
pub subcategory: Option<String>,
pub is_mature: Option<bool>,
pub history_sections: Vec<HistorySection>,
pub disks: Vec<Disk>,
pub extended_data: Option<ExtendedData>,
pub resources: Vec<Resource>,
}
impl Machine {
pub fn new(name: String) -> Self {
Machine {
name,
source_file: None,
rom_of: None,
clone_of: None,
is_bios: None,
is_device: None,
runnable: None,
is_mechanical: None,
sample_of: None,
description: None,
year: None,
manufacturer: None,
bios_sets: Vec::new(),
roms: Vec::new(),
device_refs: Vec::new(),
software_list: Vec::new(),
samples: Vec::new(),
driver_status: None,
languages: Vec::new(),
players: None,
series: None,
category: None,
subcategory: None,
is_mature: None,
history_sections: Vec::new(),
disks: Vec::new(),
extended_data: Some(Default::default()),
resources: Vec::new(),
}
}
pub fn combine(&mut self, other: &Machine) {
if self.source_file.is_none() {
self.source_file = other.source_file.clone();
}
if self.rom_of.is_none() {
self.rom_of = other.rom_of.clone();
}
if self.clone_of.is_none() {
self.clone_of = other.clone_of.clone();
}
if self.is_bios.is_none() {
self.is_bios = other.is_bios;
}
if self.is_device.is_none() {
self.is_device = other.is_device;
}
if self.runnable.is_none() {
self.runnable = other.runnable;
}
if self.is_mechanical.is_none() {
self.is_mechanical = other.is_mechanical;
}
if self.sample_of.is_none() {
self.sample_of = other.sample_of.clone();
}
if self.description.is_none() {
self.description = other.description.clone();
}
if self.year.is_none() {
self.year = other.year.clone();
}
if self.manufacturer.is_none() {
self.manufacturer = other.manufacturer.clone();
}
if self.driver_status.is_none() {
self.driver_status = other.driver_status.clone();
}
if self.players.is_none() {
self.players = other.players.clone();
}
if self.series.is_none() {
self.series = other.series.clone();
}
if self.category.is_none() {
self.category = other.category.clone();
}
if self.subcategory.is_none() {
self.subcategory = other.subcategory.clone();
}
if self.is_mature.is_none() {
self.is_mature = other.is_mature;
}
self.bios_sets.extend(other.bios_sets.clone());
self.roms.extend(other.roms.clone());
self.device_refs.extend(other.device_refs.clone());
self.software_list.extend(other.software_list.clone());
self.samples.extend(other.samples.clone());
self.languages.extend(other.languages.clone());
self.history_sections.extend(other.history_sections.clone());
self.disks.extend(other.disks.clone());
self.resources.extend(other.resources.clone());
match (&mut self.extended_data, &other.extended_data) {
(Some(self_data), Some(other_data)) => {
self_data.combine(other_data);
}
(None, Some(other_data)) => {
self.extended_data = Some(other_data.clone());
}
_ => {}
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BiosSet {
pub name: String,
pub description: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Rom {
pub name: String,
pub size: u64,
pub merge: Option<String>,
pub status: Option<String>,
pub crc: Option<String>,
pub sha1: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceRef {
pub name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Software {
pub name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Sample {
pub name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Disk {
pub name: String,
pub sha1: Option<String>,
pub merge: Option<String>,
pub status: Option<String>,
pub region: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HistorySection {
pub name: String,
pub text: String,
pub order: usize,
}
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
pub struct ExtendedData {
pub name: Option<String>,
pub manufacturer: Option<String>,
pub players: Option<String>,
pub is_parent: Option<bool>,
pub year: Option<String>,
}
impl ExtendedData {
pub fn combine(&mut self, other: &ExtendedData) {
if self.name.is_none() {
self.name = other.name.clone();
}
if self.manufacturer.is_none() {
self.manufacturer = other.manufacturer.clone();
}
if self.players.is_none() {
self.players = other.players.clone();
}
if self.is_parent.is_none() {
self.is_parent = other.is_parent;
}
if self.year.is_none() {
self.year = other.year.clone();
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Resource {
pub type_: String,
pub name: String,
pub size: u64,
pub crc: String,
pub sha1: String,
}