terra-wld 0.3.0

Terraria world parser
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
pub mod default;
pub mod read;
pub mod write;

use crate::{
	banner::Banner,
	entity::{Entity, EntityType},
	tile::{Tile, TileType},
	world_manifest::WorldManifest,
};
use bounded_vector::BoundedVec;
use cs_datetime_parse::DateTimeCs;
use grid::Grid;
use std::collections::{HashMap, HashSet};
use terra_items::{Item, WorldItemSlot};
use terra_types::{
	Evil, InDays, InMph, InPixels, InTiles, MoonPhase, Rain, Value, Vec2, XAxis, YAxis,
};
use time::{Duration, Time};
use uuid::Uuid;

#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct World {
	pub name: String,
	pub id: i32,
	pub uuid: Option<Uuid>,
	pub times_saved: u32,
	pub is_favorite: bool,
	pub seed: Option<String>,
	pub generator_version: Option<u64>,
	pub left_border: XAxis<InPixels, i32>,
	pub right_border: XAxis<InPixels, i32>,
	pub top_border: YAxis<InPixels, i32>,
	pub bottom_border: YAxis<InPixels, i32>,
	pub spawn: Vec2<InTiles, i32>,
	pub team_spawns: Option<TeamSpawns>,
	pub dungeon: Vec2<InTiles, i32>,
	pub moon_type: MoonType,
	pub moon_phase: MoonPhase,
	pub difficulty: Difficulty,
	pub evil: Evil,
	pub creation_time: Option<DateTimeCs>,
	pub last_played: Option<DateTimeCs>,
	pub time: Time,
	pub is_shadow_orb_or_crimson_heart_destroyed: bool,
	pub destroyed_shadow_orb_or_crimson_heart_count: u8,
	pub destroyed_altar_count: i32,
	pub tier_1_hardmode_ore: Option<TileType>,
	pub tier_2_hardmode_ore: Option<TileType>,
	pub tier_3_hardmode_ore: Option<TileType>,
	pub tier_1_ore: Option<TileType>,
	pub tier_2_ore: Option<TileType>,
	pub tier_3_ore: Option<TileType>,
	pub tier_4_ore: Option<TileType>,
	pub surface_level: YAxis<InTiles, f64>,
	pub cavern_level: YAxis<InTiles, f64>,
	pub weighted_pressure_plates: HashSet<Vec2<InTiles, i32>>,
	pub homes: Vec<Home>,
	pub tile_entities: Vec<TileEntity>,
	pub bestiary: HashMap<EntityType, BestiaryEntry>,
	pub kill_count: HashMap<Banner, i32>,
	pub claimable_banners: HashMap<Banner, u16>,
	pub entities: BoundedVec<Entity, 0, 201>,
	pub signs: BoundedVec<Sign, 0, 32000>,
	pub chests: BoundedVec<Chest, 0, 8000>,
	pub tiles: Grid<Tile>,

	pub invasion: Option<Invasion>,
	pub slime_rain_time: Duration,
	pub sundial_cooldown: Value<InDays, u8>,
	pub moondial_cooldown: Value<InDays, u8>,
	pub lantern_night_cooldown: Value<InDays, i32>,
	pub invasion_cooldown: Value<InDays, i32>,
	pub rain: Option<Rain>,
	pub meteor_shower_remaining: i32,
	pub coin_rain_remaining: i32,
	pub cultist_delay: Duration,
	pub party_cooldown: Duration,
	pub party: Option<Party>,
	pub lantern_night: Option<LanternNight>,
	pub sandstorm: Option<Sandstorm>,
	pub clouds_count: i16,
	pub cloud_bg_active: i32,
	pub wind: XAxis<InMph, f32>,

	pub players_finished_angler_quest_today: Vec<String>,
	pub angler_quest: AnglerQuest,

	pub is_drunk_world: bool,
	pub is_for_the_worthy_world: bool,
	pub is_tenth_anniversary_world: bool,
	pub is_dont_starve_world: bool,
	pub is_not_the_bees_world: bool,
	pub is_remix_world: bool,
	pub is_no_traps_world: bool,
	pub is_zenith_world: bool,
	pub is_skyblock_world: bool,
	pub is_dual_dungeon_seed: bool,
	pub is_vampire_seed: bool,
	pub is_infected_seed: bool,

	pub is_blood_moon: bool,
	pub is_solar_eclipse: bool,
	pub is_sundial_forward_time_active: bool,
	pub is_moondial_forward_time_active: bool,
	pub is_solar_pillar_active: bool,
	pub is_vortex_pillar_active: bool,
	pub is_nebula_pillar_active: bool,
	pub is_stardust_pillar_active: bool,
	pub is_lunar_apocalypse: bool,
	pub is_next_night_lantern_night: bool,

	pub is_eye_of_cthulhu_downed: bool,
	pub is_eater_of_worlds_or_brain_of_cthulhu_downed: bool,
	pub is_goblin_army_downed: bool,
	pub is_skeleton_downed: bool,
	pub is_queen_bee_downed: bool,
	pub is_destroyer_downed: bool,
	pub is_twins_downed: bool,
	pub is_skeletron_prime_downed: bool,
	pub is_any_mechanical_boss_downed: bool,
	pub is_plantera_downed: bool,
	pub is_golem_downed: bool,
	pub is_king_slime_downed: bool,
	pub is_clown_downed: bool,
	pub is_frost_legion_downed: bool,
	pub is_pirate_invasion_downed: bool,
	pub is_fishron_downed: bool,
	pub is_martian_madness_downed: bool,
	pub is_ancient_cultist_downed: bool,
	pub is_moonlord_downed: bool,
	pub is_pumpking_downed: bool,
	pub is_mourning_wood_downed: bool,
	pub is_ice_queen_downed: bool,
	pub is_santa_nk1_downed: bool,
	pub is_everscream_downed: bool,
	pub is_solar_pillar_downed: bool,
	pub is_vortex_pillar_downed: bool,
	pub is_nebula_pillar_downed: bool,
	pub is_stardust_pillar_downed: bool,
	pub is_dd2_t1_downed: bool,
	pub is_dd2_t2_downed: bool,
	pub is_dd2_t3_downed: bool,
	pub is_empress_of_light_downed: bool,
	pub is_queen_slime_downed: bool,
	pub is_deerclops_downed: bool,

	pub is_cat_bought: bool,
	pub is_dog_bought: bool,
	pub is_bunny_bought: bool,
	pub is_blue_slime_spawn_unlocked: bool,
	pub is_green_slime_spawn_unlocked: bool,
	pub is_old_slime_spawn_unlocked: bool,
	pub is_purple_slime_spawn_unlocked: bool,
	pub is_rainbow_slime_spawn_unlocked: bool,
	pub is_red_slime_unlocked: bool,
	pub is_yellow_slime_spawn_unlocked: bool,
	pub is_copper_slime_spawn_unlocked: bool,
	pub is_merchant_spawn_unlocked: bool,
	pub is_demolitionist_spawn_unlocked: bool,
	pub is_party_girl_spawn_unlocked: bool,
	pub is_goblin_tinkerer_saved: bool,
	pub is_dye_trader_spawn_unlocked: bool,
	pub is_truffle_spawn_unlocked: bool,
	pub is_arms_dealer_spawn_unlocked: bool,
	pub is_nurse_spawn_unlocked: bool,
	pub is_princess_spawn_unlocked: bool,
	pub is_wizard_saved: bool,
	pub is_mechanic_saved: bool,
	pub is_stylist_saved: bool,
	pub is_angler_saved: bool,
	pub is_tax_collector_saved: bool,
	pub is_golfer_saved: bool,
	pub is_bartender_saved: bool,

	pub is_merchant_shimmered: bool,
	pub is_nurse_shimmered: bool,
	pub is_arms_dealer_shimmered: bool,
	pub is_dryad_shimmered: bool,
	pub is_guide_shimmered: bool,
	pub is_old_man_shimmered: bool,
	pub is_demolitionist_shimmered: bool,
	pub is_clothier_shimmered: bool,
	pub is_goblin_tinkerer_shimmered: bool,
	pub is_wizard_shimmered: bool,
	pub is_mechanic_shimmered: bool,
	pub is_santa_claus_shimmered: bool,
	pub is_truffle_shimmered: bool,
	pub is_steampunker_shimmered: bool,
	pub is_dye_trader_shimmered: bool,
	pub is_party_girl_shimmered: bool,
	pub is_cyborg_shimmered: bool,
	pub is_painter_shimmered: bool,
	pub is_witch_doctor_shimmered: bool,
	pub is_pirate_shimmered: bool,
	pub is_stylist_shimmered: bool,
	pub is_travelling_merchant_shimmered: bool,
	pub is_angler_shimmered: bool,
	pub is_tax_collector_shimmered: bool,
	pub is_bartender_shimmered: bool,
	pub is_golfer_shimmered: bool,
	pub is_zoologist_shimmered: bool,
	pub is_town_cat_shimmered: bool,
	pub is_town_dog_shimmered: bool,
	pub is_town_bunny_shimmered: bool,
	pub is_princess_shimmered: bool,
	pub is_town_slime_blue_shimmered: bool,
	pub is_town_slime_green_shimmered: bool,
	pub is_town_slime_old_shimmered: bool,
	pub is_town_slime_purple_shimmered: bool,
	pub is_town_slime_rainbow_shimmered: bool,
	pub is_town_slime_red_shimmered: bool,
	pub is_town_slime_yellow_shimmered: bool,
	pub is_town_slime_copper_shimmered: bool,
	pub is_skeleton_merchant_shimmered: bool,

	pub is_hallowen_forced_today: bool,
	pub is_xmas_forced_today: bool,
	pub is_hallowen_forced_forever: bool,
	pub is_xmas_forced_forever: bool,
	pub is_meteor_to_spawn: bool,
	pub is_hardmode: bool,
	pub is_after_party_of_doom: bool,
	pub is_combat_book_used: bool,
	pub is_combat_book_volume_two_used: bool,
	pub is_peddlers_satchel_used: bool,

	pub ice_cave_background: i32,
	pub jungle_cave_background: i32,
	pub hell_background: i32,
	pub forest_background: u8,
	pub corruption_background: u8,
	pub jungle_background: u8,
	pub snow_background: u8,
	pub hallow_background: u8,
	pub crimson_background: u8,
	pub desert_background: u8,
	pub ocean_background: u8,
	pub mushroom_background: u8,
	pub underworld_background: u8,

	pub tree_backgrounds: [u8; 3],
	pub tree_styles: [i32; 4],
	pub tree_style_changes: [XAxis<InTiles, i32>; 3],
	pub cave_back_styles: [i32; 4],
	pub cave_back_style_changes: [XAxis<InTiles, i32>; 3],
	pub tree_tops_forest: [i32; 4],
	pub tree_tops_corruption: i32,
	pub tree_tops_jungle: i32,
	pub tree_tops_snow: i32,
	pub tree_tops_hallow: i32,
	pub tree_tops_crimson: i32,
	pub tree_tops_desert: i32,
	pub tree_tops_ocean: i32,
	pub tree_tops_glowing_mushroom: i32,
	pub tree_tops_underworld: i32,

	pub is_time_frozen: bool,
	pub is_rain_frozen: bool,
	pub is_wind_frozen: bool,
	pub is_biome_spread_disabled: bool,
	pub time_rate_power: f32,
	pub difficulty_power: f32,

	pub manifest: WorldManifest,
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Sandstorm {
	pub time: Duration,
	pub current_severity: f32,
	pub intended_severity: f32,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LanternNight {
	pub is_mannual: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Party {
	pub is_mannual: bool,
	pub celebrating_npcs: Vec<EntityType>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TileEntity {
	pub entity: TileEntityType,
	pub position: Vec2<InTiles, i16>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum TileEntityType {
	TrainingDummy {
		entity_idx: i16,
	},
	ItemFrame(Option<WorldItemSlot>),
	LogicSensor {
		check: Option<LogicCheck>,
		is_on: bool,
	},
	DisplayDoll {
		pose: DisplayDollPose,
		helmet: ItemDyeRow,
		breastplate: ItemDyeRow,
		pants: ItemDyeRow,
		accessories: [ItemDyeRow; 5],
		mount: ItemDyeRow,
		hand: Option<WorldItemSlot>,
	},
	WeaponRack(Option<WorldItemSlot>),
	HatRack {
		upper: ItemDyeRow,
		lower: ItemDyeRow,
	},
	FoodPlatter(Option<WorldItemSlot>),
	Pylon,
	DisplayJar(Option<WorldItemSlot>),
	KiteAnchor(Option<Item>),
	CritterAnchor(Option<Item>),
}

impl TileEntityType {
	pub fn id(&self) -> u8 {
		match self {
			TileEntityType::TrainingDummy { .. } => 0,
			TileEntityType::ItemFrame(_) => 1,
			TileEntityType::LogicSensor { .. } => 2,
			TileEntityType::DisplayDoll { .. } => 3,
			TileEntityType::WeaponRack(_) => 4,
			TileEntityType::HatRack { .. } => 5,
			TileEntityType::FoodPlatter(_) => 6,
			TileEntityType::Pylon => 7,
			TileEntityType::DisplayJar(_) => 8,
			TileEntityType::KiteAnchor(_) => 9,
			TileEntityType::CritterAnchor(_) => 10,
		}
	}

	fn supported_version(&self) -> i32 {
		match self {
			&TileEntityType::TrainingDummy { .. } | &TileEntityType::ItemFrame(_) => 146,
			&TileEntityType::LogicSensor { .. } => 168,
			&TileEntityType::DisplayDoll { .. }
			| &TileEntityType::WeaponRack(_)
			| &TileEntityType::HatRack { .. }
			| &TileEntityType::FoodPlatter(_)
			| &TileEntityType::Pylon => 225,
			&TileEntityType::DisplayJar(_)
			| TileEntityType::CritterAnchor(_)
			| TileEntityType::KiteAnchor(_) => 315,
		}
	}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum DisplayDollPose {
	#[default]
	Standing = 0,
	Sitting = 1,
	Jumping = 2,
	Walking = 3,
	ItemUse1 = 4,
	ItemUse2 = 5,
	ItemUse3 = 6,
	ItemUse4 = 7,
	ItemUse5 = 8,
}

impl DisplayDollPose {
	fn to_id(self) -> u8 {
		self as u8
	}

	fn from_id(id: u8) -> Option<DisplayDollPose> {
		Some(match id {
			0 => DisplayDollPose::Standing,
			1 => DisplayDollPose::Sitting,
			2 => DisplayDollPose::Jumping,
			3 => DisplayDollPose::Walking,
			4 => DisplayDollPose::ItemUse1,
			5 => DisplayDollPose::ItemUse2,
			6 => DisplayDollPose::ItemUse3,
			7 => DisplayDollPose::ItemUse4,
			8 => DisplayDollPose::ItemUse5,
			_ => return None,
		})
	}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct ItemDyeRow {
	pub item: Option<WorldItemSlot>,
	pub dye: Option<WorldItemSlot>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum LogicCheck {
	Day = 1,
	Night = 2,
	PlayerAbove = 3,
	Water = 4,
	Lava = 5,
	Honey = 6,
	Liquid = 7,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct TeamSpawns {
	pub no_team: Vec2<InTiles, i16>,
	pub red: Vec2<InTiles, i16>,
	pub green: Vec2<InTiles, i16>,
	pub blue: Vec2<InTiles, i16>,
	pub yellow: Vec2<InTiles, i16>,
	pub pink: Vec2<InTiles, i16>,
}

impl TeamSpawns {
	pub const COUNT: u8 = 6;
}

impl LogicCheck {
	pub fn from_id(id: u8) -> Option<LogicCheck> {
		Some(match id {
			1 => LogicCheck::Day,
			2 => LogicCheck::Night,
			3 => LogicCheck::PlayerAbove,
			4 => LogicCheck::Water,
			5 => LogicCheck::Lava,
			6 => LogicCheck::Honey,
			7 => LogicCheck::Liquid,
			_ => return None,
		})
	}

	pub fn to_id(self) -> u8 {
		self as u8
	}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct BestiaryEntry {
	pub is_chatted_with: bool,
	pub is_seen: bool,
	pub killed_count: i32,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Home {
	pub resident: EntityType,
	pub position: Vec2<InPixels, i32>,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Chest {
	pub name: String,
	pub position: Vec2<InTiles, i32>,
	pub slots: Vec<Option<WorldItemSlot>>,
}

impl Chest {
	pub fn new(position: Vec2<InTiles, i32>) -> Self {
		Chest {
			name: "".to_owned(),
			position,
			slots: Vec::new(),
		}
	}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Sign {
	pub position: Vec2<InTiles, i32>,
	pub text: String,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum AnglerQuest {
	Batfish = 0,
	BumblebeeTuna = 1,
	Catfish = 2,
	Cloudfish = 3,
	Cursedfish = 4,
	Dirtfish = 5,
	DynamiteFish = 6,
	EaterOfPlankton = 7,
	FallenStarfish = 8,
	TheFishOfCthulu = 9,
	Fishotron = 10,
	Harpyfish = 11,
	Hungerfish = 12,
	Ichorfish = 13,
	Jewelfish = 14,
	MirageFish = 15,
	MutantFlinxfin = 16,
	Pengfish = 17,
	Pixiefish = 18,
	Spiderfish = 19,
	TundraTrout = 20,
	UnicornFish = 21,
	GuideVoodooFish = 22,
	Wyverntail = 23,
	ZombieFish = 24,
	AmanitaFungifin = 25,
	Angelfish = 26,
	BloodyManowar = 27,
	Bonefish = 28,
	Bunnyfish = 29,
	CapnTunabeard = 30,
	Clownfish = 31,
	DemonicHellfish = 32,
	Derpfish = 33,
	Fishron = 34,
	InfectedScabbardfish = 35,
	Mudfish = 36,
	Slimefish = 37,
	TropicalBarracuda = 38,
	ScarabFish = 39,
	ScorpioFish = 40,
}

impl AnglerQuest {
	pub fn from_id(id: i32) -> Option<Self> {
		Some(match id {
			0 => Self::Batfish,
			1 => Self::BumblebeeTuna,
			2 => Self::Catfish,
			3 => Self::Cloudfish,
			4 => Self::Cursedfish,
			5 => Self::Dirtfish,
			6 => Self::DynamiteFish,
			7 => Self::EaterOfPlankton,
			8 => Self::FallenStarfish,
			9 => Self::TheFishOfCthulu,
			10 => Self::Fishotron,
			11 => Self::Harpyfish,
			12 => Self::Hungerfish,
			13 => Self::Ichorfish,
			14 => Self::Jewelfish,
			15 => Self::MirageFish,
			16 => Self::MutantFlinxfin,
			17 => Self::Pengfish,
			18 => Self::Pixiefish,
			19 => Self::Spiderfish,
			20 => Self::TundraTrout,
			21 => Self::UnicornFish,
			22 => Self::GuideVoodooFish,
			23 => Self::Wyverntail,
			24 => Self::ZombieFish,
			25 => Self::AmanitaFungifin,
			26 => Self::Angelfish,
			27 => Self::BloodyManowar,
			28 => Self::Bonefish,
			29 => Self::Bunnyfish,
			30 => Self::CapnTunabeard,
			31 => Self::Clownfish,
			32 => Self::DemonicHellfish,
			33 => Self::Derpfish,
			34 => Self::Fishron,
			35 => Self::InfectedScabbardfish,
			36 => Self::Mudfish,
			37 => Self::Slimefish,
			38 => Self::TropicalBarracuda,
			39 => Self::ScarabFish,
			40 => Self::ScorpioFish,
			_ => return None,
		})
	}

	pub fn to_id(self) -> i32 {
		self as i32
	}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum InvasionType {
	GoblinArmy = 1,
	SnowLegion = 2,
	PirateInvasion = 3,
	MartianMadness = 4,
}

impl InvasionType {
	pub fn to_id(self) -> i32 {
		self as i32
	}

	pub fn from_id(id: i32) -> Option<Self> {
		Some(match id {
			1 => Self::GoblinArmy,
			2 => Self::SnowLegion,
			3 => Self::PirateInvasion,
			4 => Self::MartianMadness,
			_ => return None,
		})
	}
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Invasion {
	pub start_size: i32,
	pub size: i32,
	pub invasion_type: InvasionType,
	pub position: XAxis<InTiles, f64>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
pub enum Difficulty {
	#[default]
	Normal = 0,
	Expert = 1,
	Master = 2,
	Journey = 3,
}

impl Difficulty {
	pub fn from_id(id: i32) -> Option<Self> {
		Some(match id {
			0 => Self::Normal,
			1 => Self::Expert,
			2 => Self::Master,
			3 => Self::Journey,
			_ => return None,
		})
	}

	pub fn to_id(self) -> i32 {
		self as i32
	}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
#[non_exhaustive]
pub enum MoonType {
	#[default]
	Normal = 0,
	Yellow = 1,
	Ringed = 2,
	Mythril = 3,
	BrightBlue = 4,
	Green = 5,
	Pink = 6,
	Orange = 7,
	Purple = 8,
}

impl MoonType {
	pub fn from_id(id: u8) -> Option<Self> {
		Some(match id {
			0 => Self::Normal,
			1 => Self::Yellow,
			2 => Self::Ringed,
			3 => Self::Mythril,
			4 => Self::BrightBlue,
			5 => Self::Green,
			6 => Self::Pink,
			7 => Self::Purple,
			_ => return None,
		})
	}

	pub fn to_id(self) -> u8 {
		self as u8
	}
}

const TILE_SIZE: i16 = 16 + 1;

const TILE_IS_IMPORTANT: [bool; 693] = [
	false, false, false, true, true, true, false, false, false, false, true, true, true, true,
	true, true, true, true, true, true, true, true, false, false, true, false, true, true, true,
	true, false, true, false, true, true, true, true, false, false, false, false, false, true,
	false, false, false, false, false, false, true, true, false, false, false, false, true, false,
	false, false, false, false, true, false, false, false, false, false, false, false, false,
	false, true, true, true, true, false, false, true, true, true, false, true, true, true, true,
	true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
	true, true, true, true, true, true, false, false, false, true, false, false, true, true, false,
	false, false, false, false, false, false, false, false, false, true, true, false, true, true,
	false, false, true, true, true, true, true, true, true, true, false, true, true, true, true,
	false, false, false, false, true, false, false, false, false, false, false, false, false,
	false, false, false, false, false, false, false, true, false, false, false, false, false, true,
	true, true, true, false, false, false, true, false, false, false, false, false, true, true,
	true, true, false, false, false, false, false, false, false, false, false, false, false, false,
	false, true, false, false, false, false, false, true, false, true, true, false, true, false,
	false, true, true, true, true, true, true, false, false, false, false, false, false, true,
	true, false, false, true, false, true, false, true, true, true, true, true, true, true, true,
	true, true, true, true, true, false, false, false, false, false, false, true, false, false,
	false, false, false, false, false, false, false, false, false, false, false, false, true, true,
	true, false, false, false, true, true, true, true, true, true, true, true, true, false, true,
	true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
	true, true, true, true, true, true, true, true, true, false, false, false, true, false, true,
	true, true, true, true, false, false, true, true, false, false, false, false, false, false,
	false, false, false, true, true, false, true, true, true, false, false, false, false, false,
	false, false, false, false, true, false, false, false, false, true, true, true, false, true,
	true, true, true, true, true, true, false, false, false, false, false, false, false, true,
	true, true, true, true, true, true, false, true, false, false, false, false, false, true, true,
	true, true, true, true, true, true, true, true, false, false, false, false, false, false,
	false, false, false, true, true, false, false, false, true, true, true, true, true, false,
	false, false, false, true, true, false, false, true, true, true, false, true, true, true,
	false, false, false, false, false, true, true, true, true, true, true, true, true, true, true,
	true, false, false, false, false, false, false, true, true, true, true, true, true, false,
	false, false, true, true, true, true, true, true, true, true, true, true, true, false, false,
	false, true, true, false, false, false, true, false, false, false, true, true, true, true,
	true, true, true, true, false, true, true, false, false, true, false, true, false, false,
	false, false, false, true, true, false, false, true, true, true, false, false, false, false,
	false, false, true, true, true, true, true, true, true, true, true, true, false, true, true,
	true, true, true, false, false, false, false, true, false, false, false, true, true, true,
	true, false, true, true, true, true, true, true, true, true, true, true, false, true, true,
	true, false, false, false, true, true, false, true, true, true, true, true, true, true, false,
	false, false, false, false, true, true, true, true, true, true, true, true, true, true, true,
	true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
	true, true, true, true, true, true, true, true, true, true, true, true, false, true, true,
	true, true, true, true, false, false, false, false, true, true, true, true, false, true, false,
	false, true, false, true, true, false, true, true, true, true, true, true, true, true, true,
	true, true, true, true, false, true, true, true, false, true, false, false, true, true, true,
	false, false, false, false, false, false, false, false, false, false, false, false, false,
	false, false, false, false, false, false, false, false, false, false, false, false, false,
	false,
];