@@ -53,8 +53,8 @@ impl std::fmt::Display for Language {
53
53
pub struct ScriptAsset {
54
54
/// The body of the script
55
55
pub content : Box < [ u8 ] > ,
56
- /// The virtual filesystem path of the asset, used to map to the script Id for asset backed scripts
57
- pub asset_path : AssetPath < ' static > ,
56
+ /// The language of the script
57
+ pub language : Language ,
58
58
}
59
59
60
60
#[ derive( Event , Debug , Clone ) ]
@@ -97,7 +97,7 @@ impl AssetLoader for ScriptAssetLoader {
97
97
}
98
98
let asset = ScriptAsset {
99
99
content : content. into_boxed_slice ( ) ,
100
- asset_path : load_context . asset_path ( ) . to_owned ( ) ,
100
+ language : Language :: Lua ,
101
101
} ;
102
102
Ok ( asset)
103
103
}
@@ -107,60 +107,61 @@ impl AssetLoader for ScriptAssetLoader {
107
107
}
108
108
}
109
109
110
- #[ derive( Clone , Resource ) ]
111
- /// Settings to do with script assets and how they are handled
112
- pub struct ScriptAssetSettings {
113
- /// Strategy for mapping asset paths to script ids, by default this is the identity function
114
- pub script_id_mapper : AssetPathToScriptIdMapper ,
115
- /// Mapping from extension to script language
116
- pub extension_to_language_map : HashMap < & ' static str , Language > ,
117
-
118
- /// The currently supported asset extensions
119
- /// Should be updated by each scripting plugin to include the extensions it supports.
120
- ///
121
- /// Will be used to populate the script asset loader with the supported extensions
122
- pub supported_extensions : & ' static [ & ' static str ] ,
123
- }
124
-
125
- #[ profiling:: all_functions]
126
- impl ScriptAssetSettings {
127
- /// Selects the language for a given asset path
128
- pub fn select_script_language ( & self , path : & AssetPath ) -> Language {
129
- let extension = path
130
- . path ( )
131
- . extension ( )
132
- . and_then ( |ext| ext. to_str ( ) )
133
- . unwrap_or_default ( ) ;
134
- self . extension_to_language_map
135
- . get ( extension)
136
- . cloned ( )
137
- . unwrap_or_default ( )
138
- }
139
- }
140
-
141
- impl Default for ScriptAssetSettings {
142
- fn default ( ) -> Self {
143
- Self {
144
- script_id_mapper : AssetPathToScriptIdMapper {
145
- map : ( |path : & AssetPath | path. path ( ) . to_string_lossy ( ) . into_owned ( ) . into ( ) ) ,
146
- } ,
147
- extension_to_language_map : HashMap :: from_iter ( vec ! [
148
- ( "lua" , Language :: Lua ) ,
149
- ( "luau" , Language :: Lua ) ,
150
- ( "rhai" , Language :: Rhai ) ,
151
- ( "rn" , Language :: Rune ) ,
152
- ] ) ,
153
- supported_extensions : & [ "lua" , "luau" , "rhai" , "rn" ] ,
154
- }
155
- }
156
- }
157
-
158
- /// Strategy for mapping asset paths to script ids, by default this is the identity function
159
- #[ derive( Clone , Copy ) ]
160
- pub struct AssetPathToScriptIdMapper {
161
- /// The mapping function
162
- pub map : fn ( & AssetPath ) -> ScriptId ,
163
- }
110
+ // #[derive(Clone, Resource)]
111
+ // /// Settings to do with script assets and how they are handled
112
+ // pub struct ScriptAssetSettings {
113
+ // /// Strategy for mapping asset paths to script ids, by default this is the identity function
114
+ // pub script_id_mapper: AssetPathToScriptIdMapper,
115
+ // /// Mapping from extension to script language
116
+ // pub extension_to_language_map: HashMap<&'static str, Language>,
117
+
118
+ // /// The currently supported asset extensions
119
+ // /// Should be updated by each scripting plugin to include the extensions it supports.
120
+ // ///
121
+ // /// Will be used to populate the script asset loader with the supported extensions
122
+ // pub supported_extensions: &'static [&'static str],
123
+ // }
124
+
125
+ // #[profiling::all_functions]
126
+ // impl ScriptAssetSettings {
127
+ // /// Selects the language for a given asset path
128
+ // pub fn select_script_language(&self, path: &AssetPath) -> Language {
129
+ // let extension = path
130
+ // .path()
131
+ // .extension()
132
+ // .and_then(|ext| ext.to_str())
133
+ // .unwrap_or_default();
134
+ // self.extension_to_language_map
135
+ // .get(extension)
136
+ // .cloned()
137
+ // .unwrap_or_default()
138
+ // }
139
+ // }
140
+
141
+ // impl Default for ScriptAssetSettings {
142
+ // fn default() -> Self {
143
+ // Self {
144
+ // script_id_mapper: AssetPathToScriptIdMapper {
145
+ // // map: (|path: &AssetPath| path.path().to_string_lossy().into_owned().into()),
146
+ // map: (|path: &AssetPath| path.id()),
147
+ // },
148
+ // extension_to_language_map: HashMap::from_iter(vec![
149
+ // ("lua", Language::Lua),
150
+ // ("luau", Language::Lua),
151
+ // ("rhai", Language::Rhai),
152
+ // ("rn", Language::Rune),
153
+ // ]),
154
+ // supported_extensions: &["lua", "luau", "rhai", "rn"],
155
+ // }
156
+ // }
157
+ // }
158
+
159
+ // /// Strategy for mapping asset paths to script ids, by default this is the identity function
160
+ // #[derive(Clone, Copy)]
161
+ // pub struct AssetPathToScriptIdMapper {
162
+ // /// The mapping function
163
+ // pub map: fn(&AssetPath) -> ScriptId,
164
+ // }
164
165
165
166
/// A cache of asset id's to their script id's. Necessary since when we drop an asset we won't have the ability to get the path from the asset.
166
167
#[ derive( Default , Debug , Resource ) ]
@@ -174,8 +175,8 @@ pub struct ScriptMetadataStore {
174
175
pub struct ScriptMetadata {
175
176
/// The asset id of the script
176
177
pub asset_id : AssetId < ScriptAsset > ,
177
- /// The script id of the script
178
- pub script_id : ScriptId ,
178
+ // The script id of the script
179
+ // pub script_id: ScriptId,
179
180
/// The language of the script
180
181
pub language : Language ,
181
182
}
@@ -211,7 +212,7 @@ pub(crate) fn dispatch_script_asset_events(
211
212
mut script_asset_events : EventWriter < ScriptAssetEvent > ,
212
213
assets : Res < Assets < ScriptAsset > > ,
213
214
mut metadata_store : ResMut < ScriptMetadataStore > ,
214
- settings : Res < ScriptAssetSettings > ,
215
+ // settings: Res<ScriptAssetSettings>,
215
216
) {
216
217
for event in events. read ( ) {
217
218
match event {
@@ -220,23 +221,24 @@ pub(crate) fn dispatch_script_asset_events(
220
221
if !metadata_store. contains ( * id) {
221
222
let asset = assets. get ( * id) ;
222
223
if let Some ( asset) = asset {
223
- let path = & asset. asset_path ;
224
- let converter = settings. script_id_mapper . map ;
225
- let script_id = converter ( path) ;
226
-
227
- let language = settings. select_script_language ( path) ;
228
- if language == Language :: Unknown {
229
- let extension = path
230
- . path ( )
231
- . extension ( )
232
- . and_then ( |ext| ext. to_str ( ) )
233
- . unwrap_or_default ( ) ;
234
- warn ! ( "A script {:?} was added but its language is unknown. Consider adding the {:?} extension to the `ScriptAssetSettings`." , & script_id, extension) ;
224
+ // let path = &asset.asset_path;
225
+ // let converter = settings.script_id_mapper.map;
226
+ // let script_id = converter(path);
227
+
228
+ // let language = settings.select_script_language(path);
229
+ let language = & asset. language ;
230
+ if * language == Language :: Unknown {
231
+ // let extension = path
232
+ // .path()
233
+ // .extension()
234
+ // .and_then(|ext| ext.to_str())
235
+ // .unwrap_or_default();
236
+ // warn!("A script {:?} was added but its language is unknown. Consider adding the {:?} extension to the `ScriptAssetSettings`.", &script_id, extension);
235
237
}
236
238
let metadata = ScriptMetadata {
237
239
asset_id : * id,
238
- script_id,
239
- language,
240
+ // script_id,
241
+ language : language . clone ( ) ,
240
242
} ;
241
243
debug ! ( "Script loaded, populating metadata: {:?}:" , metadata) ;
242
244
script_asset_events. send ( ScriptAssetEvent :: Added ( metadata. clone ( ) ) ) ;
@@ -309,26 +311,26 @@ pub(crate) fn sync_script_data<P: IntoScriptPluginParams>(
309
311
ScriptAssetEvent :: Added ( _) | ScriptAssetEvent :: Modified ( _) => {
310
312
if metadata. language != P :: LANGUAGE {
311
313
trace ! (
312
- "{}: Script asset with id: {} is for a different langauge than this sync system. Skipping." ,
314
+ "{}: Script asset {} is for a different langauge than this sync system. Skipping." ,
313
315
P :: LANGUAGE ,
314
- metadata. script_id
316
+ metadata. asset_id
315
317
) ;
316
318
continue ;
317
319
}
318
320
319
- info ! ( "{}: Loading Script: {:?}" , P :: LANGUAGE , metadata. script_id , ) ;
321
+ info ! ( "{}: Loading Script: {:?}" , P :: LANGUAGE , metadata. asset_id , ) ;
320
322
321
323
if let Some ( asset) = script_assets. get ( metadata. asset_id ) {
322
324
commands. queue ( CreateOrUpdateScript :: < P > :: new (
323
- metadata. script_id . clone ( ) ,
325
+ metadata. asset_id . clone ( ) ,
324
326
asset. content . clone ( ) ,
325
327
Some ( script_assets. reserve_handle ( ) . clone_weak ( ) ) ,
326
328
) ) ;
327
329
}
328
330
}
329
331
ScriptAssetEvent :: Removed ( _) => {
330
- info ! ( "{}: Deleting Script: {:?}" , P :: LANGUAGE , metadata. script_id , ) ;
331
- commands. queue ( DeleteScript :: < P > :: new ( metadata. script_id . clone ( ) ) ) ;
332
+ info ! ( "{}: Deleting Script: {:?}" , P :: LANGUAGE , metadata. asset_id , ) ;
333
+ commands. queue ( DeleteScript :: < P > :: new ( metadata. asset_id . clone ( ) ) ) ;
332
334
}
333
335
} ;
334
336
}
@@ -356,7 +358,7 @@ pub(crate) fn configure_asset_systems(app: &mut App) -> &mut App {
356
358
) ,
357
359
)
358
360
. init_resource :: < ScriptMetadataStore > ( )
359
- . init_resource :: < ScriptAssetSettings > ( )
361
+ // .init_resource::<ScriptAssetSettings>()
360
362
. add_event :: < ScriptAssetEvent > ( ) ;
361
363
362
364
app
0 commit comments