{"id":"jaeymo/classy","name":"classy","scope":"jaeymo","platform":"roblox","description":"A Classy is useful because writing compositional code for instances becomes much easier!","version":"2.1.1","latest":"2.1.1","versions":["1.0.0","1.0.1","1.1.0","1.2.0","1.3.0","1.4.0","1.5.0","1.6.0","1.7.0","1.7.1","1.7.2","1.7.3","1.7.4","1.7.5","1.7.6","1.7.7","1.7.8","1.7.9","2.0.0","2.1.0","2.1.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{"howmanysmall/janitor":{"version":"^1.18.3","alias":"Janitor"},"sleitnick/signal":{"version":"^2.0.3","alias":"Signal"}},"integrity":"968de5adbfc6318eec3d8f2bb325cd319869bd418365608e0e100930dcee4151","likes":0,"downloads":0,"install":"forest install jaeymo/classy","url":"https://forest.dev/p/roblox/jaeymo/classy","files":"https://api.forest.dev/ai/package/roblox/jaeymo/classy/files","readme":"\r\n# Classy\r\nClassy library. Class is a tag-driven lifecycle manager that makes a composition approach much easier in luau!\r\n\r\n## Why Use Classy?\r\n- You have the option of tracking instances with classes or functions.\r\n- Classy handles the cleanup of a class object's metatable and the provided [Janitor](https://github.com/howmanysmall/Janitor) object.\r\n- Full generic type safety is preserved when accessing applied objects.\r\n- If you are a fanatic about object-oriented programming, this is the module for you! Simply create classes for game objects and track them with tags.\r\n\r\n## Installation\r\nClassy is installable via [wally](https://wally.run/), and you can visit the page [here](https://wally.run/package/jaeymo/classy?version=1.0.1).\r\n\r\n## Dependencies\r\n- [Janitor](https://github.com/howmanysmall/Janitor)\r\n- [Signal](https://github.com/Sleitnick/RbxUtil/blob/main/modules/signal/init.luau)\r\n  \r\n## Example Usage\r\n```lua\r\n--!strict\r\n\r\nlocal Classy = require(path.to.classy)\r\n\r\n-- Example class\r\nlocal KillPartClass = {}\r\nKillPartClass.__index = KillPartClass\r\n\r\nexport type KillPart = typeof(setmetatable({} :: {\r\n    Part: BasePart,\t\r\n    Janitor: Classy.Janitor,\r\n}, KillPartClass))\r\n\r\n-- every time a part with the \"KillPart\" tag is added, this runs.\r\nfunction KillPartClass.new(Part: Instance, JanitorObject: Classy.Janitor): KillPart\r\n    return setmetatable({\r\n        Part = Part :: BasePart,\r\n        Janitor = JanitorObject,\r\n    }, KillPartClass)\r\nend\r\n\r\nfunction KillPartClass.Init(self: KillPart) -- automatically runs!\r\n    self:WatchTouchedEvent()\r\nend\r\n\r\nfunction KillPartClass.DoSomething(self: KillPart)\r\n    print(self)\r\nend\r\n\r\nfunction KillPartClass.WatchTouchedEvent(self: KillPart)\r\n    self.Janitor: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 Janitor and metatable are cleaned externally, no need to do it here.\r\nend\r\n\r\n-- Usage\r\nlocal KillPartClassy = Classy.new(\"KillPart\", KillPartClass, {\r\n    ClassNames = { \"BasePart\" },\r\n    Ancestors = { workspace },\r\n})\r\n\r\nKillPartClassy.InstanceAdded:Connect(function(Instance: Instance, Applied)\r\n    Applied:GetData():DoSomething()\r\nend)\r\n```\r\n","readmeTruncated":false}