Skip to content

Commit

Permalink
eslint pass
Browse files Browse the repository at this point in the history
  • Loading branch information
tballmsft committed Aug 10, 2020
1 parent 9287d0e commit 107bf6b
Show file tree
Hide file tree
Showing 29 changed files with 6,870 additions and 718 deletions.
19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"env": {
"browser": true,
"es2020": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 11
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
13 changes: 0 additions & 13 deletions analysis.ts

This file was deleted.

52 changes: 0 additions & 52 deletions debugger.ts

This file was deleted.

40 changes: 20 additions & 20 deletions editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace tileworld {
const paintSize = 8;
const editorY = 16+yoff;

enum CursorType { Menu, Map };
enum CursorType { Menu, Map }
const paintOut = img`
5 5 5 5 5 5 5 5
5 . . . . . . 5
Expand Down Expand Up @@ -145,20 +145,20 @@ namespace tileworld {
this.selected.y = this.cursor.y;
}

private cursorAction(repeated: boolean = false) {
private cursorAction(repeated = false) {
if (!this.aDown)
return;
if (this.cursorType == CursorType.Map) {
let col = (this.paintCursor.x >> 3) + this.offsetX;
let row = ((this.paintCursor.y - (editorY +4)) >> 3) + this.offsetY;
let backs = this.p.getWorldBackgrounds();
const col = (this.paintCursor.x >> 3) + this.offsetX;
const row = ((this.paintCursor.y - (editorY +4)) >> 3) + this.offsetY;
const backs = this.p.getWorldBackgrounds();
if (this.userSpriteIndex == 0xf) {
backs.setPixel(col, row, 0xf);
} else if (this.userSpriteIndex < this.p.backCnt())
backs.setPixel(col, row, this.userSpriteIndex);
else {
let sprs = this.p.getWorldSprites();
let spriteIndex = this.userSpriteIndex - this.p.backCnt();
const sprs = this.p.getWorldSprites();
const spriteIndex = this.userSpriteIndex - this.p.backCnt();
if (sprs.getPixel(col, row) == spriteIndex)
sprs.setPixel(col, row, 0xf);
else
Expand All @@ -179,19 +179,19 @@ namespace tileworld {
this.update();
}

private col(current: boolean = true) {
private col(): number {
return this.cursor.x >> 4;
}

private row(current: boolean = true) {
private row(): number {
return (this.cursor.y - yoff) >> 4;
}

private drawImage(img: Image, col: number, row: number) {
private drawImage(img: Image, col: number, row: number): void {
screen.drawTransparentImage(img, col << 4, (row << 4)+yoff);
}

public update() {
public update(): void {
screen.fill(0);
screen.fillRect(0, yoff, 16, 16, 11);
this.drawImage(map, 0, 0);
Expand All @@ -205,21 +205,21 @@ namespace tileworld {
index++;
});
// this.drawImage(emptyDiagTile, 9, 0);
let backs = this.p.getWorldBackgrounds();
const backs = this.p.getWorldBackgrounds();
for(let x = this.offsetX; x<this.offsetX+20; x++) {
for (let y = this.offsetY; y < this.offsetY + 15; y++) {
let inRange = 0 <= x && x < backs.width && 0 <= y && y < backs.height;
let col = x - this.offsetX;
let row = y - this.offsetY;
let nx = col * paintSize;
let ny = editorY + row * paintSize;
const inRange = 0 <= x && x < backs.width && 0 <= y && y < backs.height;
const col = x - this.offsetX;
const row = y - this.offsetY;
const nx = col * paintSize;
const ny = editorY + row * paintSize;
// tile
let index = inRange ? backs.getPixel(x, y) : -1;
let img = index == -1 ? emptyTile : index == 0xf ? emptyDiagTile : this.p.getBackgroundImage(index);
const index = inRange ? backs.getPixel(x, y) : -1;
const img = index == -1 ? emptyTile : index == 0xf ? emptyDiagTile : this.p.getBackgroundImage(index);
drawHalfSize(img, nx, ny);
// sprite
if (inRange) {
let index = this.p.getWorldSprites().getPixel(x, y);
const index = this.p.getWorldSprites().getPixel(x, y);
if (index != 0xf) {
drawHalfSize(this.p.getSpriteImage(index), nx, ny, true);
}
Expand Down
8 changes: 4 additions & 4 deletions gallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ namespace tileworld {
this.setCol(0); this.setRow(0);

controller.A.onEvent(ControllerButtonEvent.Pressed, () => {
let isCurrent = this.col() == 2 && this.row() == 1 ;
let index = this.dirMap.getPixel(this.col(), this.row());
const isCurrent = this.col() == 2 && this.row() == 1 ;
const index = this.dirMap.getPixel(this.col(), this.row());
if (isCurrent || index != 0xf) {
this.setTileSaved();
let img = this.gallery[index];
const img = this.gallery[index];
this.newImage.copyFrom(isCurrent ? this.current : img);
}
});
Expand All @@ -30,7 +30,7 @@ namespace tileworld {
});
}

protected update() {
protected update(): void{
this.dirMap.fill(0xf);
screen.fill(0);
screen.print("Gallery", 0, yoff);
Expand Down
18 changes: 9 additions & 9 deletions home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace tileworld {
this.setRow(0);

controller.A.onEvent(ControllerButtonEvent.Pressed, () => {
let index = this.dirMap.getPixel(this.col(), this.row())
const index = this.dirMap.getPixel(this.col(), this.row())
if (index != 0xf) {
game.pushScene();
new Gallery(this.p, index,
Expand All @@ -21,12 +21,12 @@ namespace tileworld {
}
if (this.row()>0)
return;
let command = commandImages[this.col()];
const command = commandImages[this.col()];
if (command == play) {
let rules = this.p.getRules();
const rules = this.p.getRules();
if (rules.length > 0) {
game.pushScene();
let g = new RunGame(this.p, rules);
const g = new RunGame(this.p, rules);
g.setWorld(this.p.getWorldBackgrounds(), this.p.getWorldSprites());
g.start();
}
Expand Down Expand Up @@ -56,13 +56,13 @@ namespace tileworld {
});
}

protected cursorMove(dir: MoveDirection, pressed: boolean = true) {
protected cursorMove(dir: MoveDirection, pressed: boolean): void {
if(this.p.help) {
this.helpCursor.x = this.col() < 7 ? this.cursor.x + 8 : this.cursor.x-16;
this.helpCursor.y = this.cursor.y + 32;
let index = this.dirMap.getPixel(this.col(), this.row())
const index = this.dirMap.getPixel(this.col(), this.row())
if (this.row() < 1) {
let message = getHelp(helpString, this.col(), this.row());
const message = getHelp(helpString, this.col(), this.row());
this.helpCursor.say(message);
} else if (index != 0xf) {
this.helpCursor.say("A: gallery");
Expand All @@ -72,14 +72,14 @@ namespace tileworld {
}
}

protected update() {
protected update(): void {
if (!this.p.help) {
this.helpCursor.say(null);
}
screen.fill(0);
this.dirMap.fill(0xf);
commandImages.forEach((img,i) => {
let img2 = img == play ? (this.p.getRules().length > 0 ? img : greyImage(img)) : img;
const img2 = img == play ? (this.p.getRules().length > 0 ? img : greyImage(img)) : img;
this.drawImage(i, 0, img2);
});
this.drawImage(9, 0, settingsIcon);
Expand Down
30 changes: 15 additions & 15 deletions imageeditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace tileworld {
. . . . . .
`;

enum CursorType { Color, Paint, Menu };
enum CursorType { Color, Paint, Menu }

// UI region order
// Menu -> sprite -> color choice -> canvas
Expand All @@ -58,9 +58,9 @@ namespace tileworld {
private menuCursor: Sprite;
private selectedColor: number;
private image: Image; // 16x16
private Adown: boolean = false;
private kind: number = 0;
private dirty: boolean = false;
private Adown = false;
private kind = 0;
private dirty = false;
constructor(private p: AllExport) {
super();
this.image = p.getImage(this.kind);
Expand Down Expand Up @@ -109,17 +109,17 @@ namespace tileworld {
if (!this.Adown)
return;
if (this.cursorType == CursorType.Color) {
let col = ((this.colorCursor.x - colorsX) / colorSize) | 0x0;
let row = ((this.colorCursor.y - (colorSize << 1) - colorsY) / colorSize) | 0x0;
const col = ((this.colorCursor.x - colorsX) / colorSize) | 0x0;
const row = ((this.colorCursor.y - (colorSize << 1) - colorsY) / colorSize) | 0x0;
this.selectedColor = row * 2 + col;
this.setCursor(CursorType.Paint);
} else if (this.cursorType == CursorType.Paint) {
this.dirty = true;
let col = ((this.paintCursor.x - (paintSize * 5 + 2)) / paintSize) | 0x0;
let row = ((this.paintCursor.y - (editorY + 2)) / paintSize) | 0x0;
const col = ((this.paintCursor.x - (paintSize * 5 + 2)) / paintSize) | 0x0;
const row = ((this.paintCursor.y - (editorY + 2)) / paintSize) | 0x0;
this.image.setPixel(col, row, this.selectedColor);
} else {
let col = this.menuCursor.x >> 4;
const col = this.menuCursor.x >> 4;
if (2 <= col && col < 2 + this.p.getImages().length) {
if (this.dirty)
this.p.saveImage(this.kind);
Expand Down Expand Up @@ -206,7 +206,7 @@ namespace tileworld {
this.cursorType= ct;
}

protected update() {
protected update(): void {
screen.fill(0);
screen.fillRect(0, yoff, 16, 16, 11);
screen.drawTransparentImage(paint, 0, yoff)
Expand All @@ -220,8 +220,8 @@ namespace tileworld {
// draw the 16 colors
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 2; col++) {
let color = row * 2 + col
let yOffset = colorsY + colorSize + (colorSize >> 1)
const color = row * 2 + col
const yOffset = colorsY + colorSize + (colorSize >> 1)
screen.fillRect(colorsX + col * colorSize + 1, yOffset + row * colorSize + 1, colorSize-2, colorSize-2, color)
if (this.selectedColor == color) {
screen.drawRect(colorsX + col * colorSize, yOffset + row * colorSize, colorSize, colorSize, 1)
Expand All @@ -234,10 +234,10 @@ namespace tileworld {
// frame the sprite editor
// draw the sprite editor
for (let row = 0; row < this.image.height; row++) {
let y = editorY + row * paintSize
const y = editorY + row * paintSize
for (let col = 0; col < this.image.width; col++) {
let x = paintSize * 5 + col * paintSize
let color = this.image.getPixel(col, row)
const x = paintSize * 5 + col * paintSize
const color = this.image.getPixel(col, row)
screen.fillRect(x, y, paintSize-1, paintSize-1, color)
if (color == 0) {
screen.fillRect(x, y, (paintSize >> 1) -1, (paintSize >> 1) -1, 13)
Expand Down
16 changes: 8 additions & 8 deletions loadScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ namespace tileworld {
super(null);
controller.setRepeatDefault(500, 80);
controller.A.onEvent(ControllerButtonEvent.Pressed, () => {
let first = this.col() >= loadLeft && this.col() <= loadLeft+1;
let second = this.col() >= loadLeft+2 && this.col() <= loadLeft+3;
const first = this.col() >= loadLeft && this.col() <= loadLeft+1;
const second = this.col() >= loadLeft+2 && this.col() <= loadLeft+3;
if ( ( first || second) && (this.row() > loadTop && this.row() <= loadTop+numRows) ) {
let slot = (this.row()-loadTop) + (first ? 0 : numRows);
let prefix = "TW"+slot.toString()+"-";
const slot = (this.row()-loadTop) + (first ? 0 : numRows);
const prefix = "TW"+slot.toString()+"-";
this.p = loadProject(prefix);
this.update();
if (!this.p) {
Expand All @@ -33,20 +33,20 @@ namespace tileworld {
}

private lastDir: MoveDirection = -1;
protected cursorMove(dir: MoveDirection, pressed: boolean) {
protected cursorMove(dir: MoveDirection, pressed: boolean): void {
this.lastDir = pressed ? dir : -1;
}

private makeIt(col: number, row: number, id: string) {
let prefix = "TW" + id + "-";
let projectAvailable = settings.list(prefix).length > 0;
const prefix = "TW" + id + "-";
const projectAvailable = settings.list(prefix).length > 0;
this.drawImage(col, row, diskIcon);
this.fillTile(col+1, row, (this.col() == col || this.col() == col + 1) && this.row() == row ? 7 :
(projectAvailable ? 6 : 12));
screen.print(id, ((col+1) << 4) + 6, (row << 4) + 4 + yoff);
}

protected update() {
protected update(): void {
for(let col = 0; col < 10; col ++) {
for (let row = 0; row < 7; row++) {
this.drawImage(col, row, emptyTile)
Expand Down
3 changes: 2 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// see games.ts for built-in games

let tw = new tileworld.LoadScreen();
const tw =new tileworld.LoadScreen();
tw;
Loading

0 comments on commit 107bf6b

Please sign in to comment.