Skip to content

Commit

Permalink
feat: added light locators generator
Browse files Browse the repository at this point in the history
  • Loading branch information
The24thDS committed Jul 27, 2022
1 parent 8f2baf2 commit e8e1a99
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@mantine/core": "5.0.0",
"@mantine/hooks": "5.0.0",
"@mantine/notifications": "^5.0.0",
"random": "^3.0.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.3.0"
Expand Down
5 changes: 3 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import { theme } from "./theme";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { ROUTES } from "./constants";
import { Home } from "./components/Home";
import LightLocatorsGeneratorTab from "./components/LightLocatorsGeneratorTab";

export default function App() {
return (
<MantineProvider theme={theme} withGlobalStyles withNormalizeCSS>
<BrowserRouter>
<Container size="xl">
<Container size={1500} style={{ minHeight: "100vh" }}>
<HeaderTabs />
<Container fluid mt="md" p="sm">
<Routes>
<Route path={ROUTES.HOME.path} element={<Home />} />
<Route
path={ROUTES.LIGHT_LOCATORS_GENERATOR.path}
element={<p>generator page</p>}
element={<LightLocatorsGeneratorTab />}
/>
</Routes>
</Container>
Expand Down
81 changes: 81 additions & 0 deletions src/components/LightLocatorsGeneratorTab.tsx
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>
</>
);
}
22 changes: 22 additions & 0 deletions src/utils/factories.ts
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;
};
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,13 @@ prop-types@^15.6.2:
object-assign "^4.1.1"
react-is "^16.13.1"

random@^3.0.6:
version "3.0.6"
resolved "https://registry.yarnpkg.com/random/-/random-3.0.6.tgz#c918e9498dee461affde72986c79ac4d9ef486cf"
integrity sha512-B53pp/8eFBxULg6sfQgjjmy3vZ2CWVt0Nk4OgkSpvmAf3VXfcEUgGASbNWbXiTiExWe8hCIf5HlddNHzrte9jg==
dependencies:
seedrandom "^3.0.5"

react-dom@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
Expand Down Expand Up @@ -1128,6 +1135,11 @@ scheduler@^0.23.0:
dependencies:
loose-envify "^1.1.0"

seedrandom@^3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-3.0.5.tgz#54edc85c95222525b0c7a6f6b3543d8e0b3aa0a7"
integrity sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==

semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
Expand Down

0 comments on commit e8e1a99

Please sign in to comment.