IDE hinting: add MetaDataRef & all it inheritors

This commit is contained in:
Alexander Chibrikin
2022-12-27 04:25:40 +03:00
parent f8b932d5f9
commit 062c3709f5
6 changed files with 107 additions and 48 deletions

67
classes/MetaDataRef.lua Normal file
View File

@@ -0,0 +1,67 @@
--- Base class used by [`StorageRef`], [`NodeMetaRef`], [`ItemStackMetaRef`],
--- and [`PlayerMetaRef`].
---
--- Note: If a metadata value is in the format `${k}`, an attempt to get the value
--- will return the value associated with key `k`. There is a low recursion limit.
--- This behavior is **deprecated** and will be removed in a future version. Usage
--- of the `${k}` syntax in formspecs is not deprecated.
---
--- @class MetaDataRef
MetaDataRef = {}
---@param key string
---@return boolean|nil
function MetaDataRef:contains(key) end
---@param key string
---@return string|nil
function MetaDataRef:get(key) end
---@param key string
---@param value string
---@return number
function MetaDataRef:set_string(key, value) end
---@param key string
---@return number
function MetaDataRef:get_string(key) end
---@param key string
---@param value number
---@return number
function MetaDataRef:set_int(key, value) end
---@param key string
---@return number
function MetaDataRef:get_int(key) end
---@param key string
---@param value number
---@return number
function MetaDataRef:set_float(key, value) end
---@param key string
---@return number
function MetaDataRef:get_float(key) end
--- Returns a list of all keys in the metadata.
--- @return table
function MetaDataRef:get_keys() end
--- returns `nil` or a table with keys:
--- * `fields`: key-value storage
--- * `inventory`: `{list1 = {}, ...}}` (NodeMetaRef only)
--- @return table|nil
function MetaDataRef:to_table() end
--- * Any non-table value will clear the metadata
--- * See [Node Metadata] for an example
--- * returns `true` on success
--- @param value table|nil
--- @return boolean
function MetaDataRef:from_table(value) end
--- * returns `true` if this metadata has the same key-value pairs as `other`
--- @param other
--- @return boolean
function MetaDataRef:equals(other) end

View File

@@ -0,0 +1,9 @@
--- ItemStack metadata: reference extra data and functionality stored in a stack.
--- Can be obtained via `item:get_meta()`.
---
--- @class ItemStackMetaRef: MetaDataRef
ItemStackMetaRef = {}
--- * Overrides the item's tool capabilities
--- * A nil value will clear the override data and restore the original behavior.
function ItemStackMetaRef:set_tool_capabilities(tool_capabilities) end

View File

@@ -0,0 +1,16 @@
--- Node metadata: reference extra data and functionality stored in a node.
--- Can be obtained via `minetest.get_meta(pos)`.
---
--- @class NodeMetaRef: MetaDataRef
NodeMetaRef = {}
--- @return InvRef
function NodeMetaRef:get_inventory() end
--- Mark specific vars as private.
--- This will prevent them from being sent to the client. Note that the "private"
--- status will only be remembered if an associated key-value pair exists,
--- meaning it's best to call this when initializing all other meta (e.g.
--- `on_construct`).
--- @param name string|table name or {name1, name2, ...}
function NodeMetaRef:mark_as_private(name) end

View File

@@ -0,0 +1,7 @@
--- Player metadata.
--- Uses the same method of storage as the deprecated player attribute API, so
--- data there will also be in player meta.
--- Can be obtained using `player:get_meta()`.
---
--- @class PlayerMetaRef: MetaDataRef
PlayerMetaRef = {}

View File

@@ -0,0 +1,8 @@
--- Mod metadata: per mod metadata, saved automatically.
--- Can be obtained via `minetest.get_mod_storage()` during load time.
---
--- WARNING: This storage backend is incapable of saving raw binary data due
--- to restrictions of JSON.
---
--- @class StorageRef: MetaDataRef
StorageRef = {}

View File

@@ -1,48 +0,0 @@
---@class NodeMetaRef
NodeMetaRef = {}
---@param key string
---@return boolean|nil
function NodeMetaRef:contains(key) end
---@param key string
---@return string|nil
function NodeMetaRef:get(key) end
---@param key string
---@param value string
---@return number
function NodeMetaRef:set_string(key, value) end
---@param key string
---@return number
function NodeMetaRef:get_string(key) end
---@param key string
---@param value number
---@return number
function NodeMetaRef:set_int(key, value) end
---@param key string
---@return number
function NodeMetaRef:get_int(key) end
---@param key string
---@param value number
---@return number
function NodeMetaRef:set_float(key, value) end
---@param key string
---@return number
function NodeMetaRef:get_float(key) end
---@return table|nil
function NodeMetaRef:to_table() end
---@param value table|nil
---@return boolean
function NodeMetaRef:from_table(value) end
---@param other NodeMetaRef
---@return boolean
function NodeMetaRef:equals(other) end