Auto generate message class docs

This commit is contained in:
ChillerDragon 2022-11-26 12:16:05 +01:00
parent 93b4b136af
commit 0dad3f9ca9
12 changed files with 223 additions and 0 deletions

View file

@ -0,0 +1,6 @@
# ClEmoticon
Client -> Server
### @emoticon [Integer]

View file

@ -0,0 +1,8 @@
# ClSay
Client -> Server
### @mode [Integer]
### @target_id [Integer]
### @message [String]

View file

@ -0,0 +1,30 @@
# ClientInfo
Server -> Client
### @client_id [Integer]
### @local [Integer]
### @team [Integer]
### @name [String]
### @clan [String]
### @country [Integer]
### @body [String]
### @marking [String]
### @decoration [String]
### @hands [String]
### @feet [String]
### @eyes [String]
### @custom_color_body [Integer]
### @custom_color_marking [Integer]
### @custom_color_decoration [Integer]
### @custom_color_hands [Integer]
### @custom_color_feet [Integer]
### @custom_color_eyes [Integer]
### @color_body [Integer]
### @color_marking [Integer]
### @color_decoration [Integer]
### @color_hands [Integer]
### @color_feet [Integer]
### @color_eyes [Integer]
### @silent [Integer]

View file

@ -0,0 +1,5 @@
# GameInfo

View file

@ -0,0 +1,7 @@
# InputTiming
Server -> Client
### @intended_tick [Integer]
### @time_left [Integer]

View file

@ -0,0 +1,8 @@
# RconCmdAdd
Server -> Client
### @name [String]
### @help [String]
### @params [String]

View file

@ -0,0 +1,6 @@
# RconCmdRem
Server -> Client
### @name [String]

View file

@ -0,0 +1,5 @@
# ServerInfo

View file

@ -0,0 +1,5 @@
# ServerSettings

View file

@ -0,0 +1,26 @@
# StartInfo
Client -> Server
### @name [String]
### @clan [String]
### @country [Integer]
### @body [String]
### @marking [String]
### @decoration [String]
### @hands [String]
### @feet [String]
### @eyes [String]
### @custom_color_body [Integer]
### @custom_color_marking [Integer]
### @custom_color_decoration [Integer]
### @custom_color_hands [Integer]
### @custom_color_feet [Integer]
### @custom_color_eyes [Integer]
### @color_body [Integer]
### @color_marking [Integer]
### @color_decoration [Integer]
### @color_hands [Integer]
### @color_feet [Integer]
### @color_eyes [Integer]

View file

@ -0,0 +1,8 @@
# SvClientDrop
Server -> Client
### @client_id [Integer]
### @reason [String]
### @silent [Integer]

109
scripts/messages.sh Executable file
View file

@ -0,0 +1,109 @@
#!/bin/bash
if [ ! -d spec ]
then
echo "Error: spec folder not found"
echo " run this script from the root of repo"
exit 1
fi
arg_generate_docs=0
for arg in "$@"
do
if [ "$arg" == "--fix" ] || [ "$arg" == "--generate-docs" ]
then
arg_generate_docs=1
fi
done
function missing_doc() {
local rb_file="$1"
local version="$2"
local line
local ifs="$IFS"
local dir=''
local class_name=''
local is_init_raw=0
local field
local fields=''
local dst_file
while IFS='' read -r line
do
if [ "$line" == "# Client -> Server" ]
then
dir='Client -> Server'
elif [ "$line" == "# Server -> Client" ]
then
dir='Server -> Client'
elif [[ "$line" =~ ^class\ ([^ ]+) ]]
then
class_name="${BASH_REMATCH[1]}"
elif [ "$line" == " def init_raw(data)" ]
then
is_init_raw=1
elif [ "$line" == " end" ]
then
is_init_raw=0
fi
if [ "$is_init_raw" == "1" ]
then
if [[ "$line" =~ @(.*)\ =\ u.get_string ]]
then
field="${BASH_REMATCH[1]}"
fields+="### @$field [String]\n"
elif [[ "$line" =~ @(.*)\ =\ u.get_int ]]
then
field="${BASH_REMATCH[1]}"
fields+="### @$field [Integer]\n"
elif [[ "$line" =~ @(.*)\ =\ u.get_raw ]]
then
field="${BASH_REMATCH[1]}"
fields+="### @$field [Raw]\n"
fi
fi
done < "$rb_file"
IFS="$ifs"
dst_file="docs/$version/classes/messages/$class_name.md"
if [ -f "$dst_file" ]
then
return 1
fi
if [ "$arg_generate_docs" == "0" ]
then
return 0
fi
{
echo "# $class_name"
echo ''
echo "$dir"
echo ''
echo -e "$fields"
} > "$dst_file"
return 1
}
function generate_msg_docs() {
local version
version="$(grep TEEWORLDS_NETWORK_VERSION lib/version.rb | cut -d"'" -f2)"
if [ "$version" == "" ]
then
echo "Error: failed to get library version"
exit 1
fi
local rb_file
for rb_file in ./lib/messages/*.rb
do
echo -n "[*] $(basename "$rb_file") .. "
if missing_doc "$rb_file" "$version"
then
echo "ERROR: missing doc try --fix"
else
echo "OK"
fi
done
}
generate_msg_docs