build new version

This commit is contained in:
Olivier Gagnon 2021-10-16 19:10:11 -04:00
parent ab7d1a8ce9
commit 50147f6b0b
6 changed files with 41 additions and 48 deletions

36
dist/vendor.bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -18,7 +18,7 @@ export class Fragment {
this.limit = limit; this.limit = limit;
} }
fullAt(x: number, y: number, rotation: number, debug = false): boolean { fullAt(x: number, y: number, rotation: number): boolean {
if (y < 0) return false; if (y < 0) return false;
if (y >= this.height(rotation)) return false; if (y >= this.height(rotation)) return false;
if (x < 0) return false; if (x < 0) return false;
@ -34,9 +34,6 @@ export class Fragment {
} }
let [qx, qy] = [sx + mx * x, sy + my * y]; let [qx, qy] = [sx + mx * x, sy + my * y];
if (rotation % 2 === 1) [qx, qy] = [qy, qx]; if (rotation % 2 === 1) [qx, qy] = [qy, qx];
if (debug) {
console.log("q " + [qx, qy]);
}
return this.shape[qy][qx]; return this.shape[qy][qx];
} }

@ -17,12 +17,8 @@ type IOptionProps = {
}; };
function FragmentOption(props: IOptionProps): React.ReactElement { function FragmentOption(props: IOptionProps): React.ReactElement {
const remaining = const left = props.fragment.limit - props.gift.count(props.fragment);
props.fragment.limit !== Infinity ? ( const remaining = props.fragment.limit !== Infinity ? <>{left} remaining</> : <></>;
<>{props.fragment.limit - props.gift.count(props.fragment)} remaining</>
) : (
<></>
);
return ( return (
<Box display="flex"> <Box display="flex">
<Box sx={{ mx: 2 }}> <Box sx={{ mx: 2 }}>
@ -30,11 +26,9 @@ function FragmentOption(props: IOptionProps): React.ReactElement {
width={props.fragment.width(0)} width={props.fragment.width(0)}
height={props.fragment.height(0)} height={props.fragment.height(0)}
colorAt={(x, y) => { colorAt={(x, y) => {
return !props.fragment.fullAt(x, y, 0) if (!props.fragment.fullAt(x, y, 0)) return "";
? "" if (left === 0) return "grey";
: props.fragment.type === FragmentType.Booster return props.fragment.type === FragmentType.Booster ? "blue" : "green";
? "blue"
: "green";
}} }}
/> />
</Box> </Box>

@ -63,13 +63,12 @@ export function MainBoard(props: IProps): React.ReactElement {
const [rotation, setRotation] = React.useState(0); const [rotation, setRotation] = React.useState(0);
const [selectedFragment, setSelectedFragment] = React.useState(NoneFragment); const [selectedFragment, setSelectedFragment] = React.useState(NoneFragment);
function moveGhost(worldX: number, worldY: number): void { function moveGhost(worldX: number, worldY: number, rotation: number): void {
if (selectedFragment.type === FragmentType.None || selectedFragment.type === FragmentType.Delete) return; if (selectedFragment.type === FragmentType.None || selectedFragment.type === FragmentType.Delete) return;
const newgrid = zeros([props.gift.width(), props.gift.height()]); const newgrid = zeros([props.gift.width(), props.gift.height()]);
for (let y = 0; y < selectedFragment.height(rotation); y++) { for (let y = 0; y < selectedFragment.height(rotation); y++) {
for (let x = 0; x < selectedFragment.width(rotation); x++) { for (let x = 0; x < selectedFragment.width(rotation); x++) {
console.log([x, y]); if (!selectedFragment.fullAt(x, y, rotation)) continue;
if (!selectedFragment.fullAt(x, y, rotation, true)) continue;
if (worldX + x > newgrid.length - 1) continue; if (worldX + x > newgrid.length - 1) continue;
if (worldY + y > newgrid[worldX + x].length - 1) continue; if (worldY + y > newgrid[worldX + x].length - 1) continue;
newgrid[worldX + x][worldY + y] = 1; newgrid[worldX + x][worldY + y] = 1;
@ -117,7 +116,12 @@ export function MainBoard(props: IProps): React.ReactElement {
const cells = []; const cells = [];
for (let i = 0; i < props.gift.width(); i++) { for (let i = 0; i < props.gift.width(); i++) {
cells.push( cells.push(
<Cell key={i} onMouseEnter={() => moveGhost(i, j)} onClick={() => clickAt(i, j)} color={color(i, j)} />, <Cell
key={i}
onMouseEnter={() => moveGhost(i, j, rotation)}
onClick={() => clickAt(i, j)}
color={color(i, j)}
/>,
); );
} }
elems.push( elems.push(
@ -136,22 +140,20 @@ export function MainBoard(props: IProps): React.ReactElement {
React.useEffect(() => { React.useEffect(() => {
function doRotate(this: Document, event: KeyboardEvent): void { function doRotate(this: Document, event: KeyboardEvent): void {
if (event.key === "q") { if (event.key === "q") {
setRotation((rotation - 1 + 4) % 4); const r = (rotation - 1 + 4) % 4;
console.log((rotation - 1 + 4) % 4); setRotation(r);
moveGhost(pos[0], pos[1], r);
} }
if (event.key === "e") { if (event.key === "e") {
setRotation((rotation + 1) % 4); const r = (rotation + 1) % 4;
console.log((rotation + 1) % 4); setRotation(r);
moveGhost(pos[0], pos[1], r);
} }
} }
document.addEventListener("keydown", doRotate); document.addEventListener("keydown", doRotate);
return () => document.removeEventListener("keydown", doRotate); return () => document.removeEventListener("keydown", doRotate);
}); });
// try {
// console.log(selectedFragment);
// } catch (err) {}
return ( return (
<> <>
<Button onClick={clear}>Clear</Button> <Button onClick={clear}>Clear</Button>