Restructuring how we present stakes and moons

This commit is contained in:
Joseph Ferano 2023-02-21 14:18:41 +07:00
parent 8b6cd161c2
commit d148ceba6a

44
mm.py
View File

@ -45,9 +45,32 @@ def get_moons():
""", (sid,))
wells = {name: (supply,timestamp) for name,supply,timestamp in cursor.fetchall()}
staking_sources[sid] = (ts,wells)
cursor.close()
return staking_sources
def get_stakes(source_id):
cursor = conn.cursor()
stakes = {}
for id in staking_sources:
cursor.execute("""
SELECT staking_source.id,staking_event.id,well_id,staking_event.source_id,
inventory_item_id,staking_event.created_at,expiration_at
FROM staking_event
INNER JOIN resource_well ON resource_well.id = well_id
INNER JOIN resource_well ON resource_well.id = well_id
INNER JOIN staking_source on staking_event.source_id = staking_source.id
WHERE staking_event.source_id = ? AND staking_source.user_id = ?;
""", (source_id,current_user_id))
inventory = {item[0]:item[1:] for item in cursor.fetchall()}
staking_sources[id] = (*staking_sources[id],stakes)
cursor.close()
return stakes
def get_inventory():
inventory = {}
cursor = conn.cursor()
@ -84,7 +107,6 @@ def get_stakes(source_id):
cursor.close()
return stakes
def mint():
cursor = conn.cursor()
rand_hash = "%010x" % random.randrange(16 ** 16)
@ -127,17 +149,16 @@ def buy_item(item_id):
world.inventory = get_inventory()
return item_id
def mine(a,b,user_data):
source_id,well_name = user_data
def mine(source_id, item_id):
cursor = conn.cursor()
cursor.execute("""
INSERT INTO staking_event (source_id, well_id)
VALUES (?, ?)
""", (source_id, resource_to_id[well_name]))
INSERT INTO staking_event (source_id, well_id, inventory_item_id)
VALUES (?, (SELECT well_id FROM inventory_item WHERE inventory_item.id = ?), ?)
""", (source_id, item_id, item_id))
conn.commit()
get_moons()
world.staking_sources = get_moons()
cursor.close()
def upgrade(a,b,user_data):
@ -231,7 +252,12 @@ def draw_moons():
im.image(world.moon_img_tex_id, 240, 200)
im.next_column()
for well in wells:
im.button("Mine")
for item_id,(sid,tier) in world.inventory.items():
im.push_id(f"Inv-Item{item_id}")
if im.button(f"Mine {world.store[sid][0].split()[1]}"):
mine(id, world.inventory[0])
im.pop_id()
im.same_line()
im.same_line()
im.text(well)
im.next_column()
@ -307,6 +333,7 @@ class World:
store = dict()
inventory = dict()
staking_sources = dict()
stakes = dict()
moon_img_tex_id = -1
world = World()
@ -328,6 +355,7 @@ world.bank = get_bank()
world.store = get_store_items()
world.inventory = get_inventory()
world.staking_sources = get_moons()
# world.stakes = get_stakes()
def imgui_init():
world.moon_img_tex_id = texture_id = load_texture("moon.png")