Simulating dice rolls as a component for your game
At a glance
| Item | Summary |
|---|---|
| Purpose | Create a physically realistic dice game by adding interactive rolling and scoring. |
| App architecture | A Swift sample with the source-visible chain DiceSampleApp → ContentView → TabletopKit APIs. |
| Main patterns | Delegate or data-source callbacks, Actor-isolated state |
| Project style | 11 scanned source file(s) across Swift, organized around ranked entry, type, and file boundaries. |
Project structure
Source bundle/
├── TabletopKit-Dice/
│ ├── TabletopKitDiceExample/
│ │ ├── DiceSampleApp.swift
│ │ ├── Views/
│ │ │ └── ContentView.swift
│ │ ├── Support/
│ │ │ ├── FaceMappingHelpers.swift
│ │ │ ├── Game.swift
│ │ │ └── Utils.swift
│ │ ├── Equipment/
│ │ │ ├── Die.swift
│ │ │ ├── PlayerSeat.swift
│ │ │ └── RoundTabletop.swift
│ │ └── Interaction/
│ │ └── DiceInteraction.swift
│ └── Packages/
│ └── RealityKitContent/
│ ├── Sources/
│ │ └── RealityKitContent/
│ │ └── RealityKitContent.swift
│ └── Package.swift
└── Configuration/
└── SampleCode.xcconfig
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: Swift.
- The verified tree contains 4 project/configuration file(s) and 9 source declaration(s).
Overall architecture
flowchart LR
N1["DiceSampleApp"]
N2["ContentView"]
N3["TabletopKit APIs"]
N1 --> N2
N2 --> N3
Reference code
TabletopKit-Dice/TabletopKitDiceExample/DiceSampleApp.swift:10 — architecture anchor
@MainActor
@main
struct DiceSampleApp: App {
// ...
}Interpretation
The arrows summarize the source-visible entry, role-named types or folders, and framework direction; when nodes come from structural folders, the sequence is a high-level interpretation rather than proof that every adjacent node calls the next. Ownership is claimed only where the next section cites a stored property or assignment. The diagram is intentionally limited to the dominant path into TabletopKit.
Ownership and state
classDiagram
DiceSampleApp *-- Game : game
ContentView *-- Bool : predeterminedOutcome
ContentView *-- Bool : tossAllDice
FaceMap *-- Dictionary : faceToValue
Ownership evidence
TabletopKit-Dice/TabletopKitDiceExample/DiceSampleApp.swift:12 — stored dependency or nearest verified ownership anchor
@State var game = Game()| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
DiceSampleApp |
Game (game) |
owns wrapper-managed state | App/module collaborators |
ContentView |
Bool (predeterminedOutcome) |
owns wrapper-managed state | App/module collaborators |
ContentView |
Bool (tossAllDice) |
owns wrapper-managed state | App/module collaborators |
FaceMap |
Dictionary (faceToValue) |
owns value state | Initialized by the owner; the binding is immutable |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Class and protocol design
TabletopKit-Dice/TabletopKitDiceExample/Support/FaceMappingHelpers.swift:44 — representative type boundary
protocol TossableFaceMap {
func value(for face: any TossableRepresentation.TossableFace) -> Int?
func face(for value: Int) -> (any TossableRepresentation.TossableFace)?
var values: Set<Int> { get }
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
DiceSampleApp |
Application entry and top-level composition | App |
ContentView |
User-interface presentation and input forwarding | View |
TossableFaceMap |
Defines a capability or collaboration contract | Concrete collaborators/imported frameworks |
FaceMap |
Represents a feature value or composable behavior | Concrete collaborators/imported frameworks |
Die |
Owns feature behavior and collaborator lifecycle | EntityEquipment |
PlayerSeat |
Represents a feature value or composable behavior | TableSeat |
RoundTabletop |
Represents a feature value or composable behavior | EntityTabletop |
DiceInteraction |
Owns feature behavior and collaborator lifecycle | TabletopInteraction.Delegate |
Game |
Owns feature behavior and collaborator lifecycle | Concrete collaborators/imported frameworks |
No local protocol conformance is claimed as protocol-oriented design; external framework conformances are listed only as dependencies.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
realityKitContentBundle (TabletopKit-Dice/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift:11) |
public |
The symbol is visible to importing modules. | Inference: make the declaration available across a module or target boundary. |
hexagonPoses (TabletopKit-Dice/TabletopKitDiceExample/Interaction/DiceInteraction.swift:117) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
faceToValue (TabletopKit-Dice/TabletopKitDiceExample/Support/FaceMappingHelpers.swift:21) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
valueToFace (TabletopKit-Dice/TabletopKitDiceExample/Support/FaceMappingHelpers.swift:22) |
private |
Use is restricted to the lexical declaration and same-file extensions allowed by Swift. | Inference: keep state mutation or dependency lifetime inside the owning implementation. |
Reference code
TabletopKit-Dice/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift:11 — representative boundary
public let realityKitContentBundle = Bundle.moduleSwift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| Application entry and top-level composition | DiceSampleApp |
The source’s App suffix makes this role explicit. |
| User-interface presentation and input forwarding | ContentView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| Delegate or data-source callbacks | TabletopKit-Dice/TabletopKitDiceExample/Interaction/DiceInteraction.swift:11 |
Callback protocols invert event delivery back into the sample’s owner. |
| Actor-isolated state | TabletopKit-Dice/TabletopKitDiceExample/DiceSampleApp.swift:9 |
Actor annotations make the concurrency ownership boundary explicit. |
Naming conventions
- Types: App: DiceSampleApp; View: ContentView.
- Protocols:
TossableFaceMap. - Methods:
value,face,handID,diceID,restingOrientation,calculateScore,faceWithHighestScore,tetrahedronDie. - Files:
TabletopKit-Dice/TabletopKitDiceExample/DiceSampleApp.swift,TabletopKit-Dice/TabletopKitDiceExample/Views/ContentView.swift,TabletopKit-Dice/TabletopKitDiceExample/Equipment/Die.swift,TabletopKit-Dice/TabletopKitDiceExample/Equipment/PlayerSeat.swift,TabletopKit-Dice/TabletopKitDiceExample/Equipment/RoundTabletop.swift,TabletopKit-Dice/TabletopKitDiceExample/Interaction/DiceInteraction.swift.
Architecture takeaways
DiceSampleAppis the main source-visible entry or composition anchor for this sample.- Framework work reaches RealityKit, TabletopKit, SwiftUI, RealityKitContent through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- The source does not justify labeling the design protocol-oriented.
Source map
| Source file | Relevant symbols |
|---|---|
TabletopKit-Dice/TabletopKitDiceExample/DiceSampleApp.swift |
DiceSampleApp |
TabletopKit-Dice/TabletopKitDiceExample/Views/ContentView.swift |
ContentView |
TabletopKit-Dice/TabletopKitDiceExample/Support/FaceMappingHelpers.swift |
FaceMap, TossableFaceMap |
TabletopKit-Dice/Packages/RealityKitContent/Sources/RealityKitContent/RealityKitContent.swift |
Feature implementation |
TabletopKit-Dice/TabletopKitDiceExample/Equipment/Die.swift |
Die |
TabletopKit-Dice/TabletopKitDiceExample/Equipment/PlayerSeat.swift |
PlayerSeat |
TabletopKit-Dice/TabletopKitDiceExample/Equipment/RoundTabletop.swift |
RoundTabletop |
TabletopKit-Dice/TabletopKitDiceExample/Interaction/DiceInteraction.swift |
DiceInteraction |
TabletopKit-Dice/TabletopKitDiceExample/Support/Game.swift |
Game |
TabletopKit-Dice/Packages/RealityKitContent/Package.swift |
Feature implementation |