Skip to content

Instantly share code, notes, and snippets.

@chosig
Created March 25, 2017 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chosig/be3a0e7afd7179dd99fa44d7982d70d8 to your computer and use it in GitHub Desktop.
Save chosig/be3a0e7afd7179dd99fa44d7982d70d8 to your computer and use it in GitHub Desktop.
TinyFugue GMCP negotiation
; -*- folded-file: t -*-
; {{{ gmcp_handler
/def gmcp_handler = \
/if (gmcp_debug) /echo % gmcp: %{*} %; /endif %;\
/if ({1} !~ "Char.Vitals") \
/echo % gmcp unrecognised %;\
/return %;\
/endif %;\
/shift %;\
/let s $[substr({*}, 1, -1)] %;\
/while (strlen(s)) \
/splitat , %{s} %;\
/test s := {P2} %;\
/splitat : %{P1} %;\
/let var $[substr({P1}, 1, -1)] %;\
/if (var =~ "hp") /set hpcur %P2 %; /endif %;\
/if (var =~ "maxhp") /set hpmax %P2 %; /endif %;\
/if (var =~ "gp") /set gpcur %P2 %; /endif %;\
/if (var =~ "maxgp") /set gpmax %P2 %; /endif %;\
/if (var =~ "xp") /set xpcur %P2 %; /endif %;\
/if (var =~ "burden") /set burden %P2 %; /endif %;\
/done %;\
/status_redraw
; }}}
; {{{ /gmcp {0|off|1|on}
/def gmcp = \
/if (!{#}) /echo gmcp=%{gmcp} %; /return %; /endif %;\
/set gmcp %{*} %;\
/if (gmcp) \
/def -hGMCP gmcp_hook = /gmcp_handler %%{*} %;\
/test gmcp("core.supports.set [ \\"Char.Vitals\\" ]") %;\
/else \
/undef gmcp_hook %;\
/test gmcp("core.supports.set [ ]") %;\
/endif
; }}}
/set gmcp_debug 1
/gmcp on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment