{"id":"jaeymo/wrapper","name":"wrapper","scope":"jaeymo","platform":"roblox","description":"A Wrapper is useful for instantiating and managing instances of a class based off tags","version":"2.2.3","latest":"2.2.3","versions":["0.2.4","0.2.5","0.2.6","0.2.7","0.2.8","0.2.9","0.3.0","0.4.0","0.5.0","1.0.0","1.0.1","1.1.0","1.2.0","2.0.0","2.0.1","2.0.2","2.0.3","2.0.4","2.0.5","2.0.6","2.0.7","2.0.8","2.0.9","2.1.0","2.1.1","2.1.2","2.2.0","2.2.1","2.2.2","2.2.3"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"jaeymo/general-util":{"version":"^0.4.0","alias":"general-util"},"howmanysmall/janitor":{"version":"^1.18.3","alias":"janitor"},"howmanysmall/typed-promise":{"version":"^4.0.6","alias":"promise"},"sleitnick/signal":{"version":"^2.0.3","alias":"signal"},"jaeymo/viewer":{"version":"^0.1.0","alias":"viewer"}},"integrity":"c64c688b88a961f7ce884be5f540347cc744a7f19cd48df02cf7c74ddc86f19a","likes":0,"downloads":0,"install":"forest install jaeymo/wrapper","url":"https://forest.dev/p/roblox/jaeymo/wrapper","files":"https://api.forest.dev/ai/package/roblox/jaeymo/wrapper/files","readme":"# Wrapper\r\nWrapper library. A module that manages the lifecycle of class objects tied to tagged instances.\r\n\r\nWrapper automates the creation, initialization, and destruction of class objects based on tag instances.\r\nWrapper provides the constructor with a [Trove](https://github.com/Sleitnick/RbxUtil/blob/main/modules/trove/init.luau) object and an optional GUID.\r\n\r\n## Why Use Wrapper?\r\n- Wrapper makes object-oriented code quicker and cleaner to write.\r\n- Wrapper handles the cleanup of the object's metatable and the provided [Trove](https://github.com/Sleitnick/RbxUtil/blob/main/modules/trove/init.luau) object.\r\n- There's plenty of customization when it comes to what naming convention Wrapper uses for your class' methods.\r\n- Generic type-checking does great in this case. Accessing a wrapper object from elsewhere will still provide the class' type-checking.\r\n- Promise support for the `AwaitObject` method.\r\n- If you are a fanatic about object-oriented programming, this is the module for you! Simply store classes for game objects and apply them via tags.\r\n\r\n## Installation\r\nWrapper is installable via [wally](https://wally.run/) and you can visit the page [here](https://wally.run/package/jaeymo/wrapper?version=2.0.8).\r\n\r\n## Dependencies\r\n- [Trove](https://github.com/Sleitnick/RbxUtil/blob/main/modules/trove/init.luau)\r\n- [Promise](https://github.com/evaera/roblox-lua-promise/blob/master/lib/init.lua)\r\n- [Signal](https://github.com/Sleitnick/RbxUtil/blob/main/modules/signal/init.luau)\r\n- [Viewer](https://github.com/jaeymo/roblox-packages/blob/main/Viewer/init.luau)\r\n- [GeneralUtil](https://github.com/jaeymo/roblox-packages/blob/main/GeneralUtil/init.luau)\r\n  \r\n## Example Usage\r\n```lua\r\n--!strict\r\n\r\n-- Example class\r\nlocal KillPartClass = {}\r\nKillPartClass.__index = KillPartClass\r\n\r\ntype KillPart = typeof(setmetatable({} :: {\r\n    Part: BasePart,\t\r\n    Trove: any,\r\n    GUID: string\r\n}, KillPartClass))\r\n\r\n-- everytime a part with the \"KillPart\" tag is added, this runs.\r\nfunction KillPartClass.new(Part: Instance, Trove: any, GUID: string?): KillPart\r\n    local self = setmetatable({}, KillPartClass)\r\n    self.Part = Part :: BasePart\r\n    self.Trove = Trove\r\n    self.GUID = GUID :: string\r\n\r\n    return self\r\nend\r\n\r\nfunction KillPartClass.Init(self: KillPart) -- automatically runs!\r\n    self:WatchTouchedEvent()\r\nend\r\n\r\nfunction KillPartClass.WatchTouchedEvent(self: KillPart)\r\n    self.Trove:Add(self.Part.Touched:Connect(function(Hit: BasePart)\r\n        local Humanoid = Hit.Parent and Hit.Parent:FindFirstChildWhichIsA(\"Humanoid\")\r\n        if not Humanoid then return end\r\n\r\n        Humanoid.Health = 0\r\n    end))\r\nend\r\n\r\nfunction KillPartClass.Destroy(self: KillPart)\r\n    print(\"This object has been destroyed!\") -- the trove and metatable are cleaned externally, no need to do it here.\r\nend\r\n\r\n-- Usage of class\r\nlocal Wrapper = require(path.to.Wrapper)\r\n\r\nlocal KillPartWrapper = Wrapper.new(KillPartClass, \"KillPart\", {\r\n    Logging = true,\r\n    AutoInit = true, -- AutoInit is true automatically, this redundant but shows what it does nonetheless\r\n    GUID = \"KillPart\"\r\n})\r\n```\r\n","readmeTruncated":false}