# Baker Family Example A comprehensive example demonstrating Storybook v0.3.0 features through a realistic multi-character scenario. ## Features Demonstrated ### Type System (NEW in v0.3.0) - **Species definitions**: `species Human { ... }` provides default fields for all human characters - **Species-based templates**: `template Person: Human { ... }` inherits species fields as base layer - **Concepts and sub-concepts**: `concept BakedGood` with `sub_concept BakedGood.Category { Bread, Pastry, Cake }` - **Sub-concept dot notation**: Parent.Name format for clear ownership - **Concept comparisons**: Compile-time pattern matching for concept variants - **Life arc requirements**: `life_arc BakerCareer requires { baking_skill: Number }` for compile-time validation ### Resource Linking - **Templates with behaviors**: `Baker` template specifies `BakingSkills` and `CustomerService` - **Templates with schedules**: `Baker` template uses `BakerSchedule` - **Multi-level inheritance**: `Baker` -> `Worker` -> `Person` template chain - **Character inheritance**: Characters automatically inherit behaviors and schedules from templates ### Schedule Composition - **Schedule inheritance**: `BakerSchedule extends WorkWeek` - **Override blocks**: Modify inherited time blocks with `override work { ... }` - **Named blocks**: All blocks have names for the override system - **Action references**: Schedule blocks reference behavior trees via `action: BehaviorName` - **Recurrence patterns**: Market day repeats `on Saturday` ### Behavior Trees - Comprehensive behavior definitions for all activities - Referenced from schedule blocks showing integration - Hierarchical behaviors (sequences, selectors, repeaters) ## File Structure ``` baker-family/ ├── README.md ├── schema/ │ ├── templates.sb # Template definitions with species base │ ├── types.sb # Concepts, sub-concepts, species (NEW) │ └── life_arcs.sb # Life arc definitions with requires (NEW) ├── schedules/ │ └── work_schedules.sb # Composable schedules ├── behaviors/ │ └── baker_behaviors.sb # Behavior tree definitions └── characters/ ├── martha.sb # Master baker (uses Baker template) ├── jane.sb # Pastry chef (uses Baker template) └── emma.sb # Daughter (uses Child template) ``` ## Template Hierarchy ``` Human (species - default fields: age, energy, mood, occupation) └─> Person: Human (behaviors: BasicNeeds, SocialInteraction) └─> Worker (schedule: WorkWeek) └─> Baker (behaviors: +BakingSkills, +CustomerService, schedule: BakerSchedule) └─> Child: Human (behaviors: PlayBehavior, LearnBehavior, no schedule) ``` Override chain: Species -> Includes -> Template -> Character (last-one-wins) ## Schedule Inheritance ``` WorkWeek ├─ morning_prep (08:00-09:00) ├─ work (09:00-17:00) └─ evening_rest (18:00-22:00) BakerSchedule extends WorkWeek ├─ pre_dawn_prep (04:00-05:00) [NEW] ├─ work (05:00-13:00) [OVERRIDE] -> action: BakingWork ├─ evening_rest (18:00-22:00) [INHERITED] └─ recurrence MarketDay on Saturday └─ market (06:00-14:00) -> action: SellAtMarket ``` ## Life Arcs (NEW in v0.3.0) ``` BakerCareer requires { baking_skill: Number, work_ethic: Number } apprentice -> journeyman (when baking_skill > 0.5 and work_ethic > 0.7) journeyman -> master (when baking_skill > 0.8 and work_ethic > 0.9) Childhood requires { age: Number, curiosity: Number } young_child -> school_age -> teenager -> adult ``` ## Key Integration Points 1. **Martha (character)** -> inherits from **Baker (template)** -> inherits from **Human (species)** - Gets default fields from Human species (age, energy, mood, occupation) - Gets behaviors: `BakingSkills`, `CustomerService`, `BasicNeeds`, `SocialInteraction` - Gets schedule: `BakerSchedule` (which extends `WorkWeek`) 2. **BakerSchedule (schedule)** -> references **BakingWork (behavior)** - `action: BakingWork` in the work block - Creates link between scheduling and behavior systems 3. **Template chain** -> cascading resource inheritance with species base - `Human` species provides defaults - `Baker` includes `Worker` includes `Person: Human` - All behaviors, schedules, and fields flow down the hierarchy 4. **Life arcs** -> compile-time field requirement validation - `BakerCareer` requires `baking_skill` and `work_ethic` fields - Any character using this life arc must have these fields ## Usage This example shows how to: - Define species with default fields for character archetypes - Build reusable templates with species inheritance - Use concepts and sub-concepts for type-safe enumerations - Create concept comparisons for compile-time pattern matching - Define life arcs with field requirements for validation - Compose schedules through inheritance and overrides - Link schedules to behaviors through action references - Model realistic daily routines with time-of-day variations