initial commit

This commit is contained in:
2021-09-29 04:55:14 +03:00
parent 1b168019d9
commit c29915e87e
13 changed files with 211 additions and 0 deletions

View File

@ -0,0 +1,45 @@
local containers = require("containers")
local params = {
pocketwatchpack = {
widget = {
slotpos = {},
animbank = "ui_piggyback_2x6",
animbuild = "ui_piggyback_2x6",
pos = Vector3(-5, -50, 0)
},
issidewidget = true,
openlimit = 1,
type = "pack"
}
}
for y = 0, 5 do
table.insert(params.pocketwatchpack.widget.slotpos, Vector3(-162, -75 * y + 170, 0))
table.insert(params.pocketwatchpack.widget.slotpos, Vector3(-162 + 75, -75 * y + 170, 0))
end
function params.pocketwatchpack.itemtestfn(container, item, slot)
return (item:HasTag("pocketwatch") or (item.prefab == "pocketwatch_parts" or item.prefab == "pocketwatch_dismantler"))
end
for k, v in pairs(params) do
containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, v.widget.slotpos and #v.widget.slotpos or 0)
end
local containers_widgetsetup = containers.widgetsetup
function containers.widgetsetup(container, prefab, data)
local t = data or params[prefab or container.inst.prefab]
if t ~= nil then
for k, v in pairs(t) do
container[k] = v
end
container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
else
return containers_widgetsetup(container, prefab, data)
end
end

View File

@ -0,0 +1,69 @@
local assets = {
Asset("ANIM", "anim/pocketwatchpack.zip"),
Asset("ATLAS", "images/inventoryimages/pocketwatchpack.xml")
}
local prefabs = {}
local function onopen(inst)
end
local function onclose(inst)
local owner = inst.components.inventoryitem.owner
if owner then
local container = owner.components.inventory:GetOverflowContainer()
if container then
container:Open(owner)
end
end
end
local function ondropped(inst)
if inst.components.container then
inst.components.container:Close()
end
end
local function fn()
local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddAnimState()
inst.entity:AddSoundEmitter()
inst.entity:AddNetwork()
MakeInventoryPhysics(inst)
inst.AnimState:SetBank("pocketwatchpack")
inst.AnimState:SetBuild("pocketwatchpack")
inst.AnimState:PlayAnimation("idle")
MakeInventoryFloatable(inst)
inst.entity:SetPristine()
if not TheWorld.ismastersim then
return inst
end
inst:AddComponent("inspectable")
inst:AddComponent("inventoryitem")
inst.components.inventoryitem.imagename = "pocketwatchpack"
inst.components.inventoryitem.atlasname = "images/inventoryimages/pocketwatchpack.xml"
inst.components.inventoryitem.canonlygoinpocket = true -- can't store a pocket watch bag into a backpack etc
inst.components.inventoryitem.keepondeath = true
inst.components.inventoryitem.keepondrown = true
inst.components.inventoryitem:SetOnDroppedFn(ondropped)
inst:AddComponent("container")
inst.components.container:WidgetSetup("pocketwatchpack")
--inst.components.container.onopenfn = onopen
inst.components.container.onclosefn = onclose
MakeHauntableLaunchAndDropFirstItem(inst)
return inst
end
return Prefab("pocketwatchpack", fn, assets, prefabs)