Skip to content

Commit 0b80ecc

Browse files
authored
Merge pull request #68 from FL3SH/delete-me-offset
Delete me offset
2 parents 6be335b + 7c1e5dd commit 0b80ecc

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ current buffer (only if its empty) set `vim_be_good_floating` to 0.
2424

2525
`let g:vim_be_good_floating = 0`
2626

27+
### Games - relative
28+
By default vim be good returns random offset for game difficult above noob, if
29+
you with to set fixed offset set `vim_be_good_delete_me_offset` to desired
30+
value.
31+
32+
`let g:vim_be_good_delete_me_offset = 35`
33+
2734
## Instructions are at top of games.
2835
here too!
2936

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

4148
## Installation
4249

43-
1. Use your favorite plugin manager to install! Only works on Nvim, the one true
50+
1. Use your favorite plugin manager to install! Only works on Nvim, the one true
4451
vim.
4552

4653
Linux

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "src/index.ts",
66
"scripts": {
77
"copy-rplugin-json": "cp ./rplugin-package.json ./rplugin/node/vim-be-good/package.json",
8-
"build": "tsc && npm run copy-rplugin-json",
8+
"build": "prettier ./src --check && tsc && npm run copy-rplugin-json",
99
"prebuild:watch": "npm run copy-rplugin-json",
1010
"build:watch": "nodemon -e ts --exec \"npm run build && echo '\nGood to go 👍'\"",
1111
"lint": "prettier ./src --check",

src/game/base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ export function getRandomSentence(): string {
6868
}
6969

7070
export class Game implements IGame {
71-
private difficulty: GameDifficulty;
7271
private timerId?: ReturnType<typeof setTimeout>;
7372
private onExpired: (() => void)[];
7473
private timerExpired: boolean;
7574
public currentRound!: Round;
75+
public difficulty!: GameDifficulty;
7676

7777
constructor(
7878
public nvim: Neovim,

src/game/delete-round.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,30 @@ export class DeleteRound extends Round {
1414
super();
1515
}
1616

17+
private async getColumnOffset(game: IGame) {
18+
const isDefindedUserOffset = await game.nvim.eval(
19+
'exists("vim_be_good_delete_me_offset")',
20+
);
21+
let offset;
22+
console.log(
23+
"delete-round#getColumnOffset - isDefindedUserOffset ",
24+
isDefindedUserOffset,
25+
);
26+
if (game.difficulty === "noob") {
27+
offset = 3;
28+
}
29+
30+
if (isDefindedUserOffset) {
31+
offset = Number(
32+
await game.nvim.getVar("vim_be_good_delete_me_offset"),
33+
);
34+
console.log("delete-round#getColumnOffset - userOffset ", offset);
35+
} else {
36+
offset = Math.floor(Math.random() * (40 - 5)) + 5;
37+
}
38+
return " ".repeat(offset);
39+
}
40+
1741
public getInstructions(): string[] {
1842
return deleteRoundInstructions;
1943
}
@@ -23,7 +47,8 @@ export class DeleteRound extends Round {
2347
const line = game.gameBuffer.midPointRandomPoint(high);
2448

2549
const lines = new Array(game.state.lineLength).fill("");
26-
lines[line] = " DELETE ME";
50+
51+
lines[line] = (await this.getColumnOffset(game)) + "DELETE ME";
2752

2853
const middlePoint = game.gameBuffer.midPointRandomPoint(!high);
2954
console.log(

src/game/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,5 @@ export interface IGame {
102102
nvim: Neovim;
103103
gameBuffer: IGameBuffer;
104104
state: GameState;
105+
difficulty: GameDifficulty;
105106
}

src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ export default function createPlugin(plugin: NvimPlugin): void {
266266
const useCurrentBuffer =
267267
Number(await plugin.nvim.getVar("vim_be_good_floating")) ===
268268
0;
269-
270269
const isDefined = await plugin.nvim.eval(
271270
'exists("vim_be_good_floating")',
272271
);

0 commit comments

Comments
 (0)