Last active 1 day ago

A small menu system with configurable actions.

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 :: the test passed! yay!
34
35
36
37
38|# A testing framework, whatever that is. #|
39|:: I should be on menu $menu :menu: $menu?|
40|:: I should be on menu $menu :menu: $other?|
41 :: error :message: we wanted to be in $menu but we're in $other
42|:: I should be on menu $menu|
43 :: error :message: we wanted to be in $menu but we're not in any menu
44
45
46|# Some default actions that switch the menu and navigate to a parent menu. #|
47|:: fire switch-menu for $menu|
48 :: enter menu $menu
49|:: fire exit-menu for $option|
50 :: exit menu
51
52|# The menu definition language. #|
53|:: define menu $menu| :menu: $menu
54|:: $option -> $action :menu: $menu?|
55 :menus: $menu $option $action
56|:: end menu :menu: $menu|
57|:: end menu|
58 :: error :message: you need to start a menu to end one
59
60
61
62
63|# The rest of this is menu mechanics. #|
64
65
66
67
68|:: enter menu $menu|
69 :: load menu options for $menu
70 :menu: $menu
71 :options:
72
73|:: exit menu|
74 :: unload menu options
75
76|:: select $option :options: $option $action?|
77 :: reset options
78 :: fire $action for $option
79|:: select $option? :options: $other $action|
80 :seen options: $other $action
81|:: select $option|
82 :: error :message: $option is not available
83
84|:: load menu options for $menu? :menus: $menu $option $action|
85 :options: $option $action
86|:: load menu options for $menu? :menus: $other $option $action|
87 :seen menus: $other $option $action
88|:: load menu options for $menu|
89 :: reset menus
90
91|:: unload menu options? :menu: $menu? :options: $option $action|
92 :menus: $menu $option $action
93|:: unload menu options :menu: $menu :options:|
94|:: unload menu options|
95 :: error :message: we're not in a menu
96
97|:: reset menus? :seen menus: $menu $option $action|
98 :menus: $menu $option $action
99|:: reset menus|
100
101|:: reset options? :seen options: $option $action|
102 :options: $option $action
103|:: reset options|