### Create Startup System Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md Defines a system that runs specifically during the 'Startup' phase of the Planck scheduler, suitable for initial setup logic. ```lua ```lua local Matter = require("@packages/Matter") local Planck = require("@packages/Planck") local Phase = Planck.Phase local components = require("@shared/components") local function systemA(world) -- Runs only once before all other Phases end return { system = systemA, phase = Phase.Startup } ``` ``` -------------------------------- ### Create Planck Scheduler Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md Initializes and exports a Planck Scheduler, responsible for managing and executing game logic systems. ```lua ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local scheduler = scheduler.new() return scheduler ``` ``` -------------------------------- ### Startup Function Implementation Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md Provides the main startup function that initializes the scheduler, adds systems, and sets up debugging tools. ```lua ```lua local scheduler = require("@shared/scheduler") local world = require("@shared/world") return function(systems) if #systems ~= 0 then scheduler:addSystems(systems) -- Assuming you're using SystemTables! end end ``` ``` -------------------------------- ### Create Matter World Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md Initializes and exports a Matter World instance, serving as the core simulation environment for entities and components. ```lua ```lua local Matter = require("@packages/Matter") local World = Matter.World local world = World.new() return world ``` ``` -------------------------------- ### Initialize Scheduler with World Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md Configures the Planck Scheduler by passing the Matter World instance to its constructor, linking the scheduler to the simulation environment. ```lua ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local world = require("@shared/world") local scheduler = scheduler.new(world) return scheduler ``` ``` -------------------------------- ### ServerScriptService/server/server.server.luau Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md This Lua script configures server-side systems for a Roblox game. It loads shared systems and server-specific modules from ReplicatedStorage, aggregates them, and passes them to a startup function for initialization. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local startup = require("@shared/startup") local systems = {} local function addSystems(folder) for _, system in folder:GetChildren() do if not system:IsA("ModuleScript") then continue end table.insert(systems, require(system)) end end addSystems(ReplicatedStorage.shared.systems) addSystems(ReplicatedStorage.server.systems) startup(systems) ``` -------------------------------- ### ReplicatedStorage/client/client.client.luau Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md This Lua script sets up client-side systems for a Roblox game. It requires shared and client-specific modules from ReplicatedStorage, adds them to a list, and then initializes them using a startup function. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local startup = require("@shared/startup") local systems = {} local function addSystems(folder) for _, system in folder:GetChildren() do if not system:IsA("ModuleScript") then continue end table.insert(systems, require(system)) end end addSystems(ReplicatedStorage.shared.systems) addSystems(ReplicatedStorage.client.systems) startup(systems) ``` -------------------------------- ### wally.toml Dependencies Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md Defines project dependencies using the Wally package manager, including Matter, Planck, and related debugger/hooks packages. ```toml ```toml [dependencies] Matter = "matter-ecs/matter@0.8.4" Planck = "yetanotherclown/planck@0.2.0" PlanckMatterDebugger = "yetanotherclown/planck-matter-debugger@0.2.0" PlanckMatterHooks = "yetanotherclown/planck-matter-hooks@0.2.1" ``` ``` -------------------------------- ### Create Normal System Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md Defines a standard system function that will be executed by the Planck scheduler without a specific phase constraint. ```lua ```lua local function systemB(world) -- ... end return systemB ``` ``` -------------------------------- ### Create New Scheduler Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/scheduler.md Demonstrates the basic setup for creating a new Scheduler instance in Planck. This is the minimal initialization required, with no explicit start or initialization methods. ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local scheduler = Scheduler.new() ``` -------------------------------- ### Add Plugins to Scheduler Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md Configures the Planck Scheduler by adding Matter plugins like HooksPlugin and DebuggerPlugin, enhancing functionality and debugging capabilities. ```lua ```lua local Matter = require("@packages/Matter") local Plasma = require("@packages/Plasma") local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local world = require("@shared/world") local DebuggerPlugin = require("@packages/DebuggerPlugin") local debuggerPlugin = DebuggerPlugin.new({ world }) local debugger = Matter.Debugger.new(Plasma) local widgets = debugger:getWidgets() local HooksPlugin = require("@packages/HooksPlugin") local hooksPlugin = HooksPlugin.new() local scheduler = scheduler.new(world, widgets) :addPlugin(hooksPlugin) :addPlugin(debuggerPlugin) debugger:autoInitialize(debuggerPlugin:getLoop()) return scheduler ``` ``` -------------------------------- ### Wally Installation Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/introduction.md Installs the Planck library using Wally, a package manager for Roblox development. This dependency declaration ensures Planck is available for use in your project. ```toml [dependencies] Planck = "yetanotherclown/planck@0.2.0" ``` -------------------------------- ### Define Matter Components Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/matter.md Defines custom Matter components within a module, registering them with Matter for use in entities. ```lua ```lua local Matter = require("@packages/Matter") return { MyComponent = Matter.component("myComponent"), } ``` ``` -------------------------------- ### Setup Scheduler with PlanckRunService Plugin (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/runservice.md This Lua code demonstrates the initial setup for the Planck scheduler. It involves requiring the Planck core library and the PlanckRunService plugin, instantiating the plugin, and adding it to a new scheduler instance. ```lua ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local world = require("@shared/world") local PlanckRunService = require("@packages/PlanckRunService") local runServicePlugin = PlanckRunService.new() local scheduler = scheduler.new(world) :addPlugin(runServicePlugin) return scheduler ``` ``` -------------------------------- ### PlanckRunService Plugin Installation Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/phases.md Provides the TOML dependency declaration required to install the PlanckRunService plugin using Wally, which adds RunService-based phases and pipelines. ```toml [dependencies] PlanckRunService = "yetanotherclown/planck-runservice@0.2.0" ``` -------------------------------- ### Install PlanckRunService Plugin (TOML) Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/runservice.md This snippet shows how to add the PlanckRunService plugin as a dependency in your project's wally.toml file. It specifies the package name and version required for installation. ```toml ```toml [dependencies] PlanckRunService = "yetanotherclown/planck-runservice@0.2.0" ``` ``` -------------------------------- ### Setup Matter Debugger Scheduler Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/matter_debugger.md This Lua code demonstrates setting up a scheduler with the Matter Debugger plugin. It initializes the debugger and adds the plugin to the scheduler, returning the configured scheduler instance. ```luau local ReplicatedStorage = game:GetService("ReplicatedStorage") local Matter = require("@packages/Matter") local Plasma = require("@packages/Plasma") local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local world = require("@shared/world") local DebuggerPlugin = require("@packages/DebuggerPlugin") local debuggerPlugin = DebuggerPlugin.new({ world }) local debugger = Matter.Debugger.new(Plasma) local widgets = debugger:getWidgets() local scheduler = scheduler.new(world, widgets) :addPlugin(debuggerPlugin) debugger:autoInitialize(debuggerPlugin:getLoop()) return scheduler ``` -------------------------------- ### Serve Project with Rojo Source: https://github.com/yetanotherclown/planck/blob/main/CONTRIBUTING.md Start a development server for the project using Rojo. This allows tests to run and output results directly when the server is active in Roblox Studio, without direct CLI invocation for testing. ```bash #!/bin/bash # This script is a placeholder for the actual development server startup logic. # It assumes Rojo is installed and configured for the project. echo "Serving project with Rojo using scripts/dev.sh..." # Example command (actual command may vary): # ./scripts/dev.sh echo "Development server started. Check Studio for test results." ``` -------------------------------- ### Install Debugger Plugin Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/matter_debugger.md This snippet shows how to add the DebuggerPlugin dependency to your project's wally.toml file for installation. ```toml [dependencies] DebuggerPlugin = "yetanotherclown/planck-matter-debugger@0.2.0" ``` -------------------------------- ### Scheduler Setup with Jabby Plugin Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/jabby.md Demonstrates how to initialize the Planck Scheduler and add the Jabby Plugin to it. This Lua code sets up the scheduler for use with the Jabby debugger, requiring the Planck and PlanckJabby packages. ```luau local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local world = require("@shared/world") local PlanckJabby = require("@packages/PlanckJabby") local jabbyPlugin = PlanckJabby.new() local scheduler = scheduler.new(world) :addPlugin(jabbyPlugin) return scheduler ``` -------------------------------- ### Setup Scheduler with Matter Hooks Plugin and Reference (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/matter_hooks.md This Luau snippet demonstrates initializing the Matter Hooks plugin with an explicit reference to the Matter library, which is useful when the plugin cannot automatically locate it. It then adds this configured plugin to the Planck Scheduler. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local MatterHooks = require("@packages/MatterHooks") local hooksPlugin = MatterHooks.new(ReplicatedStorage.Matter) local scheduler = scheduler.new() :addPlugin(hooksPlugin) return scheduler ``` -------------------------------- ### Install Planck with Wally Source: https://github.com/yetanotherclown/planck/blob/main/README.md This snippet shows how to add Planck as a dependency to your project using Wally, a package manager for Luau. It specifies the package name and version required for installation. ```TOML [dependencies] Planck = "yetanotherclown/planck@0.2.0" ``` -------------------------------- ### Setup Scheduler with Matter Hooks Plugin (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/matter_hooks.md This Luau snippet illustrates the process of creating a Planck Scheduler and adding the Matter Hooks plugin to it. It requires importing both Planck and the MatterHooks package. ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local MatterHooks = require("@packages/MatterHooks") local hooksPlugin = MatterHooks.new() local scheduler = scheduler.new() :addPlugin(hooksPlugin) return scheduler ``` -------------------------------- ### Install Matter Hooks Plugin (TOML) Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/matter_hooks.md This snippet shows how to add the Matter Hooks plugin as a dependency in a `wally.toml` file. It specifies the package name and version required for installation. ```toml [dependencies] MatterHooks = "yetanotherclown/planck-matter-hooks@0.2.1" ``` -------------------------------- ### On Event Condition (Basic) Source: https://github.com/yetanotherclown/planck/blob/main/docs/design/conditions.md Sets up a system to run when a specific event occurs, such as `Players.PlayerAdded`. This example shows how to define the condition. ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local onEvent = Planck.onEvent local scheduler = Scheduler.new(world) -- Run out system only when there is a new Player :addRunCondition(systemA, onEvent(Players.PlayerAdded)) ``` -------------------------------- ### Use Matter Hooks in System (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/matter_hooks.md This Luau code demonstrates how to import and utilize hooks provided by the Matter Hooks plugin within a system. It shows examples of using `useThrottle`, `useDeltaTime`, and `useEvent`. ```lua local MatterHooks = require("@packages/MatterHooks") local useDeltaTime = MatterHooks.useDeltaTime local useEvent = MatterHooks.useEvent local useThrottle = MatterHooks.useThrottle function systemA() if useThrottle(5) then print("Throttled for 5 seconds") end end return systemA ``` -------------------------------- ### Using Built-in Startup Phases Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/phases.md Illustrates how to access and use Planck's predefined startup phases (PreStartup, Startup, PostStartup). These phases are executed once at the beginning of the application lifecycle, before the main game loop. ```lua local Planck = require("@packages/Planck") local Phase = Planck.Phase local PreStartup = Phase.PreStartup local Startup = Phase.Startup local PostStartup = Phase.PostStartup ``` -------------------------------- ### Define Planck/Jecs Startup System A Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/jecs.mdx Sets up initial entities and components using Planck and Jecs. It configures entities with names and food quantities, and associates them with specific components for the Startup phase. ```lua local Jecs = require("@packages/Jecs") local pair = Jecs.pair local Planck = require("@packages/Planck") local Phase = Planck.Phase local components = require("@shared/components") local Name = components.Name local Eats = components.Eats local Apples = components.Apples local Oranges = components.Oranges local function systemA(world) world:set(Apples, Name, "apples") world:set(Oranges, Name, "oranges") local bob = world:entity() world:set(bob, pair(Eats, Apples), 10) world:set(bob, pair(Eats, Oranges), 5) world:set(bob, Name, "bob") local alice = world:entity() world:set(alice, pair(Eats, Apples), 4) world:set(alice, Name, "alice") end return { system = systemA, phase = Phase.Startup } ``` -------------------------------- ### Implement Planck/Jabby Startup Function Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/jecs.mdx Initializes the application by adding systems to the scheduler and setting up Jabby for client-side interaction. It includes logic for binding a key to spawn an app and registering the world with Jabby. ```lua local Jabby = require("@packages/Jabby") local scheduler = require("@shared/scheduler") local world = require("@shared/world") return function(systems) if #systems ~= 0 then scheduler:addSystems(systems) -- Assuming you're using SystemTables! end if RunService:IsClient() then local client = Jabby.obtain_client() local function createWidget(_, state: Enum.UserInputState) if state ~= Enum.UserInputState.Begin then return end client.spawn_app(client.apps.home, nil) end ContextActionService:BindAction("Open Jabby", createWidget, false, Enum.KeyCode.F4) end Jabby.register({ applet = Jabby.applets.world, name = "Jecs World", configuration = { world = world } }) end ``` -------------------------------- ### Load Client Systems with Startup Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/jecs.mdx Loads shared and client-specific systems from folders and passes them to the main startup function. This script runs on the client to initialize client-side logic and systems. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local startup = require("@shared/startup") local systems = {} local function addSystems(folder) for _, system in folder:GetChildren() do if not system:IsA("ModuleScript") then continue end table.insert(systems, require(system)) end end addSystems(ReplicatedStorage.shared.systems) addSystems(ReplicatedStorage.client.systems) startup(systems) ``` -------------------------------- ### Add System Set to Scheduler (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/systems.md Demonstrates how to group multiple systems into a set (an array) and add them to the scheduler simultaneously using the `addSystems` method. This is useful for bulk registration and managing related systems. ```lua -- ... local systemA = require("@shared/systems/systemA") local systemB = require("@shared/systems/systemB") local systemSet = { systemA, systemB } local scheduler = Scheduler.new(world, state) :addSystems(systemSet) ``` -------------------------------- ### Add System to Scheduler (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/systems.md Shows how to instantiate a Scheduler and add a previously defined system to it. The scheduler manages the execution of these systems, often passing world and state data to them. ```lua -- ... local systemA = require("@shared/systems/systemA") local scheduler = Scheduler.new(world, state) :addSystem(systemA) ``` -------------------------------- ### Time Passed Condition Source: https://github.com/yetanotherclown/planck/blob/main/docs/design/conditions.md Uses the built-in `timePassed` condition to execute a system at a specified interval, for example, every 10 seconds. ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local timePassed = Planck.timePassed local scheduler = Scheduler.new(world) :addRunCondition(systemA, timePassed(10)) -- Run every 10 seconds ``` -------------------------------- ### Create Scheduler with State Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/scheduler.md Illustrates how to initialize the Scheduler by passing state, such as a Jecs World and custom data, directly into the Scheduler.new() function. ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local Jecs = require("@packages/Jecs") local World = Jecs.World local world = World.new() local state = {} local scheduler = Scheduler.new(world, state) ``` -------------------------------- ### Define System using SystemTable (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/systems.md Explains how to define a system using a SystemTable, which is a more structured approach. A SystemTable can include the system function itself, along with optional metadata like a name, phase, and run conditions for advanced control. ```lua local function systemA(world, state) -- ... end local function condition(world, state) if someCondition then return true else return false end end return { name = "systemA", system = systemA, phase = Planck.Phase.PreUpdate, runConditions = { condition } } ``` -------------------------------- ### Load Server Systems with Startup Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/jecs.mdx Loads shared and server-specific systems from folders and passes them to the main startup function. This script runs on the server to initialize server-side logic and systems. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local startup = require("@shared/startup") local systems = {} local function addSystems(folder) for _, system in folder:GetChildren() do if not system:IsA("ModuleScript") then continue end table.insert(systems, require(system)) end end addSystems(ReplicatedStorage.shared.systems) addSystems(ReplicatedStorage.server.systems) startup(systems) ``` -------------------------------- ### Create and Add Phase to Scheduler Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/phases.md Demonstrates how to create a new Phase instance and add it to the Planck Scheduler, associating a system with this phase. This is a fundamental step in organizing system execution order. ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local Phase = Planck.Phase -- ... local systemA = require("@shared/systems/systemA") local myPhase = Phase.new("myPhase") local scheduler = Scheduler.new(world, state) :insert(myPhase) :addSystem(systemA, myPhase) ``` -------------------------------- ### Initialize Planck Scheduler Source: https://github.com/yetanotherclown/planck/blob/main/README.md Demonstrates the initialization of the Planck Scheduler, which is the core component for managing systems and their execution order. It requires a World object and a state object. ```luau local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local Jecs = require("@packages/Jecs") local World = Jecs.World local world = World.new() local state = {} local scheduler = Scheduler.new(world, state) ``` -------------------------------- ### Lua: Scheduler explicit phase dependency (insertBefore) Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/order.md Demonstrates how to explicitly define an execution order using `insertBefore`. This ensures that `phaseB` will run immediately before `phaseA`. ```lua local scheduler = Scheduler.new() :insert(phaseA) :insertBefore(phaseB, phaseA) :runAll() -- phaseB runs before phaseA ``` -------------------------------- ### Create and Schedule Lua Phases and Pipelines Source: https://github.com/yetanotherclown/planck/blob/main/docs/design/phases-and-pipelines.md Demonstrates how to define custom Phases, group them into a Pipeline, and then schedule the entire Pipeline to run on a specific event using the Planck framework. This approach simplifies managing multiple related execution steps. ```lua local Phase = Planck.Phase local Pipeline = Planck.Pipeline local Scheduler = Planck.Scheduler local PreUpdate = Phase.new() local Update = Phase.new() local PostUpdate = Phase.new() local UpdatePipeline = Pipeline.new() :insert(PreUpdate) :insert(Update) :insert(PostUpdate) local scheduler = scheduler.new(world) :insert(UpdatePipeline, RunService, "Heartbeat") ``` -------------------------------- ### Lua: Scheduler system insertion order Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/order.md Illustrates how Systems are ordered within a Planck Scheduler. Systems are ordered strictly by their insertion sequence, without explicit dependency management. ```lua local scheduler = Scheduler.new() :addSystem(systemA) :addSystem(systemB) :runAll() -- systemA runs before systemB ``` -------------------------------- ### Accessing RunService Pipelines Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/phases.md Demonstrates how to require the PlanckRunService plugin and access its predefined Pipelines, which correspond to various Roblox RunService events like PreRender, PreSimulation, and Heartbeat. ```lua local PlanckRunService = require("@packages/PlanckRunService") local Pipelines = PlanckRunService.Pipelines local PreRender = Pipelines.PreRender local PreAnimation = Pipelines.PreAnimation local PreSimulation = Pipelines.PreSimulation local PostSimulation = Pipelines.PostSimulation local Heartbeat = Pipelines.Heartbeat ``` -------------------------------- ### Create and Use Pipelines Source: https://github.com/yetanotherclown/planck/blob/main/README.md Demonstrates the creation of Pipelines, which are ordered collections of Phases. This helps in organizing related phases and scheduling them to run at specific times, often tied to engine events like 'Heartbeat'. ```luau local Phase = Planck.Phase local Pipeline = Planck.Pipeline local Scheduler = Planck.Scheduler -- Define phases (can be custom or built-in) local PreUpdate = Phase.new("PreUpdate") local Update = Phase.new("Update") local PostUpdate = Phase.new("PostUpdate") -- Create a pipeline and insert phases in order local UpdatePipeline = Pipeline.new() :insert(PreUpdate) :insert(Update) :insert(PostUpdate) -- Assuming 'scheduler' is an initialized Scheduler instance -- and 'RunService' is an object providing engine events -- local RunService = ... scheduler:insert(UpdatePipeline, RunService, "Heartbeat") -- Schedule the pipeline to run on Heartbeat ``` -------------------------------- ### Create Planck Scheduler Source: https://github.com/yetanotherclown/planck/blob/main/docs/setup_guides/jecs.mdx Initializes a new Planck Scheduler instance in `scheduler.luau`, responsible for managing systems and plugins. ```lua local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local scheduler = Scheduler.new() return scheduler ``` -------------------------------- ### Lua: Scheduler basic insertion order Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/order.md Demonstrates the default ordering behavior of custom Pipelines or Phases when added sequentially to a Planck Scheduler. The last added item becomes a dependency of the next, ensuring sequential execution. ```lua local scheduler = Scheduler.new() :insert(phaseA) :insert(phaseB) :runAll() -- phaseA will run before phaseB ``` -------------------------------- ### Define System Function with Parameters (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/systems.md Illustrates a system function designed to accept parameters, typically the world state and custom state data managed by the scheduler. This allows systems to interact with the game's data. ```lua local function systemA(world, state) -- ... end return systemA ``` -------------------------------- ### Lua: Scheduler explicit phase dependency (insertAfter) Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/order.md Shows how to explicitly define a dependency between two Phases using `insertAfter`. This ensures that `phaseB` will only run after `phaseA` has completed. ```lua local scheduler = Scheduler.new() :insert(phaseA) :insertAfter(phaseB, phaseA) :runAll() -- phaseB depends on phaseA and runs after it ``` -------------------------------- ### Lua: Scheduler grouping by events Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/order.md Illustrates how to group Pipelines or Phases by specific events, such as `RunService.Heartbeat` or `RunService.PostSimulation`. The scheduler processes all items in one group before moving to the next group, maintaining internal order within each group. ```lua local scheduler = Scheduler.new() :insert(pipelineA, RunService.Heartbeat) :insertAfter(pipelineB, RunService.PostSimulation) :runAll() -- Processes Heartbeat group, then PostSimulation group ``` -------------------------------- ### Define a Basic System Function (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/systems.md Demonstrates the fundamental way to define a system as a standalone function within a ModuleScript. This function represents a single unit of logic that can be executed by the scheduler. ```lua local function systemA() -- ... end return systemA ``` -------------------------------- ### Test Runner Configuration (run-tests.luau) Source: https://github.com/yetanotherclown/planck/blob/main/CONTRIBUTING.md Configuration file for defining CLI options and project directories for Jest. This script dictates how tests are discovered and executed within the project's testing framework. ```luau -- scripts/run-tests.luau -- Placeholder for Luau script defining CLI options and Jest project directories. -- This file configures the testing environment and test discovery. local cliOptions = { -- Define CLI options here } local jestProjectDirs = { -- Specify directories containing tests here } print("Configuring test runner...") -- Logic to use cliOptions and jestProjectDirs would go here. print("Test runner configured.") ``` -------------------------------- ### Accessing RunService Phases Source: https://github.com/yetanotherclown/planck/blob/main/docs/getting_started/phases.md Shows how to access the Phases provided by the PlanckRunService plugin, which map directly to RunService events. Note that 'Heartbeat' is mapped to the 'Update' phase. ```lua local PlanckRunService = require("@packages/PlanckRunService") local Phases = PlanckRunService.Phases local PreRender = Phases.PreRender local PreAnimation = Phases.PreAnimation local PreSimulation = Phases.PreSimulation local PostSimulation = Phases.PostSimulation local Update = Phases.Update ``` -------------------------------- ### Create and Use Phases Source: https://github.com/yetanotherclown/planck/blob/main/README.md Explains how to create custom Phases within Planck to segment the frame's execution. Systems can then be associated with specific phases, allowing for controlled execution order. ```luau local Planck = require("@packages/Planck") local Scheduler = Planck.Scheduler local Phase = Planck.Phase -- ... (Scheduler initialization) local systemA = require("@shared/systems/systemA") local myPhase = Phase.new("myPhase") -- Create a new phase named 'myPhase' scheduler :insert(myPhase) -- Add the phase to the scheduler's known phases :addSystem(systemA, myPhase) -- Add systemA to run within myPhase ``` -------------------------------- ### Generic Move Models System Source: https://github.com/yetanotherclown/planck/blob/main/docs/design/systems.md This Lua code demonstrates a refactored, generic system for moving any game entity that has Position and Velocity components, promoting reusability. ```lua local world = require("@shared/world") local scheduler = require("@shared/scheduler") local Enemy = world:component() local Position = world:component() local Velocity = world:component() local function moveModels() -- Move models every frame for entity, position, velocity in world:query(Position, Velocity):iter() do local deltaTime = scheduler:getDeltaTime() world:set(entity, Position, position * deltaTime * velocity) end end ``` -------------------------------- ### Run Tests with run-in-roblox Source: https://github.com/yetanotherclown/planck/blob/main/CONTRIBUTING.md Execute the test suite from the command line using the provided shell script. This script leverages run-in-roblox to automate test execution within Roblox Studio. ```bash #!/bin/bash # This script is a placeholder for the actual test execution logic. # It assumes run-in-roblox is set up and configured. echo "Running tests using scripts/test.sh..." # Example command (actual command may vary): # ./scripts/test.sh echo "Tests executed." ``` -------------------------------- ### Add System to Scheduler (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/matter_hooks.md This Luau code shows how to add a previously defined system (e.g., `systemA`) to the scheduler. This is typically done during the application's startup phase. ```lua local scheduler = require("@shared/scheduler") local systemA = require("@shared/systems/systemA") return function() scheduler :addSystem(systemA) end ``` -------------------------------- ### Access Additional Update Phases (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/runservice.md This Lua snippet demonstrates accessing the multiple Phases available for the RunService.Heartbeat event. These phases, including First, PreUpdate, Update, PostUpdate, and Last, allow for granular control over the order of game logic execution. ```lua ```lua local PlanckRunService = require("@packages/PlanckRunService") local Phases = PlanckRunService.Phases local First = Phases.First local PreUpdate = Phases.PreUpdate local Update = Phases.Update local PostUpdate = Phases.PostUpdate local Last = Phases.Last ``` ``` -------------------------------- ### Access RunService Pipelines (Lua) Source: https://github.com/yetanotherclown/planck/blob/main/docs/plugins/runservice.md This Lua snippet illustrates how to access the predefined RunService Pipelines provided by the PlanckRunService plugin. These pipelines correspond to specific RunService events like PreRender, PreAnimation, and Heartbeat. ```lua ```lua local PlanckRunService = require("@packages/PlanckRunService") local Pipelines = PlanckRunService.Pipelines local PreRender = Pipelines.PreRender local PreAnimation = Pipelines.PreAnimation local PreSimulation = Pipelines.PreSimulation local PostSimulation = Pipelines.PostSimulation local Heartbeat = Pipelines.Heartbeat ``` ``` -------------------------------- ### Glossary Navigation Data Structures Source: https://github.com/yetanotherclown/planck/blob/main/docs/intro.mdx JavaScript arrays containing structured data for the glossary navigation. Each object represents a section with a title, an ID for linking, and a description that includes a list of related topics or API references. ```javascript export const ROW_ONE = [ { title: "Getting Started", id: "getting-started", description: <> , }, { title: "Designing with Planck", id: "designing-with-planck", description: <> , }, ]; export const ROW_TWO = [ { title: "Setup Guides", id: "setup-guides", description: <> , }, { title: "Plugins", id: "plugins", description: <> , }, { title: "API", id: "api", description: <> , }, ]; ```