Active stakes and Staking a drill is now being mostly rendered in the UI
This commit is contained in:
parent
d148ceba6a
commit
0dd5f2c6b6
7
data.sql
7
data.sql
@ -47,3 +47,10 @@ GROUP BY inventory_item.id;
|
||||
|
||||
SELECT inventory_item.id,store_item_id
|
||||
FROM inventory_item;
|
||||
|
||||
|
||||
SELECT staking_event.id,well_id,staking_event.source_id,
|
||||
inventory_item_id,staking_event.created_at,expiration_at
|
||||
FROM staking_event
|
||||
INNER JOIN staking_source on staking_event.source_id = staking_source.id
|
||||
WHERE staking_event.source_id = 4 AND staking_source.user_id = 1;
|
||||
|
97
mm.py
97
mm.py
@ -44,33 +44,12 @@ def get_moons():
|
||||
WHERE resource_well.source_id = ?;
|
||||
""", (sid,))
|
||||
wells = {name: (supply,timestamp) for name,supply,timestamp in cursor.fetchall()}
|
||||
staking_sources[sid] = (ts,wells)
|
||||
stakes = get_stakes(sid)
|
||||
staking_sources[sid] = (ts,wells,stakes)
|
||||
|
||||
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()
|
||||
@ -94,15 +73,14 @@ def get_stakes(source_id):
|
||||
|
||||
cursor.execute("""
|
||||
SELECT staking_event.id,well_id,staking_event.source_id,
|
||||
inventory_item_id,staking_event.created_at,expiration_at
|
||||
inventory_item_id,duration_in_mins,staking_event.created_at
|
||||
FROM staking_event
|
||||
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))
|
||||
""", (source_id, world.current_user_id))
|
||||
|
||||
fall = cursor.fetchall()
|
||||
inventory = {item[0]:item[1:] for item in fall}
|
||||
# (id, ( wellId, sourceId, invId, duration, created ))
|
||||
stakes = {item[0]:item[1:] for item in cursor.fetchall()}
|
||||
|
||||
cursor.close()
|
||||
return stakes
|
||||
@ -149,13 +127,14 @@ def buy_item(item_id):
|
||||
world.inventory = get_inventory()
|
||||
return item_id
|
||||
|
||||
def mine(source_id, item_id):
|
||||
def mine(source_id, resource, item_id):
|
||||
cursor = conn.cursor()
|
||||
|
||||
print(world.resource_to_id)
|
||||
cursor.execute("""
|
||||
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))
|
||||
INSERT INTO staking_event (source_id, well_id, inventory_item_id, duration_in_mins)
|
||||
VALUES (?, (SELECT id FROM resource_well WHERE resource_id = ? AND source_id = ?), ?, ?)
|
||||
""", (source_id, world.resource_to_id[resource], source_id, item_id, 3))
|
||||
|
||||
conn.commit()
|
||||
world.staking_sources = get_moons()
|
||||
@ -171,6 +150,7 @@ def destroy(source_id):
|
||||
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
world.staking_sources = get_moons()
|
||||
|
||||
def sell(item_id):
|
||||
cursor = conn.cursor()
|
||||
@ -238,31 +218,48 @@ def draw_moons():
|
||||
im.begin_child("Moons")
|
||||
im.columns(3, 'fileLlist')
|
||||
im.set_column_width(0, 250)
|
||||
im.set_column_width(1, 650)
|
||||
im.set_column_width(1, 600)
|
||||
im.separator()
|
||||
im.text("Moon")
|
||||
im.next_column()
|
||||
im.text("Resources")
|
||||
im.next_column()
|
||||
im.text("Created")
|
||||
im.text("Active Stakes")
|
||||
im.next_column()
|
||||
im.separator()
|
||||
|
||||
for id,(ts,wells) in world.staking_sources.items():
|
||||
for source_id,(ts,wells,stakes) in world.staking_sources.items():
|
||||
im.image(world.moon_img_tex_id, 240, 200)
|
||||
im.push_id(f"Destroy{id}")
|
||||
if im.button("Destroy"):
|
||||
destroy(source_id)
|
||||
im.pop_id()
|
||||
|
||||
im.next_column()
|
||||
for well in wells:
|
||||
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])
|
||||
|
||||
for name,(supply,ts) in wells.items():
|
||||
im.text(f"{name.capitalize()}: {supply}")
|
||||
items = [(item[0], world.store[item[1][0]][0]) for item in world.inventory.items()]
|
||||
for item_id,item_name in items:
|
||||
im.push_id(f"Mine{id}{name}")
|
||||
if im.button(item_name):
|
||||
mine(source_id, name, item_id)
|
||||
im.pop_id()
|
||||
im.same_line()
|
||||
im.same_line()
|
||||
im.text(well)
|
||||
im.spacing()
|
||||
|
||||
im.next_column()
|
||||
im.text(str(ts))
|
||||
for (sid,wid,invId,dur,start) in stakes.values():
|
||||
start_time = parse(start)
|
||||
now = datetime.datetime.utcnow().replace(microsecond=0)
|
||||
delta = now - start_time
|
||||
if im.button("Claim"):
|
||||
if delta > datetime.timedelta(minutes=dur):
|
||||
print("Passed")
|
||||
im.text(f"{world.store[world.inventory[invId][0]][0]}: {delta}")
|
||||
|
||||
im.next_column()
|
||||
|
||||
im.separator()
|
||||
|
||||
im.columns(1)
|
||||
@ -294,7 +291,7 @@ def draw_panels():
|
||||
|
||||
# Store
|
||||
im.set_next_window_position(402, 0)
|
||||
im.set_next_window_size(400, 450)
|
||||
im.set_next_window_size(500, 450)
|
||||
f = im.WINDOW_NO_RESIZE | im.WINDOW_NO_MOVE
|
||||
im.begin("Store", flags=f)
|
||||
|
||||
@ -303,8 +300,8 @@ def draw_panels():
|
||||
im.end()
|
||||
|
||||
# Inventory
|
||||
im.set_next_window_position(802, 0)
|
||||
im.set_next_window_size(400, 450)
|
||||
im.set_next_window_position(902, 0)
|
||||
im.set_next_window_size(500, 450)
|
||||
f = im.WINDOW_NO_RESIZE | im.WINDOW_NO_MOVE
|
||||
im.begin("Inventory", flags=f)
|
||||
|
||||
@ -314,7 +311,7 @@ def draw_panels():
|
||||
|
||||
# Moons
|
||||
im.set_next_window_position(0, 452)
|
||||
im.set_next_window_size(1200, 540)
|
||||
im.set_next_window_size(1400, 540)
|
||||
f = im.WINDOW_NO_RESIZE | im.WINDOW_NO_MOVE | im.WINDOW_ALWAYS_VERTICAL_SCROLLBAR
|
||||
im.begin("Moons", flags=f)
|
||||
|
||||
@ -322,7 +319,7 @@ def draw_panels():
|
||||
|
||||
im.end()
|
||||
|
||||
|