Skip to content

Commit

Permalink
PacificBankHeistのジェネレーターが完成
Browse files Browse the repository at this point in the history
  • Loading branch information
DekoKiyo committed Oct 4, 2024
1 parent 12ed33d commit 27b9354
Show file tree
Hide file tree
Showing 10 changed files with 822 additions and 131 deletions.
14 changes: 12 additions & 2 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import Epic from './pages/Installation/Epic';
import Rockstar from './pages/Installation/Rockstar';
import Configurations from './pages/Configurations';
import { Callouts, CalloutsBase } from './pages/Callouts';
import { PacificBankHeistGen } from './generators/pages/Callouts/PacificBankHeist';
import { PacificBankHeistGen_Objects } from './generators/pages/Callouts/PacificBankHeist_Objects';
import { VehicleGen } from './generators/pages/Objects/Vehicle';
import { Toaster } from './components/ui/toaster';
import { PedGen } from './generators/pages/Objects/Ped';
import { WeaponGen } from './generators/pages/Objects/Weapon';
import Generators from './pages/Generators';
import { OutfitGen } from './generators/pages/Outfits/Outfits';
import { PacificBankHeistGen_Positions } from './generators/pages/Callouts/PacificBankHeist_Positions';
import PacificBankHeist_Root from './generators/pages/Callouts/PacificBankHeist_Root';

function App() {
return (
Expand All @@ -37,7 +39,15 @@ function App() {
<Route path="/installation/epic" Component={Epic} />
<Route path="/installation/rockstar" Component={Rockstar} />
<Route path="/configurations" Component={Configurations} />
<Route path="/generators/callouts/pacific-bank-heist" Component={PacificBankHeistGen} />
<Route path="/generators/callouts/pacific-bank-heist" Component={PacificBankHeist_Root} />
<Route
path="/generators/callouts/pacific-bank-heist-objects"
Component={PacificBankHeistGen_Objects}
/>
<Route
path="/generators/callouts/pacific-bank-heist-positions"
Component={PacificBankHeistGen_Positions}
/>
<Route path="/generators" Component={Generators} />
<Route path="/generators/vehicles" Component={VehicleGen} />
<Route path="/generators/peds" Component={PedGen} />
Expand Down
78 changes: 69 additions & 9 deletions web/src/generators/components/ValueWithChance.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import {
Accordion,
AccordionContent,
Expand All @@ -20,7 +20,14 @@ import { Popover, PopoverContent, PopoverTrigger } from '../../components/ui/pop
import { Slider } from '../../components/ui/slider';
import { v4 as uuidv4 } from 'uuid';
import { Label } from '../../components/ui/label';
import { GetOutfits, GetPeds, GetVehicles, GetWeapons } from '../../store/helpers';
import {
GetOutfits,
GetPeds,
GetVehicles,
GetWeapons,
LoadSettingsRaw,
SaveSettingsRaw
} from '../../store/helpers';
import { toast } from '../../components/ui/use-toast';

type Vwc = {
Expand All @@ -33,16 +40,33 @@ type Vwc = {
type Props = {
mode: 'vehicle' | 'ped' | 'weapon' | 'outfit';
title: string;
id: string;
handleValueChange(value: string): void;
};

const defaultChance = 100;
const chanceMin = 1;
const chanceMax = 1000;

type VwcData = {
parents_id: string;
chance: number;
value: string;
};

let VWC_SAVE_JSON: { [key: string]: VwcData | null } = {};
const VWC_SAVE_KEY = 'VWC_SAVE';

const VWC_SETTINGS: { [key: string]: Props } = {};

export const ValueWithChance = (props: Props) => {
const [vwcItems, setVwcItems] = useState<Vwc[]>([]);

useEffect(() => {
VWC_SETTINGS[props.id] = props;
setValueOnLoaded();
}, []);

const presets: string[] = [];
let type = 'Unknown';
switch (props.mode) {
Expand Down Expand Up @@ -88,23 +112,51 @@ export const ValueWithChance = (props: Props) => {
}
}

const setValueOnLoaded = () => {
const json = LoadSettingsRaw(VWC_SAVE_KEY);
if (json) {
VWC_SAVE_JSON = JSON.parse(json) as { [key: string]: VwcData | null };
for (const key in VWC_SAVE_JSON) {
const value = VWC_SAVE_JSON[key];
if (value) {
for (const setting in VWC_SETTINGS) {
if (props.id === VWC_SETTINGS[setting].id) {
if (props.id === value.parents_id) {
createNew(key, value?.chance, value?.value);
}
}
}
} else {
handleDelete(key);
}
}
}
};

const saveLocal = (value: Vwc) => {
VWC_SAVE_JSON[value.id] = {
parents_id: props.id,
value: value.value,
chance: value.chance
};
SaveSettingsRaw(VWC_SAVE_KEY, JSON.stringify(VWC_SAVE_JSON));
};

const returnJson = (values: Vwc[]) => {
const jsonBase: [number, string][] = [];
values.map((vwc) => jsonBase.push([vwc.chance, vwc.value]));
props.handleValueChange(JSON.stringify(jsonBase));
};

const onAddClicked = () => {
const createNew = (id?: string, chance?: number, value?: string) => {
const newValue: Vwc = {
chance: defaultChance,
value: '',
id: uuidv4(),
chance: chance ? chance : defaultChance,
value: value ? value : '',
id: id ? id : uuidv4(),
open: false
};

setVwcItems((previous) => {
const value = [...previous, newValue];
console.log(value);
returnJson(value);
return value;
});
Expand All @@ -115,6 +167,7 @@ export const ValueWithChance = (props: Props) => {
const newVwcItems = deepCopy.map((vwc) => {
if (vwc.id === id) {
vwc.chance = chance;
saveLocal(vwc);
}
return vwc;
});
Expand All @@ -130,6 +183,7 @@ export const ValueWithChance = (props: Props) => {
if (vwc.id === id) {
vwc.value = value;
vwc.open = false;
saveLocal(vwc);
}
return vwc;
});
Expand All @@ -144,6 +198,7 @@ export const ValueWithChance = (props: Props) => {
const newVwcItems = deepCopy.map((vwc) => {
if (vwc.id === id) {
vwc.open = isOpen;
saveLocal(vwc);
}
return vwc;
});
Expand Down Expand Up @@ -176,6 +231,7 @@ export const ValueWithChance = (props: Props) => {
vwc.chance = temp;
}
}
saveLocal(vwc);
return vwc;
});
setVwcItems(() => {
Expand All @@ -186,6 +242,10 @@ export const ValueWithChance = (props: Props) => {

const handleDelete = (id: string) => {
const newVwcItems = vwcItems.filter((vwc) => vwc.id !== id);

VWC_SAVE_JSON[id] = null;
SaveSettingsRaw(VWC_SAVE_KEY, JSON.stringify(VWC_SAVE_JSON));

setVwcItems(() => {
returnJson(newVwcItems);
return newVwcItems;
Expand All @@ -197,7 +257,7 @@ export const ValueWithChance = (props: Props) => {
<div className="vwc">
<div className="vwc-header">
<Label>{props.title}</Label>
<Button type="button" onClick={onAddClicked}>
<Button type="button" onClick={() => createNew()}>
Add
</Button>
</div>
Expand Down
Loading

0 comments on commit 27b9354

Please sign in to comment.