roblox-ability-lifecycle
Ability and skill lifecycle, lifted out of the framework I ship commissions on.
- 1,569 lines of Luau across 11 modules
- 1,347 lines of tests, 7 spec files
- Runnable: lune run tests/run-all.luau
- MIT, my copyright, no client code in it
29local Lifecycle = {} :: Lifecycle30 31Lifecycle.Plan = function(ModeValue: Mode, ActionValue: Action, HasActiveUse: boolean): PlanResult32 if ModeValue == "Instant" then33 if ActionValue == "Begin" then34 return { Ok = true, Steps = { "Begin", "Release" }, Reason = nil }35 end36 return { Ok = false, Steps = {}, Reason = "Instant skills only accept Begin" }37 end38 39 if ModeValue == "Toggle" then40 if ActionValue == "Begin" then41 return {42 Ok = true,43 Steps = if HasActiveUse then { "CancelExisting" } else { "Begin" },44 Reason = nil,45 }46 end47 if ActionValue == "Cancel" and HasActiveUse then48 return { Ok = true, Steps = { "Cancel" }, Reason = nil }49 end50 return { Ok = false, Steps = {}, Reason = "Toggle skills accept Begin or Cancel" }51 end52 53 if ActionValue == "Begin" then54 if HasActiveUse then55 return { Ok = false, Steps = {}, Reason = "Skill already has an active use" }56 end57 return { Ok = true, Steps = { "Begin" }, Reason = nil }58 end59 60 if not HasActiveUse then61 return { Ok = false, Steps = {}, Reason = "Skill has no active use" }62 end63 64 return { Ok = true, Steps = { ActionValue :: Step }, Reason = nil }65end29local Lifecycle = {} :: Lifecycle30 31Lifecycle.Plan = function(ModeValue: Mode, ActionValue: Action, HasActiveUse: boolean): PlanResult32 if ModeValue == "Instant" then33 if ActionValue == "Begin" then34 return { Ok = true, Steps = { "Begin", "Release" }, Reason = nil }35 end36 return { Ok = false, Steps = {}, Reason = "Instant skills only accept Begin" }37 end38 39 if ModeValue == "Toggle" then40 if ActionValue == "Begin" then41 return {42 Ok = true,43 Steps = if HasActiveUse then { "CancelExisting" } else { "Begin" },44 Reason = nil,45 }46 end47 if ActionValue == "Cancel" and HasActiveUse then48 return { Ok = true, Steps = { "Cancel" }, Reason = nil }49 end50 return { Ok = false, Steps = {}, Reason = "Toggle skills accept Begin or Cancel" }51 end52 53 if ActionValue == "Begin" then54 if HasActiveUse then55 return { Ok = false, Steps = {}, Reason = "Skill already has an active use" }56 end57 return { Ok = true, Steps = { "Begin" }, Reason = nil }58 end59 60 if not HasActiveUse then61 return { Ok = false, Steps = {}, Reason = "Skill has no active use" }62 end63 64 return { Ok = true, Steps = { ActionValue :: Step }, Reason = nil }65end