@@ -6,71 +6,57 @@ use spring_native::prelude::NativeInterfaceRef;
66
77use super :: helpers:: { game_id, rand_u32} ;
88use super :: paths:: PROJECTS_DIR ;
9- use crate :: sbc:: envelope:: envelope_fields;
9+ use crate :: sbc:: command_system:: command:: Command ;
10+ use crate :: sbc:: project:: commands:: { ReloadIntoProjectCommand , SaveProjectInfoCommand } ;
11+ use crate :: sbc:: project:: ProjectData ;
1012
1113/// The blank map's archive name; its size comes from `randomMapOptions`.
1214const BLANK_MAP : & str = "SB_Blank_Map" ;
1315
14- /// Build the command envelopes for creating a new project, called by the
15- /// manager after the NewProject dialog completes.
16+ /// Build the commands for creating a new project, called by the manager after
17+ /// the NewProject dialog completes.
1618pub fn commit_new_project (
1719 name : & str ,
1820 map_name : & str ,
1921 size_x : Option < f32 > ,
2022 size_y : Option < f32 > ,
2123 interface : & NativeInterfaceRef ,
22- next : & mut u64 ,
23- ) -> Vec < String > {
24+ ) -> Vec < Box < dyn Command > > {
2425 let project_name = name. trim ( ) . trim_end_matches ( ".sdd" ) ;
2526 let path = format ! ( "{PROJECTS_DIR}{project_name}.sdd" ) ;
2627 let ( game_name, game_version) = game_id ( interface) ;
2728
2829 // For the blank map, the size is carried in randomMapOptions and the engine
2930 // generates a fresh map; a seed keeps the archive out of a stale cache.
3031 let random_map_options = if map_name == BLANK_MAP {
31- serde_json:: json!( {
32+ Some ( serde_json:: json!( {
3233 "mapSeed" : rand_u32( ) ,
3334 "new_map_x" : size_x. unwrap_or( 10.0 ) ,
3435 "new_map_y" : size_y. unwrap_or( 10.0 ) ,
35- } )
36+ } ) )
3637 } else {
37- serde_json :: Value :: Null
38+ None
3839 } ;
3940
4041 // The full project record, so the chosen map and target game are saved into
4142 // the start script the reload reads back.
42- let mut project = serde_json:: json!( {
43- "name" : project_name,
44- "path" : path,
45- "mapName" : map_name,
46- "game" : { "name" : game_name, "version" : game_version } ,
47- "mutators" : [ format!( "{project_name} 1.0" ) ] ,
48- } ) ;
49- if !random_map_options. is_null ( ) {
50- project[ "randomMapOptions" ] = random_map_options;
51- }
43+ let project = ProjectData {
44+ name : Some ( project_name. to_string ( ) ) ,
45+ path : Some ( path. clone ( ) ) ,
46+ map_name : Some ( map_name. to_string ( ) ) ,
47+ game : Some ( serde_json:: json!( { "name" : game_name, "version" : game_version } ) ) ,
48+ random_map_options,
49+ mutators : vec ! [ format!( "{project_name} 1.0" ) ] ,
50+ } ;
5251
5352 vec ! [
54- envelope_fields(
55- "SaveProjectInfoCommand" ,
56- next,
57- serde_json:: json!( {
58- "name" : project_name,
59- "path" : path,
60- "isNewProject" : true ,
61- "project" : project,
62- } ) ,
63- ) ,
64- envelope_fields(
65- "ReloadIntoProjectCommand" ,
66- next,
67- serde_json:: json!( {
68- "path" : path,
69- "modOptions" : serde_json:: json!( { } ) ,
70- "gameName" : game_name,
71- "gameVersion" : game_version,
72- } ) ,
73- ) ,
53+ Box :: new( SaveProjectInfoCommand :: new(
54+ project_name. to_string( ) ,
55+ path. clone( ) ,
56+ true ,
57+ Some ( project) ,
58+ ) ) ,
59+ Box :: new( ReloadIntoProjectCommand :: new( path, game_name, game_version) ) ,
7460 ]
7561}
7662
0 commit comments