Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete me offset #68

Merged
merged 3 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThePrimeagen @FL3SH this line will overwrite the value set on line 27, won't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aaa, my bad, of course offset = 3 will always be overwritten ;/
Tbh I personally like it way more with random offset event in 'noob' this is why I missed it.

Fixed in #70

}
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