summaryrefslogtreecommitdiffstats
path: root/MCServer
diff options
context:
space:
mode:
Diffstat (limited to 'MCServer')
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua28
-rw-r--r--MCServer/Plugins/APIDump/main_APIDump.lua138
2 files changed, 147 insertions, 19 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index c5599b212..74e7bf860 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1666,25 +1666,26 @@ a_Player:OpenWindow(Window);
GetClientHandle = { Params = "", Return = "{{cClientHandle}}", Notes = "Returns the client handle representing the player's connection. May be nil (AI players)." },
GetColor = { Return = "string", Notes = "Returns the full color code to be used for this player (based on the first group). Prefix player messages with this code." },
GetCurrentXp = { Params = "", Return = "number", Notes = "Returns the current amount of XP" },
- GetEffectiveGameMode = { Params = "", Return = "{{eGameMode|GameMode}}", Notes = "Returns the current resolved game mode of the player. If the player is set to inherit the world's gamemode, returns that instead. See also GetGameMode() and IsGameModeXXX() functions." },
+ GetEffectiveGameMode = { Params = "", Return = "{{Globals#GameMode|GameMode}}", Notes = "(OBSOLETE) Returns the current resolved game mode of the player. If the player is set to inherit the world's gamemode, returns that instead. See also GetGameMode() and IsGameModeXXX() functions. Note that this function is the same as GetGameMode(), use that function instead." },
GetEquippedItem = { Params = "", Return = "{{cItem}}", Notes = "Returns the item that the player is currently holding; empty item if holding nothing." },
GetEyeHeight = { Return = "number", Notes = "Returns the height of the player's eyes, in absolute coords" },
GetEyePosition = { Return = "{{Vector3d|EyePositionVector}}", Notes = "Returns the position of the player's eyes, as a {{Vector3d}}" },
GetFloaterID = { Params = "", Return = "number", Notes = "Returns the Entity ID of the fishing hook floater that belongs to the player. Returns -1 if no floater is associated with the player. FIXME: Undefined behavior when the player has used multiple fishing rods simultanously." },
+ GetFlyingMaxSpeed = { Params = "", Return = "number", Notes = "Returns the maximum flying speed, relative to the default game flying speed. Defaults to 1, but plugins may modify it for faster or slower flying." },
GetFoodExhaustionLevel = { Params = "", Return = "number", Notes = "Returns the food exhaustion level" },
GetFoodLevel = { Params = "", Return = "number", Notes = "Returns the food level (number of half-drumsticks on-screen)" },
GetFoodPoisonedTicksRemaining = { Params = "", Return = "", Notes = "Returns the number of ticks left for the food posoning effect" },
GetFoodSaturationLevel = { Params = "", Return = "number", Notes = "Returns the food saturation (overcharge of the food level, is depleted before food level)" },
GetFoodTickTimer = { Params = "", Return = "", Notes = "Returns the number of ticks past the last food-based heal or damage action; when this timer reaches 80, a new heal / damage is applied." },
- GetGameMode = { Return = "{{eGameMode|GameMode}}", Notes = "Returns the player's gamemode. The player may have their gamemode unassigned, in which case they inherit the gamemode from the current {{cWorld|world}}.<br /> <b>NOTE:</b> Instead of comparing the value returned by this function to the gmXXX constants, use the IsGameModeXXX() functions. These functions handle the gamemode inheritance automatically."},
+ GetGameMode = { Return = "{{Globals#GameMode|GameMode}}", Notes = "Returns the player's gamemode. The player may have their gamemode unassigned, in which case they inherit the gamemode from the current {{cWorld|world}}.<br /> <b>NOTE:</b> Instead of comparing the value returned by this function to the gmXXX constants, use the IsGameModeXXX() functions. These functions handle the gamemode inheritance automatically."},
GetGroups = { Return = "array-table of {{cGroup}}", Notes = "Returns all the groups that this player is member of, as a table. The groups are stored in the array part of the table, beginning with index 1."},
GetIP = { Return = "string", Notes = "Returns the IP address of the player, if available. Returns an empty string if there's no IP to report."},
GetInventory = { Return = "{{cInventory|Inventory}}", Notes = "Returns the player's inventory"},
- GetMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's current maximum speed (as reported by the 1.6.1+ protocols)" },
+ GetMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's current maximum speed, relative to the game default speed. Takes into account the sprinting / flying status." },
GetName = { Return = "string", Notes = "Returns the player's name" },
- GetNormalMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's maximum walking speed (as reported by the 1.6.1+ protocols)" },
+ GetNormalMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's maximum walking speed, relative to the game default speed. Defaults to 1, but plugins may modify it for faster or slower walking." },
GetResolvedPermissions = { Return = "array-table of string", Notes = "Returns all the player's permissions, as a table. The permissions are stored in the array part of the table, beginning with index 1." },
- GetSprintingMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's maximum sprinting speed (as reported by the 1.6.1+ protocols)" },
+ GetSprintingMaxSpeed = { Params = "", Return = "number", Notes = "Returns the player's maximum sprinting speed, relative to the game default speed. Defaults to 1.3, but plugins may modify it for faster or slower sprinting." },
GetStance = { Return = "number", Notes = "Returns the player's stance (Y-pos of player's eyes)" },
GetThrowSpeed = { Params = "SpeedCoeff", Return = "{{Vector3d}}", Notes = "Returns the speed vector for an object thrown with the specified speed coeff. Basically returns the normalized look vector multiplied by the coeff, with a slight random variation." },
GetThrowStartPos = { Params = "", Return = "{{Vector3d}}", Notes = "Returns the position where the projectiles should start when thrown by this player." },
@@ -1721,17 +1722,18 @@ a_Player:OpenWindow(Window);
SetCrouch = { Params = "IsCrouched", Return = "", Notes = "Sets the crouch state, broadcasts the change to other players." },
SetCurrentExperience = { Params = "XPAmount", Return = "", Notes = "Sets the current amount of experience (and indirectly, the XP level)." },
SetFlying = { Params = "IsFlying", Notes = "Sets if the player is flying or not." },
+ SetFlyingMaxSpeed = { Params = "FlyingMaxSpeed", Return = "", Notes = "Sets the flying maximum speed, relative to the game default speed. The default value is 1. Sends the updated speed to the client." },
SetFoodExhaustionLevel = { Params = "ExhaustionLevel", Return = "", Notes = "Sets the food exhaustion to the specified level." },
SetFoodLevel = { Params = "FoodLevel", Return = "", Notes = "Sets the food level (number of half-drumsticks on-screen)" },
SetFoodPoisonedTicksRemaining = { Params = "FoodPoisonedTicksRemaining", Return = "", Notes = "Sets the number of ticks remaining for food poisoning. Doesn't send foodpoisoning effect to the client, use FoodPoison() for that." },
SetFoodSaturationLevel = { Params = "FoodSaturationLevel", Return = "", Notes = "Sets the food saturation (overcharge of the food level)." },
SetFoodTickTimer = { Params = "FoodTickTimer", Return = "", Notes = "Sets the number of ticks past the last food-based heal or damage action; when this timer reaches 80, a new heal / damage is applied." },
- SetGameMode = { Params = "{{eGameMode|NewGameMode}}", Return = "", Notes = "Sets the gamemode for the player. The new gamemode overrides the world's default gamemode, unless it is set to gmInherit." },
+ SetGameMode = { Params = "{{Globals#GameMode|NewGameMode}}", Return = "", Notes = "Sets the gamemode for the player. The new gamemode overrides the world's default gamemode, unless it is set to gmInherit." },
SetIsFishing = { Params = "IsFishing, [FloaterEntityID]", Return = "", Notes = "Sets the 'IsFishing' flag for the player. The floater entity ID is expected for the true variant, it can be omitted when IsFishing is false. FIXME: Undefined behavior when multiple fishing rods are used simultanously" },
SetName = { Params = "Name", Return = "", Notes = "Sets the player name. This rename will NOT be visible to any players already in the server who are close enough to see this player." },
- SetNormalMaxSpeed = { Params = "NormalMaxSpeed", Return = "", Notes = "Sets the normal (walking) maximum speed (as reported by the 1.6.1+ protocols)" },
+ SetNormalMaxSpeed = { Params = "NormalMaxSpeed", Return = "", Notes = "Sets the normal (walking) maximum speed, relative to the game default speed. The default value is 1. Sends the updated speed to the client, if appropriate." },
SetSprint = { Params = "IsSprinting", Return = "", Notes = "Sets whether the player is sprinting or not." },
- SetSprintingMaxSpeed = { Params = "SprintingMaxSpeed", Return = "", Notes = "Sets the sprinting maximum speed (as reported by the 1.6.1+ protocols)" },
+ SetSprintingMaxSpeed = { Params = "SprintingMaxSpeed", Return = "", Notes = "Sets the sprinting maximum speed, relative to the game default speed. The default value is 1.3. Sends the updated speed to the client, if appropriate." },
SetVisible = { Params = "IsVisible", Return = "", Notes = "Sets the player visibility to other players" },
XpForLevel = { Params = "XPLevel", Return = "number", Notes = "(STATIC) Returns the total amount of XP needed for the specified XP level. Inverse of CalcLevelFromXp()." },
},
@@ -2792,11 +2794,11 @@ end
"Globals.xpcall",
"Globals.decoda_output", -- When running under Decoda, this function gets added to the global namespace
"sqlite3.__newindex",
- "%a+\.__%a+", -- AnyClass.__Anything
- "%a+\.\.collector", -- AnyClass..collector
- "%a+\.new", -- AnyClass.new
- "%a+.new_local", -- AnyClass.new_local
- "%a+.delete", -- AnyClass.delete
+ "%a+%.__%a+", -- AnyClass.__Anything
+ "%a+%.%.collector", -- AnyClass..collector
+ "%a+%.new", -- AnyClass.new
+ "%a+%.new_local", -- AnyClass.new_local
+ "%a+%.delete", -- AnyClass.delete
-- Functions global in the APIDump plugin:
"CreateAPITables",
diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua
index 6d4a6ebc5..7455c3cd2 100644
--- a/MCServer/Plugins/APIDump/main_APIDump.lua
+++ b/MCServer/Plugins/APIDump/main_APIDump.lua
@@ -1231,10 +1231,6 @@ local function DumpAPIHtml(a_API)
return (Hook1.Name < Hook2.Name);
end
);
-
- -- Read in the descriptions:
- LOG("Reading descriptions...");
- ReadDescriptions(a_API);
ReadHooks(Hooks);
-- Create a "class index" file, write each class as a link to that file,
@@ -1329,6 +1325,126 @@ end
+--- Returns the string with extra tabs and CR/LFs removed
+local function CleanUpDescription(a_Desc)
+ -- Get rid of indent and newlines, normalize whitespace:
+ local res = a_Desc:gsub("[\n\t]", "")
+ res = a_Desc:gsub("%s%s+", " ")
+
+ -- Replace paragraph marks with newlines:
+ res = res:gsub("<p>", "\n")
+ res = res:gsub("</p>", "")
+
+ -- Replace list items with dashes:
+ res = res:gsub("</?ul>", "")
+ res = res:gsub("<li>", "\n - ")
+ res = res:gsub("</li>", "")
+
+ return res
+end
+
+
+
+
+
+--- Writes a list of methods into the specified file in ZBS format
+local function WriteZBSMethods(f, a_Methods)
+ for _, func in ipairs(a_Methods or {}) do
+ f:write("\t\t\t[\"", func.Name, "\"] =\n")
+ f:write("\t\t\t{\n")
+ f:write("\t\t\t\ttype = \"method\",\n")
+ if ((func.Notes ~= nil) and (func.Notes ~= "")) then
+ f:write("\t\t\t\tdescription = [[", CleanUpDescription(func.Notes or ""), " ]],\n")
+ end
+ f:write("\t\t\t},\n")
+ end
+end
+
+
+
+
+
+--- Writes a list of constants into the specified file in ZBS format
+local function WriteZBSConstants(f, a_Constants)
+ for _, cons in ipairs(a_Constants or {}) do
+ f:write("\t\t\t[\"", cons.Name, "\"] =\n")
+ f:write("\t\t\t{\n")
+ f:write("\t\t\t\ttype = \"value\",\n")
+ if ((cons.Desc ~= nil) and (cons.Desc ~= "")) then
+ f:write("\t\t\t\tdescription = [[", CleanUpDescription(cons.Desc or ""), " ]],\n")
+ end
+ f:write("\t\t\t},\n")
+ end
+end
+
+
+
+
+
+--- Writes one MCS class definition into the specified file in ZBS format
+local function WriteZBSClass(f, a_Class)
+ assert(type(a_Class) == "table")
+
+ -- Write class header:
+ f:write("\t", a_Class.Name, " =\n\t{\n")
+ f:write("\t\ttype = \"class\",\n")
+ f:write("\t\tdescription = [[", CleanUpDescription(a_Class.Desc or ""), " ]],\n")
+ f:write("\t\tchilds =\n")
+ f:write("\t\t{\n")
+
+ -- Export methods and constants:
+ WriteZBSMethods(f, a_Class.Functions)
+ WriteZBSConstants(f, a_Class.Constants)
+
+ -- Finish the class definition:
+ f:write("\t\t},\n")
+ f:write("\t},\n\n")
+end
+
+
+
+
+
+--- Dumps the entire API table into a file in the ZBS format
+local function DumpAPIZBS(a_API)
+ LOG("Dumping ZBS API description...")
+ local f, err = io.open("mcserver.lua", "w")
+ if (f == nil) then
+ LOG("Cannot open mcserver.lua for writing, ZBS API will not be dumped. " .. err)
+ return
+ end
+
+ -- Write the file header:
+ f:write("-- This is a MCServer API file automatically generated by the APIDump plugin\n")
+ f:write("-- Note that any manual changes will be overwritten by the next dump\n\n")
+ f:write("return {\n")
+
+ -- Export each class except Globals, store those aside:
+ local Globals
+ for _, cls in ipairs(a_API) do
+ if (cls.Name ~= "Globals") then
+ WriteZBSClass(f, cls)
+ else
+ Globals = cls
+ end
+ end
+
+ -- Export the globals:
+ if (Globals) then
+ WriteZBSMethods(f, Globals.Functions)
+ WriteZBSConstants(f, Globals.Constants)
+ end
+
+ -- Finish the file:
+ f:write("}\n")
+ f:close()
+ LOG("ZBS API dumped...")
+end
+
+
+
+
+
local function DumpApi()
LOG("Dumping the API...")
@@ -1377,9 +1493,16 @@ local function DumpApi()
Globals.Name = "Globals";
table.insert(API, Globals);
- -- Dump all available API object in HTML format into a subfolder:
+ -- Read in the descriptions:
+ LOG("Reading descriptions...");
+ ReadDescriptions(API);
+
+ -- Dump all available API objects in HTML format into a subfolder:
DumpAPIHtml(API);
+ -- Dump all available API objects in format used by ZeroBraneStudio API descriptions:
+ DumpAPIZBS(API)
+
LOG("APIDump finished");
return true
end
@@ -1418,9 +1541,12 @@ function Initialize(Plugin)
LOG("Initialising " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
+ -- Bind a console command to dump the API:
cPluginManager:BindConsoleCommand("api", HandleCmdApi, "Dumps the Lua API docs into the API/ subfolder")
+
+ -- Add a WebAdmin tab that has a Dump button
g_Plugin:AddWebTab("APIDump", HandleWebAdminDump)
- -- TODO: Add a WebAdmin tab that has a Dump button
+
return true
end