@@ -14,6 +14,8 @@ use bones_framework::prelude::*;
14
14
// Allow asset to be loaded from "game.yaml" assets.
15
15
#[ type_data( metadata_asset( "game" ) ) ]
16
16
struct GameMeta {
17
+ /// A lua script that will be run every frame on the menu.
18
+ menu_script : Handle < LuaScript > ,
17
19
/// The image displayed on the menu.
18
20
menu_image : Handle < Image > ,
19
21
/// The image for the sprite demo
@@ -79,6 +81,7 @@ struct TileMeta {
79
81
idx : u32 ,
80
82
}
81
83
84
+ /// Struct containing data that will be persisted with the storage API.
82
85
#[ derive( HasSchema , Default , Clone ) ]
83
86
#[ repr( C ) ]
84
87
struct PersistedTextData ( String ) ;
@@ -88,8 +91,16 @@ fn main() {
88
91
PersistedTextData :: register_schema ( ) ;
89
92
90
93
// Create a bones bevy renderer from our bones game
91
- BonesBevyRenderer :: new ( create_game ( ) )
92
- // Get a bevy app for running our game
94
+ let mut renderer = BonesBevyRenderer :: new ( create_game ( ) ) ;
95
+ // Set the app namespace which will be used by the renderer to decide where to put
96
+ // persistent storage files.
97
+ renderer. app_namespace = (
98
+ "org" . into ( ) ,
99
+ "fishfolk" . into ( ) ,
100
+ "bones.demo_features" . into ( ) ,
101
+ ) ;
102
+ // Get a bevy app for running our game
103
+ renderer
93
104
. app ( )
94
105
// We can add our own bevy plugins now
95
106
. add_plugins ( ( FrameTimeDiagnosticsPlugin , LogDiagnosticsPlugin :: default ( ) ) )
@@ -119,13 +130,26 @@ pub fn create_game() -> Game {
119
130
game
120
131
}
121
132
133
+ /// Resource containing data that we will access from our menu lua script.
134
+ #[ derive( HasSchema , Default , Clone ) ]
135
+ #[ repr( C ) ]
136
+ struct MenuData {
137
+ /// The index of the frame that we are on.
138
+ pub frame : u32 ,
139
+ }
140
+
122
141
/// Menu plugin
123
142
pub fn menu_plugin ( session : & mut Session ) {
124
143
// Register our menu system
125
144
session
126
145
// Install the bones_framework default plugins for this session
127
146
. install_plugin ( DefaultSessionPlugin )
128
- // And add our systems.
147
+ . world
148
+ // Initialize our menu data resource
149
+ . init_resource :: < MenuData > ( ) ;
150
+
151
+ // And add our systems.
152
+ session
129
153
. add_system_to_stage ( Update , menu_system)
130
154
. add_startup_system ( menu_startup) ;
131
155
}
@@ -150,7 +174,11 @@ fn menu_system(
150
174
// Get the localization field from our `GameMeta`
151
175
localization : Localization < GameMeta > ,
152
176
world : & World ,
177
+ lua_engine : Res < LuaEngine > ,
153
178
) {
179
+ // Run our menu script.
180
+ lua_engine. run_script_system ( world, meta. menu_script ) ;
181
+
154
182
// Render the menu.
155
183
egui:: CentralPanel :: default ( )
156
184
. frame ( egui:: Frame :: none ( ) )
0 commit comments