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:
258
examples/new-syntax-demo.sb
Normal file
258
examples/new-syntax-demo.sb
Normal file
@@ -0,0 +1,258 @@
|
||||
//! Demonstration of new behavior tree keyword syntax
|
||||
//! This file showcases all the new features approved for implementation
|
||||
|
||||
// Simple behavior with choose and then
|
||||
behavior SimpleGuardPatrol {
|
||||
---description
|
||||
A village guard who responds to threats or patrols.
|
||||
Demonstrates basic choose/then keywords.
|
||||
---
|
||||
|
||||
choose patrol_action {
|
||||
then respond_to_threat {
|
||||
if(threat_detected)
|
||||
sound_alarm
|
||||
rush_to_threat
|
||||
}
|
||||
|
||||
repeat {
|
||||
then {
|
||||
patrol_north
|
||||
patrol_east
|
||||
patrol_south
|
||||
patrol_west
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Named nodes
|
||||
behavior ComplexBehavior {
|
||||
---description
|
||||
Demonstrates named nodes for better organization and debugging.
|
||||
Labels help identify which part of the tree is executing.
|
||||
---
|
||||
|
||||
choose root {
|
||||
then handle_urgent {
|
||||
when(need.any is urgent)
|
||||
identify_need
|
||||
satisfy_need
|
||||
}
|
||||
|
||||
then social_interaction {
|
||||
when(friend_nearby)
|
||||
greet_friend
|
||||
chat
|
||||
}
|
||||
|
||||
then default_activity {
|
||||
idle_wait
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Advanced decorators
|
||||
behavior WhiteRabbitAnxiety {
|
||||
---description
|
||||
The White Rabbit from Alice in Wonderland, demonstrating
|
||||
all decorator types: repeat, retry, timeout, cooldown, if.
|
||||
---
|
||||
|
||||
choose {
|
||||
// Extreme panic when very late
|
||||
then panic_mode {
|
||||
if(minutes_late > 100)
|
||||
timeout(3s) {
|
||||
repeat(5) {
|
||||
then {
|
||||
check_pocket_watch
|
||||
mutter_desperately
|
||||
}
|
||||
}
|
||||
}
|
||||
sprint_to_destination
|
||||
}
|
||||
|
||||
// Try to find alternate route when blocked
|
||||
then find_route {
|
||||
if(obstacle_encountered)
|
||||
drop_gloves
|
||||
drop_fan
|
||||
retry(2) {
|
||||
find_alternate_route
|
||||
}
|
||||
}
|
||||
|
||||
// Queen response with cooldown
|
||||
then queen_response {
|
||||
if(queen_nearby)
|
||||
flatten_ears_in_fear
|
||||
trembling_bow
|
||||
cooldown(60s) {
|
||||
await_commands
|
||||
}
|
||||
}
|
||||
|
||||
// Only run if energy is sufficient
|
||||
if(energy > 30) {
|
||||
scurry_around_frantically
|
||||
}
|
||||
|
||||
// Default: perpetual anxiety
|
||||
repeat {
|
||||
then {
|
||||
check_watch
|
||||
mutter_anxiously
|
||||
scurry_forward
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mad Tea Party with infinite repeat
|
||||
behavior MadTeaParty {
|
||||
---description
|
||||
The Mad Hatter's tea party that loops forever.
|
||||
Demonstrates infinite repeat decorator.
|
||||
---
|
||||
|
||||
repeat {
|
||||
choose tea_party_activities {
|
||||
then riddles {
|
||||
pose_riddle
|
||||
wait_for_answer
|
||||
declare_answer_wrong
|
||||
}
|
||||
|
||||
then seat_rotation {
|
||||
switch_seats
|
||||
clean_dirty_teacup
|
||||
pour_fresh_tea
|
||||
}
|
||||
|
||||
then dormouse_interaction {
|
||||
wake_dormouse
|
||||
listen_to_brief_story
|
||||
stuff_dormouse_in_teapot
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cheshire Cat with timing decorators
|
||||
behavior CheshireCatMaterialization {
|
||||
---description
|
||||
Complex behavior with nested decorators showing gradual
|
||||
materialization and dematerialization with timing controls.
|
||||
---
|
||||
|
||||
choose {
|
||||
// Materialize when Alice is near
|
||||
then materialize {
|
||||
if(alice_nearby and visibility < 0.1)
|
||||
timeout(10s) {
|
||||
repeat(5) {
|
||||
then {
|
||||
increase_visibility(0.2)
|
||||
pause_for_effect(1s)
|
||||
}
|
||||
}
|
||||
}
|
||||
materialize_grin
|
||||
speak_in_riddles
|
||||
}
|
||||
|
||||
// Dematerialize when fully visible
|
||||
then dematerialize {
|
||||
if(visibility > 0.9)
|
||||
cooldown(30s) {
|
||||
timeout(8s) {
|
||||
repeat(5) {
|
||||
then {
|
||||
decrease_visibility(0.2)
|
||||
pause_for_effect(1s)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
vanish_except_grin
|
||||
}
|
||||
|
||||
// Only float when partially visible
|
||||
if(visibility >= 0.5) {
|
||||
idle_float
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Subtree inclusion
|
||||
behavior WorkBehaviorWithSubtree {
|
||||
---description
|
||||
Demonstrates subtree inclusion with the new 'include' keyword.
|
||||
---
|
||||
|
||||
choose {
|
||||
include common::handle_urgent_needs
|
||||
|
||||
then work {
|
||||
when(at_workplace)
|
||||
perform_work_tasks
|
||||
}
|
||||
|
||||
idle_wait
|
||||
}
|
||||
}
|
||||
|
||||
// Invert decorator
|
||||
behavior AvoidEnemies {
|
||||
---description
|
||||
Uses invert decorator to reverse condition logic.
|
||||
---
|
||||
|
||||
choose {
|
||||
then safe_path {
|
||||
invert {
|
||||
if(enemy_nearby)
|
||||
}
|
||||
take_direct_route
|
||||
}
|
||||
|
||||
then danger_path {
|
||||
take_long_safe_route
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Repeat with range
|
||||
behavior SearchBehavior {
|
||||
---description
|
||||
Demonstrates repeat with min..max range.
|
||||
---
|
||||
|
||||
repeat(3..7) {
|
||||
then {
|
||||
search_area
|
||||
rest_briefly
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Always succeed/fail decorators (for debugging)
|
||||
behavior DebugBehavior {
|
||||
---description
|
||||
Shows succeed_always and fail_always decorators.
|
||||
---
|
||||
|
||||
choose {
|
||||
succeed_always {
|
||||
experimental_feature
|
||||
}
|
||||
|
||||
fail_always {
|
||||
disabled_legacy_behavior
|
||||
}
|
||||
|
||||
fallback_behavior
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user