-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflexScript.py
2661 lines (1925 loc) · 103 KB
/
flexScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import os
import time
import string
import json
import shutil
# import pygame
# Declare IDs, Versions and Mode Variables
stellaris_id = "281990" # This might need updating if Stellaris' game id changes
mod_id = "3038118849" # This is the mod id that might need updating if the Mod id changes
flex_v = "2.1.1" # Flex Script version
flex_ab_v = "2.1.1" # The real constant version of this FS Script
mod_v = "1" # Mod version
stellaris_v = "3.10.XX" # Designed for Stellaris Version...
fs_set_st_v = None # The version of "Designed for Stellaris Version" that was stored last time on the settings file // This is intended for troubleshooting
virgin = True # Is it the first time FS is being run?
fs_mode = "NORMAL" # NORMAL - Normal mode as it was intended to work /// RUSH - Fast mode, tries to run in the most autonomous & quick way /// DEBUG - Software Dev Mode // SERVER - Server client ready
previous_fs_mode = "NORMAL" # The mode that was previously of selecting the SERVER mode...
# Declare Folder Path Variables
game_directory = None # Stellaris Game folder path
steam_mods_directory = None # Steam Mods folder path
mod_directory = None # Mod folder path
# Declare Mod Folderpath Variables
defines_van_folder_path = None # Vanilla folder paths // paths that go into the folder where defines are at
species_van_folder_path = None
defines_mod_folder_path = None # Mod folder paths
species_mod_folder_path = None
# Declare Filepath Variables
defines_van_file_path = None # Vanilla file paths // paths that go into the file path with the .txt
species_van_file_path = None
defines_mod_file_path = None # Mod file paths
species_mod_file_path = None
fs_settings_present = False # If fs_settings.js is on the same path of flexScript.exe
# Declare Booleans
optional_semi_search = False
tutorial_active = True
is_any_custom_none = True # Check if any MPP customization variable is Null / None
auto_update_enabled = False # Turns auto-update on or off
## Declare General Variables
prompt = None
answer = None
## Declare Folder/File Path Keys
workshop_mod_key = "steamapps/workshop"
st_confirmation_key = "stellaris.exe"
descriptor_check = True
defines_name = "00_defines.txt" # The name of the file "00_define.txt" // in case paradox changes it's name
species_arc_name = "00_species_archetypes.txt" # The name of the file "00_species_archetypes..txt" // in case paradox changes it's name
## Declare picks & points
ethos_max_points = None
civic_points_base = None
machine_trait_points = None
machine_max_traits = None
species_trait_points = None
species_max_traits = None
## Declare command dictionaries
p_yes = ["yes", "y", "p_yes"]
p_no = ["no", "n", "p_no"]
p_semi = ["semi", "semi-autonomous", "semiauto", "semiautonomous", "s", "p_semi"]
p_manual = ["manually", "manual", "alternative", "m", "p_manual"]
p_continue = ["", 'y', "yes", "continue", "next", "advance", "proceed", "agreed", "please", "yes, please", "ok", "okey", "avança", "execute", "run", "enter", "confirm", "a", "p_continue"]
p_cancel = ["cancel", "delete", "back", "return", "del", "none", "rewind", "stop", "undo", "go back", "c", "p_cancel"]
p_reset = ["reset", "retry", "replay", "reiniciar", "retentar", "r", "p_reset"]
p_help = ["help", "?", "I need help", "help me", "ajuda", "h", "p_help"]
p_tutorial = ["tutorial", "how to", "how to do this", "explanation", "t", "p_tutorial"]
p_quit = ["q", "quit", "exit", "shut", "shutdown", "turn off", "bye", "bye bye", "see ya", "p_quit"]
p_settings = ["settings", "config", "configuration file", "fs_settings"]
print_tut = ["print_tutorial", "print tutorial", "p_tutorial", "p tutorial"]
## Delcare headers
header = f"""
##################################################
# #
# Welcome to FLEX SCRIPT (FS): #
# Enhancing your Stellaris MPP experience #
# "More Picks & Points: Traits|Civics|Ethics" #
# [FLEX EDITION] #
# #
##################################################
## MPP v{mod_v} - FS v{flex_ab_v}
## Designed for Stellaris {stellaris_v}+
## Stellaris id: {stellaris_id} // MPP Mod id: {mod_id}
Flex Script, empowered by the community and crafted with care by Hubert Dungen,
and with the help of GPT 4, is your gateway to a tailored Stellaris adventure.
Our script automates the customization of MPP, ensuring your galactic empire
is uniquely yours.
Attention: MPP impacts both player and NPC Empires, enhancing genetic diversity and realism.
It is designed for a richer gameplay experience, not as a cheat tool.
Discover my journey and other projects at: https://hubertdungen.com
To know more about this script visit: https://github.com/hubertdungen/Stellaris_flexScript
You can find MPP [FLEX EDITION] at: https://steamcommunity.com/workshop/filedetails/?id=3038118849
Support ongoing development and maintenance at: https://ko-fi.com/hubertkenobi
"MPP" stands for "More Picks & Points"
"FS" stands for "Flex Script"
Launching Flex Script... Please stand by.
--------------------------------------------------
"""
tutorial = """
##############################################
# #
# Flex Script Tutorial #
# #
##############################################
Welcome to Flex Script, your Stellaris MPP customization assistant.
Here are some tips to ensure a smooth experience:
- User-Friendly Questions: The script asks clear, straightforward questions.
It intelligently interprets your responses, normalizing text and removing extra spaces.
Responses have multiple valid forms for your convenience, some doesn't even appear on
the description suggestions but are intuitive.
- Sequential Approach: Simply follow the script's prompts one by one.
There's no need to rush; each step guides you through the customization process.
- You can cancel, reset, quit, tutorial or ask for help at any time just by writing that or similar.
- Autonomy in Detection: Flex Script autonomously detects paths for Stellaris installations and MPP mod folders.
And its main task is to assist you in MPP mod customization, but will prompt for semi-autonomous or manual input when needed.
- Server Hosting Assistance: This script is tailored for server hosting, facilitating the sharing of mod customizations.
Just ensure the executable and settings files are in the same folder. If possible, the script will handle the rest,
making multiplayer setup with friends a breeze.
- Semi-Automatic Mod Updates: Activate this feature in the settings to keep your mod updated accordingly to Stellaris updates.
With this, the script will automatically adapt to game updates, reducing your waiting time for manual mod maintenance.
For additional support or inquiries, consult the README on GitHub or ask on the Steam community page.
Here's to an enhanced and personalized Stellaris MPP experience!
##############################################
"""
## Declare Help texts
help_parent = None
help_header = """
##############################################
# #
# Flex Script Help #
# #
##############################################
Here are some tips of the {help_parent} menu:
"""
## Declare help texts
help_texts = {
"find_game_folder": (
"### Help: Find Game Files ###\n"
"This function searches for the Stellaris game installation directory. "
"\nIt checks common installation paths and tries to automatically locate the game."
),
"find_mod_folder": (
"### Help: Find Mod Files ###\n"
"This function looks for the location of Stellaris mods within the Steam directory. "
"\nIt aims to find where your Stellaris mods are stored for further customization."
),
"semiautonomous_search_ui": (
"### Help: Semi-Autonomous Search ###\n"
"In this semi-autonomous mode, the software asks for a drive letter, then searches "
"for a possible path for Stellaris or mods."
"\nYou should know in what driver your files are placed and then provide the driver letter."
"\nThe search duration depends on drive size and contents."
),
"insert_path_manually": (
"### Help: Insert Path Manually ###\n"
"This option allows you to manually input the full path of a file or directory. "
"\n\n> Ensure the path is correctly typed and complete."
"\n> Use this option if automatic or semi-automatic search methods fail to locate the desired path."
"\n> Don't worry about the direction of slashes ('/') in the path;"
"\n the software automatically corrects them if they are inverted."
"\n> It's not necessary to add or remove the trailing slash ('/');"
"\n the software automatically adjusts it for you."
),
"help_prompt": (
"### Help: Help Menu ###\n"
"You already are at the \"Tutorial Menu\"... "
"\nThere is no rush for this process, so you can just enter \"yes\" and go step by step."
"\nYou can find detailed explanations at the following links:"
"\n\nFLEX SCRIPT Github page: https://github.com/hubertdungen/Stellaris_flexScript"
"\nMPP [FLEX EDITION] mod link at: https://steamcommunity.com/workshop/filedetails/?id=3038118849"
),
"main_menu":(
"### Help: Main Menu ###\n"
"The main menu provides a central hub for navigating Flex Script's features. "
"Here's a breakdown of the options available:\n"
"1. Restart: Resets the entire path finding and customization process.\n"
"2. Customization Menu: Access the customization interface for Stellaris MPP mod.\n"
"3. Initial Header: Displays the initial header and information about Flex Script.\n"
"4. Tutorial: Shows a detailed tutorial to guide new users through Flex Script.\n"
"5. Settings: Modify script settings like mode (NORMAL, FAST, etc.) and update game/mod IDs.\n"
"6. Update: Update mod files based on the latest game updates or customization changes.\n"
"7. Prepare for Server Clients: Setup the script for server client use, optimizing for multiplayer game hosting.\n"
"8. Quit: Exit Flex Script.\n\n"
"Each option is designed to provide a specific functionality, from basic setup to advanced customization and preparation for server hosting."
),
"other": (
"### Help: General ###\n"
"This menu has no specific help function. Please navigate back to the previous menus "
"\nand prompt 'help' for more info, or request a 'tutorial' for general guidance."
)
}
def display_main_menu_header():
global fs_mode
print("\n##############################################")
print("# Flex Script Menu #")
print("##############################################\n")
print(f"# Mode: {fs_mode}\n")
print("\nWelcome to the Flex Script main menu. Here you can:")
print("1. RESTART: Restart the path finding and customization process")
print(" \-> This will delete every value in settings!")
print("2. CUSTOMIZE: Go to the customization menu")
print("3. CREDITS: Show the initial FS header")
print("4. TUTORIAL: View the tutorial")
print("5. SETTINGS: Access settings")
print("6. UPDATE: Update mod files")
print("7. SERVER MODE: Prepare settings for server clients")
print("8. QUIT: Quit Flex Script\n")
print("\n-- SAVE & LOAD --")
print("9. Save Settings")
print("10. Load Settings\n\n\n")
def display_server_mode_header():
print("\n##############################################")
print("# Flex Script Server Mode Menu #")
print("##############################################\n")
print(" ")
print(" # All files are ready. ")
print(" > You can quit and play Stellaris! ")
print("\n ")
print("\nServer Mode Active. Limited menu options:\n")
print("1. Deactivate SERVER Mode ")
print("2. Restart path and variable finding process")
print("3. Quit Flex Script\n ")
### STRING OPERATORS ######################################################################
## String engineering
def replace_slashes(input_string):
return input_string.replace("\\", "/")
def separator_timer(timer):
print("\n\n...\n\n")
if timer != 0:
custom_sleep(timer)
def separator_btimer(btimer, atimer):
custom_sleep(btimer)
print("\n\n...\n\n")
custom_sleep(atimer)
def custom_sleep(duration):
global fs_mode
if fs_mode == "NORMAL":
time.sleep(duration)
elif fs_mode == "FAST":
if duration <= 1:
time.sleep(0.5)
else:
time.sleep(1)
elif fs_mode == "SERVER":
if duration <= 1:
time.sleep(0.05)
else:
time.sleep(0.4)
elif fs_mode in ["RUSH", "DEBUG"]:
# time.sleep(0) # No delay for RUSH, DEBUG, and SERVER modes
if duration <= 1:
time.sleep(0)
else:
time.sleep(0.2)
def print_sep(print_p, sep_timer):
print(print_p)
separator_timer(sep_timer)
def misspell_exception():
separator_timer(1)
print("You have entered characters, words or phrases other than those that this software is programmed to respond to.")
separator_timer(1)
print("Going back a few steps.")
separator_timer(1)
custom_sleep(2)
return
## This is a function to detect the function name and turn it into a "history" string variable
def with_history(func):
def wrapper(*args, **kwargs):
# If 'history' is not already in kwargs, set it to the function's name
if 'history' not in kwargs:
kwargs['history'] = func.__name__
return func(*args, **kwargs)
return wrapper
###########################################################################################
### PATH FINDERS #########################################################################
@with_history
def find_game_folder(history=None):
"""
# Attempt to find the game directory, workshop content and necessary files
"""
# DECLARE VARS
global game_directory
global optional_semi_search
game_directory = None
confirmation_file = st_confirmation_key
searched_subject = st_confirmation_key
path_conf = None
optional_semi_search = False
# Common paths where Steam and Stellaris might be installed
common_game_paths = generate_game_paths()
## Debug Paths
if fs_mode == "DEBUG":
for game_path in common_game_paths:
print(f"{game_path}")
# Attempt to find the Stellaris directory in common paths
while True:
for path in common_game_paths:
if os.path.exists(path):
path = path_checker("Stellaris", path, confirmation_file)
if path == None: return None
while True:
game_directory = path
print("### FLEX SCRIPT has detected a Stellaris game folder! ###")
print(f"\n### At: \"{game_directory}\"")
separator_timer(3)
## CALL PRIMARY PATH QUESTION
path_conf = primary_path_question("Stellaris installation" ,"You will provide the drive letter where you think Stellaris is installed, and FS will search there", history)
if path_conf in p_continue or path_conf == "1": # Assign automatic folder
return game_directory
break
elif path_conf in p_semi or path_conf == "2": # Semi-automatic search
game_directory = None
optional_semi_search = True
break
elif path_conf in p_manual or path_conf == "3": # Manually apply folder
game_directory = insert_path_manually("Stellaris installation", "\"C:/Program Files (x86)/Steam/steamapps/common/Stellaris/\"", "Please ensure you have provided the correct path.", "stellaris.exe") # 1st var: Content \\ 2nd var: PATH \\ 3rd var: Exception error alert \\ 4rd var: confirmation_file which can be Stellaris exe file f.ex.
separator_timer(1)
if game_directory == "cancel" or game_directory == None:
game_directory == None
continue
return game_directory
elif path_conf == "cancel":
main_updated()
elif path_conf == "help":
help_prompt(path_conf, history=history)
else:
misspell_exception()
if game_directory is None:
# If the initial search failed, or it was optionally selected, offer to semi-autonomous search in a specific drive
separator_timer(0)
while True:
if optional_semi_search == False: # If it failed to automatically search
print("### FLEX SCRIPT has failed to find the Stellaris path automatically! ###")
separator_timer(2)
## CALL SECONDARY PATH QUESTION
prompt = secondary_path_question("Stellaris installation", "You will provide the drive letter where you think Stellaris is installed, and FS will search there", history)
if prompt in p_yes or prompt in p_semi or prompt == "1":
game_directory = semiautonomous_search_ui("Stellaris game", searched_subject, confirmation_file)
if game_directory == "cancel" or game_directory == None:
game_directory == None
continue
return game_directory
elif prompt in p_manual or prompt in p_no or prompt in ["other", "2"]:
game_directory = insert_path_manually("Stellaris installation", "\"C:/Program Files (x86)/Steam/steamapps/common/Stellaris/\"", "Please ensure you have provided the correct path.", "stellaris.exe") # 1st var: Content \\ 2nd var: PATH \\ 3rd var: Exception error alert \\ 4rd var: confirmation_file which can be Stellaris exe file f.ex.
separator_timer(1)
if game_directory == "cancel" or game_directory == None:
game_directory == None
continue
return game_directory
elif prompt in ["retry", "redo", "go back", "back", "3"]:
continue
elif prompt in p_cancel:
prompt == None
continue
else:
misspell_exception()
else: # If semiauto was optionally chosen
print("## You have selected semiautonomous Stellaris path search. ##")
optional_semi_search = False
game_directory = semiautonomous_search_ui("Stellaris", searched_subject, confirmation_file)
if game_directory == "cancel" or game_directory == None:
game_directory == None
continue
return game_directory
return game_directory
@with_history
def find_mod_folder(history=None):
"""
# Attempt to find the steam stellaris mod directory, workshop content and necessary files
"""
# DECLARE GLOBAL VARS
global stellaris_id
global mod_id
global steam_mods_directory
global mod_directory
global optional_semi_search
# DECLARE VARS
potential_path = None
mod_directory = None
confirmation_key = mod_id
confirmation_folder = os.path.join(stellaris_id, mod_id)
path_conf = None
optional_semi_search = False
# Common paths where Steam and Stellaris might be installed
common_mod_paths = generate_mod_paths(stellaris_id, mod_id)
## Debug Paths
if fs_mode == "DEBUG":
for mod_path in common_mod_paths:
print(f"{mod_path}")
# Attempt to find the Stellaris directory in common paths
while True:
for path in common_mod_paths:
if os.path.exists(path):
steam_mods_directory = path_checker("Stellaris MPP Mod folder", path, confirmation_key)
if steam_mods_directory == None: potential_path = path ; break
while True:
mod_directory = os.path.join(steam_mods_directory, confirmation_key)
print("### FLEX SCRIPT has detected the Stellaris Mods and MPP Mod folder! ###")
print(f"\n### At: \"{mod_directory}\"")
separator_timer(3)
path_conf = primary_path_question("MPP Mod folder" ,"You will provide the drive letter where Steam is installed, and FS will search for MPP Mod on that drive", history)
if path_conf in p_continue or path_conf == "1": # Assign automatic folder
return mod_directory
elif path_conf in p_semi or path_conf == "2": # Semi-automatic search
mod_directory = None
optional_semi_search = True
break
elif path_conf in p_manual or path_conf == "3": # Manually apply folder
mod_directory = insert_path_manually("Steamapps -> Workshop -> Content folder", "\"C:/Program Files (x86)/Steam/steamapps/workshop/content/", "Please ensure you have provided the correct \"Steam\" / \"steamapps/\" \"workshop/\" \"content/\" path.\nThis is not to insert the MPP's Mod path directly\nBut to point where the stellaris workshop mods are located.", confirmation_folder).strip() # 1st var: Content \\ 2nd var: PATH \\ 3rd var: Exception error alert \\ 4rd var: confirmation_file which can be Stellaris MPP folder f.ex.
separator_timer(1)
if mod_directory == "cancel":
mod_directory == None
continue
return mod_directory
elif path_conf == "cancel":
main_updated()
elif path_conf == "help":
help_prompt(path_conf, history=history)
else:
misspell_exception()
if mod_directory is None:
# If the initial search failed, or it was optionally selected, offer to semi-autonomous search in a specific drive
separator_timer(0)
if potential_path is not None:
print("### FLEX SCRIPT has failed to find the Stellaris MPP Mod path automatically! ###")
separator_timer(2)
print("But it found a folder that may have the mods with different IDs.")
custom_sleep(2)
while True:
print(f"\nThis is the path FS has found: \n{path}")
print("\n\nPlease provide the id of Stellaris:")
prompt = input(
"\n> Enter the ID - It will check if that ID is inside {path}."
"\n> Press Enter / manual / cancel / 2 - Will ask for you to insert the entire MPP Mod folder entirely."
"\n> retry / 3 - Will retry the fully autonomous search. (only useful if you have changed the Steam folder path"
"\n\n(ID/manual/retry) Answer: "
).lower()
separator_timer(1)
prompt = prompt_handler(answer, history)
if prompt.strip().isdigit():
potential_path = os.path.join(potential_path, prompt)
path = path_checker("Steam Workshop Stellaris folder", potential_path, confirmation_key)
if path == None: continue
if potential_path is not None:
print("### FLEX SCRIPT has found the Stellaris Mods File! ###")
separator_timer(2)
print("Now let's automatically try checking the MPP folder...")
separator_timer(2)
potential_path = os.path.join(potential_path, mod_id)
path = path_checker("MPP Mod folder", potential_path, "descriptor")
if path == None: potential_path = path; continue
print("### FLEX SCRIPT successfully found the MPP Mod folder! ###")
separator_timer(2)
return mod_directory
elif prompt in p_yes or prompt in p_continue or prompt in p_semi or prompt == "1":
mod_directory = semiautonomous_search_ui("Stellaris MPP Mod", stellaris_id, confirmation_key)
separator_timer(1)
if mod_directory == "cancel" or mod_directory == None:
mod_directory == None
continue
return mod_directory
elif prompt in ["retry", "redo", "go back", "back", "3"]:
continue
elif prompt in p_cancel:
prompt == None
continue
else:
misspell_exception()
else:
while True:
if optional_semi_search == False: # If it failed to automatically search
print("### FLEX SCRIPT has failed to find the Stellaris MPP Mod path automatically! ###")
separator_timer(2)
## CALL SECONDARY PATH QUESTION
prompt = secondary_path_question("Stellaris MPP Mod", "You will provide the drive letter where Steam is installed, and FS will search for MPP Mod on that drive.", history)
if prompt in p_yes or prompt in p_continue or prompt in p_semi or prompt == "1":
mod_directory = semiautonomous_search_ui("Stellaris MPP Mod", stellaris_id, confirmation_key)
if mod_directory == "cancel" or mod_directory == None:
mod_directory == None
continue
return mod_directory
elif prompt in p_manual or prompt in p_no or prompt in ["other", "2"]:
mod_directory = insert_path_manually("Steamapps -> Workshop -> Content folder", "\"C:/Program Files (x86)/Steam/steamapps/workshop/content/", "Please ensure you have provided the correct \"Steam\" / \"steamapps/\" \"workshop/\" \"content/\" path.\nThis is not to insert the MPP's Mod path directly\nBut to point where the stellaris workshop mods are located.", confirmation_folder).strip() # 1st var: Content \\ 2nd var: PATH \\ 3rd var: Exception error alert \\ 4rd var: confirmation_file which can be Stellaris MPP folder f.ex.
separator_timer(1)
if mod_directory == "cancel" or mod_directory == None:
mod_directory == None
continue
return mod_directory
elif prompt in ["retry", "redo", "go back", "back", "3"]:
continue
elif prompt in p_cancel:
prompt == None
continue
else:
misspell_exception()
else: # If semiauto was optionally chosen
print("## You have selected semiautonomous MPP Mod path search. ##")
optional_semi_search = False
mod_directory = semiautonomous_search_ui("Stellaris MPP Mod", stellaris_id, confirmation_key)
if mod_directory == "cancel" or mod_directory == None:
mod_directory == None
continue
return mod_directory
return mod_directory
## BACKUP CODE
# if os.path.exists(steam_mods_directory):
# # List all game codes in the steam workshop content directory
# game_codes = os.listdir(steam_mods_directory)
# # Check if Stellaris game code exists
# if stellaris_id in game_codes:
# steam_mods_directory = os.path.join(steam_mods_directory, stellaris_id)
# mods = os.listdir(steam_mods_directory)
# if mods: # if there's any mod folder
# print("Multiple mods detected. Please ensure you know the mod's specific code.")
# for mod in mods:
# print(f"- {mod}")
# mod_code = input("Please enter this mod's specific code which should be \"3038118849\". The mod id is the suffix number of it's steam link.\nMod ID: ")
# return os.path.join(steam_mods_directory, mod_code)
# # If the initial search failed, offer to search in a specific drive
# search_drive = input("Failed to find the mod path automatically. Would you like to search a specific drive for the Stellaris installation? (yes/no): ").lower()
# if search_drive == "yes":
# drive_letter = input("Enter the drive letter (e.g., D, E, F, etc.): ").upper()
# steamapps_path = search_subject_in_drive(drive_letter, "steamapps", descriptor_check=True)
# if steamapps_path:
# workshop_path = os.path.join(steamapps_path, "workshop", "content", stellaris_id)
# if os.path.exists(workshop_path):
# mods = os.listdir(workshop_path)
# if mods: # if there's any mod folder
# print("Multiple mods detected. This mod should be code number \"3038118849\". Please ensure you know the mod's specific code.")
# print(", ".join(mods))
# mod_code = input("Enter your mod's specific code: ")
# return os.path.join(workshop_path, mod_code)
# else:
# print("There are no mods on your stellaris folder. Please ensure you installed \"More Picks\" mod before running this script.")
# # If all attempts fail, return None
# return None
@with_history
def find_mod_files(mod_directory, history = None):
global defines_name
global species_arc_name
global defines_mod_folder_path
global species_mod_folder_path
if fs_mode == "DEBUG": print(f"DEBUG_mod_files_0: mod_directory:{mod_directory} // defines_name:{defines_name} // defines_mod_folder_path:{defines_mod_folder_path} // species_mod_folder_path:{species_mod_folder_path} // species_arc_name:{species_arc_name}\n\n")
## DETECT 00_defines.txt
defines_mod_folder_path = path_file_checker("MPP Mod folder", mod_directory, defines_name)
if defines_mod_folder_path:
# Implement logic to assign the mod files
# defines_mod_folder_path = os.path.join(mod_directory, defines_name)
if fs_mode == "DEBUG": print(f"DEBUG_mod_files_1: mod_directory:{mod_directory} // defines_name:{defines_name} // defines_mod_folder_path:{defines_mod_folder_path} // species_mod_folder_path:{species_mod_folder_path} // species_arc_name:{species_arc_name}\n\n")
## DETECT 00_species_archetypes.txt
species_mod_folder_path = path_file_checker("MPP Mod folder", mod_directory, species_arc_name)
if species_mod_folder_path:
# Implement logic to assign the mod files
# species_mod_folder_path = os.path.join(mod_directory, species_arc_name)
if fs_mode == "DEBUG": print(f"DEBUG_mod_files_2: mod_directory:{mod_directory} // defines_name:{defines_name} // defines_mod_folder_path:{defines_mod_folder_path} // species_mod_folder_path:{species_mod_folder_path} // species_arc_name:{species_arc_name}\n\n")
if fs_mode == "DEBUG": print(f"DEBUG_mod_files_3: mod_directory:{mod_directory} // defines_name:{defines_name} // defines_mod_folder_path:{defines_mod_folder_path} // species_mod_folder_path:{species_mod_folder_path} // species_arc_name:{species_arc_name}\n\n")
return defines_mod_folder_path, species_mod_folder_path
@with_history
def find_game_files(game_directory, history = None):
global defines_name
global species_arc_name
global defines_van_folder_path
global species_van_folder_path
if fs_mode == "DEBUG": print(f"DEBUG_mod_files_0: game_directory:{game_directory} // defines_name:{defines_name} // defines_van_folder_path:{defines_van_folder_path} // species_van_folder_path:{species_van_folder_path} // species_arc_name:{species_arc_name}\n\n")
## DETECT 00_defines.txt
defines_van_folder_path = path_file_checker("Stellaris Installation", game_directory, defines_name)
if defines_van_folder_path:
# Implement logic to assign the mod files
if fs_mode == "DEBUG": print(f"DEBUG_mod_files_1: game_directory:{game_directory} // defines_name:{defines_name} // defines_van_folder_path:{defines_van_folder_path} // species_van_folder_path:{species_van_folder_path} // species_arc_name:{species_arc_name}\n\n")
## DETECT 00_species_archetypes.txt
species_van_folder_path = path_file_checker("Stellaris Installation", game_directory, species_arc_name)
if species_van_folder_path:
# Implement logic to assign the mod files
if fs_mode == "DEBUG": print(f"DEBUG_mod_files_2: game_directory:{game_directory} // defines_name:{defines_name} // defines_van_folder_path:{defines_van_folder_path} // species_van_folder_path:{species_van_folder_path} // species_arc_name:{species_arc_name}\n\n")
if fs_mode == "DEBUG": print(f"DEBUG_mod_files_3: game_directory:{game_directory} // defines_name:{defines_name} // defines_van_folder_path:{defines_van_folder_path} // species_van_folder_path:{species_van_folder_path} // species_arc_name:{species_arc_name}\n\n")
return defines_van_folder_path, species_van_folder_path
def define_van_files_path():
# Declare globals
global defines_van_folder_path
global species_van_folder_path
global defines_van_file_path
global species_van_file_path
global defines_name
global species_arc_name
# Paths to the mod files
defines_van_file_path = os.path.join(defines_van_folder_path, defines_name)
species_van_file_path = os.path.join(species_van_folder_path, species_arc_name)
print(f"Assigned defines vanilla file path at: \"{defines_van_file_path}\"")
print(f"Assigned species vanilla file path at: \"{species_van_file_path}\"")
separator_timer(2)
def define_mod_files_path():
# Declare globals
global defines_mod_folder_path
global species_mod_folder_path
global defines_mod_file_path
global species_mod_file_path
global defines_name
global species_arc_name
# Paths to the mod files
defines_mod_file_path = os.path.join(defines_mod_folder_path, defines_name)
species_mod_file_path = os.path.join(species_mod_folder_path, species_arc_name)
###########################################################################################
### SEARCH ENGINEERS & PATH INJECTORS ####################################################
@with_history
def semiautonomous_search_ui(subject, searched_subject, confirmation_path, history=None):
## Declaring vars
path = None
global prompt
global optional_semi_search
optional_semi_search = True
while True:
## Confirming the user wants to continue
separator_timer(0)
print("### WARNING! ###")
custom_sleep(1)
print("\n\n### For your information, this process may take sometime. ###\n")
custom_sleep(2)
## Proceed confirmation
prompt = proceed_confirmation(history)
if prompt in p_cancel or prompt in p_no:
return "cancel"
###############################
separator_timer(1)
print("### INITIATING SEMI-AUTONOMOUS PROCESS ###")
separator_timer(2)
print("\n### STEP ONE \nEnter the drive letter\n\n(e.g., C, D, E, F, etc.)")
# custom_sleep(1)
drive_letter = input("\nDrive Letter: ").upper().strip()
separator_timer(1)
## PATH AUTO SEARCH ON DRIVE
# 'path' has the full file path including the file name
path = search_subject_in_drive(drive_letter, searched_subject, descriptor_check=True)
## DEBUG 1
if fs_mode == "DEBUG": print(f"DEBUG1: path:{path} // subject:{subject} // history:{history} // drive_letter:{drive_letter} // optional_semi_search:{optional_semi_search} // confirmation_path:{confirmation_path}")
# Check if a path was found
if path is not None:
# If the path is a file, get the directory name
if os.path.isfile(path):
path = os.path.dirname(path)
# Ensure there is a trailing slash
if not path.endswith(os.sep):
path += os.sep
## DEBUG 2
if fs_mode == "DEBUG": print(f"DEBUG2: path:{path} // subject:{subject} // history:{history} // drive_letter:{drive_letter} // optional_semi_search:{optional_semi_search} // confirmation_path:{confirmation_path}")
try:
print("### STEP TWO")
# custom_sleep(1)
print(f"\nSearching for {subject} on the drive {drive_letter}...")
if fs_mode == "DEBUG": print(f"\nWith the following searched_subject: {searched_subject}\nAnd the following history:{history}")
if path is not None:
separator_timer(0)
print("### STEP THREE\n")
# custom_sleep(1)
print(f"Directory of {subject} found at {path}...")
separator_timer(2)
print("### STEP FOUR\n")
# custom_sleep(1)
print("Checking for path integrity...")
separator_timer(2)
path = path_checker(subject, path, confirmation_path)
print("Thinking...")
separator_timer(2)
return path
separator_timer(1)
print("### ERROR: PATH NOT FOUND")
custom_sleep(1)
print (f"\nThe SEMI-AUTONOMOUS Process could not find any path related to {subject} on the \"{drive_letter}\" drive")
separator_timer(3)
print("Returning...")
separator_timer(1)
return None
except:
separator_timer(1)
print("### ERROR: PATH ###")
custom_sleep(1)
print("\nThere was an error while trying to assign the directory path...")
custom_sleep(1)
print("\nTry again or try the manual method.")
return "cancel"
# Method to insert stellaris or mod paths manually
@with_history
def insert_path_manually(subject_var, text_path, text_exception, confirmation_path, history=None):
"""
Allows the user to manually enter a directory path and retries if the path is invalid.
"""
separator_timer(0)
print(f"You chose to insert the {subject_var} path manually...")
separator_timer(1)
while True:
print(f"Please, enter the directory path of {subject_var}.")
path = input(f"\nThe path should look something similar to this: \n{text_path} \n \n\nPath: ").strip()
path = replace_slashes(path)
## DEBUG 1
if fs_mode == "DEBUG": print(f"DEBUG1: path:{path} // history:{history} // subject_var:{subject_var} // text_path:{text_path} // text_exception:{text_exception} // confirmation_path:{confirmation_path}")
## ASKING FOR THE PATH
## Prompt handler
path = prompt_handler(path, history=history)
if path == "cancel": return "cancel"
####################################
## DEBUG 2
if fs_mode == "DEBUG": print(f"DEBUG2: path:{path} // history:{history} // subject_var:{subject_var} // text_path:{text_path} // text_exception:{text_exception} // confirmation_path:{confirmation_path}")
separator_timer(1)
print(f"The path you have inserted looks like this:\n.\n{path}\n.\n")
## ASKING FOR CONFIRMATION THE PATH
## Proceed confirmation
prompt = proceed_confirmation(history)
if prompt in p_cancel or prompt in p_no:
return "cancel"
###############################
separator_timer(1)
## DEBUG 3
if fs_mode == "DEBUG": print(f"DEBUG3: path:{path} // history:{history} // subject_var:{subject_var} // text_path:{text_path} // text_exception:{text_exception} // confirmation_path:{confirmation_path}")
if os.path.exists(path):
separator_timer(0)