Create and destroy moons
This commit is contained in:
parent
c164d563d0
commit
852f134e47
43
mm.py
43
mm.py
@ -76,6 +76,7 @@ def mint():
|
|||||||
rand_hash = "%010x" % random.randrange(16 ** 16)
|
rand_hash = "%010x" % random.randrange(16 ** 16)
|
||||||
|
|
||||||
cursor.execute('BEGIN')
|
cursor.execute('BEGIN')
|
||||||
|
source_id = -1
|
||||||
try:
|
try:
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
INSERT INTO staking_source (user_id, address) VALUES (?, ?)
|
INSERT INTO staking_source (user_id, address) VALUES (?, ?)
|
||||||
@ -94,7 +95,8 @@ def mint():
|
|||||||
conn.rollback()
|
conn.rollback()
|
||||||
finally:
|
finally:
|
||||||
cursor.close()
|
cursor.close()
|
||||||
get_moons()
|
|
||||||
|
return source_id
|
||||||
|
|
||||||
def buy_item(item_id):
|
def buy_item(item_id):
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
@ -167,12 +169,21 @@ def get_store_ui():
|
|||||||
disabled=owned)])
|
disabled=owned)])
|
||||||
return store_ui
|
return store_ui
|
||||||
|
|
||||||
def inventory_row(id, si_id, tier):
|
def inventory_row(item_id, si_id, tier):
|
||||||
name = store[si_id][0]
|
name = store[si_id][0]
|
||||||
row = [sg.Text(f"{name} - Tier {tier+1}"),
|
row = [sg.Text(f"{name} - Tier {tier+1}"),
|
||||||
sg.Button("Upgrade", key=("-UPGRADE-",id)),
|
sg.Button("Upgrade", key=("-UPGRADE-",item_id)),
|
||||||
sg.Button("Sell", key=("-SELL-",id))]
|
sg.Button("Sell", key=("-SELL-",item_id))]
|
||||||
return [sg.pin(sg.Column([row], key=("-IROW-",id)))]
|
return [sg.pin(sg.Column([row], key=("-IROW-",item_id)))]
|
||||||
|
|
||||||
|
def moon_row(id,source):
|
||||||
|
wells_ui = []
|
||||||
|
for name,(supply,ts) in source[1].items():
|
||||||
|
wells_ui.append(sg.Text(name))
|
||||||
|
row = [sg.Image("moon.png"),
|
||||||
|
sg.Column(layout=[wells_ui]),
|
||||||
|
sg.Button("Destroy", key=("-DESTROY-",id))]
|
||||||
|
return [sg.pin(sg.Column([row], key=("-MROW-",id)))]
|
||||||
|
|
||||||
def get_inventory_ui():
|
def get_inventory_ui():
|
||||||
inventory_ui = []
|
inventory_ui = []
|
||||||
@ -185,12 +196,7 @@ def get_sources_ui():
|
|||||||
staking_sources = get_moons()
|
staking_sources = get_moons()
|
||||||
sources_ui = []
|
sources_ui = []
|
||||||
for id,source in staking_sources.items():
|
for id,source in staking_sources.items():
|
||||||
wells_ui = []
|
sources_ui.append(moon_row(id,source))
|
||||||
for name,(supply,ts) in source[1].items():
|
|
||||||
wells_ui.append(sg.Text(name))
|
|
||||||
sources_ui.append([sg.Image("moon.png"),
|
|
||||||
sg.Column(layout=[wells_ui]),
|
|
||||||
sg.Button("Destroy", key=("-DESTROY-",id))])
|
|
||||||
return sources_ui
|
return sources_ui
|
||||||
|
|
||||||
layout = [
|
layout = [
|
||||||
@ -200,10 +206,10 @@ layout = [
|
|||||||
[sg.Button("Sell All", key="-SELLALL-")],
|
[sg.Button("Sell All", key="-SELLALL-")],
|
||||||
[sg.HorizontalSeparator()],
|
[sg.HorizontalSeparator()],
|
||||||
[[sg.Column(get_store_ui(), size=(400, 280),),
|
[[sg.Column(get_store_ui(), size=(400, 280),),
|
||||||
sg.Column(get_inventory_ui(), key="-COL-", vertical_alignment='t')]],
|
sg.Column(get_inventory_ui(), key="-ICOL-", vertical_alignment='t')]],
|
||||||
[sg.HorizontalSeparator()],
|
[sg.HorizontalSeparator()],
|
||||||
[sg.Button("Mint Moon", key="-MINT-")],
|
[sg.Button("Mint Moon", key="-MINT-")],
|
||||||
[sg.Column(layout=get_sources_ui(), size=(1200, 500),
|
[sg.Column(layout=get_sources_ui(), key="-MCOL-", size=(1200, 500),
|
||||||
scrollable=True, vertical_scroll_only=True)]
|
scrollable=True, vertical_scroll_only=True)]
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -216,7 +222,6 @@ while True:
|
|||||||
elif type(event) is tuple:
|
elif type(event) is tuple:
|
||||||
if event[0] == "-UPGRADE-":
|
if event[0] == "-UPGRADE-":
|
||||||
sg.Window.Layout([[sg.Text("IT WORKED")]])
|
sg.Window.Layout([[sg.Text("IT WORKED")]])
|
||||||
print('asdf')
|
|
||||||
elif event[0] == "-SELL-":
|
elif event[0] == "-SELL-":
|
||||||
id = event[1]
|
id = event[1]
|
||||||
inv = get_inventory()
|
inv = get_inventory()
|
||||||
@ -227,12 +232,16 @@ while True:
|
|||||||
id = event[1]
|
id = event[1]
|
||||||
item_id = buy_item(id)
|
item_id = buy_item(id)
|
||||||
window[("-BUY-",id)].update(disabled=True)
|
window[("-BUY-",id)].update(disabled=True)
|
||||||
window.extend_layout(window["-COL-"], [inventory_row(item_id,id,0)])
|
window.extend_layout(window["-ICOL-"], [inventory_row(item_id,id,0)])
|
||||||
elif event[0] == "-DESTROY-":
|
elif event[0] == "-DESTROY-":
|
||||||
destroy(event[1])
|
id = event[1]
|
||||||
|
destroy(id)
|
||||||
|
window[("-MROW-",id)].update(visible=False)
|
||||||
else:
|
else:
|
||||||
if event == "-MINT-":
|
if event == "-MINT-":
|
||||||
mint()
|
id = mint()
|
||||||
|
moons = get_moons()
|
||||||
|
window.extend_layout(window["-MCOL-"], [moon_row(id,moons[id])])
|
||||||
elif event.startswith("Mine-"):
|
elif event.startswith("Mine-"):
|
||||||
print("Mine")
|
print("Mine")
|
||||||
elif event == "-SELLALL-":
|
elif event == "-SELLALL-":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user