Made setupFeatures use more accurate types

This commit is contained in:
thepaperpilot 2021-08-17 22:30:49 -05:00
parent 78ca3713a1
commit 6e1536930e
2 changed files with 22 additions and 23 deletions

View file

@ -92,11 +92,10 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
} }
} }
if (layer.upgrades) { if (layer.upgrades) {
setupFeatures< setupFeatures<NonNullable<RawLayer["upgrades"]>, NonNullable<Layer["upgrades"]>, Upgrade>(
RawGridFeatures<GridFeatures<Upgrade>, Upgrade>, layer.id,
GridFeatures<Upgrade>, layer.upgrades
Upgrade );
>(layer.id, layer.upgrades);
setRowCol(layer.upgrades); setRowCol(layer.upgrades);
for (const id in layer.upgrades.data) { for (const id in layer.upgrades.data) {
layer.upgrades.data[id].bought = function() { layer.upgrades.data[id].bought = function() {
@ -190,8 +189,8 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
} }
if (layer.achievements) { if (layer.achievements) {
setupFeatures< setupFeatures<
RawGridFeatures<GridFeatures<Achievement>, Achievement>, NonNullable<RawLayer["achievements"]>,
GridFeatures<Achievement>, NonNullable<Layer["achievements"]>,
Achievement Achievement
>(layer.id, layer.achievements); >(layer.id, layer.achievements);
setRowCol(layer.achievements); setRowCol(layer.achievements);
@ -209,8 +208,8 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
} }
if (layer.challenges) { if (layer.challenges) {
setupFeatures< setupFeatures<
RawGridFeatures<GridFeatures<Challenge>, Challenge>, NonNullable<RawLayer["challenges"]>,
GridFeatures<Challenge>, NonNullable<Layer["challenges"]>,
Challenge Challenge
>(layer.id, layer.challenges); >(layer.id, layer.challenges);
setRowCol(layer.challenges); setRowCol(layer.challenges);
@ -301,11 +300,10 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
} }
} }
if (layer.buyables) { if (layer.buyables) {
setupFeatures< setupFeatures<NonNullable<RawLayer["buyables"]>, NonNullable<Layer["buyables"]>, Buyable>(
RawGridFeatures<GridFeatures<Buyable>, Buyable>, layer.id,
GridFeatures<Buyable>, layer.buyables
Buyable );
>(layer.id, layer.buyables);
setRowCol(layer.buyables); setRowCol(layer.buyables);
setDefault(layer.buyables, "respec", undefined, false); setDefault(layer.buyables, "respec", undefined, false);
setDefault( setDefault(
@ -353,8 +351,8 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
} }
if (layer.clickables) { if (layer.clickables) {
setupFeatures< setupFeatures<
RawGridFeatures<GridFeatures<Clickable>, Clickable>, NonNullable<RawLayer["clickables"]>,
GridFeatures<Clickable>, NonNullable<Layer["clickables"]>,
Clickable Clickable
>(layer.id, layer.clickables); >(layer.id, layer.clickables);
setRowCol(layer.clickables); setRowCol(layer.clickables);
@ -375,10 +373,11 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
} }
} }
if (layer.milestones) { if (layer.milestones) {
setupFeatures<RawFeatures<Features<Milestone>, Milestone>, Features<Milestone>, Milestone>( setupFeatures<
layer.id, NonNullable<RawLayer["milestones"]>,
layer.milestones NonNullable<Layer["milestones"]>,
); Milestone
>(layer.id, layer.milestones);
for (const id in layer.milestones.data) { for (const id in layer.milestones.data) {
layer.milestones.data[id].earned = function() { layer.milestones.data[id].earned = function() {
return ( return (
@ -416,7 +415,7 @@ export function addLayer(layer: RawLayer, player?: Partial<PlayerData>): void {
} }
} }
if (layer.grids) { if (layer.grids) {
setupFeatures<RawFeatures<Features<Grid>, Grid>, Features<Grid>, Grid>( setupFeatures<NonNullable<RawLayer["grids"]>, NonNullable<Layer["grids"]>, Grid>(
layer.id, layer.id,
layer.grids layer.grids
); );

View file

@ -37,7 +37,7 @@ export interface RawLayer extends RawFeature<Layer> {
subtabs?: Record<string, RawFeature<Subtab>>; subtabs?: Record<string, RawFeature<Subtab>>;
microtabs?: Record<string, RawMicrotabFamily>; microtabs?: Record<string, RawMicrotabFamily>;
upgrades?: RawGridFeatures<NonNullable<Layer["upgrades"]>, Upgrade>; upgrades?: RawGridFeatures<NonNullable<Layer["upgrades"]>, Upgrade>;
startData?: () => Record<string, any>; startData?: () => Record<string, State>;
} }
export interface Layer extends Feature { export interface Layer extends Feature {
@ -115,7 +115,7 @@ export interface Layer extends Feature {
activeSubtab?: Subtab | undefined; activeSubtab?: Subtab | undefined;
microtabs?: Record<string, MicrotabFamily>; microtabs?: Record<string, MicrotabFamily>;
upgrades?: GridFeatures<Upgrade>; upgrades?: GridFeatures<Upgrade>;
startData?: () => Record<string, any>; startData?: () => Record<string, State>;
click?: () => void; click?: () => void;
automate?: () => void; automate?: () => void;
reset: (force?: boolean) => void; reset: (force?: boolean) => void;