{"id":"chroma-hade/lunora","name":"lunora","scope":"chroma-hade","platform":"roblox","description":"Tiny Roblox game framework. Your whole game talks through one ModuleScript.","version":"1.0.3","latest":"1.0.3","versions":["1.0.0","1.0.1","1.0.2","1.0.3"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"9236d84112fd4d10da03650f3014532cf20966f876d8c347aa0eac98b3dd6e0e","likes":0,"downloads":0,"install":"forest install chroma-hade/lunora","url":"https://forest.dev/p/roblox/chroma-hade/lunora","files":"https://api.forest.dev/ai/package/roblox/chroma-hade/lunora/files","readme":"# Lunora\r\n\r\nA tiny game framework for Roblox! You hand it your modules, it starts them up, and your server and client can call each other by name. The whole thing is one ModuleScript, under 500 lines.\r\n\r\nI use it for my own games☆\r\n\r\n## Getting it\r\n\r\nGrab `Lunora.rbxm` from the [releases page](https://github.com/chroma-hade/Lunora/releases) and put it in a folder inside ReplicatedStorage, like `ReplicatedStorage.Packages`.\r\n\r\nNot straight into ReplicatedStorage itself, though! Lunora makes a folder there called `Lunora` for its remotes, and the two would clash.\r\n\r\nIf you use Wally, add it to your `wally.toml`:\r\n\r\n```toml\r\n[dependencies]\r\nLunora = \"chroma-hade/lunora@1.0.3\"\r\n```\r\n\r\nOr just copy `src/init.luau` into your project.\r\n\r\n## Setting it up\r\n\r\nOne script on each side, that's it! Tell Lunora where your modules are, then start it.\r\n\r\n```lua\r\n-- ServerScriptService/Server.server.luau\r\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\r\nlocal ServerStorage = game:GetService(\"ServerStorage\")\r\n\r\nlocal Lunora = require(ReplicatedStorage.Packages.Lunora)\r\nLunora.AddModules(ServerStorage.Services)\r\n\r\nLunora.Start()\r\n```\r\n\r\n```lua\r\n-- StarterPlayerScripts/Client.client.luau\r\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\r\n\r\nlocal Lunora = require(ReplicatedStorage.Packages.Lunora)\r\nLunora.AddModules(script.Parent.Controllers)\r\n\r\nLunora.Start()\r\n```\r\n\r\nEvery ModuleScript in those folders gets loaded, nested folders too. Lunora keeps track of them by name, so give each one a different name. If two share a name, Lunora warns you and keeps the first one.\r\n\r\nIf a ModuleScript sits directly inside another ModuleScript, Lunora leaves it alone. Handy for private helpers☆\r\n\r\n## A module\r\n\r\nA module is just a table. `Init` and `Start` are optional.\r\n\r\n```lua\r\nlocal ShopService = {\r\n    Public = {},\r\n}\r\n\r\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\r\nlocal Players = game:GetService(\"Players\")\r\n\r\nlocal Lunora = require(ReplicatedStorage.Packages.Lunora)\r\n\r\nlocal ShopController = Lunora.Load(\"ShopController\")\r\n\r\nlocal CashService = nil\r\n\r\nlocal Prices = {\r\n    Sword = 100,\r\n    Shield = 80,\r\n}\r\n\r\nlocal function GetPrice(Player: Player, ItemName: string): number?\r\n    return Prices[ItemName]\r\nend\r\n\r\nlocal function Buy(Player: Player, ItemName: string)\r\n    local Price = Prices[ItemName]\r\n    if not Price then\r\n        return\r\n    end\r\n    if not CashService.TakeCash(Player, Price) then\r\n        return\r\n    end\r\n    ShopController.ShowPurchase(ItemName):Fire(Player)\r\nend\r\n\r\nfunction ShopService.Init()\r\n    CashService = Lunora.LoadSelf(\"CashService\")\r\nend\r\n\r\nfunction ShopService.Start()\r\n    Players.PlayerAdded:Connect(function(Player: Player)\r\n        ShopController.ShowPrices(Prices):Fire(Player)\r\n    end)\r\nend\r\n\r\nShopService.Public.GetPrice = GetPrice\r\nShopService.Public.Buy = Buy\r\n\r\nreturn ShopService\r\n```\r\n\r\n`Init` runs on every module first. Use it to grab other modules on the same side with `LoadSelf`, and that's about it.\r\n\r\n`Start` only runs once every `Init` is done, so by the time it runs, `CashService` is already there. This is where your module actually comes alive! Hook up events, start loops, send things to clients. Each `Start` gets its own thread, so one slow module won't hold up the others.\r\n\r\nDon't count on modules starting in any particular order.\r\n\r\n`Prices[ItemName]` doubles as the check on what the client sent. If someone sends an item that isn't on the list, `Buy` just stops there☆\r\n\r\n## Talking across\r\n\r\n`Lunora.Load(\"Name\")` gives you the module on the other side. Call a function on it, then `:Fire()` to send it off or `:Invoke()` to wait for an answer.\r\n\r\nFrom the client:\r\n\r\n```lua\r\nlocal ShopService = Lunora.Load(\"ShopService\")\r\nlocal Price = ShopService.GetPrice(\"Sword\"):Invoke()\r\nShopService.Buy(\"Sword\"):Fire()\r\n```\r\n\r\nOn the server that runs `ShopService.Public.Buy(Player, \"Sword\")`. Only functions inside `Public` can be reached from a client, and the player always comes first. Anything else a client sends could be made up, so always check it!\r\n\r\nFrom the server:\r\n\r\n```lua\r\nlocal ShopController = Lunora.Load(\"ShopController\")\r\nShopController.ShowPurchase(\"Sword\"):Fire(Player)\r\nShopController.Refresh():Fire()\r\n```\r\n\r\n`:Fire(Player)` goes to one player and `:Fire()` goes to everyone. `:Invoke(Player)` needs a player, and if that client errors you get `nil` back instead of an error on the server.\r\n\r\nAnything you send before your modules start gets dropped with a warning, and that includes sending from inside `Init`.\r\n\r\n## Signals\r\n\r\nFor events that stay on one side, no remotes involved☆\r\n\r\n```lua\r\nlocal Damaged = Lunora.NewSignal()\r\n\r\nlocal Connection = Damaged:Connect(function(Victim, Amount)\r\n    print(Victim, Amount)\r\nend)\r\n\r\nDamaged:Fire(Victim, 10)\r\n\r\nConnection:Disconnect()\r\n```\r\n\r\nEach listener runs in its own thread. `Damaged:Wait()` waits for the next `Fire` and gives you its arguments, and `Damaged:Destroy()` drops every listener.\r\n\r\n## Everything\r\n\r\nThat's the whole API!\r\n\r\n| | |\r\n|---|---|\r\n| `Lunora.AddModules(Folder)` | Loads every ModuleScript under the folder |\r\n| `Lunora.Start()` | Sets up the remotes, then runs every `Init`, then every `Start` |\r\n| `Lunora.Load(Name)` | A module on the other side |\r\n| `Lunora.LoadSelf(Name)` | A module on the same side |\r\n| `Lunora.NewSignal()` | A new same-side signal |\r\n| `Lunora.IsReady()` | Whether `Start` has run yet |\r\n| `Lunora.OnReady()` | Waits until `Start` has run |\r\n| `Lunora.Stop()` | Calls `Stop` on modules that have one and disconnects the remotes |\r\n\r\nThe client waits up to five seconds for the server's remote folder before it gives up.\r\n\r\n## License\r\n\r\nMIT, so go wild☆ Just keep the license file around.\r\n","readmeTruncated":false}