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

View file

@ -1,5 +1,4 @@
{ [
"enchants": [
{ {
"id": 0, "id": 0,
"name": "protection", "name": "protection",
@ -546,5 +545,4 @@
"random_selection": true "random_selection": true
} }
} }
] ]
}

View file

@ -17,7 +17,6 @@ public class Enchants implements Main.Extractor {
@Override @Override
public JsonElement extract() { public JsonElement extract() {
var topLevelJson = new JsonObject();
var enchantsJson = new JsonArray(); var enchantsJson = new JsonArray();
for (var enchant : Registry.ENCHANTMENT) { for (var enchant : Registry.ENCHANTMENT) {
@ -35,7 +34,7 @@ public class Enchants implements Main.Extractor {
var enchantmentSources = new JsonObject(); var enchantmentSources = new JsonObject();
enchantmentSources.addProperty("treasure", enchant.isTreasure()); enchantmentSources.addProperty("treasure", enchant.isTreasure());
enchantmentSources.addProperty("enchantment_table", enchant.isAvailableForEnchantedBookOffer()); enchantmentSources.addProperty("enchantment_table", enchant.isAvailableForEnchantedBookOffer());
//All enchants except for 'Soul speed' and 'Swift sneak' are available for random selection and are only obtainable from loot chests. // All enchants except for 'Soul speed' and 'Swift sneak' are available for random selection and are only obtainable from loot chests.
enchantmentSources.addProperty("random_selection", enchant.isAvailableForRandomSelection()); enchantmentSources.addProperty("random_selection", enchant.isAvailableForRandomSelection());
enchantJson.add("sources", enchantmentSources); enchantJson.add("sources", enchantmentSources);
@ -43,7 +42,6 @@ public class Enchants implements Main.Extractor {
enchantsJson.add(enchantJson); enchantsJson.add(enchantJson);
} }
topLevelJson.add("enchants", enchantsJson); return enchantsJson;
return topLevelJson;
} }
} }