From 43bea26640424979781c63038c2c74058bd55552 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sun, 17 Sep 2023 19:42:47 +0200 Subject: [PATCH] Add send_input api --- docs/README.md | 2 +- docs/classes/TeeworldsClient.md | 22 +++++++++++++++++----- lib/teeworlds_client.rb | 22 +++++++++++----------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/docs/README.md b/docs/README.md index 072c810..5021b66 100644 --- a/docs/README.md +++ b/docs/README.md @@ -81,4 +81,4 @@ Version v0.0.3 [#send_enter_game](classes/TeeworldsClient.md#send_enter_game) -[#send_input](classes/TeeworldsClient.md#send_input) +[#send_input(input = {})](classes/TeeworldsClient.md#send_input) diff --git a/docs/classes/TeeworldsClient.md b/docs/classes/TeeworldsClient.md index ae3f02d..47a43a7 100644 --- a/docs/classes/TeeworldsClient.md +++ b/docs/classes/TeeworldsClient.md @@ -607,16 +607,28 @@ client.send_enter_game client.connect('localhost', 8303, detach: false) ``` -### #send_input -**Parameter: TODO** +### #send_input(input = {}) + +**Parameter: Hash** **Example:** ```ruby client = TeeworldsClient.new -# TODO: generated documentation -client.send_input - client.connect('localhost', 8303, detach: false) + +loop do + client.send_input( + direction: -1, + target_x: 10, + target_y: 10, + jump: rand(0..1), + fire: 0, + hook: 0, + player_flags: 0, + wanted_weapon: 0, + next_weapon: 0, + prev_weapon: 0) +end ``` diff --git a/lib/teeworlds_client.rb b/lib/teeworlds_client.rb index 19224ab..7b1b71b 100644 --- a/lib/teeworlds_client.rb +++ b/lib/teeworlds_client.rb @@ -310,18 +310,18 @@ class TeeworldsClient ) end - def send_input + def send_input(input = {}) inp = { - direction: -1, - target_x: 10, - target_y: 10, - jump: rand(0..1), - fire: 0, - hook: 0, - player_flags: 0, - wanted_weapon: 0, - next_weapon: 0, - prev_weapon: 0 + direction: input[:direction] || -1, + target_x: input[:target_x] || 10, + target_y: input[:target_y] || 10, + jump: input[:jump] || rand(0..1), + fire: input[:fire] || 0, + hook: input[:hook] || 0, + player_flags: input[:player_flags] || 0, + wanted_weapon: input[:wanted_weapon] || 0, + next_weapon: input[:next_weapon] || 0, + prev_weapon: input[:prev_weapon] || 0 } data = []