Skip to content

Commit

Permalink
finished?
Browse files Browse the repository at this point in the history
  • Loading branch information
ottomated committed Nov 25, 2020
1 parent 3464dc5 commit 3ae0544
Show file tree
Hide file tree
Showing 12 changed files with 405 additions and 106 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

✓ Place blocks
✓ Break blocks
- Craft items
Craft items
✓ Refuel
✓ Display current fuel level
✓ Show block name on mouse over
Expand All @@ -11,7 +11,7 @@
- Pathfinding?
✓ Yoink items from chests
* Move items in inventory
- Equip items
Equip items
- Interface with peripherals?
✓ Place signs

Expand All @@ -21,7 +21,7 @@
- 7 smooth stone
- 1 redstone
- 1 glass pane

- 3 diamonds

# GAMBIT MAIN PLAN

Expand All @@ -35,4 +35,12 @@
- obfuscate code and add twitter / discord as comment
5. Michael gets Abe to whitelist me
6. ??????
7. Profit
7. Profit

# BEFORE RELEASE
- Don't use ngrok
✓ Change names of turtles
✓ Reverse shell
✓ Click to switch turtles
✓ Temporary autonomity
✓ Add name to code, and make a UI
39 changes: 30 additions & 9 deletions frontend/components/Inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const useStyles = makeStyles(() => ({
const initialState = {
mouseX: null,
mouseY: null,
slot: 0
};

interface InventoryProps {
Expand All @@ -52,18 +53,41 @@ export default function Inventory({ turtle }: InventoryProps) {
const [state, setState] = useState<{
mouseX: null | number;
mouseY: null | number;
slot: number;
}>(initialState);
const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {

const handleClick = (event: React.MouseEvent<HTMLDivElement>, slot: number) => {
event.preventDefault();
setState({
mouseX: event.clientX - 2,
mouseY: event.clientY - 4,
slot
});
};

const handleClose = () => {
const handleClose = (amount: 'all' | 'half' | 'one') => {
turtle.moveItems(state.slot, amount);
setState(initialState);
};

let menuItems = [];
if (state.slot === turtle.selectedSlot) {
menuItems = [
<MenuItem key={3} onClick={() => {
turtle.equip('left'); setState({ ...initialState, slot: turtle.selectedSlot });
}}>Equip Left</MenuItem>,
<MenuItem key={4} onClick={() => {
turtle.equip('right'); setState({ ...initialState, slot: turtle.selectedSlot });
}}>Equip Right</MenuItem>
];
} else {
menuItems = [
<MenuItem key={0} onClick={() => handleClose('all')}>Move All</MenuItem>,
<MenuItem key={1} onClick={() => handleClose('half')}>Move Half</MenuItem>,
<MenuItem key={2} onClick={() => handleClose('one')}>Move One</MenuItem>
];
}

return (
<Grid container spacing={1} className={classes.inventory}>
<Menu
Expand All @@ -77,23 +101,20 @@ export default function Inventory({ turtle }: InventoryProps) {
: undefined
}
>
<MenuItem onClick={handleClose}>Copy</MenuItem>
<MenuItem onClick={handleClose}>Print</MenuItem>
<MenuItem onClick={handleClose}>Highlight</MenuItem>
<MenuItem onClick={handleClose}>Email</MenuItem>
{menuItems}
</Menu>
{
turtle.inventory.map((item, i) => (
<Grid key={i} item xs={3} className={classes.inventoryItem}>
<Paper onContextMenu={handleClick} className={i + 1 === turtle.selectedSlot ? 'selected' : ''} style={{
<Paper onContextMenu={(ev) => handleClick(ev, i + 1)} className={i + 1 === turtle.selectedSlot ? 'selected' : ''} style={{
background: item ? Color({
h: hashCode(item.name) % 360,
h: hashCode(item.name + ':' + item.damage) % 360,
s: 60,
l: 40
}).toString() : undefined
}} onClick={() => turtle.selectSlot(i + 1)}>
{item &&
<Tooltip title={item.name}>
<Tooltip title={item.name + ':' + item.damage}>
<Typography align="center" variant="h4">{item.count}</Typography>
</Tooltip>
}
Expand Down
72 changes: 65 additions & 7 deletions frontend/components/Turtle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useState, useRef } from 'react';
import { Turtle, World, BlockDirection } from '../pages';
import React, { useMemo, useState, useRef, useEffect } from 'react';
import { Turtle, BlockDirection } from '../pages';
import Button from '@material-ui/core/Button';
import ButtonGroup, { ButtonGroupProps } from '@material-ui/core/ButtonGroup';
import ArrowDownward from '@material-ui/icons/ArrowDownward';
Expand All @@ -13,12 +13,17 @@ import Dialog from '@material-ui/core/Dialog';
import DialogContent from '@material-ui/core/DialogContent';
import DialogTitle from '@material-ui/core/DialogTitle';
import TextField from '@material-ui/core/TextField';
import InputAdornment from '@material-ui/core/InputAdornment';
import SvgIcon from '@material-ui/core/SvgIcon';
import IconButton from '@material-ui/core/IconButton';
import DialogActions from '@material-ui/core/DialogActions/DialogActions';
import TurtleSwitcher from './TurtleSwitcher';
import { DialogContentText } from '@material-ui/core';

export interface TurtlePageProps {
turtle: Turtle;
enabled: boolean;
setDisableEvents: (_: boolean) => void;
}

const useStyles = makeStyles(theme => ({
Expand All @@ -31,27 +36,33 @@ const useStyles = makeStyles(theme => ({
width: '100%',
},
groups: {
display: 'flex',
alignItems: 'center',
justifyContent: 'start',
'&>*': {
marginLeft: theme.spacing(1),
marginRight: theme.spacing(1),
}
}
}));

function CircularProgressWithLabel(props: CircularProgressProps) {
function CircularProgressWithLabel(props: CircularProgressProps & { label: any }) {
return (
<Box style={{ position: 'relative', display: 'inline-flex' }}>
<CircularProgress variant="static" {...props} />
<Box style={{ top: 0, left: 0, bottom: 0, right: 0, position: 'absolute', display: 'flex', alignItems: 'center', justifyContent: 'center' }} >
<Typography variant="caption" component="div" color="textSecondary">{`${Math.round(props.value!)}%`}</Typography>
<Typography variant="caption" component="div" color="textSecondary">{props.label}</Typography>
</Box>
</Box>
);
}


export default function TurtlePage({ turtle, enabled }: TurtlePageProps) {
export default function TurtlePage({ turtle, enabled, setDisableEvents }: TurtlePageProps) {
const [signText, setSignText] = useState<string | null>(null);
const [commandText, setCommandText] = useState<string | null>(null);
const [commandResult, setCommandResult] = useState<string | null>(null);
const [mineLength, setMineLength] = useState<string>('');
const currentSignDirection = useRef<BlockDirection>(BlockDirection.FORWARD);
const classes = useStyles({ enabled });

Expand All @@ -64,6 +75,10 @@ export default function TurtlePage({ turtle, enabled }: TurtlePageProps) {
}
}

useEffect(() => {
setDisableEvents(signText !== null || commandText !== null || commandResult !== null);
}, [signText, commandText]);

return (
<>
<Dialog disableBackdropClick open={signText !== null} onClose={() => setSignText(null)}>
Expand All @@ -79,6 +94,28 @@ export default function TurtlePage({ turtle, enabled }: TurtlePageProps) {
}}>Place</Button>
</DialogActions>
</Dialog>
<Dialog disableBackdropClick open={commandText !== null} onClose={() => setCommandText(null)}>
<DialogTitle>Command</DialogTitle>
<DialogContent>
<TextField value={commandText || ''} onChange={(ev) => setCommandText(ev.target.value)} variant="outlined" />
</DialogContent>
<DialogActions>
<Button onClick={() => setCommandText(null)}>Cancel</Button>
<Button onClick={() => {
setCommandText(null);
turtle.exec(commandText!).then((res) => setCommandResult(res));
}}>Run</Button>
</DialogActions>
</Dialog>
<Dialog disableBackdropClick open={commandResult !== null} onClose={() => setCommandResult(null)}>
<DialogTitle>Command Result</DialogTitle>
<DialogContent>
<DialogContentText>{commandResult}</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={() => setCommandResult(null)}>Ok</Button>
</DialogActions>
</Dialog>
<div className={classes.toolbar} style={{ display: enabled ? undefined : "none" }}>
<Inventory turtle={turtle} />
<div className={classes.groups}>
Expand All @@ -93,13 +130,34 @@ export default function TurtlePage({ turtle, enabled }: TurtlePageProps) {
<TurtleButtonGroup turtle={turtle} func="suck" color='#f1c40f' />
<TurtleButtonGroup turtle={turtle} func="drop" color='#2ecc71' />
<ColoredButtonGroup size="small" orientation="vertical" groupColor='#3498db'>
<Button tabIndex="-1" variant="outlined" color="primary" onClick={() => turtle.refresh()}>Refresh Info</Button>
<Button tabIndex="-1" variant="outlined" color="primary" onClick={() => turtle.craft('all')}>Craft All</Button>
<Button tabIndex="-1" variant="outlined" color="primary" onClick={() => turtle.craft('one')}>Craft One</Button>
<Button tabIndex="-1" variant="outlined" color="primary" onClick={() => turtle.refuel()}>Refuel</Button>
</ColoredButtonGroup>
<ColoredButtonGroup size="small" orientation="vertical" groupColor='#9b59b6'>
<Button tabIndex="-1" variant="outlined" color="primary" onClick={() => turtle.refresh()}>Refresh Info</Button>
<Button tabIndex="-1" variant="outlined" color="primary" onClick={() => turtle.undergoMitosis()}>Undergo Mitosis</Button>
<Button tabIndex="-1" variant="outlined" color="primary" onClick={() => setCommandText('')}>Run Command</Button>
</ColoredButtonGroup>
<TextField
label="Mine Tunnel"
variant="outlined"
value={mineLength}
onChange={(ev) => setMineLength(ev.target.value)}
InputProps={{
endAdornment: <InputAdornment position="end">
<IconButton onClick={() => turtle.mineTunnel(parseInt(mineLength))}>
<SvgIcon>
<path d="M14.79,10.62L3.5,21.9L2.1,20.5L13.38,9.21L14.79,10.62M19.27,7.73L19.86,7.14L19.07,6.35L19.71,5.71L18.29,4.29L17.65,4.93L16.86,4.14L16.27,4.73C14.53,3.31 12.57,2.17 10.47,1.37L9.64,3.16C11.39,4.08 13,5.19 14.5,6.5L14,7L17,10L17.5,9.5C18.81,11 19.92,12.61 20.84,14.36L22.63,13.53C21.83,11.43 20.69,9.47 19.27,7.73Z" />
</SvgIcon>
</IconButton>
</InputAdornment>
}}
/>
<Button variant="contained" color="primary" onClick={() => turtle.checkMiningResults().then(console.log)}>Check Mining Results</Button>
</div>
<TurtleSwitcher />
<CircularProgressWithLabel variant="static" value={turtle.fuel / turtle.maxFuel * 100} />
<CircularProgressWithLabel variant="static" value={turtle.fuel / turtle.maxFuel * 100} label={turtle.fuel} />
</div>
</>
);
Expand Down
Loading

0 comments on commit 3ae0544

Please sign in to comment.