generated from mantinedev/vite-template
-
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.
feat: added light locators generator
- Loading branch information
Showing
5 changed files
with
119 additions
and
2 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,81 @@ | ||
import { | ||
Button, | ||
CopyButton, | ||
Grid, | ||
NumberInput, | ||
Stack, | ||
Text, | ||
Textarea, | ||
} from "@mantine/core"; | ||
import { useDocumentTitle, useInputState } from "@mantine/hooks"; | ||
import { makeLocators } from "../utils/factories"; | ||
|
||
export default function LightLocatorsGeneratorTab() { | ||
const [locators, setLocators] = useInputState(10); | ||
const [stateTime, setStateTime] = useInputState(5); | ||
const [generatedLocators, setGeneratedLocators] = useInputState(""); | ||
useDocumentTitle("RMG Utils for Stellaris - Light Locators Generator"); | ||
|
||
const onGenerateClick = () => { | ||
const result = makeLocators(locators, stateTime); | ||
setGeneratedLocators(result.join("\n")); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Text size="lg" mb="sm"> | ||
This will help you generate light locators for ships quickly. Just input | ||
the number of locators you need, the state time value and hit the | ||
button. | ||
</Text> | ||
<Grid columns={3}> | ||
<Grid.Col span={3} sm={1}> | ||
<Stack> | ||
<NumberInput | ||
value={locators} | ||
onChange={setLocators} | ||
description="The number of light locators you have" | ||
label="Locators number" | ||
min={1} | ||
required | ||
/> | ||
<NumberInput | ||
value={stateTime} | ||
onChange={setStateTime} | ||
description="How long is this state in seconds. Usually it's 5 seconds" | ||
label="State time" | ||
min={1} | ||
required | ||
/> | ||
<Button onClick={onGenerateClick}>Generate locators</Button> | ||
</Stack> | ||
</Grid.Col> | ||
<Grid.Col span={3} lg={2}> | ||
<Stack> | ||
<Textarea | ||
value={generatedLocators} | ||
onChange={setGeneratedLocators} | ||
label="Generated locators" | ||
description="The generated locators will show here" | ||
autosize | ||
minRows={5} | ||
maxRows={15} | ||
readOnly | ||
/> | ||
<CopyButton value={generatedLocators}> | ||
{({ copied, copy }) => ( | ||
<Button | ||
color={copied ? "teal" : "blue"} | ||
onClick={copy} | ||
styles={{ root: { alignSelf: "flex-end" } }} | ||
> | ||
{copied ? "Done!" : "Copy locators to clipboard"} | ||
</Button> | ||
)} | ||
</CopyButton> | ||
</Stack> | ||
</Grid.Col> | ||
</Grid> | ||
</> | ||
); | ||
} |
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,22 @@ | ||
import random from "random"; | ||
|
||
type LocatorColor = "blue" | "yellow" | "orange" | "green"; | ||
|
||
const locatorColors: LocatorColor[] = ["blue", "yellow", "green", "orange"]; | ||
|
||
export const makeLocator = (index: string, time: string, color: LocatorColor) => | ||
`event = { time = ${time} node = "light_locator_${index}" particle = "ship_light_${color}_regular_effect" keep_particle = yes trigger_once = yes }`; | ||
|
||
export const makeLocators = (amount: number, stateTime: number) => { | ||
const locators = Array(amount) | ||
.fill(null) | ||
.map((_, i) => { | ||
const index = (i + 1) | ||
.toString() | ||
.padStart(amount.toString().length + 1, "0"); | ||
const time = random.float(0, stateTime).toFixed(2); | ||
const color = locatorColors[random.int(0, locatorColors.length - 1)]; | ||
return makeLocator(index, time, color); | ||
}); | ||
return locators; | ||
}; |
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