Ultima attività 2 days ago

A small menu system with configurable actions.

Revisione 0df1b7d2794c6eb67c0b0a74ac0523663d985dda

menu.nv Raw Playground
1||:: set up the menus
2 :: run the test
3
4|:: set up the menus|
5 :: define menu title-screen
6 :: start -> switch-menu
7 :: options -> switch-menu
8 :: quit -> quit-game
9 :: end menu
10 :: define menu start
11 :: easy -> easy-difficulty
12 :: medium -> medium-difficulty
13 :: hard -> hard-difficulty
14 :: back -> exit-menu
15 :: end menu
16 :: define menu options
17 :: video -> switch-menu
18 :: audio -> switch-menu
19 :: controls -> switch-menu
20 :: back -> exit-menu
21 :: end menu
22
23|:: run the test|
24 :: enter menu title-screen
25 :: select start
26 :: I should be on menu start
27 :: select back
28 :: I should be on menu title-screen
29 :: select options
30 :: I should be on menu options
31 :: select back
32 :: I should be on menu title-screen
33
34
35
36
37|# A "testing framework", whatever that is. #|
38|:: I should be on menu $menu :menu: $menu?|
39|:: I should be on menu $menu :menu: $other?|
40 :: error :message: we wanted to be in $menu but we're in $other
41|:: I should be on menu $menu|
42 :: error :message: we wanted to be in $menu but we're not in any menu
43
44
45|# Some default actions that switch the menu and navigate to a parent menu. #|
46|:: fire switch-menu for $menu|
47 :: enter menu $menu
48|:: fire exit-menu for $option|
49 :: exit menu
50
51|# The menu "definition language". #|
52|:: define menu $menu| :menu: $menu
53|:: $option -> $action :menu: $menu?|
54 :menus: $menu $option $action
55|:: end menu :menu: $menu|
56|:: end menu|
57 :: error :message: you need to start a menu to end one
58
59|# The rest of this is menu mechanics. #|
60
61|:: enter menu $menu|
62 :: load menu options for $menu
63 :menu: $menu
64 :options:
65
66|:: exit menu|
67 :: unload menu options
68
69|:: select $option :options: $option $action?|
70 :: reset options
71 :: fire $action for $option
72|:: select $option? :options: $other $action|
73 :seen options: $other $action
74|:: select $option|
75 :: error :message: $option is not available
76
77|:: load menu options for $menu? :menus: $menu $option $action|
78 :options: $option $action
79|:: load menu options for $menu? :menus: $other $option $action|
80 :seen menus: $other $option $action
81|:: load menu options for $menu|
82 :: reset menus
83
84|:: unload menu options? :menu: $menu? :options: $option $action|
85 :menus: $menu $option $action
86|:: unload menu options :menu: $menu :options:|
87|:: unload menu options|
88 :: error :message: we're not in a menu
89
90|:: reset menus? :seen menus: $menu $option $action|
91 :menus: $menu $option $action
92|:: reset menus|
93
94|:: reset options? :seen options: $option $action|
95 :options: $option $action
96|:: reset options|