TabletopGame
An object that manages the setup and gameplay of a tabletop game.
Declaration
class TabletopGameOverview
First, create a TableSetup object that represents your game layout and equipment. Add seats for players to occupy, conforming to the TableSeat protocol, and equipment for them to manipulate, conforming to the Equipment protocol.
Pass an object that conforms to the Tabletop or EntityTabletop protocol to the TableSetup initializer.
let table = Table()
root = createRootEntity(table: table.entity)
var setup = TableSetup(tabletop: table)Implement your structure to initialize the protocol properties, such as shape, entity, and id properties for the EntityTabletop protocol.
struct Table: EntityTabletop {
var shape: TabletopShape
var entity: Entity
var id: EquipmentIdentifier
init() {
self.entity = try! Entity.load(named: "table/table", in: contentBundle)
self.shape = .round(entity: entity)
self.id = .table
}
}Then, create the TabletopGame object that represents your game instance by passing the TableSetup object to the init(tableSetup:version:) initializer.
game = TabletopGame(tableSetup: setup)Place the localPlayer in a seat at the table using claimSeat(_:) or a similar method.
game.claimAnySeat()Next, implement an object that renders your game layout and equipment. Set the game’s renderer, conforming to the TabletopGame.RenderDelegate protocol, using the addRenderDelegate(_:) method. Implement the onUpdate(timeInterval:snapshot:visualState:) method to render the current state of the game. Alternatively, conform to the EntityRenderDelegate protocol.
game.addRenderDelegate(self)If needed, you can draw a debug representation of selected items in the game using the debugDraw(options:) method.
game.debugDraw(options: [.drawTable, .drawSeats, .drawEquipment])Then, add actions to the equipment that controls gameplay using the addAction(_:) and addActions(_:) methods.
Finally, pass an object to the addObserver(_:) method that conforms to the TabletopGame.Observer protocol. Implement the Observer protocol methods to progress gameplay when players interact with the equipment.
Topics
Creating a tabletop game
Adding equipment to the game
equipmentequipmentIDsequipment(matching:)equipment(of:)equipment(of:forEntity:)equipment(of:matching:)
Managing seats
Getting the player
Adding actions
Observing actions
Jumping to bookmarks
Starting interactions
Canceling interactions
Rendering the table
Supporting multiple players
attachNetworkCoordinator(_:)detachNetworkCoordinator()multiplayerDelegateTabletopGame.MultiplayerDelegate