Une version rudimentaire de Slay The Spire dans le terminal - retour accueil
git clone git://bebou.netlib.re/sts-term
Log | Files | Refs | README |
commit 11bb3c2b38ef2ccecc902166d1e84ee7d8c2b7be parent bc983b8c8d2c64608794be13d94111d8402906e4 Auterice: Arthur Pons <arthur.pons@unistra.fr> Date: Wed, 19 Jun 2024 22:27:07 +0200 Légère modifs de perfs Pour les chmod des cartes, on n'exécute l'awk plus qu'une fois Est certainement un peu plus performant mais de pas beaucoup ? C'est pas comme si on avait des soucis de perf mais soit Diffstat:
M | makegame | | | 1 | - |
M | utils | | | 41 | ++++++++++++++++++++--------------------- |
2 files changed, 20 insertions(+), 22 deletions(-)
diff --git a/makegame b/makegame @@ -20,7 +20,6 @@ addcard() { /^attack/ s/$/ "${1:?need a target}"/; /^(attack|defend|cost|status)/ s/^/_/' | sort) _discard "\$0" - _updatecardexecutability _refreshUI . mv A deck/$2-$i diff --git a/utils b/utils @@ -17,16 +17,16 @@ _makeui() { [ ! -e "player" ] && printf "No current game\n" currentenergy=$(grep energy fight/player | cut -f2) - grep -H cost fight/hand/* | - awk "\$2>$currentenergy{print}" | - cut -d':' -f1 | xargs -r -n1 basename > $tmpdir/nonexeccards + tree --noreport fight/stack > $tmpdir/stack tree --noreport fight/hand > $tmpdir/hand tree --noreport fight/discard > $tmpdir/discard + cat $tmpdir/nonexeccards | + xargs -r -n1 basename | while read card;do sed -i -E "/$card/ s/^/$grayed/;/$card/ s/$/$norm/" $tmpdir/hand - done < $tmpdir/nonexeccards + done <<-. cat Floor : $(cat fight/floor) @@ -101,8 +101,10 @@ _setstat() { ("*player*") _gameover;; (*) _killennemie "$target";; esac - else - sed -i --follow-symlinks -E "/$stat/ s/ .*/ $value/" "$target" + fi + sed -i --follow-symlinks -E "/$stat/ s/ .*/ $value/" "$target" + if [ "$stat" = "energy" ];then + _updatecardexecutability fi } @@ -146,17 +148,17 @@ _hasstatus() { _updatecardexecutability() { currentenergy=$(grep energy fight/player | cut -f2) grep -H cost fight/hand/* | - awk "\$2<=$currentenergy{print}" | - cut -d':' -f1 | - while read card;do - chmod +x "$card" - done - grep -H cost fight/hand/* | awk "\$2>$currentenergy{print}" | - cut -d':' -f1 | - while read card;do - chmod -x "$card" - done + cut -d':' -f1 > $tmpdir/nonexeccards + + for card in $(cat $tmpdir/nonexeccards);do + chmod -x "$card" + done + + for card in $(find fight/hand/* -type f | grep -v -f $tmpdir/nonexeccards) + do + chmod +x "$card" + done } _cost() { @@ -183,14 +185,11 @@ endturn() { _draw() { nbtodraw="$1" - for nb in $(seq $nbtodraw);do + for nb in $(seq "$nbtodraw");do [ "$(find fight/stack -type f | wc -l)" = "0" ] && _shufflediscard - card=$(find fight/stack -type f | - shuf | - head -n 1) + card=$(find fight/stack -type f | shuf | head -n 1) chmod +x "$card" mv "$card" fight/hand - _updatecardexecutability done }