Skip to content

Commit

Permalink
feat: material tracker greenstacks + hide raw json data button
Browse files Browse the repository at this point in the history
  • Loading branch information
Morta1 committed Aug 18, 2024
1 parent 596a651 commit 3f89bcd
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 39 deletions.
4 changes: 2 additions & 2 deletions components/account/Worlds/World6/farming/Plot.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Card, CardContent, Stack, Typography } from '@mui/material';
import { msToDate, notateNumber, prefix } from '@utility/helpers';
import { commaNotation, msToDate, notateNumber, prefix } from '@utility/helpers';
import Timer from '@components/common/Timer';
import React from 'react';
import LockIcon from '@mui/icons-material/Lock';
Expand All @@ -18,7 +18,7 @@ const Plot = ({ plot, market, ranks, lastUpdated }) => {
return <Card variant={'outlined'} key={icon}>
<CardContent>
<Stack direction={'row'} gap={1}>
<Typography>{Math.round(quantity)}</Typography>
<Typography>{commaNotation(Math.round(quantity))}</Typography>
<img width={20} height={20} src={`${prefix}data/${icon}`} alt={''}/>
</Stack>
</CardContent>
Expand Down
2 changes: 1 addition & 1 deletion data/website-data.js

Large diffs are not rendered by default.

63 changes: 40 additions & 23 deletions pages/data.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {
Accordion,
AccordionDetails,
AccordionSummary,
Checkbox,
Collapse,
Container,
Expand Down Expand Up @@ -33,11 +36,14 @@ import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
import Popper from '@components/common/Popper';
import { isProd } from '@utility/helpers';
import { Adsense } from '@ctrl/react-adsense';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import { useTheme } from '@emotion/react';

const HOURS = 4;
const WAIT_TIME = 1000 * 60 * 60 * HOURS;
const Data = () => {
const router = useRouter();
const theme = useTheme();
const { state } = useContext(AppContext);
const [key, setKey] = useState('all');
const [anchorEl, setAnchorEl] = React.useState(null);
Expand Down Expand Up @@ -146,32 +152,43 @@ const Data = () => {
<div>
<Typography variant={'h4'}>Data</Typography>
<Typography variant={'body1'}>Use this when asked for data</Typography>
<ButtonStyle component={'span'} variant={'outlined'} startIcon={<FileCopyIcon/>}
<ButtonStyle sx={{ mb: 2 }} component={'span'} variant={'outlined'} startIcon={<FileCopyIcon/>}
onClick={handleCopyITRaw}>
IdleonToolbox JSON
</ButtonStyle>
<div>
<Stack mt={3} direction={'row'} alignItems={'center'}>
<ButtonStyle sx={{ textTransform: 'none', fontSize: 12 }}
variant={'outlined'}
startIcon={<FileCopyIcon/>}
size="small"
onClick={handleCopyRaw}>
Raw Game JSON
</ButtonStyle>
<IconButton onClick={() => setShowRawData(!showRawData)}>
<ArrowRightIcon style={{
transform: showRawData ? 'rotate(90deg)' : 'rotate(0deg)',
transition: 'transform 0.2s ease-in-out'
}}/>
</IconButton>
</Stack>
<Collapse in={showRawData}>
<div style={{ whiteSpace: 'pre-wrap', overflowWrap: 'break-word' }}>
{JSON.stringify(JSON.parse(localStorage.getItem('rawJson')), null, 2)}
</div>
</Collapse>
</div>
<Accordion disableGutters
sx={{
maxWidth: 500,
'&:before': { display: 'none' },
border: `1px solid ${theme.palette.divider}`,
'&:not(:last-child)': {
borderBottom: 0
}
}}>
<AccordionSummary expandIcon={<ExpandMoreIcon/>}>Advanced</AccordionSummary>
<AccordionDetails sx={{ backgroundColor: 'rgb(22, 22, 22)', p: 3 }}>
<Stack direction={'row'} alignItems={'center'}>
<ButtonStyle sx={{ textTransform: 'none', fontSize: 12 }}
variant={'outlined'}
startIcon={<FileCopyIcon/>}
size="small"
onClick={handleCopyRaw}>
Raw Game JSON
</ButtonStyle>
<IconButton onClick={() => setShowRawData(!showRawData)}>
<ArrowRightIcon style={{
transform: showRawData ? 'rotate(90deg)' : 'rotate(0deg)',
transition: 'transform 0.2s ease-in-out'
}}/>
</IconButton>
</Stack>
<Collapse in={showRawData}>
<div style={{ whiteSpace: 'pre-wrap', overflowWrap: 'break-word' }}>
{JSON.stringify(JSON.parse(localStorage.getItem('rawJson')), null, 2)}
</div>
</Collapse>
</AccordionDetails>
</Accordion>
<Popper anchorEl={anchorEl} handleClose={() => setAnchorEl(null)}/>
</div>
<Typography variant={'h4'} mt={8}>Local Storage</Typography>
Expand Down
35 changes: 28 additions & 7 deletions pages/tools/material-tracker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Checkbox,
Chip,
createFilterOptions,
Divider,
FormControlLabel,
List,
ListItem,
Expand All @@ -14,7 +15,7 @@ import {
useMediaQuery
} from '@mui/material';
import React, { useContext, useMemo, useState } from 'react';
import { cleanUnderscore, notateNumber, numberWithCommas, prefix } from '@utility/helpers';
import { cleanUnderscore, handleDownload, notateNumber, numberWithCommas, prefix } from '@utility/helpers';
import { itemsArray } from '../../data/website-data';
import Button from '@mui/material/Button';
import InfoIcon from '@mui/icons-material/Info';
Expand All @@ -26,6 +27,8 @@ import DeleteForeverIcon from '@mui/icons-material/DeleteForever';
import IconButton from '@mui/material/IconButton';
import EditIcon from '@mui/icons-material/Edit';
import Box from '@mui/material/Box';
import FileUploadButton from '@components/common/DownloadButton';
import { CardTitleAndValue } from '@components/common/styles';

const filterOptions = createFilterOptions({
trim: true,
Expand All @@ -47,14 +50,16 @@ const MaterialTracker = () => {
}) => displayName !== 'ERROR' && displayName !== 'Blank' &&
displayName !== 'Filler' && displayName !== 'DONTFILL' && displayName !== 'FILLER' && itemType !== 'Equip'
), []);

const totalOwnedItems = useMemo(() => getAllItems(state?.characters, state?.account), [state?.characters,
state?.account]);
const [errors, setErrors] = useState({ material: false, lowerBound: false, upperBound: false });

const handleAddTracker = () => {
const handleAddTracker = (allGreenStacks) => {
const greenStacks = totalOwnedItems.filter(({ amount }) => amount >= 10e6);
const tempErrors = {};
if (value.length === 0) {
if (value.length > 0 || (allGreenStacks && greenStacks.length > 0)) {
tempErrors.material = false;
} else {
tempErrors.material = true;
}
const tempLowerBound = bounds?.lowerBound?.replace(/,/g, '');
Expand All @@ -68,7 +73,7 @@ const MaterialTracker = () => {
return;
}
const updated = { ...trackedItems };
value.forEach((item) => {
(allGreenStacks ? greenStacks : value).forEach((item) => {
updated[item?.rawName] = {
item,
lowerBound: tempLowerBound ? parseInt(tempLowerBound) : '',
Expand Down Expand Up @@ -116,6 +121,15 @@ const MaterialTracker = () => {
title="Material Tracker | Idleon Toolbox"
description="Add a material, set your own threshold and keep track of your inventory."
/>
<CardTitleAndValue title={'Utility'}>
<Stack direction={'row'} alignItems={'center'} gap={2}>
<FileUploadButton onFileUpload={(data) => {
setTrackedItems(data);
}}>Import</FileUploadButton>
<Button onClick={() => handleDownload(trackedItems, 'it-material-tracker')} variant={'outlined'}
size={'small'}>Export</Button>
</Stack>
</CardTitleAndValue>
<Stack mb={3} direction={'row'} alignItems={'center'} gap={2} flexWrap={'wrap'}>
<Autocomplete
id="material tracker"
Expand Down Expand Up @@ -184,8 +198,15 @@ const MaterialTracker = () => {
control={<Checkbox checked={includeNearly} onChange={() => setIncludeNearly(!includeNearly)}/>}
label="Show an alert when value is near the bounds"
/>
<Button onClick={handleAddTracker} sx={{ height: 'fit-content', width: 'fit-content' }} variant={'contained'}>Add
tracker</Button>
<Stack direction={'row'} alignItems={'center'}
divider={<Divider orientation={'vertical'} flexItem sx={{ bgcolor: 'grey' }}/>} gap={2}>
<Button onClick={() => handleAddTracker()} sx={{ height: 'fit-content', width: 'fit-content' }}
variant={'contained'}>Add
tracker</Button>
<Button onClick={() => handleAddTracker(true)} sx={{ height: 'fit-content', width: 'fit-content' }}
variant={'contained'}
color={'secondary'}>Add tracker for all greenstacks</Button>
</Stack>
</Stack>
<Stack>
<Typography mt={2} variant={'caption'}>Conditions:</Typography>
Expand Down
3 changes: 1 addition & 2 deletions parsers/arcade.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export const getArcade = (idleonData, account, serverVars) => {
const parseArcade = (arcadeRaw, account, serverVars) => {
const balls = account?.accountOptions?.[74];
const goldBalls = account?.accountOptions?.[75];
const maxBalls = Math.round(getMaxClaimTime(account)
/ Math.max(1, getSecPerBall(account)));
const maxBalls = Math.round(getMaxClaimTime(account) / Math.max(1, getSecPerBall(account)));
const arcadeShopList = arcadeShop?.map((upgrade, index) => {
const { x1, x2, func } = upgrade;
const level = arcadeRaw?.[index] ?? 0;
Expand Down
3 changes: 1 addition & 2 deletions parsers/dungeons.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ export const getMaxClaimTime = (account) => {
}

export const getSecPerBall = (account) => {
return 4e3 /
(1 + (getBallBonus(account) + getBribeBonus(account?.bribes, 'Weighted_Marbles')) / 100)
return 4e3 / (1 + (getBallBonus(account) + getBribeBonus(account?.bribes, 'Weighted_Marbles')) / 100)
}

export const getBallBonus = (account) => {
Expand Down
4 changes: 2 additions & 2 deletions utility/dashboard/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ export const getWorld2Alerts = (account, fields, options, characters) => {
if (options?.arcade?.balls?.checked) {
const ballsToClaim = Math.floor(Math.min(account?.timeAway?.GlobalTime - account?.timeAway?.Arcade, getMaxClaimTime(account))
/ Math.max(getSecPerBall(account), 1800));
const onePercent = 5 * account?.arcade?.maxBalls / 100;
const balls = ballsToClaim >= account?.arcade?.maxBalls - onePercent;
const percent = 5 * account?.arcade?.maxBalls / 100;
const balls = ballsToClaim >= account?.arcade?.maxBalls - percent;
if (balls) {
arcade.balls = balls;
}
Expand Down

0 comments on commit 3f89bcd

Please sign in to comment.