diff options
-rwxr-xr-x | srb.py | 7 | ||||
-rw-r--r-- | srb_lib.py | 7 | ||||
-rwxr-xr-x | srb_tk.py | 56 |
3 files changed, 45 insertions, 25 deletions
@@ -58,6 +58,7 @@ parser.add_argument("--set-levelset-available-levels",action="append",help="Set parser.add_argument("--get-name",action="store_true",help="Print name for profile.") parser.add_argument("--set-name",help="Set name for profile.") parser.add_argument("--get-profile-in-use",action="store_true",help="Print if profile is in use.") +parser.add_argument("--set-profile-in-use",choices=["True","False"],help="Print if profile is in use.") parser.add_argument("--get-tutorial-completed",action="store_true",help="Print if profile has completed the tutorial.") parser.add_argument("--set-tutorial-completed",choices=["True","False"],help="Set tutorial-completed for profile.") parser.add_argument("--get-health",action="store_true",help="Print stat health for profile.") @@ -88,7 +89,7 @@ profile_id = args.profile #print(f"profile_id={profile_id}") # New actions that need --profile must be added here. -if not profile_id and (args.get_money or args.set_money or args.get_weapon or args.set_weapon or args.get_level or args.get_name or args.set_name or args.get_profile_in_use or args.get_purchased_weapons or args.get_tutorial_completed or args.add_purchased_weapons or args.remove_purchased_weapons or args.get_health or args.get_stunt or args.get_gun or args.set_health or args.set_stunt or args.set_gun or args.get_levelset or args.get_purchased_planes or args.add_purchased_planes or args.remove_purchased_planes or args.set_level_status or args.set_level_balloons or args.set_levelset_available_levels or args.set_level_letters or args.unlock_everything or args.lock_everything or args.buy_everything or args.unbuy_everything or args.set_level): +if not profile_id and (args.get_money or args.set_money or args.get_weapon or args.set_weapon or args.get_level or args.get_name or args.set_name or args.get_profile_in_use or args.get_purchased_weapons or args.get_tutorial_completed or args.add_purchased_weapons or args.remove_purchased_weapons or args.get_health or args.get_stunt or args.get_gun or args.set_health or args.set_stunt or args.set_gun or args.get_levelset or args.get_purchased_planes or args.add_purchased_planes or args.remove_purchased_planes or args.set_level_status or args.set_level_balloons or args.set_levelset_available_levels or args.set_level_letters or args.unlock_everything or args.lock_everything or args.buy_everything or args.unbuy_everything or args.set_level or args.set_profile_in_use): ferror("Warning: Cannot perform most actions without --profile. Not all tasks may run.") else: if args.get_money: @@ -161,6 +162,10 @@ else: srb_lib.write_file(args.file,0,data) if args.get_profile_in_use: print(f"Profile {profile_id} in use is {srb_lib.get_profile_in_use(args.file,profile_id)}") + if args.set_profile_in_use: + thisbool = False if args.set_profile_in_use == "False" else True + data, newstatus = srb_lib.set_profile_in_use(args.file, profile_id, thisbool) + srb_lib.write_file(args.file,0,data) if args.get_purchased_weapons: print(f"Profile {profile_id} has weapons {srb_lib.get_purchased_weapons(args.file,profile_id)}") if args.add_purchased_weapons: @@ -22,7 +22,6 @@ # Improve: # Rewrite as a class so we do not have to pass data around everywhere? # Write: set level breakables -# Write: set profile-in-use # Documentation: # winetricks vd=1024x768 # winetricks vd=off @@ -736,6 +735,12 @@ def get_profile_in_use(data_object,profile_id): #print(f"debug: in_use: {in_use}, type {type(in_use)}") return in_use +def set_profile_in_use(data_object,profile_id,in_use = True): + """ Set profile_id in-use. Be careful when disabling a profile! """ + data = _get_data_from_data_object(data_object) + data = srb_pack("<1?",data,PROFILE_START_POSITION[profile_id]+POS_PROFILE_IN_USE,in_use) + return data, get_profile_in_use(data,profile_id) + def get_tutorial_completed(data_object,profile_id): """ Print if the profile has completed the tutorial. """ data = _get_data_from_data_object(data_object) @@ -20,12 +20,11 @@ # icon courtesy of https://icons8.com/icon/9336/aircraft # possible way to have a widget store its variable: https://stackoverflow.com/questions/63871376/tkinter-widget-cgetvariable # count number of 1s in a binary value https://stackoverflow.com/questions/8871204/count-number-of-1s-in-binary-representation/71307775#71307775 +# https://stackoverflow.com/questions/67334913/can-i-possibly-put-an-image-label-into-an-option-box-in-tkinter # Improve: -# Enable the checkbox for profile-in-use # Add reset-level-breakables # disable/gray out levels labels not reachable because of levelset_available_levels # setting that sets the background colors of the regions -# add images to option menus if possible: https://stackoverflow.com/questions/67334913/can-i-possibly-put-an-image-label-into-an-option-box-in-tkinter # Dependencies: # dep-devuan: python3-tkinter, python3-pil.imagetk # rec-devuan: python3-cairosvg @@ -95,12 +94,12 @@ class App(tk.Frame): self.silent.set(True) # data variables + # Do not use traces for most things, because it will catch itself in a loop. Instead, use the bind <Key-Enter> on the form fields. self.current_file = tk.StringVar(value = os.path.join(os.getenv("HOME"),"Documents","Snoopy vs. the Red Baron","Profile 1","Profile 1.sav")) #print(f"beginning: {self.current_file.get()}") self.checksum = tk.IntVar() self.selected_profile = tk.IntVar(value=1) self.prof1_used = tk.BooleanVar() - # Do not use traces for most things though, because it will catch itself in a loop. Instead, use the bind <Key-Enter> on the form fields. self.prof1name = tk.StringVar() self.prof1tut = tk.BooleanVar() self.prof2_used = tk.BooleanVar() @@ -174,44 +173,46 @@ class App(tk.Frame): self.frm_profiles = tk.Frame(self.master) #,background="orange",borderwidth=1) self.frm_profiles.grid(row=3,column=0,columnspan=2) # investigate radio button key-bind, up-down, to increment/decrement choice? + tk.Label(self.frm_profiles,text="Used").grid(row=0,column=2) + tk.Label(self.frm_profiles,text="Tutorial").grid(row=0,column=3) self.rad_prof1 = stk.Radiobutton(self.frm_profiles,value=1,text="Profile 1",variable=self.selected_profile,underline=8) - self.rad_prof1.grid(row=0,column=0) - self.chk_prof1_used = tk.Checkbutton(self.frm_profiles,text="used",state="disabled",variable=self.prof1_used) - self.chk_prof1_used.grid(row=0,column=2) - self.chk_prof1_tut = stk.Checkbutton(self.frm_profiles,text="tutorial",variable=self.prof1tut,func=self.load_form_into_data) + self.rad_prof1.grid(row=1,column=0) + self.chk_prof1_used = tk.Checkbutton(self.frm_profiles,variable=self.prof1_used) + self.chk_prof1_used.grid(row=1,column=2) + self.chk_prof1_tut = stk.Checkbutton(self.frm_profiles,variable=self.prof1tut,func=self.load_form_into_data) #self.hook_checkbox_enter_keys(self.chk_prof1_tut,self.load_form_into_data) - self.chk_prof1_tut.grid(row=0,column=3) + self.chk_prof1_tut.grid(row=1,column=3) self.ent_prof1name = stk.Entry(self.frm_profiles,textvariable=self.prof1name,func=self.load_form_into_data,width=11) self.ent_prof1name.bind("<Key-Return>",self.load_form_into_data) self.ent_prof1name.bind("<Key-KP_Enter>",self.load_form_into_data) - self.ent_prof1name.grid(row=0,column=4) + self.ent_prof1name.grid(row=1,column=4) self.rad_prof2 = stk.Radiobutton(self.frm_profiles,value=2,text="Profile 2",variable=self.selected_profile,underline=8) - self.rad_prof2.grid(row=1,column=0) + self.rad_prof2.grid(row=2,column=0) self.prof2_used.set(False) - self.chk_prof2_used = tk.Checkbutton(self.frm_profiles,text="used",state="disabled",variable=self.prof2_used) - self.chk_prof2_used.grid(row=1,column=2) - self.chk_prof2_tut = stk.Checkbutton(self.frm_profiles,text="tutorial",variable=self.prof2tut,func=self.load_form_into_data) + self.chk_prof2_used = tk.Checkbutton(self.frm_profiles,variable=self.prof2_used) + self.chk_prof2_used.grid(row=2,column=2) + self.chk_prof2_tut = stk.Checkbutton(self.frm_profiles,variable=self.prof2tut,func=self.load_form_into_data) #self.hook_checkbox_enter_keys(self.chk_prof2_tut,self.load_form_into_data) - self.chk_prof2_tut.grid(row=1,column=3) + self.chk_prof2_tut.grid(row=2,column=3) self.ent_prof2name = stk.Entry(self.frm_profiles,textvariable=self.prof2name,func=self.load_form_into_data,width=11) self.ent_prof2name.bind("<Key-Return>",self.load_form_into_data) - self.ent_prof2name.grid(row=1,column=4) + self.ent_prof2name.grid(row=2,column=4) self.rad_prof3 = stk.Radiobutton(self.frm_profiles,value=3,text="Profile 3",variable=self.selected_profile,underline=8) - self.rad_prof3.grid(row=2,column=0) + self.rad_prof3.grid(row=3,column=0) self.prof3_used.set(False) - self.chk_prof3_used = tk.Checkbutton(self.frm_profiles,text="used",state="disabled",variable=self.prof3_used) - self.chk_prof3_used.grid(row=2,column=2) - self.chk_prof3_tut = stk.Checkbutton(self.frm_profiles,text="tutorial",variable=self.prof3tut,func=self.load_form_into_data) + self.chk_prof3_used = tk.Checkbutton(self.frm_profiles,variable=self.prof3_used) + self.chk_prof3_used.grid(row=3,column=2) + self.chk_prof3_tut = stk.Checkbutton(self.frm_profiles,variable=self.prof3tut,func=self.load_form_into_data) #self.hook_checkbox_enter_keys(self.chk_prof3_tut,self.load_form_into_data) - self.chk_prof3_tut.grid(row=2,column=3) + self.chk_prof3_tut.grid(row=3,column=3) self.ent_prof3name = stk.Entry(self.frm_profiles,textvariable=self.prof3name,func=self.load_form_into_data,width=11) self.ent_prof3name.bind("<Key-Return>",self.load_form_into_data) - self.ent_prof3name.grid(row=2,column=4) + self.ent_prof3name.grid(row=3,column=4) #self.selected_profile.set(1) # purposefully do not set this value. # one profile, so we will have to use the value of self.selected_profile self.frm_curprof = tk.Frame(self.master) #,background="red") - self.frm_curprof.grid(row=4,column=0,rowspan=22,columnspan=2) + self.frm_curprof.grid(row=5,column=0,rowspan=22,columnspan=2) # most form fields are inside the current profile self.img_money = get_srb_image("money.png",20,16) self.lbl_money = tk.Label(self.frm_curprof,text="Money",image=self.img_money,compound="right") @@ -410,6 +411,9 @@ class App(tk.Frame): else: raise Exception("No file loaded.") try: + bdata, _ = srb_lib.set_profile_in_use(bdata,1,self.prof1_used.get()) + bdata, _ = srb_lib.set_profile_in_use(bdata,2,self.prof2_used.get()) + bdata, _ = srb_lib.set_profile_in_use(bdata,3,self.prof3_used.get()) bdata, message = srb_lib.set_name(bdata,1,self.prof1name.get()) if message != "": self.flash_entry(self.ent_prof1name) @@ -563,7 +567,10 @@ class App(tk.Frame): self.health, self.stunt, self.gun, - self.equipped_weapon + self.equipped_weapon, + self.prof1_used, + self.prof2_used, + self.prof3_used, #self.prof1name, # do not trace the profile names, because it prevents spaces ending on the variables #self.prof2name, #self.prof3name, @@ -582,6 +589,9 @@ class App(tk.Frame): self.stunt, self.gun, self.equipped_weapon, + self.prof1_used, + self.prof2_used, + self.prof3_used, ] + self.levelset_status_ints + self.level_statuses: for i in j.trace_info(): if i[0][0] == "write": |