Compare commits
No commits in common. "9cd7646805c1d13063bf1bdbb837aa10ada1dbf1" and "7c128cc540d6cd07dfee44b5720bd9c03cd34f38" have entirely different histories.
9cd7646805
...
7c128cc540
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1 @@
|
|||||||
/__pycache__/
|
/__pycache__/
|
||||||
/mm.db
|
|
||||||
|
@ -54,7 +54,7 @@ class ImguiWindow():
|
|||||||
|
|
||||||
# Load a new font
|
# Load a new font
|
||||||
io = im.get_io()
|
io = im.get_io()
|
||||||
new_font = io.fonts.add_font_from_file_ttf("./fira.ttf", 24)
|
new_font = io.fonts.add_font_from_file_ttf("/usr/share/fonts/TTF/RobotoMono-Regular.ttf", 24)
|
||||||
impl.refresh_font_texture()
|
impl.refresh_font_texture()
|
||||||
|
|
||||||
init_fn()
|
init_fn()
|
||||||
|
50
data.sql
50
data.sql
@ -12,18 +12,52 @@ INSERT INTO users(name) VALUES
|
|||||||
('Plug'),
|
('Plug'),
|
||||||
('Upgrade');
|
('Upgrade');
|
||||||
|
|
||||||
INSERT INTO resource_account(user_id, resource_id, balance) VALUES
|
|
||||||
|
INSERT INTO bank_account(user_id, resource_id, balance) VALUES
|
||||||
(1, 1, 200),
|
(1, 1, 200),
|
||||||
(1, 2, 175),
|
(1, 2, 175),
|
||||||
(1, 3, 0),
|
(1, 3, 0),
|
||||||
(1, 4, 25),
|
(1, 4, 25),
|
||||||
(1, 5, 10);
|
(1, 5, 10);
|
||||||
|
|
||||||
INSERT INTO bank_account(user_id, balance) VALUES (1, 500);
|
INSERT INTO store_item(name, currency, target_resource, price, claim_amount) VALUES
|
||||||
|
('Drill 1A', 1, 1, 25, 500),
|
||||||
|
('Drill 1B', 1, 2, 25, 500),
|
||||||
|
('Drill 1C', 1, 3, 25, 500),
|
||||||
|
('Drill 1D', 1, 4, 25, 500),
|
||||||
|
('Drill 1E', 1, 5, 25, 500);
|
||||||
|
|
||||||
INSERT INTO store_item(name, price, claim_amount, completion_time_mins) VALUES
|
SELECT staking_event.id,well_id,staking_event.source_id,
|
||||||
('Drill A', 25, 50, 2),
|
inventory_item_id,staking_event.created_at,expiration_at
|
||||||
('Drill B', 25, 50, 2),
|
FROM staking_event
|
||||||
('Drill C', 25, 50, 2),
|
INNER JOIN resource_well ON resource_well.id = well_id
|
||||||
('Drill D', 25, 50, 2),
|
INNER JOIN staking_source on staking_event.source_id = staking_source.id
|
||||||
('Drill E', 25, 50, 2);
|
WHERE staking_event.source_id = ? AND staking_source.user_id = ?;
|
||||||
|
|
||||||
|
SELECT name,init_supply
|
||||||
|
FROM resource_well
|
||||||
|
INNER JOIN resource ON resource.id = resource_well.resource_id
|
||||||
|
WHERE source_id = 1;
|
||||||
|
|
||||||
|
SELECT inventory_item.id,store_item_id, COUNT(upgrade_event.id) as upgrades
|
||||||
|
FROM inventory_item
|
||||||
|
LEFT JOIN upgrade_event ON inventory_item.id = upgrade_event.inventory_item_id
|
||||||
|
WHERE inventory_item.user_id = 1
|
||||||
|
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;
|
||||||
|
|
||||||
|
SELECT staking_event.id, staking_event.well_id, staking_event.source_id,
|
||||||
|
staking_event.inventory_item_id, staking_event.duration_in_mins,
|
||||||
|
staking_event.created_at
|
||||||
|
FROM staking_event
|
||||||
|
LEFT JOIN claim_event ON staking_event.id = claim_event.staking_event_id
|
||||||
|
WHERE staking_event.source_id = 4 AND claim_event.staking_event_id IS NULL;
|
||||||
|
318
mm.py
318
mm.py
@ -1,6 +1,7 @@
|
|||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import sqlite3 as sql
|
import sqlite3 as sql
|
||||||
|
import PySimpleGUI as sg
|
||||||
from ImguiWindow import ImguiWindow, load_texture
|
from ImguiWindow import ImguiWindow, load_texture
|
||||||
import glfw
|
import glfw
|
||||||
import imgui as im
|
import imgui as im
|
||||||
@ -10,104 +11,41 @@ import datetime
|
|||||||
def get_bank():
|
def get_bank():
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT resource_account.id,resource.name,balance FROM resource_account
|
SELECT resource.name,balance FROM bank_account
|
||||||
INNER JOIN resource ON resource.id = resource_account.resource_id
|
INNER JOIN resource ON resource.id = bank_account.resource_id
|
||||||
WHERE user_id = ?
|
WHERE user_id = ?
|
||||||
""", (world.current_user_id,))
|
""", (world.current_user_id,))
|
||||||
resources = {id:(name, balance) for id,name,balance in cursor.fetchall()}
|
bank = {name: balance for name,balance in cursor.fetchall()}
|
||||||
cursor.execute("SELECT bank_account.id,balance FROM bank_account WHERE user_id = ?",
|
|
||||||
(world.current_user_id,))
|
|
||||||
bank = cursor.fetchone()
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return (bank, resources)
|
return bank
|
||||||
|
|
||||||
def get_store_items():
|
def get_store_items():
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT store_item.id, store_item.name, price, claim_amount, completion_time_mins
|
SELECT store_item.id,store_item.name,resource.name,price,claim_amount FROM store_item
|
||||||
FROM store_item
|
INNER JOIN resource ON resource.id = currency
|
||||||
""")
|
""")
|
||||||
items = {item[0]:item[1:] for item in cursor.fetchall()}
|
items = {item[0]:item[1:] for item in cursor.fetchall()}
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def get_stakes():
|
def get_moons():
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("SELECT id,created_at FROM staking_source")
|
||||||
|
|
||||||
|
staking_sources = {}
|
||||||
|
for i,(sid,ts) in enumerate(cursor.fetchall()):
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT staking_event.id, well_id, inventory_item_id, stake_amount, duration_in_mins,
|
SELECT name,supply,staking_event.created_at
|
||||||
staking_event.created_at,
|
|
||||||
CASE WHEN claim_event.staking_event_id IS NULL THEN 1 ELSE 0 END AS is_active
|
|
||||||
FROM staking_event
|
|
||||||
INNER JOIN resource_well ON resource_well.id = staking_event.well_id
|
|
||||||
INNER JOIN staking_source ON staking_source.id = resource_well.source_id
|
|
||||||
LEFT JOIN claim_event ON claim_event.staking_event_id = staking_event.id
|
|
||||||
WHERE staking_source.user_id = ?;
|
|
||||||
""", (world.current_user_id,))
|
|
||||||
|
|
||||||
stakes = {item[0]:(item[1],item[2],item[3],item[4],bool(item[-1])) for item in cursor.fetchall()}
|
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
return stakes
|
|
||||||
|
|
||||||
# An active stake is basically defined as one that has yet to be claimed
|
|
||||||
def get_active_stakes(source_id):
|
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
cursor.execute("""
|
|
||||||
SELECT staking_event.id, well_id, inventory_item_id, stake_amount, duration_in_mins,
|
|
||||||
staking_event.created_at
|
|
||||||
FROM staking_event
|
|
||||||
LEFT JOIN claim_event ON staking_event.id = claim_event.staking_event_id
|
|
||||||
INNER JOIN resource_well ON resource_well.id = staking_event.well_id
|
|
||||||
WHERE resource_well.source_id = ? AND claim_event.staking_event_id IS NULL;
|
|
||||||
""", (source_id,))
|
|
||||||
|
|
||||||
active_stakes = {item[0]:item[1:] for item in cursor.fetchall()}
|
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
return active_stakes
|
|
||||||
|
|
||||||
def get_wells(source_id):
|
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
cursor.execute("""
|
|
||||||
SELECT resource_well.id,name,supply,staking_event.created_at
|
|
||||||
FROM resource_well
|
FROM resource_well
|
||||||
INNER JOIN resource ON resource.id = resource_well.resource_id
|
INNER JOIN resource ON resource.id = resource_well.resource_id
|
||||||
LEFT JOIN staking_event ON staking_event.well_id = resource_well.id
|
LEFT JOIN staking_event ON staking_event.well_id = resource_well.id
|
||||||
WHERE resource_well.source_id = ?;
|
WHERE resource_well.source_id = ?;
|
||||||
""", (source_id,))
|
""", (sid,))
|
||||||
|
wells = {name: (supply,timestamp) for name,supply,timestamp in cursor.fetchall()}
|
||||||
wells = {id: (name,supply,timestamp) for id,name,supply,timestamp in cursor.fetchall()}
|
stakes = get_active_stakes(sid)
|
||||||
|
staking_sources[sid] = (ts,wells,stakes)
|
||||||
cursor.close()
|
|
||||||
return wells
|
|
||||||
|
|
||||||
def get_all_wells():
|
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
cursor.execute("""
|
|
||||||
SELECT resource_well.id,name,supply FROM resource_well
|
|
||||||
INNER JOIN resource ON resource.id = resource_well.resource_id
|
|
||||||
INNER JOIN staking_source ON staking_source.id = resource_well.source_id
|
|
||||||
WHERE staking_source.user_id = ?;
|
|
||||||
""", (world.current_user_id,))
|
|
||||||
|
|
||||||
wells = {w[0]:w[1:] for w in cursor.fetchall()}
|
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
return wells
|
|
||||||
|
|
||||||
def get_moons():
|
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
cursor.execute("SELECT id,created_at FROM staking_source WHERE user_id = ?",
|
|
||||||
(world.current_user_id,))
|
|
||||||
|
|
||||||
staking_sources = {}
|
|
||||||
for sid,ts in cursor.fetchall():
|
|
||||||
staking_sources[sid] = (ts, get_wells(sid), get_active_stakes(sid))
|
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return staking_sources
|
return staking_sources
|
||||||
@ -128,6 +66,42 @@ def get_inventory():
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
return inventory
|
return inventory
|
||||||
|
|
||||||
|
# An active stake is basically defined as one that has yet to be claimed
|
||||||
|
def get_active_stakes(source_id):
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT staking_event.id, staking_event.source_id, staking_event.well_id,
|
||||||
|
staking_event.inventory_item_id, staking_event.duration_in_mins,
|
||||||
|
staking_event.created_at
|
||||||
|
FROM staking_event
|
||||||
|
LEFT JOIN claim_event ON staking_event.id = claim_event.staking_event_id
|
||||||
|
WHERE staking_event.source_id = ? AND claim_event.staking_event_id IS NULL;
|
||||||
|
""", (source_id,))
|
||||||
|
|
||||||
|
active_stakes = {item[0]:item[1:] for item in cursor.fetchall()}
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
return active_stakes
|
||||||
|
|
||||||
|
|
||||||
|
def get_stakes(source_id):
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT staking_event.id,well_id,staking_event.source_id,
|
||||||
|
inventory_item_id,duration_in_mins,staking_event.created_at
|
||||||
|
FROM staking_event
|
||||||
|
INNER JOIN staking_source on staking_event.source_id = staking_source.id
|
||||||
|
WHERE staking_event.source_id = ? AND staking_source.user_id = ?;
|
||||||
|
""", (source_id, world.current_user_id))
|
||||||
|
|
||||||
|
# (id, ( wellId, sourceId, invId, duration, created ))
|
||||||
|
stakes = {item[0]:item[1:] for item in cursor.fetchall()}
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
return stakes
|
||||||
|
|
||||||
def mint():
|
def mint():
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
rand_hash = "%010x" % random.randrange(16 ** 16)
|
rand_hash = "%010x" % random.randrange(16 ** 16)
|
||||||
@ -159,106 +133,44 @@ def mint():
|
|||||||
def buy_item(item_id):
|
def buy_item(item_id):
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
cost = world.store[item_id][1]
|
|
||||||
if cost > world.bank[0][1]:
|
|
||||||
print(f"Not enough money: Bank {world.bank[0][1]} < Cost {cost}")
|
|
||||||
return -1
|
|
||||||
|
|
||||||
cursor.execute('BEGIN')
|
|
||||||
try:
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
INSERT INTO inventory_item (user_id, store_item_id) VALUES (?, ?)
|
INSERT INTO inventory_item (user_id, store_item_id)
|
||||||
|
VALUES (?, ?)
|
||||||
""", (world.current_user_id, item_id))
|
""", (world.current_user_id, item_id))
|
||||||
cursor.execute("""
|
|
||||||
UPDATE bank_account SET balance = balance - ? WHERE bank_account.id = ?
|
|
||||||
""", (cost, world.bank[0][0]))
|
|
||||||
except sql.Error as error:
|
|
||||||
conn.rollback()
|
|
||||||
finally:
|
|
||||||
item_id = cursor.lastrowid
|
item_id = cursor.lastrowid
|
||||||
conn.commit()
|
conn.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
world.inventory = get_inventory()
|
world.inventory = get_inventory()
|
||||||
world.bank = get_bank()
|
|
||||||
return item_id
|
return item_id
|
||||||
|
|
||||||
def sell_item(item_id):
|
def mine(source_id, resource, item_id):
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
cost = world.store[world.inventory[item_id][0]][1]
|
|
||||||
cursor.execute('BEGIN')
|
|
||||||
try:
|
|
||||||
# TODO: We have to cascade delete stakes and claims after this
|
|
||||||
cursor.execute("DELETE FROM inventory_item WHERE user_id = ? AND id = ?",
|
|
||||||
(world.current_user_id, item_id))
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
UPDATE bank_account SET balance = balance + ? WHERE bank_account.id = ?
|
INSERT INTO staking_event (source_id, well_id, inventory_item_id, duration_in_mins)
|
||||||
""", (cost, world.bank[0][0]))
|
VALUES (?, (SELECT id FROM resource_well WHERE resource_id = ? AND source_id = ?), ?, ?)
|
||||||
except sql.Error as error:
|
""", (source_id, world.resource_to_id[resource], source_id, item_id, 3))
|
||||||
conn.rollback()
|
|
||||||
finally:
|
|
||||||
conn.commit()
|
|
||||||
cursor.close()
|
|
||||||
world.inventory = get_inventory()
|
|
||||||
world.bank = get_bank()
|
|
||||||
|
|
||||||
def mine(well_id, item_id):
|
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
store_item = world.store[world.inventory[item_id][0]]
|
|
||||||
cursor.execute("""
|
|
||||||
INSERT INTO staking_event (well_id, inventory_item_id, stake_amount, duration_in_mins)
|
|
||||||
VALUES (?, ?, ?, ?)
|
|
||||||
""", (well_id, item_id, store_item[2], store_item[3]))
|
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
world.staking_sources = get_moons()
|
world.staking_sources = get_moons()
|
||||||
world.stakes = get_stakes()
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
def claim(staking_event_id):
|
def claim(staking_event_id):
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
claim_amount = world.stakes[staking_event_id][2]
|
|
||||||
well_id = world.stakes[staking_event_id][0]
|
|
||||||
try:
|
|
||||||
cursor.execute("SELECT supply FROM resource_well WHERE id = ?",
|
|
||||||
(well_id,))
|
|
||||||
supply = cursor.fetchone()[0]
|
|
||||||
claim_amount = claim_amount if supply >= claim_amount else supply
|
|
||||||
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
UPDATE resource_well SET supply = supply - ? WHERE resource_well.id = ?
|
INSERT INTO claim_event (claim_amount, staking_event_id)
|
||||||
""", (claim_amount, well_id))
|
VALUES (?, ?)
|
||||||
|
""", (10, staking_event_id))
|
||||||
|
|
||||||
cursor.execute("INSERT INTO claim_event (claim_amount, staking_event_id) VALUES (?, ?)",
|
|
||||||
(claim_amount, staking_event_id))
|
|
||||||
|
|
||||||
cursor.execute("""
|
|
||||||
WITH w_res_id AS (SELECT resource_id FROM resource_well WHERE id = ?)
|
|
||||||
UPDATE resource_account SET balance = balance + ?
|
|
||||||
FROM w_res_id
|
|
||||||
WHERE resource_account.user_id = ?
|
|
||||||
AND resource_account.resource_id = w_res_id.resource_id
|
|
||||||
""", (well_id, claim_amount, world.current_user_id))
|
|
||||||
except sql.Error as error:
|
|
||||||
print(error)
|
|
||||||
conn.rollback()
|
|
||||||
finally:
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
world.stakes = get_stakes()
|
|
||||||
world.staking_sources = get_moons()
|
world.staking_sources = get_moons()
|
||||||
world.bank = get_bank()
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
def upgrade(item_id):
|
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
cursor.execute("INSERT INTO upgrade_event (inventory_item_id) VALUES (?)", (item_id,))
|
def upgrade(a,b,user_data):
|
||||||
|
()
|
||||||
conn.commit()
|
|
||||||
world.inventory = get_inventory()
|
|
||||||
cursor.close()
|
|
||||||
|
|
||||||
def destroy(source_id):
|
def destroy(source_id):
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
@ -269,6 +181,16 @@ def destroy(source_id):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
world.staking_sources = get_moons()
|
world.staking_sources = get_moons()
|
||||||
|
|
||||||
|
def sell(item_id):
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("DELETE FROM inventory_item WHERE user_id = ? AND id = ?",
|
||||||
|
(world.current_user_id, item_id))
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
cursor.close()
|
||||||
|
world.inventory = get_inventory()
|
||||||
|
|
||||||
def sell_all():
|
def sell_all():
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
@ -278,60 +200,26 @@ def sell_all():
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
world.inventory = get_inventory()
|
world.inventory = get_inventory()
|
||||||
|
|
||||||
def trade():
|
|
||||||
cursor = conn.cursor()
|
|
||||||
|
|
||||||
cursor.execute("""
|
|
||||||
UPDATE resource_account SET balance = balance - ? WHERE resource_account.user_id = ?
|
|
||||||
""", (10, world.current_user_id))
|
|
||||||
|
|
||||||
cursor.execute("""
|
|
||||||
UPDATE bank_account SET balance = balance + ? WHERE bank_account.user_id = ?
|
|
||||||
""", (1, world.current_user_id))
|
|
||||||
|
|
||||||
conn.commit()
|
|
||||||
cursor.close()
|
|
||||||
world.bank = get_bank()
|
|
||||||
|
|
||||||
|
|
||||||
def draw_dashboard():
|
def draw_dashboard():
|
||||||
im.text(f"Current User: {world.current_user}")
|
im.text(f"Current User: {world.current_user}")
|
||||||
for _ in range(5):
|
|
||||||
im.spacing()
|
|
||||||
im.text(f"Moon Bucks: {world.bank[0][1]}")
|
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
im.spacing()
|
im.spacing()
|
||||||
for id,(name,balance) in world.bank[1].items():
|
for name,balance in world.bank.items():
|
||||||
im.text(f"{name.capitalize()}: {balance}")
|
im.text(f"{name.capitalize()}: {balance}")
|
||||||
|
|
||||||
for _ in range(10):
|
|
||||||
im.spacing()
|
|
||||||
|
|
||||||
resources = world.bank[1]
|
|
||||||
can_sell = True
|
|
||||||
for _,supply in resources.values():
|
|
||||||
if supply < 10:
|
|
||||||
can_sell = False
|
|
||||||
im.text("Sell 10 resources for 1 Moon Bucks")
|
|
||||||
if can_sell:
|
|
||||||
if im.button("Sell"):
|
|
||||||
trade()
|
|
||||||
else:
|
|
||||||
im.text("Sell (Not enough funds)")
|
|
||||||
|
|
||||||
def draw_store():
|
def draw_store():
|
||||||
for id,(name,price,claim,duration) in world.store.items():
|
for id,(name,resource,price,claim) in world.store.items():
|
||||||
owned = False
|
owned = False
|
||||||
for (store_item_id,_) in world.inventory.values():
|
for (store_item_id,_) in world.inventory.values():
|
||||||
if id == store_item_id:
|
if id == store_item_id:
|
||||||
owned = True
|
owned = True
|
||||||
im.text(f"{name}: Mine {claim} in {duration} mins")
|
im.text(f"{name}: Mine {claim} {resource.capitalize()}")
|
||||||
|
|
||||||
if owned:
|
if owned:
|
||||||
im.text_disabled(f"Buy {price}")
|
im.text_disabled(f"Buy {price} {resource[0:3]}")
|
||||||
else:
|
else:
|
||||||
im.push_id(f"Buy{id}")
|
im.push_id(f"Buy{id}")
|
||||||
if im.button(f"Buy {price}"):
|
if im.button(f"Buy {price} {resource[0:3]}"):
|
||||||
buy_item(id)
|
buy_item(id)
|
||||||
im.pop_id()
|
im.pop_id()
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
@ -339,15 +227,15 @@ def draw_store():
|
|||||||
|
|
||||||
def draw_inventory():
|
def draw_inventory():
|
||||||
for id,(sid,tier) in world.inventory.items():
|
for id,(sid,tier) in world.inventory.items():
|
||||||
im.text(f"{world.store[sid][0]} - Tier {tier+1}")
|
im.text(f"{id} - {world.store[sid][0]} - Tier {tier+1}")
|
||||||
im.push_id(f"Upgrade{id}")
|
im.push_id(f"Upgrade{id}")
|
||||||
if im.button("Upgrade"):
|
if im.button("Upgrade"):
|
||||||
upgrade(id)
|
print("Upgrade")
|
||||||
im.pop_id()
|
im.pop_id()
|
||||||
im.same_line()
|
im.same_line()
|
||||||
im.push_id(f"Sell{id}")
|
im.push_id(f"Sell{id}")
|
||||||
if im.button("Sell"):
|
if im.button("Sell"):
|
||||||
sell_item(id)
|
sell(id)
|
||||||
im.pop_id()
|
im.pop_id()
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
im.spacing()
|
im.spacing()
|
||||||
@ -371,46 +259,37 @@ def draw_moons():
|
|||||||
|
|
||||||
for source_id,(ts,wells,stakes) 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.image(world.moon_img_tex_id, 240, 200)
|
||||||
im.push_id(f"Destroy{source_id}")
|
im.push_id(f"Destroy{id}")
|
||||||
if im.button("Destroy"):
|
if im.button("Destroy"):
|
||||||
destroy(source_id)
|
destroy(source_id)
|
||||||
im.pop_id()
|
im.pop_id()
|
||||||
|
|
||||||
im.next_column()
|
im.next_column()
|
||||||
|
|
||||||
for well_id,(name,supply,ts) in wells.items():
|
for name,(supply,ts) in wells.items():
|
||||||
im.text(f"{name.capitalize()}: {supply}")
|
im.text(f"{name.capitalize()}: {supply}")
|
||||||
for item_id,(store_id,_) in world.inventory.items():
|
items = [(item[0], world.store[item[1][0]][0]) for item in world.inventory.items()]
|
||||||
item_name = world.store[store_id][0]
|
for item_id,item_name in items:
|
||||||
skip = False
|
im.push_id(f"Mine{id}{name}")
|
||||||
for ss in world.stakes.values():
|
|
||||||
if ss[1] == item_id and ss[4] == True or supply == 0:
|
|
||||||
skip = True
|
|
||||||
if skip == True:
|
|
||||||
continue
|
|
||||||
im.push_id(f"Mine{well_id}")
|
|
||||||
if im.button(item_name):
|
if im.button(item_name):
|
||||||
mine(well_id, item_id)
|
mine(source_id, name, item_id)
|
||||||
im.pop_id()
|
im.pop_id()
|
||||||
im.same_line()
|
im.same_line()
|
||||||
im.spacing()
|
im.spacing()
|
||||||
|
|
||||||
im.next_column()
|
im.next_column()
|
||||||
for stake_id,(well_id,invId,amount,dur,start) in stakes.items():
|
for stake_id,(source_id,wid,invId,dur,start) in stakes.items():
|
||||||
start_time = parse(start)
|
start_time = parse(start)
|
||||||
now = datetime.datetime.utcnow().replace(microsecond=0)
|
now = datetime.datetime.utcnow().replace(microsecond=0)
|
||||||
btn_txt = f"Claim {amount} {world.wells[well_id][0].capitalize()}"
|
delta = now - start_time
|
||||||
elapsed = now - start_time
|
|
||||||
if elapsed > datetime.timedelta(minutes=dur):
|
|
||||||
im.push_id(f"Claim{stake_id}")
|
im.push_id(f"Claim{stake_id}")
|
||||||
if im.button(btn_txt):
|
if delta > datetime.timedelta(minutes=dur):
|
||||||
|
if im.button("Claim"):
|
||||||
claim(stake_id)
|
claim(stake_id)
|
||||||
im.pop_id()
|
|
||||||
im.text(f"Finished {elapsed} ago")
|
|
||||||
else:
|
else:
|
||||||
remaining = start_time + datetime.timedelta(minutes=dur) - now
|
im.text_disabled("Claim")
|
||||||
im.text_disabled(btn_txt)
|
im.pop_id()
|
||||||
im.text(f"{remaining} left")
|
im.text(f"{world.store[world.inventory[invId][0]][0]}: {delta}")
|
||||||
|
|
||||||
im.next_column()
|
im.next_column()
|
||||||
|
|
||||||
@ -422,7 +301,8 @@ def draw_moons():
|
|||||||
def draw_panels():
|
def draw_panels():
|
||||||
screen_width, screen_height = glfw.get_video_mode(glfw.get_primary_monitor())[0]
|
screen_width, screen_height = glfw.get_video_mode(glfw.get_primary_monitor())[0]
|
||||||
|
|
||||||
# TODO: We probably don't need to create a "Main" window...
|
# Main
|
||||||
|
# TODO: This is probably not the right way to do this
|
||||||
im.set_next_window_size(screen_width, screen_height)
|
im.set_next_window_size(screen_width, screen_height)
|
||||||
|
|
||||||
# Set the next window position to (0, 0) to make the window cover the entire screen
|
# Set the next window position to (0, 0) to make the window cover the entire screen
|
||||||
@ -506,8 +386,6 @@ world.bank = get_bank()
|
|||||||
world.store = get_store_items()
|
world.store = get_store_items()
|
||||||
world.inventory = get_inventory()
|
world.inventory = get_inventory()
|
||||||
world.staking_sources = get_moons()
|
world.staking_sources = get_moons()
|
||||||
world.stakes = get_stakes()
|
|
||||||
world.wells = get_all_wells()
|
|
||||||
|
|
||||||
def imgui_init():
|
def imgui_init():
|
||||||
world.moon_img_tex_id = texture_id = load_texture("moon.png")
|
world.moon_img_tex_id = texture_id = load_texture("moon.png")
|
||||||
|
44
queries.sql
44
queries.sql
@ -1,44 +0,0 @@
|
|||||||
SELECT 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 staking_source on staking_event.source_id = staking_source.id
|
|
||||||
WHERE staking_event.source_id = ? AND staking_source.user_id = ?;
|
|
||||||
|
|
||||||
SELECT name,init_supply
|
|
||||||
FROM resource_well
|
|
||||||
INNER JOIN resource ON resource.id = resource_well.resource_id
|
|
||||||
WHERE source_id = 1;
|
|
||||||
|
|
||||||
SELECT inventory_item.id,store_item_id, COUNT(upgrade_event.id) as upgrades
|
|
||||||
FROM inventory_item
|
|
||||||
LEFT JOIN upgrade_event ON inventory_item.id = upgrade_event.inventory_item_id
|
|
||||||
WHERE inventory_item.user_id = 1
|
|
||||||
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;
|
|
||||||
|
|
||||||
SELECT staking_event.id, staking_event.well_id, staking_event.source_id,
|
|
||||||
staking_event.inventory_item_id, staking_event.duration_in_mins,
|
|
||||||
staking_event.created_at
|
|
||||||
FROM staking_event
|
|
||||||
LEFT JOIN claim_event ON staking_event.id = claim_event.staking_event_id
|
|
||||||
WHERE staking_event.source_id = 4 AND claim_event.staking_event_id IS NULL;
|
|
||||||
|
|
||||||
UPDATE staking_event SET created_at = '2023-02-21 12:58:02' WHERE id = 5;
|
|
||||||
|
|
||||||
SELECT staking_event.id,well_id,inventory_item_id,duration_in_mins,
|
|
||||||
staking_event.created_at,
|
|
||||||
CASE WHEN claim_event.staking_event_id IS NULL THEN 1 ELSE 0 END AS is_active
|
|
||||||
FROM staking_event
|
|
||||||
INNER JOIN resource_well ON resource_well.id = staking_event.well_id
|
|
||||||
INNER JOIN staking_source ON staking_source.id = resource_well.source_id
|
|
||||||
LEFT JOIN claim_event ON claim_event.staking_event_id = staking_event.id
|
|
||||||
WHERE staking_source.user_id = 1;
|
|
21
tables.sql
21
tables.sql
@ -34,10 +34,12 @@ CREATE TABLE resource_well(
|
|||||||
CREATE TABLE staking_event(
|
CREATE TABLE staking_event(
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
well_id int not null,
|
well_id int not null,
|
||||||
|
source_id int not null,
|
||||||
inventory_item_id int not null,
|
inventory_item_id int not null,
|
||||||
duration_in_mins int not null,
|
duration_in_mins int not null,
|
||||||
stake_amount int not null,
|
|
||||||
created_at timestamp DEFAULT (current_timestamp),
|
created_at timestamp DEFAULT (current_timestamp),
|
||||||
|
CONSTRAINT fk_sid FOREIGN KEY(source_id)
|
||||||
|
REFERENCES staking_source(id)
|
||||||
CONSTRAINT fk_wid FOREIGN KEY(well_id)
|
CONSTRAINT fk_wid FOREIGN KEY(well_id)
|
||||||
REFERENCES resource_well(id)
|
REFERENCES resource_well(id)
|
||||||
CONSTRAINT fk_iiid FOREIGN KEY(inventory_item_id)
|
CONSTRAINT fk_iiid FOREIGN KEY(inventory_item_id)
|
||||||
@ -46,8 +48,8 @@ CREATE TABLE staking_event(
|
|||||||
|
|
||||||
CREATE TABLE claim_event(
|
CREATE TABLE claim_event(
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
staking_event_id int not null,
|
|
||||||
claim_amount int not null,
|
claim_amount int not null,
|
||||||
|
staking_event_id int not null,
|
||||||
created_at timestamp DEFAULT (current_timestamp),
|
created_at timestamp DEFAULT (current_timestamp),
|
||||||
CONSTRAINT fk_se_id FOREIGN KEY(staking_event_id)
|
CONSTRAINT fk_se_id FOREIGN KEY(staking_event_id)
|
||||||
REFERENCES staking_event(id)
|
REFERENCES staking_event(id)
|
||||||
@ -64,9 +66,14 @@ CREATE TABLE upgrade_event(
|
|||||||
CREATE TABLE store_item(
|
CREATE TABLE store_item(
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
name varchar(128) not null,
|
name varchar(128) not null,
|
||||||
|
currency int not null,
|
||||||
price int not null,
|
price int not null,
|
||||||
|
target_resource int not null,
|
||||||
claim_amount int not null,
|
claim_amount int not null,
|
||||||
completion_time_mins int not null
|
CONSTRAINT fk_rid FOREIGN KEY(currency)
|
||||||
|
REFERENCES resource(id)
|
||||||
|
CONSTRAINT fk_targetid FOREIGN KEY(target_resource)
|
||||||
|
REFERENCES resource(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE inventory_item(
|
CREATE TABLE inventory_item(
|
||||||
@ -81,14 +88,6 @@ CREATE TABLE inventory_item(
|
|||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE bank_account(
|
CREATE TABLE bank_account(
|
||||||
id integer primary key autoincrement,
|
|
||||||
user_id int not null,
|
|
||||||
balance int not null default 0 CHECK (balance >= 0),
|
|
||||||
CONSTRAINT fk_user FOREIGN KEY(user_id)
|
|
||||||
REFERENCES users(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE resource_account(
|
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
user_id int not null,
|
user_id int not null,
|
||||||
resource_id int not null,
|
resource_id int not null,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user