Skip to content

Commit

Permalink
Merge pull request #68 from FL3SH/delete-me-offset
Browse files Browse the repository at this point in the history
Delete me offset
  • Loading branch information
ThePrimeagen authored Jul 8, 2020
2 parents 6be335b + 7c1e5dd commit 0b80ecc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ current buffer (only if its empty) set `vim_be_good_floating` to 0.

`let g:vim_be_good_floating = 0`

### Games - relative
By default vim be good returns random offset for game difficult above noob, if
you with to set fixed offset set `vim_be_good_delete_me_offset` to desired
value.

`let g:vim_be_good_delete_me_offset = 35`

## Instructions are at top of games.
here too!

Expand All @@ -40,7 +47,7 @@ character's case to complete the round.

## Installation

1. Use your favorite plugin manager to install! Only works on Nvim, the one true
1. Use your favorite plugin manager to install! Only works on Nvim, the one true
vim.

Linux
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/index.ts",
"scripts": {
"copy-rplugin-json": "cp ./rplugin-package.json ./rplugin/node/vim-be-good/package.json",
"build": "tsc && npm run copy-rplugin-json",
"build": "prettier ./src --check && tsc && npm run copy-rplugin-json",
"prebuild:watch": "npm run copy-rplugin-json",
"build:watch": "nodemon -e ts --exec \"npm run build && echo '\nGood to go 👍'\"",
"lint": "prettier ./src --check",
Expand Down
2 changes: 1 addition & 1 deletion src/game/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ export function getRandomSentence(): string {
}

export class Game implements IGame {
private difficulty: GameDifficulty;
private timerId?: ReturnType<typeof setTimeout>;
private onExpired: (() => void)[];
private timerExpired: boolean;
public currentRound!: Round;
public difficulty!: GameDifficulty;

constructor(
public nvim: Neovim,
Expand Down
27 changes: 26 additions & 1 deletion src/game/delete-round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@ export class DeleteRound extends Round {
super();
}

private async getColumnOffset(game: IGame) {
const isDefindedUserOffset = await game.nvim.eval(
'exists("vim_be_good_delete_me_offset")',
);
let offset;
console.log(
"delete-round#getColumnOffset - isDefindedUserOffset ",
isDefindedUserOffset,
);
if (game.difficulty === "noob") {
offset = 3;
}

if (isDefindedUserOffset) {
offset = Number(
await game.nvim.getVar("vim_be_good_delete_me_offset"),
);
console.log("delete-round#getColumnOffset - userOffset ", offset);
} else {
offset = Math.floor(Math.random() * (40 - 5)) + 5;
}
return " ".repeat(offset);
}

public getInstructions(): string[] {
return deleteRoundInstructions;
}
Expand All @@ -23,7 +47,8 @@ export class DeleteRound extends Round {
const line = game.gameBuffer.midPointRandomPoint(high);

const lines = new Array(game.state.lineLength).fill("");
lines[line] = " DELETE ME";

lines[line] = (await this.getColumnOffset(game)) + "DELETE ME";

const middlePoint = game.gameBuffer.midPointRandomPoint(!high);
console.log(
Expand Down
1 change: 1 addition & 0 deletions src/game/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,5 @@ export interface IGame {
nvim: Neovim;
gameBuffer: IGameBuffer;
state: GameState;
difficulty: GameDifficulty;
}
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ export default function createPlugin(plugin: NvimPlugin): void {
const useCurrentBuffer =
Number(await plugin.nvim.getVar("vim_be_good_floating")) ===
0;

const isDefined = await plugin.nvim.eval(
'exists("vim_be_good_floating")',
);
Expand Down

0 comments on commit 0b80ecc

Please sign in to comment.