Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
ottomated committed Nov 26, 2020
1 parent 3ae0544 commit bb266c2
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 139 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,20 @@
✓ Reverse shell
✓ Click to switch turtles
✓ Temporary autonomity
✓ Add name to code, and make a UI
✓ Add name to code, and make a UI

# INSTRUCTIONS FOR LUDWIG
1. Materials:
- Turtle
- Disk Drive
- Floppy Disk
- Diamond Pickaxe
- Crafting Table
2. Craft Mining Crafty Turtle
3. Place disk drive
4. Place floppy disk inside disk drive
5. Place turtle on top of disk drive
6. Run this code on turtle: `pastebin get cyQCKL2Z disk/startup`, `reboot`
7. Mine the disk drive, place the floppy disk and the disk drive in the turtle's inventory
8. Run `startup` on turtle
9. Place at least 4 coal blocks in turtle inventory
9 changes: 7 additions & 2 deletions frontend/components/Turtle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,20 @@ export default function TurtlePage({ turtle, enabled, setDisableEvents }: Turtle
onChange={(ev) => setMineLength(ev.target.value)}
InputProps={{
endAdornment: <InputAdornment position="end">
<IconButton onClick={() => turtle.mineTunnel(parseInt(mineLength))}>
<IconButton onClick={() => turtle.mineTunnel('down', parseInt(mineLength))}>
<ArrowDownward />
</IconButton>
<IconButton onClick={() => turtle.mineTunnel('forward', 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>
<IconButton onClick={() => turtle.mineTunnel('up', parseInt(mineLength))}>
<ArrowUpward />
</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} label={turtle.fuel} />
Expand Down
27 changes: 26 additions & 1 deletion frontend/components/World.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ export default function WorldRenderer({ turtle, world, disableEvents, ...props }
const position = useRef({ x: 0, y: 0 });
const popperRef = useRef<any>(null);
const [hovered, setHovered] = useState<string>('');
const [showWholeWorld, setShowWholeWorld] = useState<boolean>(false);
const [dontShowStone, setDontShowStone] = useState<boolean>(false);

const disableEventsRef = useRef<boolean>(disableEvents);
useEffect(() => {
Expand All @@ -147,18 +149,35 @@ export default function WorldRenderer({ turtle, world, disableEvents, ...props }

useEventListener('keyup', (ev: KeyboardEvent) => {
if (disableEventsRef.current || !currentTurtleRef.current) return;
let moved = false;
if (ev.code === 'KeyW') {
moved = true;
currentTurtleRef.current.forward();
} else if (ev.code === 'KeyA') {
moved = true;
currentTurtleRef.current.turnLeft();
} else if (ev.code === 'KeyS') {
moved = true;
currentTurtleRef.current.back();
} else if (ev.code === 'KeyD') {
moved = true;
currentTurtleRef.current.turnRight();
} else if (ev.code === 'Space') {
moved = true;
currentTurtleRef.current.up();
} else if (ev.code === 'ShiftLeft') {
moved = true;
currentTurtleRef.current.down();
} else if (ev.code === 'KeyV') {
moved = true;
setShowWholeWorld(w => !w);
} else if (ev.code === 'KeyB') {
moved = true;
setDontShowStone(w => !w);
}
if (moved) {
ev.stopPropagation();
ev.preventDefault();
}
});
return (
Expand Down Expand Up @@ -210,6 +229,12 @@ export default function WorldRenderer({ turtle, world, disableEvents, ...props }
{Object.keys(world).map(k => {
let positions = k.split(',').map(p => parseInt(p)) as [number, number, number];
let { name, metadata } = world[k];
if (dontShowStone && name ==='minecraft:stone') {
return null;
}
if (!showWholeWorld && turtle && (Math.pow(positions[0] - turtle.x, 2) + Math.pow(positions[1] - turtle.y, 2) + Math.pow(positions[2] - turtle.z, 2)) > 1000) {
return null;
}
return <Box
transparent={name.includes('water') || name.includes('lava') || !!turtles.find(t => {
let checkEqual = (t: Turtle, positions: number[], x: number, y: number, z: number) => t.x === positions[0] + x && t.y === positions[1] + y && t.z === positions[2] + z;
Expand All @@ -227,7 +252,7 @@ export default function WorldRenderer({ turtle, world, disableEvents, ...props }
s: 60,
l: 40,
}).toString()} />
})}
}).filter(b => b)}
<Suspense fallback={null}>
<OtherTurtles switchTurtle={(turtle: Turtle) => {
setTurtleIndex(turtle.id);
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"build": "next build && next export",
"start": "next start",
"type-check": "tsc"
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function MyApp(props: AppProps) {
return (
<CacheProvider value={cache}>
<Head>
<title>My page</title>
<title>Turtle Control Panel</title>
<meta name="viewport" content="initial-scale=1, width=device-width" />
</Head>
<ThemeProvider theme={theme}>
Expand Down
7 changes: 2 additions & 5 deletions frontend/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,8 @@ export class Turtle extends EventEmitter {
async equip(side: 'left' | 'right') {
return window.exec<string>(this.id, 'equip', side);
}
async mineTunnel(length: number) {
return window.exec<string>(this.id, 'mineTunnel', length);
}
async checkMiningResults() {
return window.exec<string>(this.id, 'checkMiningResults');
async mineTunnel(direction: string, length: number) {
return window.exec<string>(this.id, 'mineTunnel', direction, length);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ turtleAddQueue.pause();
// console.log(url);
app = await launch();
app.on('exit', () => process.exit());
app.serveFolder(resolve(process.cwd(), "frontend"));
app.load('http://localhost:3000');
// await app.load('index.html');
app.serveFolder(resolve(process.cwd(), "frontend/out"));
// app.load('http://localhost:3000');

app.exposeFunction('exec', async (index: number, func: string, ...args: any[]) => {
if (typeof index === 'string') {
Expand All @@ -37,6 +36,7 @@ turtleAddQueue.pause();
await app.evaluate(`if (window.setTurtles) window.setTurtles(${serializeTurtles()})`);
})

await app.load('http://localhost:3000');
world.on('update', async (world) => {
await app.evaluate(`if (window.setWorld) window.setWorld(${JSON.stringify(world)})`);
});
Expand Down
Loading

0 comments on commit bb266c2

Please sign in to comment.