From bf677856a2df530375a21f8af355b32d2d2fbd1a Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Fri, 24 Mar 2023 14:40:39 -0600 Subject: [PATCH] script generating player offset files --- host.d/README.md | 16 +----- host.d/config.d/mayhem-party.d/env.env | 2 +- .../mayhem-party.d/remap.d/.players_offset.py | 31 +++++++++++ .../config.d/mayhem-party.d/remap.d/live.yaml | 2 +- .../remap.d/{0.yaml => players_offset_0.yaml} | 0 .../remap.d/players_offset_1.yaml | 55 +++++++++++++++++++ .../remap.d/players_offset_2.yaml | 55 +++++++++++++++++++ .../remap.d/players_offset_3.yaml | 55 +++++++++++++++++++ .../remap.d/players_offset_4.yaml | 55 +++++++++++++++++++ .../config.d/mayhem-party.d/remap.d/rotate.sh | 19 +++++++ 10 files changed, 275 insertions(+), 15 deletions(-) create mode 100644 host.d/config.d/mayhem-party.d/remap.d/.players_offset.py rename host.d/config.d/mayhem-party.d/remap.d/{0.yaml => players_offset_0.yaml} (100%) create mode 100644 host.d/config.d/mayhem-party.d/remap.d/players_offset_1.yaml create mode 100644 host.d/config.d/mayhem-party.d/remap.d/players_offset_2.yaml create mode 100644 host.d/config.d/mayhem-party.d/remap.d/players_offset_3.yaml create mode 100644 host.d/config.d/mayhem-party.d/remap.d/players_offset_4.yaml create mode 100644 host.d/config.d/mayhem-party.d/remap.d/rotate.sh diff --git a/host.d/README.md b/host.d/README.md index 33414f9..1c48d68 100644 --- a/host.d/README.md +++ b/host.d/README.md @@ -30,26 +30,16 @@ INPUT_UDP_PORT=port ## `mayhem-party` +`cd ./config.d/mayhem-party.d/remap.d; bash ./rotate.sh` and press enter at least once + ### Configs -Create some number of remap files at `/tmp/mayhem-party.d/*` -with keys for EVERY client config button like the following -with at least 1 effectively not mapped/empty - -```yaml -A: A -B: B -C: C -``` - -run `cd /tmp/mayhem-party.d; ln -s ./the-unmapped-file ./live` - ### Binary ```bash DEBUG=1 INPUT_KEYBOARD=true -INPUT_REFRESH_ON_SIGUSR=true +INPUT_REFRESH_ON_SIGUSR1=true INPUT_REMAP_FILE=/tmp/mayhem-party.d/live MAIN_INTERVAL_DURATION=5ms OUTPUT_KEYBOARD=true diff --git a/host.d/config.d/mayhem-party.d/env.env b/host.d/config.d/mayhem-party.d/env.env index 99a6c6d..4d43bc9 100644 --- a/host.d/config.d/mayhem-party.d/env.env +++ b/host.d/config.d/mayhem-party.d/env.env @@ -1,6 +1,6 @@ export DEBUG=1 export INPUT_KEYBOARD=true -export INPUT_REFRESH_ON_SIGUSR=true +export INPUT_REFRESH_ON_SIGUSR1=true export INPUT_REMAP_FILE=./config.d/mayhem-party.d/remap.d/live.yaml export MAIN_INTERVAL_DURATION=5ms export OUTPUT_KEYBOARD=false diff --git a/host.d/config.d/mayhem-party.d/remap.d/.players_offset.py b/host.d/config.d/mayhem-party.d/remap.d/.players_offset.py new file mode 100644 index 0000000..d6ecf80 --- /dev/null +++ b/host.d/config.d/mayhem-party.d/remap.d/.players_offset.py @@ -0,0 +1,31 @@ +import yaml +from sys import argv +from sys import stderr + +def log(*args): + print(*args, file=stderr) + +def main(args): + players = [] + for i in range(1, 5+1): + with open(f"../../rusty-pipe.d/{i}.yaml", "r") as f: + players.append(yaml.safe_load(f)["streams"]["input"]["engine"]["gui"]["buttons"]) + log(players[-1]) + for arg in args: + offset = int(arg) + for i in range(len(players)): + j = (i+offset)%len(players) + if i == j: + break + keys = players[i] + values = players[j] + log(f"player {i+1} plays as player {j+1}") + print(f"# player {i+1} controls {j+1}") + for k in keys: + key = keys[k] + value = values[k] + print(f"'{key}': '{value}'") + +if __name__ == "__main__": + from sys import argv + main(argv[1:]) diff --git a/host.d/config.d/mayhem-party.d/remap.d/live.yaml b/host.d/config.d/mayhem-party.d/remap.d/live.yaml index b8f2939..d9ac77e 120000 --- a/host.d/config.d/mayhem-party.d/remap.d/live.yaml +++ b/host.d/config.d/mayhem-party.d/remap.d/live.yaml @@ -1 +1 @@ -0.yaml \ No newline at end of file +players_offset_0.yaml \ No newline at end of file diff --git a/host.d/config.d/mayhem-party.d/remap.d/0.yaml b/host.d/config.d/mayhem-party.d/remap.d/players_offset_0.yaml similarity index 100% rename from host.d/config.d/mayhem-party.d/remap.d/0.yaml rename to host.d/config.d/mayhem-party.d/remap.d/players_offset_0.yaml diff --git a/host.d/config.d/mayhem-party.d/remap.d/players_offset_1.yaml b/host.d/config.d/mayhem-party.d/remap.d/players_offset_1.yaml new file mode 100644 index 0000000..8bc16c5 --- /dev/null +++ b/host.d/config.d/mayhem-party.d/remap.d/players_offset_1.yaml @@ -0,0 +1,55 @@ +# player 1 controls 2 +'1': 'q' +'2': 'w' +'3': 'e' +'4': 'r' +'5': 't' +'6': 'y' +'7': 'u' +'8': 'i' +'9': 'o' +'0': 'p' +# player 2 controls 3 +'q': 'a' +'w': 's' +'e': 'd' +'r': 'f' +'t': 'g' +'y': 'h' +'u': 'j' +'i': 'k' +'o': 'l' +'p': ';' +# player 3 controls 4 +'a': 'z' +'s': 'x' +'d': 'c' +'f': 'v' +'g': 'b' +'h': 'n' +'j': 'm' +'k': ',' +'l': '.' +';': '/' +# player 4 controls 5 +'z': '!' +'x': '@' +'c': '#' +'v': '$' +'b': '%' +'n': '^' +'m': '&' +',': '*' +'.': '(' +'/': ')' +# player 5 controls 1 +'!': '1' +'@': '2' +'#': '3' +'$': '4' +'%': '5' +'^': '6' +'&': '7' +'*': '8' +'(': '9' +')': '0' diff --git a/host.d/config.d/mayhem-party.d/remap.d/players_offset_2.yaml b/host.d/config.d/mayhem-party.d/remap.d/players_offset_2.yaml new file mode 100644 index 0000000..0e37329 --- /dev/null +++ b/host.d/config.d/mayhem-party.d/remap.d/players_offset_2.yaml @@ -0,0 +1,55 @@ +# player 1 controls 3 +'1': 'a' +'2': 's' +'3': 'd' +'4': 'f' +'5': 'g' +'6': 'h' +'7': 'j' +'8': 'k' +'9': 'l' +'0': ';' +# player 2 controls 4 +'q': 'z' +'w': 'x' +'e': 'c' +'r': 'v' +'t': 'b' +'y': 'n' +'u': 'm' +'i': ',' +'o': '.' +'p': '/' +# player 3 controls 5 +'a': '!' +'s': '@' +'d': '#' +'f': '$' +'g': '%' +'h': '^' +'j': '&' +'k': '*' +'l': '(' +';': ')' +# player 4 controls 1 +'z': '1' +'x': '2' +'c': '3' +'v': '4' +'b': '5' +'n': '6' +'m': '7' +',': '8' +'.': '9' +'/': '0' +# player 5 controls 2 +'!': 'q' +'@': 'w' +'#': 'e' +'$': 'r' +'%': 't' +'^': 'y' +'&': 'u' +'*': 'i' +'(': 'o' +')': 'p' diff --git a/host.d/config.d/mayhem-party.d/remap.d/players_offset_3.yaml b/host.d/config.d/mayhem-party.d/remap.d/players_offset_3.yaml new file mode 100644 index 0000000..9fe061c --- /dev/null +++ b/host.d/config.d/mayhem-party.d/remap.d/players_offset_3.yaml @@ -0,0 +1,55 @@ +# player 1 controls 4 +'1': 'z' +'2': 'x' +'3': 'c' +'4': 'v' +'5': 'b' +'6': 'n' +'7': 'm' +'8': ',' +'9': '.' +'0': '/' +# player 2 controls 5 +'q': '!' +'w': '@' +'e': '#' +'r': '$' +'t': '%' +'y': '^' +'u': '&' +'i': '*' +'o': '(' +'p': ')' +# player 3 controls 1 +'a': '1' +'s': '2' +'d': '3' +'f': '4' +'g': '5' +'h': '6' +'j': '7' +'k': '8' +'l': '9' +';': '0' +# player 4 controls 2 +'z': 'q' +'x': 'w' +'c': 'e' +'v': 'r' +'b': 't' +'n': 'y' +'m': 'u' +',': 'i' +'.': 'o' +'/': 'p' +# player 5 controls 3 +'!': 'a' +'@': 's' +'#': 'd' +'$': 'f' +'%': 'g' +'^': 'h' +'&': 'j' +'*': 'k' +'(': 'l' +')': ';' diff --git a/host.d/config.d/mayhem-party.d/remap.d/players_offset_4.yaml b/host.d/config.d/mayhem-party.d/remap.d/players_offset_4.yaml new file mode 100644 index 0000000..20db335 --- /dev/null +++ b/host.d/config.d/mayhem-party.d/remap.d/players_offset_4.yaml @@ -0,0 +1,55 @@ +# player 1 controls 5 +'1': '!' +'2': '@' +'3': '#' +'4': '$' +'5': '%' +'6': '^' +'7': '&' +'8': '*' +'9': '(' +'0': ')' +# player 2 controls 1 +'q': '1' +'w': '2' +'e': '3' +'r': '4' +'t': '5' +'y': '6' +'u': '7' +'i': '8' +'o': '9' +'p': '0' +# player 3 controls 2 +'a': 'q' +'s': 'w' +'d': 'e' +'f': 'r' +'g': 't' +'h': 'y' +'j': 'u' +'k': 'i' +'l': 'o' +';': 'p' +# player 4 controls 3 +'z': 'a' +'x': 's' +'c': 'd' +'v': 'f' +'b': 'g' +'n': 'h' +'m': 'j' +',': 'k' +'.': 'l' +'/': ';' +# player 5 controls 4 +'!': 'z' +'@': 'x' +'#': 'c' +'$': 'v' +'%': 'b' +'^': 'n' +'&': 'm' +'*': ',' +'(': '.' +')': '/' diff --git a/host.d/config.d/mayhem-party.d/remap.d/rotate.sh b/host.d/config.d/mayhem-party.d/remap.d/rotate.sh new file mode 100644 index 0000000..2fe9798 --- /dev/null +++ b/host.d/config.d/mayhem-party.d/remap.d/rotate.sh @@ -0,0 +1,19 @@ +#! /bin/bash + +mayhem_party_rotate() { + local currently=$(realpath live.yaml | grep -o '[0-9].yaml$' | grep -o '^[0-9]') + local next=${NEXT:-$((RANDOM%5))} + while [ -z "$NEXT" ] && [ "$next" == "$currently" ]; do + next=$((RANDOM%5)) + done + rm live.yaml + ln -s players_offset_$next.yaml live.yaml + pkill -SIGUSR1 -f mayhem-party +} + +if [ "$0" == "$BASH_SOURCE" ]; then + NEXT=0 mayhem_party_rotate + while read -p "$(date) > [press enter to rotate]"; do + mayhem_party_rotate + done +fi