Skip to content

Commit

Permalink
Added random offset to delete me
Browse files Browse the repository at this point in the history
  • Loading branch information
FL3SH committed Jun 24, 2020
1 parent 6be335b commit e65919a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
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
29 changes: 28 additions & 1 deletion src/game/delete-round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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(
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 e65919a

Please sign in to comment.