-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement a basic Grid class to keep track of grid state * Add Interaction, Cursor, Input, Support Grid.distroyCell * Ensure Cursor Remains Visible * Up and Down arrow during input save cell * Remove unused console.log s * clean up comments
- Loading branch information
1 parent
5f304ea
commit 05b5ac9
Showing
17 changed files
with
486 additions
and
80 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { BitmapText, Container, Graphics } from "pixi.js"; | ||
import { Viewport } from "pixi-viewport"; | ||
|
||
import highlightCell from "./highlightCell"; | ||
import CellReference from "../../types/cellReference"; | ||
import { CELL_WIDTH, CELL_HEIGHT } from "../../../constants/gridConstants"; | ||
|
||
interface CellReturn { | ||
container: Container; | ||
bitmap_text: BitmapText; | ||
cell_outline: Graphics; | ||
} | ||
|
||
const drawCell = ( | ||
viewport: Viewport, | ||
cell: CellReference, | ||
text: string | ||
): CellReturn => { | ||
// Calculate X and Y positions | ||
const x_pos = cell.x * CELL_WIDTH; | ||
const y_pos = cell.y * CELL_HEIGHT; | ||
const margin_left = 2; | ||
const margin_top = -1; | ||
|
||
// render text | ||
let bitmap_text = new BitmapText(text, { | ||
fontName: "OpenSans", | ||
tint: 0x000000, | ||
fontSize: 14, | ||
align: "right", | ||
}); | ||
bitmap_text.position.set(x_pos + margin_left, y_pos + margin_top); | ||
|
||
// highlight cell | ||
let cell_outline = highlightCell(cell, "normal"); | ||
|
||
// create Container | ||
let container = new Container(); | ||
container.addChild(bitmap_text); | ||
container.addChild(cell_outline); | ||
|
||
return { | ||
container, | ||
bitmap_text, | ||
cell_outline, | ||
}; | ||
}; | ||
|
||
export default drawCell; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
import { Graphics } from "pixi.js"; | ||
import { Viewport } from "pixi-viewport"; | ||
|
||
import CellReference from "./types/cellReference"; | ||
import CellReference from "../../types/cellReference"; | ||
|
||
import { CELL_WIDTH, CELL_HEIGHT } from "../../../constants/gridConstants"; | ||
|
||
import colors from "../../../utils/colors.js"; | ||
|
||
const highlightCell = ( | ||
viewport: Viewport, | ||
cell: CellReference, | ||
type: string | ||
) => { | ||
const highlightCell = (cell: CellReference, type: string): Graphics => { | ||
const x_pos = cell.x * CELL_WIDTH; | ||
const y_pos = cell.y * CELL_HEIGHT; | ||
// highlight cell | ||
let cell_outline = new Graphics(); | ||
cell_outline.lineStyle(1, colors.cellColorUserText, 0.9, 0.5, true); | ||
|
||
// set type | ||
if (type === "cursor") { | ||
cell_outline.lineStyle(1.5, colors.cursorCell); | ||
} else { | ||
cell_outline.lineStyle(1, colors.cellColorUserText, 0.9, 0.5, true); | ||
} | ||
|
||
cell_outline.drawRect(x_pos, y_pos, CELL_WIDTH, CELL_HEIGHT); | ||
viewport.addChild(cell_outline); | ||
|
||
return cell_outline; | ||
}; | ||
|
||
export default highlightCell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { BitmapText, Container, Graphics } from "pixi.js"; | ||
import { Viewport } from "pixi-viewport"; | ||
import CellReference from "../types/cellReference"; | ||
|
||
import drawCell from "../graphics/cells/drawCell"; | ||
|
||
export default class Cell { | ||
location: CellReference; | ||
bitmap_text: BitmapText; | ||
container: Container; | ||
viewport: Viewport; | ||
cell_outline: Graphics; | ||
|
||
constructor(location: CellReference, viewport: Viewport, text: string) { | ||
this.location = location; | ||
|
||
// draw cell | ||
let { bitmap_text, container, cell_outline } = drawCell( | ||
viewport, | ||
location, | ||
text | ||
); | ||
this.bitmap_text = bitmap_text; | ||
this.container = container; | ||
this.cell_outline = cell_outline; | ||
this.viewport = viewport; | ||
viewport.addChild(container); | ||
} | ||
|
||
update(text: string) { | ||
this.bitmap_text.text = text; | ||
} | ||
|
||
destroy() { | ||
this.viewport.removeChild(this.container); | ||
this.container.destroy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Cell from "./Cell"; | ||
import CellReference from "../types/cellReference"; | ||
import { Viewport } from "pixi-viewport"; | ||
|
||
export default class Grid { | ||
data: { [key: string]: { [key: string]: Cell } }; | ||
viewport: Viewport; | ||
|
||
constructor(viewport: Viewport) { | ||
this.data = {}; | ||
this.viewport = viewport; | ||
} | ||
|
||
getCell(location: CellReference): Cell | null { | ||
if (this.data[location.x] === undefined) { | ||
return null; | ||
} | ||
return this.data[location.x][location.y] || null; | ||
} | ||
|
||
destroyCell(location: CellReference) { | ||
if (this.data[location.x] !== undefined) { | ||
let cell = this.data[location.x][location.y]; | ||
if (cell) { | ||
cell.destroy(); | ||
delete this.data[location.x][location.y]; | ||
} | ||
} | ||
} | ||
|
||
createOrUpdateCell(location: CellReference, text: string) { | ||
let cell: Cell | null = this.getCell(location); | ||
|
||
if (cell === null) { | ||
if (this.data[location.x] === undefined) { | ||
this.data[location.x] = {}; | ||
} | ||
|
||
this.data[location.x][location.y] = new Cell( | ||
{ x: location.x, y: location.y }, | ||
this.viewport, | ||
text | ||
); | ||
} else { | ||
cell.update(text); | ||
} | ||
} | ||
} |
Oops, something went wrong.