TableSetup
An object that represents the arrangement of seats, equipment, and counters around the game table.
Declaration
struct TableSetupOverview
To create a TableSetup object, pass an object that conforms to the Tabletop or EntityTabletop protocol to the init(tabletop:) initializer. For example, implement a Table structure that conforms to the EntityTabletop protocol and pass an instance of it to the initializer.
let table = Table()
root = createRootEntity(table: table.entity)
var setup = TableSetup(tabletop: table)Set the protocol properties, such as shape, entity, and id properties for the EntityTabletop protocol, in the initializer.
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 add seats, equipment, and counters to the TableSetup object.
To represent seats, create structures that conform to a seat protocol. To render seats using RealityKit, conform to the EntityTableSeat protocol and use the add(seat:) or a similar method to add seats. Otherwise, conform to the TableSeat protocol and use the add(seat:) or a similar method to add seats.
setup.add(seat: Seat(index: 0, position: .init(x: 0, z: -0.5)))
setup.add(seat: Seat(index: 1, position: .init(x: 0, z: +0.5)))To represent equipment, create structures that conform to an equipment protocol. To render equipment using RealityKit, conform to the EntityEquipment protocol and use the add(equipment:) or a similar method to add equipment. Otherwise, conform to the Equipment protocol and use the add(equipment:) or a similar method to add equipment.
setup.add(equipment: Piece(position: .init(x: 0, z: 0.1)))
setup.add(equipment: Card(index: 0, faceUp: true, position: .init(x: -0.1, z: 0)))
setup.add(equipment: Card(index: 1, faceUp: true, position: .init(x: +0.1, z: 0)))
setup.add(equipment: Die(index: 0, position: .init(x: 0, z: 0.2)))Some equipment can represent a group, such as a player’s hand in a card game. To organize equipment hierarchically, set the parentID property of the State property during gameplay. In your equipment structure implementation, you can override the layoutChildren(for:visualState:) method to lay out the containing equipment.
Optionally, add one or more ScoreCounter objects to the TableSetup object to keep score of the game. Use either the add(counter:) or add(counters:) method to add score counters.
Finally, create the TabletopGame instance from the TableSetup object by passing it to the init(tableSetup:version:) initializer.
game = TabletopGame(tableSetup: setup)Topics
Creating a setup object from a table
Adding seats to place players
Adding equipment for gameplay
add(equipment:)add(equipment:)add(equipment:)add(equipment:)add(equipment:)add(equipment:)add(equipment:)add(equipment:)