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")', );