From f008df98936d1e309c736c8afbda61d46f4bda2a Mon Sep 17 00:00:00 2001 From: syldium Date: Sat, 16 Mar 2024 13:58:27 +0100 Subject: [PATCH] chore(types): simplify const types and some ts-ignore comments --- src/main/component/ui/NumberInput.tsx | 5 +++-- src/main/data/1.17/Biome.ts | 10 +++++----- src/main/data/1.17/ConfiguredDecorator.ts | 2 +- src/main/data/1.17/DimensionType.ts | 2 +- src/main/data/1.17/Direction.ts | 2 +- src/main/data/1.17/WorldgenStep.ts | 2 +- src/main/data/1.18.2/Biome.ts | 2 +- src/main/data/1.18.2/DensityFunction.ts | 4 ++-- src/main/data/1.18.2/StructureSet.ts | 2 +- src/main/data/1.18/Biome.ts | 2 +- src/main/data/1.18/BiomeSource.ts | 2 +- src/main/data/1.18/ConfiguredStructureFeature.ts | 8 ++++---- src/main/data/1.18/NoiseSettings.ts | 2 +- src/main/data/1.18/PlacementModifier.ts | 4 ++-- src/main/data/1.18/TemplatePool.ts | 2 +- src/main/data/1.19/DecorationStep.ts | 4 ++-- src/main/data/1.19/Structure.ts | 8 ++++---- src/main/data/1.19/StructureSet.ts | 4 ++-- src/main/model/Registry.ts | 3 +-- src/main/model/node/EnumNode.ts | 2 +- src/main/viewer/biome/BiomeSourceMapLayer.ts | 1 - 21 files changed, 36 insertions(+), 37 deletions(-) diff --git a/src/main/component/ui/NumberInput.tsx b/src/main/component/ui/NumberInput.tsx index 5c4f8ae..0edc1de 100644 --- a/src/main/component/ui/NumberInput.tsx +++ b/src/main/component/ui/NumberInput.tsx @@ -1,8 +1,9 @@ import { ChangeEventHandler, InputHTMLAttributes, ReactElement } from 'react'; import { INT_MAX_VALUE, INT_MIN_VALUE } from '../../util/MathHelper'; -// @ts-ignore -interface NumberInputProps extends InputHTMLAttributes { +interface NumberInputProps + extends Omit, 'onChange'> +{ onChange: (value: number) => void; value: number; step?: number; diff --git a/src/main/data/1.17/Biome.ts b/src/main/data/1.17/Biome.ts index 3fdf197..e3bb458 100644 --- a/src/main/data/1.17/Biome.ts +++ b/src/main/data/1.17/Biome.ts @@ -16,7 +16,7 @@ const BiomeEffects = Obj({ foliage_color: Opt(ColorNode()), grass_color: Opt(ColorNode()), grass_color_modifier: EnumNode( - ['none', 'dark_forest', 'swamp'] as const, + ['none', 'dark_forest', 'swamp'], 'none' ), particle: Opt( @@ -113,14 +113,14 @@ export const BiomeSettings = { 'mushroom', 'nether', 'underground' - ] as const + ] ), - precipitation: EnumNode(['none', 'rain', 'snow'] as const), + precipitation: EnumNode(['none', 'rain', 'snow']), temperature: FloatNode(), - temperature_modifier: EnumNode(['none', 'frozen'] as const, 'none'), + temperature_modifier: EnumNode(['none', 'frozen'], 'none'), surface_builder: IdentifierNode('worldgen/configured_surface_builder'), carvers: MapNode( - EnumNode(['air', 'liquid'] as const), + EnumNode(['air', 'liquid']), ListNode(ResourceNode('worldgen/configured_carver')) ), features: ListNode(ListNode(ResourceNode('worldgen/configured_feature'))), diff --git a/src/main/data/1.17/ConfiguredDecorator.ts b/src/main/data/1.17/ConfiguredDecorator.ts index 3277791..bcb7a9a 100644 --- a/src/main/data/1.17/ConfiguredDecorator.ts +++ b/src/main/data/1.17/ConfiguredDecorator.ts @@ -10,7 +10,7 @@ import { IntProvider } from './NumberProvider'; import { Heightmap, VerticalSurface } from './WorldgenStep'; const CarvingMaskConfig = Obj({ - step: EnumNode(['air', 'liquid'] as const) + step: EnumNode(['air', 'liquid']) }); const CaveSurfaceConfig = Obj({ diff --git a/src/main/data/1.17/DimensionType.ts b/src/main/data/1.17/DimensionType.ts index dff181e..78c028d 100644 --- a/src/main/data/1.17/DimensionType.ts +++ b/src/main/data/1.17/DimensionType.ts @@ -16,7 +16,7 @@ export const DimensionType: Model = DefaultedModel( height: IntNode({ min: 16, max: 4064, step: 16 }), logical_height: IntNode({ min: 0, max: 4064 }), effects: EnumNode( - ['overworld', 'the_nether', 'the_end'] as const, + ['overworld', 'the_nether', 'the_end'], 'overworld', true ), diff --git a/src/main/data/1.17/Direction.ts b/src/main/data/1.17/Direction.ts index b56f3e4..7865355 100644 --- a/src/main/data/1.17/Direction.ts +++ b/src/main/data/1.17/Direction.ts @@ -8,5 +8,5 @@ export const Direction = EnumNode( 'south', 'west', 'east' - ] as const + ] ); diff --git a/src/main/data/1.17/WorldgenStep.ts b/src/main/data/1.17/WorldgenStep.ts index ef5577c..b6a8ad0 100644 --- a/src/main/data/1.17/WorldgenStep.ts +++ b/src/main/data/1.17/WorldgenStep.ts @@ -10,4 +10,4 @@ export const Heightmap = EnumNode({ "Motion blocking no leaves (that blocks motion or contains a fluid and isn't leaves)" }); -export const VerticalSurface = EnumNode(['ceiling', 'floor'] as const); +export const VerticalSurface = EnumNode(['ceiling', 'floor']); diff --git a/src/main/data/1.18.2/Biome.ts b/src/main/data/1.18.2/Biome.ts index a9206c0..a346bc0 100644 --- a/src/main/data/1.18.2/Biome.ts +++ b/src/main/data/1.18.2/Biome.ts @@ -12,7 +12,7 @@ import { export const BiomeSettings = { ...BiomeSettings1_18, carvers: MapNode( - EnumNode(['air', 'liquid'] as const), + EnumNode(['air', 'liquid']), ListNode(ResourceNode('worldgen/configured_carver'), -1, false, true) ) }; diff --git a/src/main/data/1.18.2/DensityFunction.ts b/src/main/data/1.18.2/DensityFunction.ts index e0d3ab2..d2f2a36 100644 --- a/src/main/data/1.18.2/DensityFunction.ts +++ b/src/main/data/1.18.2/DensityFunction.ts @@ -89,7 +89,7 @@ export const DynamicRangeDensityFunction = SwitchNode( square: UnaryFunction, squeeze: UnaryFunction, terrain_shaper_spline: Obj({ - spline: EnumNode(['offset', 'factor', 'jaggedness'] as const), + spline: EnumNode(['offset', 'factor', 'jaggedness']), min_value: ConstantRange, max_value: ConstantRange, continentalness: ResourceNode('worldgen/density_function'), @@ -97,7 +97,7 @@ export const DynamicRangeDensityFunction = SwitchNode( weirdness: ResourceNode('worldgen/density_function') }), weird_scaled_sampler: Obj({ - rarity_value_mapper: EnumNode(['type_1', 'type_2'] as const), + rarity_value_mapper: EnumNode(['type_1', 'type_2']), noise: ResourceNode('worldgen/noise'), input: ResourceNode('worldgen/density_function') }), diff --git a/src/main/data/1.18.2/StructureSet.ts b/src/main/data/1.18.2/StructureSet.ts index c413b35..62c143a 100644 --- a/src/main/data/1.18.2/StructureSet.ts +++ b/src/main/data/1.18.2/StructureSet.ts @@ -19,7 +19,7 @@ export const StructureSet: Model = { count: IntNode({ min: 1, max: 4095 }) }), random_spread: Obj({ - spread_type: EnumNode(['linear', 'triangular'] as const, 'linear'), + spread_type: EnumNode(['linear', 'triangular'], 'linear'), spacing: IntNode({ min: 0, max: 4096 }), separation: IntNode({ min: 0, max: 4096 }), salt: IntNode({ min: 0 }), diff --git a/src/main/data/1.18/Biome.ts b/src/main/data/1.18/Biome.ts index 401d460..3eaebbe 100644 --- a/src/main/data/1.18/Biome.ts +++ b/src/main/data/1.18/Biome.ts @@ -38,7 +38,7 @@ export const BiomeSettings = { 'taiga', 'the_end', 'underground' - ] as const + ] ), features: ListNode(ListNode(ResourceNode('worldgen/placed_feature'))), spawners: Obj({ diff --git a/src/main/data/1.18/BiomeSource.ts b/src/main/data/1.18/BiomeSource.ts index 23b52e2..b17d82d 100644 --- a/src/main/data/1.18/BiomeSource.ts +++ b/src/main/data/1.18/BiomeSource.ts @@ -34,7 +34,7 @@ const MultiNoise = EitherNode( ) }), Obj({ - preset: EnumNode(['overworld', 'nether'] as const, undefined, true) + preset: EnumNode(['overworld', 'nether'], undefined, true) }) ); diff --git a/src/main/data/1.18/ConfiguredStructureFeature.ts b/src/main/data/1.18/ConfiguredStructureFeature.ts index 5bd19c9..59bae25 100644 --- a/src/main/data/1.18/ConfiguredStructureFeature.ts +++ b/src/main/data/1.18/ConfiguredStructureFeature.ts @@ -11,7 +11,7 @@ import { Spawners } from '../1.17/Biome'; import { HeightProvider } from '../1.17/HeightProvider'; const StructureSpawn = Obj({ - bounding_box: EnumNode(['piece', 'full'] as const), + bounding_box: EnumNode(['piece', 'full']), spawns: Spawners }); @@ -49,7 +49,7 @@ export const ConfiguredStructureFeature: Model = { jungle_pyramid: Empty, mansion: Empty, mineshaft: Obj({ - type: EnumNode(['normal', 'mesa'] as const), + type: EnumNode(['normal', 'mesa']), ...Probability }), monument: Empty, @@ -57,7 +57,7 @@ export const ConfiguredStructureFeature: Model = { height: HeightProvider }), ocean_ruin: Obj({ - biome_temp: EnumNode(['cold', 'warm'] as const), + biome_temp: EnumNode(['cold', 'warm']), large_probability: Probability.probability, cluster_probability: Probability.probability }), @@ -72,7 +72,7 @@ export const ConfiguredStructureFeature: Model = { 'ocean', 'swamp', 'nether' - ] as const + ] ) }), shipwreck: Obj({ diff --git a/src/main/data/1.18/NoiseSettings.ts b/src/main/data/1.18/NoiseSettings.ts index 0d52aba..c9b27d4 100644 --- a/src/main/data/1.18/NoiseSettings.ts +++ b/src/main/data/1.18/NoiseSettings.ts @@ -23,7 +23,7 @@ const Spline = Obj({ 'erosion', 'weirdness', 'ridges' - ] as const + ] ), points: ListNode(SplinePoint) }); diff --git a/src/main/data/1.18/PlacementModifier.ts b/src/main/data/1.18/PlacementModifier.ts index 6792568..656883d 100644 --- a/src/main/data/1.18/PlacementModifier.ts +++ b/src/main/data/1.18/PlacementModifier.ts @@ -16,7 +16,7 @@ const PlacementModifierSwitch = SwitchNode( predicate: ResourceNode('block_predicate') }), carving_mask: Obj({ - step: EnumNode(['air', 'liquid'] as const) + step: EnumNode(['air', 'liquid']) }), count: Obj({ count: IntProvider(0, 256) @@ -25,7 +25,7 @@ const PlacementModifierSwitch = SwitchNode( count: IntProvider(0, 256) }), environment_scan: Obj({ - direction_of_search: EnumNode(['up', 'down'] as const), + direction_of_search: EnumNode(['up', 'down']), target_condition: ResourceNode('block_predicate'), allowed_search_condition: Opt(ResourceNode('block_predicate')), max_steps: IntNode({ min: 1, max: 32 }) diff --git a/src/main/data/1.18/TemplatePool.ts b/src/main/data/1.18/TemplatePool.ts index 32f1d2d..1df5f0f 100644 --- a/src/main/data/1.18/TemplatePool.ts +++ b/src/main/data/1.18/TemplatePool.ts @@ -8,7 +8,7 @@ import { StringNode } from '../../model/node/StringNode'; import { SwitchNode } from '../../model/node/SwitchNode'; const Projection = { - projection: EnumNode(['rigid', 'terrain_matching'] as const) + projection: EnumNode(['rigid', 'terrain_matching']) }; export const TemplateElement = SwitchNode( { diff --git a/src/main/data/1.19/DecorationStep.ts b/src/main/data/1.19/DecorationStep.ts index 324eb0d..d86c4fd 100644 --- a/src/main/data/1.19/DecorationStep.ts +++ b/src/main/data/1.19/DecorationStep.ts @@ -13,7 +13,7 @@ export const DecorationStep = EnumNode( 'fluid_springs', 'vegetal_decoration', 'top_layer_modification' - ] as const + ] ); export const TerrainAdaptation = EnumNode( @@ -22,6 +22,6 @@ export const TerrainAdaptation = EnumNode( 'bury', 'beard_thin', 'beard_box' - ] as const, + ], 'none' ); diff --git a/src/main/data/1.19/Structure.ts b/src/main/data/1.19/Structure.ts index b5f838a..6f27890 100644 --- a/src/main/data/1.19/Structure.ts +++ b/src/main/data/1.19/Structure.ts @@ -15,7 +15,7 @@ import { Heightmap } from '../1.17/WorldgenStep'; import { DecorationStep, TerrainAdaptation } from './DecorationStep'; const StructureSpawn = Obj({ - bounding_box: EnumNode(['piece', 'full'] as const), + bounding_box: EnumNode(['piece', 'full']), spawns: Spawners }); @@ -50,14 +50,14 @@ export const Structure: Model = { }), jungle_temple: Empty, mineshaft: Obj({ - mineshaft_type: EnumNode(['normal', 'mesa'] as const) + mineshaft_type: EnumNode(['normal', 'mesa']) }), nether_fossil: Obj({ height: HeightProvider }), ocean_monument: Empty, ocean_ruin: Obj({ - biome_temp: EnumNode(['warm', 'cold'] as const), + biome_temp: EnumNode(['warm', 'cold']), large_probability: Probability.probability, cluster_probability: Probability.probability }), @@ -71,7 +71,7 @@ export const Structure: Model = { 'in_mountain', 'underground', 'in_nether' - ] as const + ] ), air_pocket_probability: Probability.probability, mossiness: Probability.probability, diff --git a/src/main/data/1.19/StructureSet.ts b/src/main/data/1.19/StructureSet.ts index cbe54b6..a20c489 100644 --- a/src/main/data/1.19/StructureSet.ts +++ b/src/main/data/1.19/StructureSet.ts @@ -23,7 +23,7 @@ export const StructureSet: Model = { preferred_biomes: TagNode('worldgen/biome') }), random_spread: Obj({ - spread_type: EnumNode(['linear', 'triangular'] as const, 'linear'), + spread_type: EnumNode(['linear', 'triangular'], 'linear'), spacing: IntNode({ min: 0, max: 4096 }), separation: IntNode({ min: 0, max: 4096 }) }) @@ -54,7 +54,7 @@ export const StructureSet: Model = { 'legacy_type_1', 'legacy_type_2', 'legacy_type_3' - ] as const, + ], 'default' ), frequency: FloatNode({ min: 0, max: 1, default: 1 }), diff --git a/src/main/model/Registry.ts b/src/main/model/Registry.ts index 421b5b8..4064d4a 100644 --- a/src/main/model/Registry.ts +++ b/src/main/model/Registry.ts @@ -129,7 +129,7 @@ export type BlockStateRegistry = { }; export const DEFAULT_BLOCK_STATE = { default: {}, properties: {} }; -export type RegistryInfo = [Model, Option[]] | [Model]; +export type RegistryInfo = [Model, Option[]?]; export type WorldgenRegistriesType = Record; export class RegistryHolder { readonly game: Record; @@ -152,7 +152,6 @@ export class RegistryHolder { this.worldgen = Object.fromEntries( Object.entries(provider).map(([key, registry]) => [ key, - // @ts-ignore new WorldgenRegistry(...registry) ]) ) as Record; diff --git a/src/main/model/node/EnumNode.ts b/src/main/model/node/EnumNode.ts index e851c99..c1b45c9 100644 --- a/src/main/model/node/EnumNode.ts +++ b/src/main/model/node/EnumNode.ts @@ -12,7 +12,7 @@ export interface EnumNodeParams extends NodeBase<'enum'> { } export const EnumNode = < - T extends ReadonlyArray | Record + const T extends ReadonlyArray | Record >( values: T, def?: T extends ReadonlyArray ? typeof values[number] : keyof T, diff --git a/src/main/viewer/biome/BiomeSourceMapLayer.ts b/src/main/viewer/biome/BiomeSourceMapLayer.ts index 99a00fc..15a74ac 100644 --- a/src/main/viewer/biome/BiomeSourceMapLayer.ts +++ b/src/main/viewer/biome/BiomeSourceMapLayer.ts @@ -1,4 +1,3 @@ -// @ts-ignore import { Coords, DoneCallback, GridLayer } from 'leaflet'; import { stripDefaultNamespace } from '../../util/LabelHelper'; import {