Skip to content

Commit

Permalink
Fix for command line parameters not checking compatible cardsets
Browse files Browse the repository at this point in the history
  • Loading branch information
joeraz committed Oct 18, 2024
1 parent cc32c03 commit 910f927
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
14 changes: 8 additions & 6 deletions pysollib/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,11 +812,13 @@ def loadCardset(self, cs, id=0, update=7, progress=None,

def checkCompatibleCardsetType(self, gi, cs):
assert gi is not None
assert cs is not None
cs_type = "None"
cs_subtype = "None"
gc = gi.category
gs = gi.subcategory
cs_type = cs.si.type
cs_subtype = cs.si.subtype
if cs is not None:
cs_type = cs.si.type
cs_subtype = cs.si.subtype
t0, t1 = None, None
if gc == GI.GC_FRENCH:
t0 = "French"
Expand Down Expand Up @@ -908,22 +910,22 @@ def getCompatibleCardset(self, gi, cs, trychange=True):
# ask
return None, 0, t

def requestCompatibleCardsetType(self, id):
def requestCompatibleCardsetType(self, id, progress=None):
gi = self.getGameInfo(id)
#
cs, cs_update_flag, t = self.getCompatibleCardset(gi, self.cardset)
if cs is self.cardset:
return 0
if cs is not None:
self.loadCardset(cs, update=1)
self.loadCardset(cs, update=1, progress=progress)
return 1

self.requestCompatibleCardsetTypeDialog(self.cardset, gi, t)

cs = self.__selectCardsetDialog(t)
if cs is None:
return -1
self.loadCardset(cs, id=id)
self.loadCardset(cs, id=id, progress=progress)
return 1

def requestCompatibleCardsetTypeDialog(self, cardset, gi, t):
Expand Down
52 changes: 36 additions & 16 deletions pysollib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def parse_option(argv):
for i in optlist:
if i[0] in ("-h", "--help"):
opts["help"] = True
elif i[0] in ("--deal"):
elif i[0] == "--deal":
opts["deal"] = i[1]
elif i[0] in ("-g", "--game"):
opts["game"] = i[1]
Expand All @@ -127,11 +127,12 @@ def parse_option(argv):
if opts["help"]:
print(_("""Usage: %s [OPTIONS] [FILE]
-g --game=GAMENAME start game GAMENAME
-i --gameid=GAMEID
--french-only
--sound-mod=MOD
-i --gameid=GAMEID start game with ID GAMEID
--deal=DEAL start game deal by number DEAL
--french-only disable non-french games
--sound-mod=MOD use a certain sound module
--nosound disable sound support
--noplugins disable load plugins
--noplugins disable loading plugins
-h --help display this help and exit
FILE - file name of a saved game
Expand Down Expand Up @@ -403,19 +404,38 @@ def progressCallback(*args):
app.loadImages3()
app.loadImages4()

# load cardset
startgameid = app.opt.last_gameid

if app.commandline.loadgame:
pass
elif app.commandline.game is not None:
gameid = app.gdb.getGameByName(app.commandline.game)
if gameid is None:
print_err(_("can't find game: %(game)s") % {
'game': app.commandline.game})
sys.exit(-1)
else:
startgameid = gameid
elif app.commandline.gameid is not None:
startgameid = app.commandline.gameid

progress = app.intro.progress
if not app.loadCardset(cardset, progress=progress, id=app.opt.last_gameid):
if not cardset:
for cardset in app.cardset_manager.getAll():
progress.reset()
# load cardset
if startgameid != app.opt.last_gameid:
success = app.requestCompatibleCardsetType(startgameid,
progress=progress)
else:
success = app.loadCardset(cardset, progress=progress, id=startgameid)
if not success and not cardset:
for cardset in app.cardset_manager.getAll():
progress.reset()

if app.loadCardset(cardset, progress=progress,
id=app.opt.last_gameid):
break
else:
fatal_no_cardsets(app)
return 3
if app.loadCardset(cardset, progress=progress,
id=startgameid):
break
else:
fatal_no_cardsets(app)
return 3

# ok
return 0
Expand Down

0 comments on commit 910f927

Please sign in to comment.