Fleshing out store/inventory system, adding more UI elements

This commit is contained in:
Joseph Ferano 2023-02-18 13:57:59 +07:00
parent ab21de5ac3
commit 286be600f5
3 changed files with 53 additions and 4 deletions

View File

@ -12,6 +12,23 @@ INSERT INTO users(name) VALUES
('Plug'), ('Plug'),
('Upgrade'); ('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 SELECT name,init_supply
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

18
mm.py
View File

@ -18,6 +18,20 @@ cursor.execute("SELECT id,name FROM resource")
resources = cursor.fetchall() resources = cursor.fetchall()
id_to_resource = {id: name for id, name in resources} id_to_resource = {id: name for id, name in resources}
resource_to_id = {name: id 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() cursor.close()
def get_moons(): def get_moons():
@ -101,8 +115,8 @@ get_moons()
sg.set_options(font=("Fira Code", 15)) sg.set_options(font=("Fira Code", 15))
banks = "" banks = ""
for _,name in resources: for name,amount in bank.items():
banks += f"{name.capitalize()}: 100 | " banks += f"{name.capitalize()}: {amount} | "
sources_ui = [] sources_ui = []
for id,source in staking_sources.items(): for id,source in staking_sources.items():

View File

@ -33,11 +33,14 @@ 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, source_id int not null,
inventory_item_id int not null,
created_at timestamp DEFAULT (current_timestamp), created_at timestamp DEFAULT (current_timestamp),
CONSTRAINT fk_sid FOREIGN KEY(source_id) CONSTRAINT fk_sid FOREIGN KEY(source_id)
REFERENCES staking_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)
REFERENCES inventory_item(id)
); );
CREATE TABLE upgrade_event( CREATE TABLE upgrade_event(
@ -58,19 +61,35 @@ CREATE TABLE claim_event(
REFERENCES staking_source(id) 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( CREATE TABLE store_item(
id integer primary key autoincrement, id integer primary key autoincrement,
name varchar(128) not null, 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( CREATE TABLE inventory_item(
id integer primary key autoincrement, id integer primary key autoincrement,
user_id int not null, user_id int not null,
store_id int not null,
name varchar(128) not null, name varchar(128) not null,
created_at timestamp DEFAULT (current_timestamp), created_at timestamp DEFAULT (current_timestamp),
CONSTRAINT fk_user FOREIGN KEY(user_id) CONSTRAINT fk_user FOREIGN KEY(user_id)
REFERENCES users(id) REFERENCES users(id)
CONSTRAINT fk_storeid FOREIGN KEY(store_id)
REFERENCES store_item(id)
); );
CREATE TABLE bank_account( CREATE TABLE bank_account(
@ -78,7 +97,6 @@ CREATE TABLE bank_account(
user_id int not null, user_id int not null,
resource_id int not null, resource_id int not null,
balance int not null default 0 CHECK (balance >= 0), balance int not null default 0 CHECK (balance >= 0),
updated_at timestamp DEFAULT (current_timestamp),
CONSTRAINT fk_user FOREIGN KEY(user_id) CONSTRAINT fk_user FOREIGN KEY(user_id)
REFERENCES users(id), REFERENCES users(id),
CONSTRAINT fk_resource FOREIGN KEY(resource_id) CONSTRAINT fk_resource FOREIGN KEY(resource_id)