@@ -381,46 +381,56 @@ def load_flight_plan(self, pln_path):
381
381
else :
382
382
return False
383
383
384
- def save_flight (self , flt_path , flt_title , flt_description ):
384
+ def save_flight (
385
+ self ,
386
+ flt_path ,
387
+ flt_title ,
388
+ flt_description ,
389
+ flt_mission_type = 'FreeFlight' ,
390
+ flt_mission_location = 'Custom departure' ,
391
+ flt_original_flight = '' ,
392
+ flt_flight_type = 'NORMAL' ):
385
393
hr = self .dll .FlightSave (self .hSimConnect , flt_path .encode (), flt_title .encode (), flt_description .encode (), 0 )
386
- if self .IsHR (hr , 0 ):
387
- return True
388
- else :
394
+ if not self .IsHR (hr , 0 ):
389
395
return False
390
396
397
+ dicp = self .flight_to_dic (flt_path )
398
+ if 'MissionType' not in dicp ['Main' ]:
399
+ dicp ['Main' ]['MissionType' ] = flt_mission_type
400
+
401
+ if 'MissionLocation' not in dicp ['Main' ]:
402
+ dicp ['Main' ]['MissionLocation' ] = flt_mission_location
403
+
404
+ if 'FlightType' not in dicp ['Main' ]:
405
+ dicp ['Main' ]['FlightType' ] = flt_flight_type
406
+
407
+ if 'OriginalFlight' not in dicp ['Main' ]:
408
+ dicp ['Main' ]['OriginalFlight' ] = flt_original_flight
409
+ self .dic_to_flight (dicp , flt_path )
410
+
411
+ return False
412
+
391
413
def get_paused (self ):
392
414
hr = self .dll .RequestSystemState (
393
415
self .hSimConnect ,
394
416
self .dll .EventID .EVENT_SIM_PAUSED ,
395
417
b"Sim"
396
418
)
397
419
398
- # not working
399
- # def dic_to_flight(self, dic):
400
- # data_folder = os.path.dirname(os.path.realpath(__file__))
401
- # file_to_open = os.path.join(data_folder, "TEMP.FLT")
402
- # if os.path.isfile(file_to_open):
403
- # os.remove(file_to_open)
404
- # with open(file_to_open, "w") as tempfile:
405
- # for root in dic:
406
- # tempfile.write("\n[%s]\n" % root)
407
- # for member in dic[root]:
408
- # tempfile.write("%s=%s\n" % (member, dic[root][member]))
409
- # if os.path.isfile(file_to_open):
410
- # self.load_flight(file_to_open)
411
-
412
- def flight_to_dic (self ):
413
- data_folder = os .path .dirname (os .path .realpath (__file__ ))
414
- file_to_open = os .path .join (data_folder , "TEMP.FLT" )
415
- if os .path .isfile (file_to_open ):
416
- os .remove (file_to_open )
417
- self .save_flight (file_to_open , "Flight" , "Supper Cool flight" )
418
- while not os .path .isfile (file_to_open ):
420
+ def dic_to_flight (self , dic , fpath ):
421
+ with open (fpath , "w" ) as tempfile :
422
+ for root in dic :
423
+ tempfile .write ("\n [%s]\n " % root )
424
+ for member in dic [root ]:
425
+ tempfile .write ("%s=%s\n " % (member , dic [root ][member ]))
426
+
427
+ def flight_to_dic (self , fpath ):
428
+ while not os .path .isfile (fpath ):
419
429
pass
420
430
time .sleep (0.5 )
421
431
dic = {}
422
432
index = ""
423
- with open (file_to_open , "r" ) as tempfile :
433
+ with open (fpath , "r" ) as tempfile :
424
434
for line in tempfile .readlines ():
425
435
if line [0 ] == '[' :
426
436
index = line [1 :- 2 ]
@@ -429,5 +439,4 @@ def flight_to_dic(self):
429
439
if index != "" and line != '\n ' :
430
440
temp = line .split ("=" )
431
441
dic [index ][temp [0 ]] = temp [1 ].strip ()
432
- os .remove (file_to_open )
433
442
return dic
0 commit comments