Fleshing out store/inventory system, adding more UI elements
This commit is contained in:
parent
ab21de5ac3
commit
286be600f5
17
data.sql
17
data.sql
@ -12,6 +12,23 @@ INSERT INTO users(name) VALUES
|
||||
('Plug'),
|
||||
('Upgrade');
|
||||
|
||||
|
||||
INSERT INTO bank_account(user_id, resource_id, balance) VALUES
|
||||
(1, 1, 0),
|
||||
(1, 2, 175),
|
||||
(1, 3, 200),
|
||||
(1, 4, 25),
|
||||
(1, 5, 10);
|
||||
|
||||
INSERT INTO store_item(name, target_resource, price) VALUES
|
||||
('Drill 1A', 1, 100),
|
||||
('Drill 1B', 2, 100),
|
||||
('Drill 1C', 3, 100),
|
||||
('Drill 1D', 4, 100),
|
||||
('Drill 1E', 5, 100);
|
||||
|
||||
|
||||
|
||||
SELECT name,init_supply
|
||||
FROM resource_well
|
||||
INNER JOIN resource ON resource.id = resource_well.resource_id
|
||||
|
18
mm.py
18
mm.py
@ -18,6 +18,20 @@ cursor.execute("SELECT id,name FROM resource")
|
||||
resources = cursor.fetchall()
|
||||
id_to_resource = {id: name for id, name in resources}
|
||||
resource_to_id = {name: id for id, name in resources}
|
||||
|
||||
cursor.execute("""
|
||||
SELECT resource.name,balance FROM bank_account
|
||||
INNER JOIN resource ON resource.id = bank_account.resource_id
|
||||
WHERE user_id = ?
|
||||
""", (current_user_id,))
|
||||
bank = {name: balance for name,balance in cursor.fetchall()}
|
||||
|
||||
# cursor.execute("""
|
||||
# SELECT store_item.name,price,currency FROM bank_account
|
||||
# INNER JOIN resource ON resource.id = bank_account.resource_id
|
||||
# """)
|
||||
# store = {name: balance for name,price,currency in cursor.fetchall()}
|
||||
|
||||
cursor.close()
|
||||
|
||||
def get_moons():
|
||||
@ -101,8 +115,8 @@ get_moons()
|
||||
sg.set_options(font=("Fira Code", 15))
|
||||
|
||||
banks = ""
|
||||
for _,name in resources:
|
||||
banks += f"{name.capitalize()}: 100 | "
|
||||
for name,amount in bank.items():
|
||||
banks += f"{name.capitalize()}: {amount} | "
|
||||
|
||||
sources_ui = []
|
||||
for id,source in staking_sources.items():
|
||||
|
22
tables.sql
22
tables.sql
@ -33,11 +33,14 @@ CREATE TABLE staking_event(
|
||||
id integer primary key autoincrement,
|
||||
well_id int not null,
|
||||
source_id int not null,
|
||||
inventory_item_id int not null,
|
||||
created_at timestamp DEFAULT (current_timestamp),
|
||||
CONSTRAINT fk_sid FOREIGN KEY(source_id)
|
||||
REFERENCES staking_source(id)
|
||||
CONSTRAINT fk_wid FOREIGN KEY(well_id)
|
||||
REFERENCES resource_well(id)
|
||||
CONSTRAINT fk_iiid FOREIGN KEY(inventory_item_id)
|
||||
REFERENCES inventory_item(id)
|
||||
);
|
||||
|
||||
CREATE TABLE upgrade_event(
|
||||
@ -58,19 +61,35 @@ CREATE TABLE claim_event(
|
||||
REFERENCES staking_source(id)
|
||||
);
|
||||
|
||||
CREATE TABLE game_config(
|
||||
id integer primary key autoincrement,
|
||||
key text not null,
|
||||
value text not null,
|
||||
);
|
||||
|
||||
"Another Drill Price": 250 Sollux
|
||||
|
||||
CREATE TABLE store_item(
|
||||
id integer primary key autoincrement,
|
||||
name varchar(128) not null,
|
||||
price int not null
|
||||
currency int not null,
|
||||
target_resource 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(
|
||||
id integer primary key autoincrement,
|
||||
user_id int not null,
|
||||
store_id int not null,
|
||||
name varchar(128) not null,
|
||||
created_at timestamp DEFAULT (current_timestamp),
|
||||
CONSTRAINT fk_user FOREIGN KEY(user_id)
|
||||
REFERENCES users(id)
|
||||
CONSTRAINT fk_storeid FOREIGN KEY(store_id)
|
||||
REFERENCES store_item(id)
|
||||
);
|
||||
|
||||
CREATE TABLE bank_account(
|
||||
@ -78,7 +97,6 @@ CREATE TABLE bank_account(
|
||||
user_id int not null,
|
||||
resource_id int not null,
|
||||
balance int not null default 0 CHECK (balance >= 0),
|
||||
updated_at timestamp DEFAULT (current_timestamp),
|
||||
CONSTRAINT fk_user FOREIGN KEY(user_id)
|
||||
REFERENCES users(id),
|
||||
CONSTRAINT fk_resource FOREIGN KEY(resource_id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user