Skip to content

Commit

Permalink
Add /d:text in the deck editor
Browse files Browse the repository at this point in the history
  • Loading branch information
tspivey committed Apr 1, 2023
1 parent 6f7174e commit 9d32b0a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ygo/deck_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,25 +438,33 @@ def group_cards_combined(self, cardlist):
return full

def find_next(self, text, start, limit=None, wrapped=False):
sql = 'SELECT id FROM texts WHERE UPPERCASE(name) LIKE ? and id in (%s) ORDER BY id ASC LIMIT 1'
field = 'name'
if text.startswith('d:'):
text = text[2:]
field = 'desc'
sql = 'SELECT id FROM texts WHERE UPPERCASE(%s) LIKE ? and id in (%s) ORDER BY id ASC LIMIT 1'
if limit:
cards = globals.server.all_cards[start:start+limit]
else:
cards = globals.server.all_cards[start:]
row = self.player.cdb.execute(sql % (', '.join([str(c) for c in cards])), ('%'+text.upper()+'%', )).fetchone()
row = self.player.cdb.execute(sql % (field, ', '.join([str(c) for c in cards])), ('%'+text.upper()+'%', )).fetchone()
if row is not None:
return globals.server.all_cards.index(row[0])
if wrapped:
return
return self.find_next(text, 0, start, wrapped=True)

def find_prev(self, text, start, end=None, wrapped=False):
sql = 'SELECT id FROM texts WHERE UPPERCASE(name) LIKE ? AND id IN (%s) ORDER BY id DESC LIMIT 1'
field = 'name'
if text.startswith('d:'):
text = text[2:]
field = 'desc'
sql = 'SELECT id FROM texts WHERE UPPERCASE(%s) LIKE ? AND id IN (%s) ORDER BY id DESC LIMIT 1'
pos = start
if end is None:
end = 0
cards = globals.server.all_cards[end:start]
row = self.player.cdb.execute(sql % (', '.join([str(c) for c in cards])), ('%'+text.upper()+'%', )).fetchone()
row = self.player.cdb.execute(sql % (field, ', '.join([str(c) for c in cards])), ('%'+text.upper()+'%', )).fetchone()
if row is not None:
return globals.server.all_cards.index(row[0])
if wrapped:
Expand Down

0 comments on commit 9d32b0a

Please sign in to comment.