release: Storybook v0.2.0 - Major syntax and features update
BREAKING CHANGES: - Relationship syntax now requires blocks for all participants - Removed self/other perspective blocks from relationships - Replaced 'guard' keyword with 'if' for behavior tree decorators Language Features: - Add tree-sitter grammar with improved if/condition disambiguation - Add comprehensive tutorial and reference documentation - Add SBIR v0.2.0 binary format specification - Add resource linking system for behaviors and schedules - Add year-long schedule patterns (day, season, recurrence) - Add behavior tree enhancements (named nodes, decorators) Documentation: - Complete tutorial series (9 chapters) with baker family examples - Complete reference documentation for all language features - SBIR v0.2.0 specification with binary format details - Added locations and institutions documentation Examples: - Convert all examples to baker family scenario - Add comprehensive working examples Tooling: - Zed extension with LSP integration - Tree-sitter grammar for syntax highlighting - Build scripts and development tools Version Updates: - Main package: 0.1.0 → 0.2.0 - Tree-sitter grammar: 0.1.0 → 0.2.0 - Zed extension: 0.1.0 → 0.2.0 - Storybook editor: 0.1.0 → 0.2.0
This commit is contained in:
249
docs/tutorial/07-schedules.md
Normal file
249
docs/tutorial/07-schedules.md
Normal file
@@ -0,0 +1,249 @@
|
||||
# Schedules and Time
|
||||
|
||||
Characters live in time. A baker wakes before dawn to prepare dough; a guard patrols during the day shift; an innkeeper serves customers until late. Schedules define these time-based routines.
|
||||
|
||||
## Basic Schedules
|
||||
|
||||
A schedule contains time blocks, each with a time range and an action:
|
||||
|
||||
```storybook
|
||||
schedule SimpleBaker {
|
||||
block morning_prep {
|
||||
05:00 - 08:00
|
||||
action: baking::prepare_dough
|
||||
}
|
||||
|
||||
block sales {
|
||||
08:00 - 14:00
|
||||
action: baking::serve_customers
|
||||
}
|
||||
|
||||
block cleanup {
|
||||
14:00 - 15:00
|
||||
action: baking::close_shop
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Time ranges use 24-hour clock format (`HH:MM`). The `action` field links to a behavior tree that drives the character's activity during that block.
|
||||
|
||||
## Named Blocks
|
||||
|
||||
Blocks can have names (like `morning_prep` above). Named blocks are important for schedule composition -- they allow child schedules to override specific blocks by name.
|
||||
|
||||
## Linking Schedules to Characters
|
||||
|
||||
Characters use the `uses schedule` clause:
|
||||
|
||||
```storybook
|
||||
character Baker: Human {
|
||||
uses schedule: SimpleBaker
|
||||
}
|
||||
```
|
||||
|
||||
For multiple schedules:
|
||||
|
||||
```storybook
|
||||
character Innkeeper: Human {
|
||||
uses schedules: [WeekdaySchedule, WeekendSchedule]
|
||||
}
|
||||
```
|
||||
|
||||
## Temporal Constraints
|
||||
|
||||
Blocks can be restricted to specific times using temporal constraints:
|
||||
|
||||
### Season Constraints
|
||||
|
||||
```storybook
|
||||
schedule SeasonalBaker {
|
||||
block summer_hours {
|
||||
06:00 - 20:00
|
||||
action: baking::long_shift
|
||||
on season summer
|
||||
}
|
||||
|
||||
block winter_hours {
|
||||
07:00 - 18:00
|
||||
action: baking::short_shift
|
||||
on season winter
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Day of Week Constraints
|
||||
|
||||
```storybook
|
||||
schedule WeeklyPattern {
|
||||
block weekday_work {
|
||||
09:00 - 17:00
|
||||
action: work::standard
|
||||
on day monday
|
||||
}
|
||||
|
||||
block weekend_rest {
|
||||
10:00 - 16:00
|
||||
action: leisure::relax
|
||||
on day saturday
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Temporal constraint values (like `summer` or `monday`) reference enums defined in your storybook:
|
||||
|
||||
```storybook
|
||||
enum Season { spring, summer, fall, winter }
|
||||
enum DayOfWeek { monday, tuesday, wednesday, thursday, friday, saturday, sunday }
|
||||
```
|
||||
|
||||
## Recurring Events
|
||||
|
||||
Use `recurs` to define events that repeat on a schedule:
|
||||
|
||||
```storybook
|
||||
schedule MarketSchedule {
|
||||
// Regular daily hours
|
||||
block work {
|
||||
08:00 - 17:00
|
||||
action: shop::regular_sales
|
||||
}
|
||||
|
||||
// Market day every Saturday
|
||||
recurs MarketDay on day saturday {
|
||||
block setup {
|
||||
06:00 - 08:00
|
||||
action: market::setup_stall
|
||||
}
|
||||
|
||||
block busy_market {
|
||||
08:00 - 18:00
|
||||
action: market::busy_sales
|
||||
}
|
||||
|
||||
block teardown {
|
||||
18:00 - 20:00
|
||||
action: market::pack_up
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Recurrences take priority over regular blocks. On Saturdays, the `MarketDay` blocks replace the regular `work` block.
|
||||
|
||||
## Schedule Composition with extends
|
||||
|
||||
Schedules can extend other schedules, inheriting and overriding blocks:
|
||||
|
||||
```storybook
|
||||
schedule BaseShopkeeper {
|
||||
block open {
|
||||
09:00 - 17:00
|
||||
action: shop::standard_hours
|
||||
}
|
||||
}
|
||||
|
||||
schedule EarlyBaker extends BaseShopkeeper {
|
||||
block open {
|
||||
05:00 - 13:00
|
||||
action: baking::early_shift
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `EarlyBaker` schedule overrides the `open` block by name -- same block name, different hours. Any blocks not overridden are inherited unchanged.
|
||||
|
||||
You can chain extensions:
|
||||
|
||||
```storybook
|
||||
schedule MasterBaker extends EarlyBaker {
|
||||
block open {
|
||||
03:00 - 11:00
|
||||
action: baking::master_work
|
||||
}
|
||||
|
||||
block teaching {
|
||||
14:00 - 16:00
|
||||
action: baking::teach_apprentice
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`MasterBaker` overrides `open` again and adds a new `teaching` block.
|
||||
|
||||
## Overnight Blocks
|
||||
|
||||
Time ranges can span midnight:
|
||||
|
||||
```storybook
|
||||
schedule NightGuard {
|
||||
block night_patrol {
|
||||
22:00 - 06:00
|
||||
action: security::patrol
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The system interprets this as 22:00 to midnight on day one, then midnight to 06:00 on day two.
|
||||
|
||||
## A Complete Schedule Example
|
||||
|
||||
```storybook
|
||||
schedule MasterBaker_FullYear {
|
||||
// Daily base
|
||||
block prep {
|
||||
04:00 - 06:00
|
||||
action: baking::prepare
|
||||
}
|
||||
|
||||
block baking {
|
||||
06:00 - 10:00
|
||||
action: baking::bake
|
||||
}
|
||||
|
||||
block sales {
|
||||
10:00 - 16:00
|
||||
action: baking::serve
|
||||
}
|
||||
|
||||
block cleanup {
|
||||
16:00 - 17:00
|
||||
action: baking::clean
|
||||
}
|
||||
|
||||
// Summer extended hours
|
||||
block summer_sales {
|
||||
10:00 - 20:00
|
||||
action: baking::busy_summer
|
||||
on season summer
|
||||
}
|
||||
|
||||
// Weekly market
|
||||
recurs MarketDay on day saturday {
|
||||
block market_prep {
|
||||
02:00 - 04:00
|
||||
action: baking::market_prep
|
||||
}
|
||||
|
||||
block market_sales {
|
||||
08:00 - 18:00
|
||||
action: baking::market_rush
|
||||
}
|
||||
}
|
||||
|
||||
// Annual harvest festival
|
||||
recurs HarvestFestival on dates "Sep 20" .. "Sep 25" {
|
||||
block festival {
|
||||
06:00 - 23:00
|
||||
action: baking::festival_mode
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Next Steps
|
||||
|
||||
Characters now have traits, behaviors, relationships, and schedules. In [Life Arcs](./08-life-arcs.md), you will learn how to model character development over time -- how they grow, change, and evolve through different phases of life.
|
||||
|
||||
---
|
||||
|
||||
**Reference**: For complete schedule syntax, see the [Schedules Reference](../reference/14-schedules.md).
|
||||
Reference in New Issue
Block a user