From 8a0a43b4e49e5e66fdcb6d13072a802ad7498ede Mon Sep 17 00:00:00 2001 From: localcc Date: Tue, 14 Jan 2025 18:02:13 +0100 Subject: [PATCH] chore: update Changelog and docs --- assets/Changelog.md | 3 +++ assets/Mods/shared/Types.lua | 39 ++++++++++++++++++++++++++++++++++++ docs/SUMMARY.md | 1 + docs/lua-api/classes/tmap.md | 39 ++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 docs/lua-api/classes/tmap.md diff --git a/assets/Changelog.md b/assets/Changelog.md index 29c119793..b2da9d40c 100644 --- a/assets/Changelog.md +++ b/assets/Changelog.md @@ -43,6 +43,8 @@ Added search filter: `IncludeClassNames`. ([UE4SS #472](https://github.com/UE4SS ### Lua API +Added `TMap` implementation. [UE4SS #755](https://github.com/UE4SS-RE/RE-UE4SS/issues/755) + Added global function `CreateInvalidObject`, which returns an invalid UObject. ([UE4SS #652](https://github.com/UE4SS-RE/RE-UE4SS/issues/652)) Added GenerateLuaTypes function. ([UE4SS #664](https://github.com/UE4SS-RE/RE-UE4SS/pull/664)) @@ -53,6 +55,7 @@ Added global Dumpers functions to Types.lua. ([UE4SS #664](https://github.com/UE - Added `NAME_None` definition - Added `EFindName` enum definition - Added `FName` function overloads with FindType parameter +- Added `TMap` definitions #### UEHelpers - Added function `GetPlayer` which is just a fast way to get player controlled Pawn (the majority of the time it will be the player character) [PR #650](https://github.com/UE4SS-RE/RE-UE4SS/pull/650) diff --git a/assets/Mods/shared/Types.lua b/assets/Mods/shared/Types.lua index fcadb895b..2b95ca9d2 100644 --- a/assets/Mods/shared/Types.lua +++ b/assets/Mods/shared/Types.lua @@ -963,6 +963,45 @@ function TArray:ForEach(Callback) end ---@class TSet : { [K]: nil } ---@class TMap : { [K]: V } +TMap = {} + +---Find the specified key in the map +---Throws an exception if the key is not found +---@generic K +---@generic V +---@param key K +---@return V +function TMap:Find(key) end + +---Inserts a key/value pair into the map +---If the key already exists in the map, replaces the value +---@generic K +---@generic V +---@param key K +---@param value V +function TMap:Add(key, value) end + +---Checks if a key exists inside of the map +---@generic K +---@param key K +---@return boolean +function TMap:Contains(key) end + +---Removes an element from the map +---If the element doesn't exist, does nothing +---@generic K +---@param key K +function TMap:Remove(key) end + +---Clears the map +function TMap:Empty() end + +--- Iterates the entire `TMap` and calls the callback function for each element in the array +--- The callback params are: `RemoteUnrealParam key`, `RemoteUnrealParam value` | `LocalUnrealParam value` +--- Use `elem:get()` and `elem:set()` to access/mutate the value +--- Mutating the key is undefined behavior +--- @param callback fun(key: RemoteUnrealParam, value: RemoteUnrealParam) +function TMap:ForEach(callback) end ---@class TScriptInterface diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index b344b3d7b..df53ee7df 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -43,6 +43,7 @@ - [FText](./lua-api/classes/ftext.md) - [FieldClass](./lua-api/classes/fieldclass.md) - [TArray](./lua-api/classes/tarray.md) + - [TMap](./lua-api/classes/tmap.md) - [RemoteUnrealParam](./lua-api/classes/remoteunrealparam.md) - [LocalUnrealParam](./lua-api/classes/localunrealparam.md) - [Property](./lua-api/classes/property.md) diff --git a/docs/lua-api/classes/tmap.md b/docs/lua-api/classes/tmap.md new file mode 100644 index 000000000..b50a8820f --- /dev/null +++ b/docs/lua-api/classes/tmap.md @@ -0,0 +1,39 @@ +# TMap + +## Inheritance +[RemoteObject](./remoteobject.md) + +## Metamethods + +### __len +- **Usage:** `#TMap` +- **Return type:** `integer` +- Returns the number of current pairs in the map. + +## Methods + +### Find(key) +- **Return type:** `RemoteUnrealParam` | `LocalUnrealParam` +- **Returns:** the element found in the map +- **Throws:** if an element was not found in the map +- Finds the specified key in the map + +### Add(key, value) +- Inserts a key/value pair into the map. If the key already exists in the map, replaces the value. + +### Contains(key) +- **Return type:** `bool` +- **Returns:** if the element exists in the map. +- Checks if a key exists inside of the map. + +### Remove(key) +- Removes an element from the map. If an element doesn't exist, does nothing. + +### Empty() +- Clears the map. + +### ForEach(function Callback) +- Iterates the entire `TMap` and calls the callback function for each element in the array. +- The callback params are: `RemoteUnrealParam key`, `RemoteUnrealParam value` | `LocalUnrealParam value`. +- Use `elem:get()` and `elem:set()` to access/mutate the value. +- Mutating the key is undefined behavior.