Skip to content

Commit

Permalink
chore(types): simplify const types and some ts-ignore comments
Browse files Browse the repository at this point in the history
  • Loading branch information
syldium committed Mar 16, 2024
1 parent b1349a8 commit f008df9
Show file tree
Hide file tree
Showing 21 changed files with 36 additions and 37 deletions.
5 changes: 3 additions & 2 deletions src/main/component/ui/NumberInput.tsx
Original file line number Diff line number Diff line change
@@ -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<HTMLInputElement> {
interface NumberInputProps
extends Omit<InputHTMLAttributes<HTMLInputElement>, 'onChange'>
{
onChange: (value: number) => void;
value: number;
step?: number;
Expand Down
10 changes: 5 additions & 5 deletions src/main/data/1.17/Biome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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'))),
Expand Down
2 changes: 1 addition & 1 deletion src/main/data/1.17/ConfiguredDecorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/main/data/1.17/DimensionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down
2 changes: 1 addition & 1 deletion src/main/data/1.17/Direction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export const Direction = EnumNode(
'south',
'west',
'east'
] as const
]
);
2 changes: 1 addition & 1 deletion src/main/data/1.17/WorldgenStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
2 changes: 1 addition & 1 deletion src/main/data/1.18.2/Biome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
};
Expand Down
4 changes: 2 additions & 2 deletions src/main/data/1.18.2/DensityFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ 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'),
erosion: ResourceNode('worldgen/density_function'),
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')
}),
Expand Down
2 changes: 1 addition & 1 deletion src/main/data/1.18.2/StructureSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
2 changes: 1 addition & 1 deletion src/main/data/1.18/Biome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const BiomeSettings = {
'taiga',
'the_end',
'underground'
] as const
]
),
features: ListNode(ListNode(ResourceNode('worldgen/placed_feature'))),
spawners: Obj({
Expand Down
2 changes: 1 addition & 1 deletion src/main/data/1.18/BiomeSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const MultiNoise = EitherNode(
)
}),
Obj({
preset: EnumNode(['overworld', 'nether'] as const, undefined, true)
preset: EnumNode(['overworld', 'nether'], undefined, true)
})
);

Expand Down
8 changes: 4 additions & 4 deletions src/main/data/1.18/ConfiguredStructureFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down Expand Up @@ -49,15 +49,15 @@ export const ConfiguredStructureFeature: Model = {
jungle_pyramid: Empty,
mansion: Empty,
mineshaft: Obj({
type: EnumNode(['normal', 'mesa'] as const),
type: EnumNode(['normal', 'mesa']),
...Probability
}),
monument: Empty,
nether_fossil: Obj({
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
}),
Expand All @@ -72,7 +72,7 @@ export const ConfiguredStructureFeature: Model = {
'ocean',
'swamp',
'nether'
] as const
]
)
}),
shipwreck: Obj({
Expand Down
2 changes: 1 addition & 1 deletion src/main/data/1.18/NoiseSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Spline = Obj({
'erosion',
'weirdness',
'ridges'
] as const
]
),
points: ListNode(SplinePoint)
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/data/1.18/PlacementModifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion src/main/data/1.18/TemplatePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/data/1.19/DecorationStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const DecorationStep = EnumNode(
'fluid_springs',
'vegetal_decoration',
'top_layer_modification'
] as const
]
);

export const TerrainAdaptation = EnumNode(
Expand All @@ -22,6 +22,6 @@ export const TerrainAdaptation = EnumNode(
'bury',
'beard_thin',
'beard_box'
] as const,
],
'none'
);
8 changes: 4 additions & 4 deletions src/main/data/1.19/Structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down Expand Up @@ -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
}),
Expand All @@ -71,7 +71,7 @@ export const Structure: Model = {
'in_mountain',
'underground',
'in_nether'
] as const
]
),
air_pocket_probability: Probability.probability,
mossiness: Probability.probability,
Expand Down
4 changes: 2 additions & 2 deletions src/main/data/1.19/StructureSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
})
Expand Down Expand Up @@ -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 }),
Expand Down
3 changes: 1 addition & 2 deletions src/main/model/Registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WorldgenRegistryKey, RegistryInfo>;
export class RegistryHolder {
readonly game: Record<RegistryKey, Registry>;
Expand All @@ -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<WorldgenRegistryKey, WorldgenRegistry>;
Expand Down
2 changes: 1 addition & 1 deletion src/main/model/node/EnumNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface EnumNodeParams extends NodeBase<'enum'> {
}

export const EnumNode = <
T extends ReadonlyArray<string> | Record<string, string>
const T extends ReadonlyArray<string> | Record<string, string>
>(
values: T,
def?: T extends ReadonlyArray<string> ? typeof values[number] : keyof T,
Expand Down
1 change: 0 additions & 1 deletion src/main/viewer/biome/BiomeSourceMapLayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore
import { Coords, DoneCallback, GridLayer } from 'leaflet';
import { stripDefaultNamespace } from '../../util/LabelHelper';
import {
Expand Down

0 comments on commit f008df9

Please sign in to comment.