fixes init file, remove old code, add template for core_inventory

This commit is contained in:
qwezert committed 2025-01-09 19:06:33 +02:00
1 parent 646b669881
commit 99f7f4eb11
5 files changed
+37 -42

No files matched your search

+11 -30
View File
@@ -1,6 +1,15 @@
Bridge = {}
local function registerModule(moduleName, moduleTable)
function Bridge.RegisterModule(moduleName, moduleTable)
if not moduleTable then
print("No moduleTable provided for module and no defaultsTable found: ", moduleName)
return
end
if Bridge[moduleName] then
print("Module already registered:", moduleName)
return
end
local wrappedModule = {}
for functionName, func in pairs(moduleTable) do
wrappedModule[functionName] = func
@@ -9,38 +18,10 @@ local function registerModule(moduleName, moduleTable)
Bridge[moduleName] = wrappedModule
end
function Bridge.RegisterModule(moduleName, moduleTable, defaultsTable)
if not moduleTable then
if not defaultsTable then
print("No moduleTable or defaultsTable provided for module:", moduleName)
return
end
moduleTable = defaultsTable
registerModule(moduleName, moduleTable)
return
end
if Bridge[moduleName] then
print("Module already registered:", moduleName)
return
end
if defaultsTable and type(defaultsTable) == "table" then
for functionName, func in pairs(defaultsTable) do
if not moduleTable[functionName] then
moduleTable[functionName] = func
print(string.format("Added function '%s' from defaultsTable to module '%s'", functionName, moduleName))
end
end
end
registerModule(moduleName, moduleTable)
end
--TODO: Create a way to overide functions or create a new functions for module
Bridge.RegisterModule("Framework", Framework)
Bridge.RegisterModule("Inventory", Inventory, DefaultInventory)
Bridge.RegisterModule("Inventory", Inventory)
Bridge.RegisterModule("Notify", Notify)
Bridge.RegisterModule("Utility", Utility)
Bridge.RegisterModule("Progressbar", Progressbar)
+3 -3
View File
@@ -1,10 +1,10 @@
DefaultInventory = DefaultInventory or {}
Inventory = Inventory or {}
DefaultInventory.GetItemInfo = function(item)
Inventory.GetItemInfo = function(item)
print('client funct')
return Framework.GetItemInfo(item)
end
DefaultInventory.GetImagePath = function(item)
Inventory.GetImagePath = function(item)
return "https://avatars.githubusercontent.com/u/47620135"
end
+9 -9
View File
@@ -1,33 +1,33 @@
DefaultInventory = DefaultInventory or {}
Inventory = Inventory or {}
DefaultInventory.AddItem = function(src, item, count, slot, metadata)
Inventory.AddItem = function(src, item, count, slot, metadata)
return Framework.AddItem(src, item, count, slot, metadata)
end
DefaultInventory.RemoveItem = function(src, item, count, slot, metadata)
Inventory.RemoveItem = function(src, item, count, slot, metadata)
return Framework.RemoveItem(src, item, count, slot, metadata)
end
DefaultInventory.GetItemInfo = function(item)
Inventory.GetItemInfo = function(item)
return false, print("This Inventory Has Not Been Bridged For An Item Info Feature.")
end
DefaultInventory.GetItemCount = function(src, item, metadata)
Inventory.GetItemCount = function(src, item, metadata)
return Framework.GetItemCount(src, item, metadata)
end
DefaultInventory.GetInventoryItems = function(src)
Inventory.GetInventoryItems = function(src)
return Framework.GetPlayerInventory(src)
end
DefaultInventory.SetMetadata = function(src, item, slot, metadata)
Inventory.SetMetadata = function(src, item, slot, metadata)
return Framework.SetMetadata(src, item, slot, metadata)
end
DefaultInventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
Inventory.OpenStash = function(src, id, label, slots, weight, owner, groups, coords)
return false, print("This Inventory Has Not Been Bridged For A Stash Feature.")
end
DefaultInventory.GetImagePath = function(item)
Inventory.GetImagePath = function(item)
return "https://avatars.githubusercontent.com/u/47620135"
end
@@ -0,0 +1,7 @@
if GetResourceState('core_inventory') ~= 'started' then return end
Inventory = Inventory or {}
Inventory.TestFunction = function(item)
return 'test funct client inv'
end
@@ -0,0 +1,7 @@
if GetResourceState('core_inventory') ~= 'started' then return end
Inventory = Inventory or {}
Inventory.TestFunction = function(item)
return 'test funct server inv'
end