Remove top level object from enchantments

This commit is contained in:
Ryan 2022-10-04 23:16:48 -07:00
parent 85cc3a28ea
commit b330f97642
3 changed files with 556 additions and 565 deletions

View file

@ -6,12 +6,7 @@ use serde::Deserialize;
use crate::ident;
#[derive(Deserialize, Debug)]
struct TopLevel {
enchants: Vec<ParsedEnchantment>,
}
#[derive(Deserialize, Debug)]
pub struct ParsedEnchantment {
pub struct Enchantment {
#[allow(unused)]
id: u16,
name: String,
@ -22,18 +17,19 @@ pub struct ParsedEnchantment {
is_curse: bool,
rarity_weight: i32,
#[serde(alias = "sources")]
source: ParsedEnchantmentSource,
source: EnchantmentSources,
}
#[derive(Deserialize, Debug)]
pub struct ParsedEnchantmentSource {
pub struct EnchantmentSources {
treasure: bool,
enchantment_table: bool,
random_selection: bool,
}
pub fn build() -> anyhow::Result<TokenStream> {
let TopLevel { enchants } = serde_json::from_str(include_str!("../extracted/enchants.json"))?;
let enchants: Vec<Enchantment> =
serde_json::from_str(include_str!("../extracted/enchants.json"))?;
let enchantmentkind_definitions = enchants
.iter()
@ -141,7 +137,6 @@ pub fn build() -> anyhow::Result<TokenStream> {
.collect::<TokenStream>();
Ok(quote! {
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct EnchantmentSources {
pub treasure: bool,
@ -165,8 +160,8 @@ pub fn build() -> anyhow::Result<TokenStream> {
}
}
/// Returns the enchantment ID.
pub const fn id(self) -> u16 {
/// Returns the raw enchantment ID.
pub const fn to_raw(self) -> u16 {
self as u16
}

View file

@ -1,5 +1,4 @@
{
"enchants": [
[
{
"id": 0,
"name": "protection",
@ -547,4 +546,3 @@
}
}
]
}

View file

@ -17,7 +17,6 @@ public class Enchants implements Main.Extractor {
@Override
public JsonElement extract() {
var topLevelJson = new JsonObject();
var enchantsJson = new JsonArray();
for (var enchant : Registry.ENCHANTMENT) {
@ -43,7 +42,6 @@ public class Enchants implements Main.Extractor {
enchantsJson.add(enchantJson);
}
topLevelJson.add("enchants", enchantsJson);
return topLevelJson;
return enchantsJson;
}
}