📦 Game Update 13963 (2)

This commit is contained in:
a2x
2023-10-20 15:23:43 +10:00
parent 415cbf1ec5
commit 74a0693f53
100 changed files with 845 additions and 630 deletions

View File

@@ -2,6 +2,7 @@ use std::io::{Result, Write};
use super::FileBuilder;
/// Represents a C++ header file builder.
#[derive(Debug, PartialEq)]
pub struct CppFileBuilder;
@@ -17,7 +18,12 @@ impl FileBuilder for CppFileBuilder {
Ok(())
}
fn write_namespace(&mut self, output: &mut dyn Write, name: &str, comment: Option<&str>) -> Result<()> {
fn write_namespace(
&mut self,
output: &mut dyn Write,
name: &str,
comment: Option<&str>,
) -> Result<()> {
if let Some(comment) = comment {
write!(output, "namespace {} {{ // {}\n", name, comment)?;
} else {

View File

@@ -2,6 +2,7 @@ use std::io::{Result, Write};
use super::FileBuilder;
/// Represents a C# file builder.
#[derive(Debug, PartialEq)]
pub struct CSharpFileBuilder;
@@ -14,7 +15,12 @@ impl FileBuilder for CSharpFileBuilder {
Ok(())
}
fn write_namespace(&mut self, output: &mut dyn Write, name: &str, comment: Option<&str>) -> Result<()> {
fn write_namespace(
&mut self,
output: &mut dyn Write,
name: &str,
comment: Option<&str>,
) -> Result<()> {
if let Some(comment) = comment {
write!(output, "public static class {} {{ // {}\n", name, comment)?;
} else {

View File

@@ -1,12 +1,22 @@
use std::io::{Result, Write};
/// Represents a file builder.
pub trait FileBuilder {
/// Returns the file extension.
fn extension(&mut self) -> &str;
/// Writes the top level of the file.
fn write_top_level(&mut self, output: &mut dyn Write) -> Result<()>;
fn write_namespace(&mut self, output: &mut dyn Write, name: &str, comment: Option<&str>) -> Result<()>;
/// Writes a namespace.
fn write_namespace(
&mut self,
output: &mut dyn Write,
name: &str,
comment: Option<&str>,
) -> Result<()>;
/// Writes a variable.
fn write_variable(
&mut self,
output: &mut dyn Write,
@@ -15,5 +25,6 @@ pub trait FileBuilder {
comment: Option<&str>,
) -> Result<()>;
/// Writes a closure.
fn write_closure(&mut self, output: &mut dyn Write, eof: bool) -> Result<()>;
}

View File

@@ -1,25 +1,30 @@
use std::{io::{Result, Write}, collections::BTreeMap};
use std::{
collections::BTreeMap,
io::{Result, Write},
};
use serde::Serialize;
use super::FileBuilder;
/// Represents an offset value in JSON format.
#[derive(Debug, PartialEq, Default, Serialize)]
struct JsonOffsetValue {
value: usize,
comment: Option<String>,
}
/// Represents a module in JSON format.
#[derive(Debug, PartialEq, Default, Serialize)]
struct JsonMod {
struct JsonModule {
data: BTreeMap<String, JsonOffsetValue>,
comment: Option<String>,
}
/// Represents a JSON file builder.
#[derive(Debug, PartialEq, Default)]
pub struct JsonFileBuilder {
data: BTreeMap<String, JsonMod>,
data: BTreeMap<String, JsonModule>,
current_namespace: String,
}
@@ -32,7 +37,12 @@ impl FileBuilder for JsonFileBuilder {
Ok(())
}
fn write_namespace(&mut self, _output: &mut dyn Write, name: &str, comment: Option<&str>) -> Result<()> {
fn write_namespace(
&mut self,
_output: &mut dyn Write,
name: &str,
comment: Option<&str>,
) -> Result<()> {
self.current_namespace = name.to_string();
self.data.entry(name.to_string()).or_default().comment = comment.map(str::to_string);
@@ -46,11 +56,17 @@ impl FileBuilder for JsonFileBuilder {
value: usize,
comment: Option<&str>,
) -> Result<()> {
self.data.entry(self.current_namespace.clone()).or_default().data
.insert(name.to_string(), JsonOffsetValue {
value: value,
comment: comment.map(str::to_string)
});
self.data
.entry(self.current_namespace.clone())
.or_default()
.data
.insert(
name.to_string(),
JsonOffsetValue {
value: value,
comment: comment.map(str::to_string),
},
);
Ok(())
}

View File

@@ -14,6 +14,7 @@ pub mod json_file_builder;
pub mod python_file_builder;
pub mod rust_file_builder;
/// Represents a file builder enum.
#[derive(Debug, PartialEq)]
pub enum FileBuilderEnum {
CppFileBuilder(CppFileBuilder),
@@ -32,7 +33,12 @@ impl FileBuilder for FileBuilderEnum {
self.as_mut().write_top_level(output)
}
fn write_namespace(&mut self, output: &mut dyn Write, name: &str, comment: Option<&str>) -> Result<()> {
fn write_namespace(
&mut self,
output: &mut dyn Write,
name: &str,
comment: Option<&str>,
) -> Result<()> {
self.as_mut().write_namespace(output, name, comment)
}

View File

@@ -2,6 +2,7 @@ use std::io::{Result, Write};
use super::FileBuilder;
/// Represents a Python file builder.
#[derive(Debug, PartialEq)]
pub struct PythonFileBuilder;
@@ -14,7 +15,12 @@ impl FileBuilder for PythonFileBuilder {
Ok(())
}
fn write_namespace(&mut self, output: &mut dyn Write, name: &str, comment: Option<&str>) -> Result<()> {
fn write_namespace(
&mut self,
output: &mut dyn Write,
name: &str,
comment: Option<&str>,
) -> Result<()> {
if let Some(comment) = comment {
write!(output, "class {}: # {}\n", name, comment)?;
} else {

View File

@@ -2,6 +2,7 @@ use std::io::{Result, Write};
use super::FileBuilder;
/// Represents a Rust file builder.
#[derive(Debug, Default, PartialEq)]
pub struct RustFileBuilder;
@@ -19,7 +20,12 @@ impl FileBuilder for RustFileBuilder {
Ok(())
}
fn write_namespace(&mut self, output: &mut dyn Write, name: &str, comment: Option<&str>) -> Result<()> {
fn write_namespace(
&mut self,
output: &mut dyn Write,
name: &str,
comment: Option<&str>,
) -> Result<()> {
if let Some(comment) = comment {
write!(output, "pub mod {} {{ // {}\n", name, comment)?;
} else {