-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Olivier Gagnon
committed
Jun 2, 2024
1 parent
76ce2f9
commit f0b9b2d
Showing
16 changed files
with
732 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Bot, Entity, EntityType, Item } from "@nsdefs"; | ||
import { factory } from "./Helper"; | ||
|
||
export interface Factory { | ||
bits: number; | ||
entities: Entity[]; | ||
} | ||
|
||
export const distance = (a: Entity, b: Entity) => Math.abs(a.x - b.x) + Math.abs(a.y - b.y); | ||
|
||
export const adjacent = (a: Entity, b: Entity) => distance(a, b) === 1; | ||
|
||
export const findBot = (name: string) => | ||
factory.entities.find((e): e is Bot => e.type === EntityType.Bot && e.name === name); | ||
|
||
export const findEntityAt = <T extends Entity>(x: number, y: number, type?: EntityType): T | undefined => | ||
factory.entities.find((e): e is T => (!type || e.type === type) && e.x === x && e.y === y); | ||
|
||
export const bitsMap: Record<Item, number> = { | ||
[Item.BasicR]: 1, | ||
[Item.BasicG]: 1, | ||
[Item.BasicB]: 1, | ||
[Item.ComplexR]: 4, | ||
[Item.ComplexG]: 4, | ||
[Item.ComplexB]: 4, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { EntityType, Item } from "@nsdefs"; | ||
import { Factory } from "./Factory"; | ||
|
||
export const factorySize = 12; | ||
|
||
const defaultFactory: Factory = { | ||
bits: 0, | ||
entities: [ | ||
{ | ||
type: EntityType.Dispenser, | ||
dispensing: Item.BasicR, | ||
x: Math.floor(factorySize / 4), | ||
y: 0, | ||
cooldown: 10000, | ||
cooldownUntil: 0, | ||
inventory: [Item.BasicR], | ||
maxInventory: 1, | ||
}, | ||
{ | ||
type: EntityType.Dispenser, | ||
dispensing: Item.BasicG, | ||
x: Math.floor(factorySize / 2), | ||
y: 0, | ||
cooldown: 10000, | ||
cooldownUntil: 0, | ||
inventory: [Item.BasicG], | ||
maxInventory: 1, | ||
}, | ||
{ | ||
type: EntityType.Dispenser, | ||
dispensing: Item.BasicB, | ||
x: Math.floor((factorySize * 3) / 4), | ||
y: 0, | ||
cooldown: 10000, | ||
cooldownUntil: 0, | ||
inventory: [Item.BasicB], | ||
maxInventory: 1, | ||
}, | ||
{ | ||
type: EntityType.Dock, | ||
x: Math.floor(factorySize / 4), | ||
y: Math.floor(factorySize - 1), | ||
potentialRequest: [Item.BasicR, Item.BasicG, Item.BasicB], | ||
potentialRequestCount: 1, | ||
currentRequest: [Item.BasicR], | ||
inventory: [], | ||
maxInventory: 1, | ||
}, | ||
{ | ||
type: EntityType.Dock, | ||
x: Math.floor(factorySize / 2), | ||
y: Math.floor(factorySize - 1), | ||
potentialRequest: [Item.BasicR, Item.BasicG, Item.BasicB], | ||
potentialRequestCount: 1, | ||
currentRequest: [Item.BasicG], | ||
inventory: [], | ||
maxInventory: 1, | ||
}, | ||
{ | ||
type: EntityType.Dock, | ||
x: Math.floor((factorySize * 3) / 4), | ||
y: Math.floor(factorySize - 1), | ||
potentialRequest: [Item.BasicR, Item.BasicG, Item.BasicB], | ||
potentialRequestCount: 1, | ||
currentRequest: [Item.BasicB], | ||
inventory: [], | ||
maxInventory: 1, | ||
}, | ||
{ | ||
type: EntityType.Dock, | ||
x: 0, | ||
y: Math.floor(factorySize - 1), | ||
potentialRequest: [Item.ComplexR], | ||
potentialRequestCount: 1, | ||
currentRequest: [Item.ComplexR], | ||
inventory: [], | ||
maxInventory: 1, | ||
}, | ||
{ | ||
type: EntityType.Bot, | ||
x: Math.floor(factorySize / 2), | ||
y: Math.floor(factorySize / 2), | ||
inventory: [], | ||
energy: 16, | ||
name: "alice", | ||
maxInventory: 1, | ||
}, | ||
{ | ||
type: EntityType.Crafter, | ||
x: 2, | ||
y: 2, | ||
inventory: [], | ||
maxInventory: 3, | ||
recipe: { | ||
input: [Item.BasicR], | ||
output: [Item.ComplexR], | ||
}, | ||
}, | ||
{ | ||
type: EntityType.Chest, | ||
inventory: [Item.BasicR], | ||
maxInventory: 3, | ||
x: Math.floor(factorySize / 2) + 1, | ||
y: Math.floor(factorySize / 2), | ||
}, | ||
], | ||
}; | ||
|
||
export const factory: Factory = defaultFactory; | ||
|
||
export const loadFactory = (save: string) => { | ||
if (!save) return; | ||
// const savedFactory = JSON.parse(save); | ||
// Object.assign(factory, savedFactory); | ||
}; | ||
|
||
export const NewBot = (name: string, x: number, y: number) => { | ||
factory.entities.push({ | ||
type: EntityType.Bot, | ||
x, | ||
y, | ||
inventory: [], | ||
energy: 16, | ||
name, | ||
maxInventory: 1, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const botPrice = (currentBots: number): number => Math.pow(2, currentBots + 3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import React from "react"; | ||
import SmartToyIcon from "@mui/icons-material/SmartToy"; | ||
import { styled } from "@mui/system"; | ||
import { Dispenser, Entity, EntityType, Item } from "@nsdefs"; | ||
|
||
import MoveToInboxIcon from "@mui/icons-material/MoveToInbox"; | ||
import OutboxIcon from "@mui/icons-material/Outbox"; | ||
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank"; | ||
import PrecisionManufacturingIcon from "@mui/icons-material/PrecisionManufacturing"; | ||
import { Tooltip, Typography } from "@mui/material"; | ||
|
||
export const cellSize = 48; | ||
|
||
const defaultIconStyle = { | ||
width: cellSize + "px", | ||
height: cellSize + "px", | ||
color: "white", | ||
}; | ||
|
||
const colorRed = "red"; | ||
const colorBlue = "#1E90FF"; | ||
const colorGreen = "#7CFC00"; | ||
|
||
const itemColorMap: Record<Item, string> = { | ||
[Item.BasicR]: colorRed, | ||
[Item.BasicB]: colorBlue, | ||
[Item.BasicG]: colorGreen, | ||
[Item.ComplexR]: colorRed, | ||
[Item.ComplexB]: colorBlue, | ||
[Item.ComplexG]: colorGreen, | ||
}; | ||
|
||
const BotIcon = styled(SmartToyIcon)(defaultIconStyle); | ||
const DispenserIcon = styled(OutboxIcon)((props: { dispenser: Dispenser; col: string }) => ({ | ||
...defaultIconStyle, | ||
color: new Date().getTime() > props.dispenser.cooldownUntil ? props.col : "gray", | ||
})); | ||
|
||
const DockIcon = styled(MoveToInboxIcon)({ | ||
...defaultIconStyle, | ||
}); | ||
|
||
const CrafterIcon = styled(PrecisionManufacturingIcon)({ | ||
...defaultIconStyle, | ||
}); | ||
|
||
const ChestIcon = styled(CheckBoxOutlineBlankIcon)({ | ||
...defaultIconStyle, | ||
}); | ||
|
||
interface ITooltipContentProps { | ||
entity: Entity; | ||
content: React.ReactElement; | ||
} | ||
const TooltipContent = ({ entity, content }: ITooltipContentProps): React.ReactElement => { | ||
return ( | ||
<> | ||
<Typography>{entity.type}</Typography> | ||
{content} | ||
</> | ||
); | ||
}; | ||
|
||
const TooltipInventory = ({ entity }: { entity: Entity }): React.ReactElement => { | ||
return ( | ||
<Typography component="span"> | ||
{entity.inventory.map((item) => ( | ||
<span key={item} style={{ color: itemColorMap[item] }}> | ||
{item} | ||
</span> | ||
))} | ||
</Typography> | ||
); | ||
}; | ||
|
||
export const EntityIcon = ({ entity }: { entity: Entity }): React.ReactElement => { | ||
switch (entity.type) { | ||
case EntityType.Chest: { | ||
return ( | ||
<Tooltip title={<TooltipContent entity={entity} content={<TooltipInventory entity={entity} />} />}> | ||
<ChestIcon /> | ||
</Tooltip> | ||
); | ||
} | ||
case EntityType.Bot: { | ||
return ( | ||
<Tooltip | ||
title={ | ||
<Typography> | ||
{entity.name} | ||
<br /> <TooltipInventory entity={entity} /> | ||
</Typography> | ||
} | ||
> | ||
<BotIcon /> | ||
</Tooltip> | ||
); | ||
} | ||
case EntityType.Dispenser: { | ||
return ( | ||
<Tooltip | ||
title={ | ||
<> | ||
<TooltipContent entity={entity} content={<Typography>{`dispensing: ${entity.dispensing}`}</Typography>} /> | ||
<TooltipInventory entity={entity} /> | ||
</> | ||
} | ||
> | ||
<DispenserIcon dispenser={entity} col={itemColorMap[entity.dispensing]} /> | ||
</Tooltip> | ||
); | ||
break; | ||
} | ||
case EntityType.Dock: { | ||
return ( | ||
<Tooltip | ||
title={ | ||
<TooltipContent | ||
entity={entity} | ||
content={<Typography>{`requesting: ${entity.currentRequest}`}</Typography>} | ||
/> | ||
} | ||
> | ||
<DockIcon sx={{ color: itemColorMap[entity.currentRequest[0] ?? Item.BasicR] }} /> | ||
</Tooltip> | ||
); | ||
} | ||
case EntityType.Crafter: { | ||
return ( | ||
<Tooltip | ||
title={ | ||
<TooltipContent | ||
entity={entity} | ||
content={ | ||
<> | ||
<Typography>{`input: ${entity.recipe.input}, output: ${entity.recipe.output}`}</Typography> | ||
<TooltipInventory entity={entity} /> | ||
</> | ||
} | ||
/> | ||
} | ||
> | ||
<CrafterIcon /> | ||
</Tooltip> | ||
); | ||
break; | ||
} | ||
} | ||
return <></>; | ||
}; |
Oops, something went wrong.