From e65919a2d8105f0eb83accf791edf6925181e5a6 Mon Sep 17 00:00:00 2001 From: FL3SH Date: Wed, 24 Jun 2020 20:36:28 +0200 Subject: [PATCH 1/3] Added random offset to delete me --- package.json | 2 +- src/game/base.ts | 2 +- src/game/delete-round.ts | 29 ++++++++++++++++++++++++++++- src/game/types.ts | 1 + src/index.ts | 1 - 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 1402a1c..5d418cf 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/game/base.ts b/src/game/base.ts index 434d097..53b1903 100644 --- a/src/game/base.ts +++ b/src/game/base.ts @@ -68,11 +68,11 @@ export function getRandomSentence(): string { } export class Game implements IGame { - private difficulty: GameDifficulty; private timerId?: ReturnType; private onExpired: (() => void)[]; private timerExpired: boolean; public currentRound!: Round; + public difficulty!: GameDifficulty; constructor( public nvim: Neovim, diff --git a/src/game/delete-round.ts b/src/game/delete-round.ts index 80b24b1..7def10c 100644 --- a/src/game/delete-round.ts +++ b/src/game/delete-round.ts @@ -14,6 +14,32 @@ export class DeleteRound extends Round { super(); } + private async getGameDeleteMeColumOffset(game: IGame) { + const isDefindedUserOffset = await game.nvim.eval( + 'exists("vim_be_good_delete_me_offset")', + ); + console.log( + "delete-round#getGameDeleteMeColumOffset - isDefindedUserOffset ", + isDefindedUserOffset, + ); + if (game.difficulty === "noob") { + return " ".repeat(3); + } + + if (isDefindedUserOffset) { + const userOffset = Number( + await game.nvim.getVar("vim_be_good_delete_me_offset"), + ); + console.log( + "delete-round#getGameDeleteMeColumOffset - userOffset ", + userOffset, + ); + return " ".repeat(userOffset); + } else { + return " ".repeat(Math.floor(Math.random() * (40 - 5)) + 5); + } + } + public getInstructions(): string[] { return deleteRoundInstructions; } @@ -23,7 +49,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] = this.getGameDeleteMeColumOffset(game) + "DELETE ME"; const middlePoint = game.gameBuffer.midPointRandomPoint(!high); console.log( diff --git a/src/game/types.ts b/src/game/types.ts index f2d906e..b0e7c19 100644 --- a/src/game/types.ts +++ b/src/game/types.ts @@ -102,4 +102,5 @@ export interface IGame { nvim: Neovim; gameBuffer: IGameBuffer; state: GameState; + difficulty: GameDifficulty; } diff --git a/src/index.ts b/src/index.ts index 5081c1b..e00b56e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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")', ); From efe2db83ac6a3e79c03ccdd5ea227a0e2ef81809 Mon Sep 17 00:00:00 2001 From: FL3SH Date: Thu, 25 Jun 2020 10:56:52 +0200 Subject: [PATCH 2/3] Fix async and small refactor --- src/game/delete-round.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/game/delete-round.ts b/src/game/delete-round.ts index 7def10c..cab8baf 100644 --- a/src/game/delete-round.ts +++ b/src/game/delete-round.ts @@ -18,26 +18,27 @@ export class DeleteRound extends Round { const isDefindedUserOffset = await game.nvim.eval( 'exists("vim_be_good_delete_me_offset")', ); + let offset; console.log( "delete-round#getGameDeleteMeColumOffset - isDefindedUserOffset ", isDefindedUserOffset, ); if (game.difficulty === "noob") { - return " ".repeat(3); + offset = 3; } if (isDefindedUserOffset) { - const userOffset = Number( + offset = Number( await game.nvim.getVar("vim_be_good_delete_me_offset"), ); console.log( "delete-round#getGameDeleteMeColumOffset - userOffset ", - userOffset, + offset, ); - return " ".repeat(userOffset); } else { - return " ".repeat(Math.floor(Math.random() * (40 - 5)) + 5); + offset = Math.floor(Math.random() * (40 - 5)) + 5; } + return " ".repeat(offset); } public getInstructions(): string[] { @@ -50,7 +51,8 @@ export class DeleteRound extends Round { const lines = new Array(game.state.lineLength).fill(""); - lines[line] = this.getGameDeleteMeColumOffset(game) + "DELETE ME"; + lines[line] = + (await this.getGameDeleteMeColumOffset(game)) + "DELETE ME"; const middlePoint = game.gameBuffer.midPointRandomPoint(!high); console.log( From 7c1e5ddfc8e13ec639ed1800a1105ab7fe7e8bda Mon Sep 17 00:00:00 2001 From: FL3SH Date: Sat, 27 Jun 2020 00:07:09 +0200 Subject: [PATCH 3/3] Fixed typo and added docs --- README.md | 9 ++++++++- src/game/delete-round.ts | 12 ++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a609e55..3d9e5dc 100644 --- a/README.md +++ b/README.md @@ -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! @@ -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 diff --git a/src/game/delete-round.ts b/src/game/delete-round.ts index cab8baf..e574004 100644 --- a/src/game/delete-round.ts +++ b/src/game/delete-round.ts @@ -14,13 +14,13 @@ export class DeleteRound extends Round { super(); } - private async getGameDeleteMeColumOffset(game: IGame) { + private async getColumnOffset(game: IGame) { const isDefindedUserOffset = await game.nvim.eval( 'exists("vim_be_good_delete_me_offset")', ); let offset; console.log( - "delete-round#getGameDeleteMeColumOffset - isDefindedUserOffset ", + "delete-round#getColumnOffset - isDefindedUserOffset ", isDefindedUserOffset, ); if (game.difficulty === "noob") { @@ -31,10 +31,7 @@ export class DeleteRound extends Round { offset = Number( await game.nvim.getVar("vim_be_good_delete_me_offset"), ); - console.log( - "delete-round#getGameDeleteMeColumOffset - userOffset ", - offset, - ); + console.log("delete-round#getColumnOffset - userOffset ", offset); } else { offset = Math.floor(Math.random() * (40 - 5)) + 5; } @@ -51,8 +48,7 @@ export class DeleteRound extends Round { const lines = new Array(game.state.lineLength).fill(""); - lines[line] = - (await this.getGameDeleteMeColumOffset(game)) + "DELETE ME"; + lines[line] = (await this.getColumnOffset(game)) + "DELETE ME"; const middlePoint = game.gameBuffer.midPointRandomPoint(!high); console.log(