Now using dearpygui, tables are more fleshed out. Some functionality works
This commit is contained in:
parent
fcfb417bd6
commit
e5d42c7b3a
27
data.sql
Normal file
27
data.sql
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
INSERT INTO resource(name) VALUES
|
||||||
|
('NEBULANCE'),
|
||||||
|
('SHADOWSTONE'),
|
||||||
|
('AZURIUM'),
|
||||||
|
('NOVAFOR'),
|
||||||
|
('SOLLUX');
|
||||||
|
|
||||||
|
INSERT INTO users(name) VALUES
|
||||||
|
('Joe'),
|
||||||
|
('Emile'),
|
||||||
|
('Niko'),
|
||||||
|
('Plug'),
|
||||||
|
('Upgrade');
|
||||||
|
|
||||||
|
INSERT INTO staking_source(user_id, address) VALUES
|
||||||
|
(1, '12345');
|
||||||
|
|
||||||
|
INSERT INTO resource_well(staking_source_id, resource_id, init_supply) VALUES
|
||||||
|
(1, 1, 100);
|
||||||
|
INSERT INTO resource_well(staking_source_id, resource_id, init_supply) VALUES
|
||||||
|
(1, 2, 100);
|
||||||
|
INSERT INTO resource_well(staking_source_id, resource_id, init_supply) VALUES
|
||||||
|
(1, 3, 100);
|
||||||
|
INSERT INTO resource_well(staking_source_id, resource_id, init_supply) VALUES
|
||||||
|
(1, 4, 100);
|
||||||
|
INSERT INTO resource_well(staking_source_id, resource_id, init_supply) VALUES
|
||||||
|
(1, 5, 100);
|
133
mm.py
Normal file
133
mm.py
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
from dateutil.parser import parse
|
||||||
|
import sqlite3 as sql
|
||||||
|
import random
|
||||||
|
import datetime
|
||||||
|
import dearpygui.demo as demo
|
||||||
|
import dearpygui.dearpygui as dpg
|
||||||
|
|
||||||
|
dpg.create_context()
|
||||||
|
dpg.create_viewport(title='Custom Title', width=1200, height=800)
|
||||||
|
dpg.setup_dearpygui()
|
||||||
|
|
||||||
|
with dpg.font_registry():
|
||||||
|
# first argument ids the path to the .ttf or .otf file
|
||||||
|
default_font = dpg.add_font("fira.ttf", 20)
|
||||||
|
dpg.bind_font(default_font)
|
||||||
|
|
||||||
|
conn = sql.connect("mm.db", check_same_thread=False)
|
||||||
|
|
||||||
|
current_user = "Joe"
|
||||||
|
current_user_id = 1
|
||||||
|
current_source = 1
|
||||||
|
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT created_at FROM staking_source WHERE user_id = ?", (current_user_id,))
|
||||||
|
staked_timestamp = parse(cursor.fetchone()[0])
|
||||||
|
|
||||||
|
cursor.execute("SELECT name FROM resource")
|
||||||
|
resources = [i[0].capitalize() for i in cursor.fetchall()]
|
||||||
|
|
||||||
|
cursor.execute("SELECT id,created_at FROM staking_source")
|
||||||
|
staking_sources = [(i[0], i[1].capitalize()) for i in cursor.fetchall()]
|
||||||
|
|
||||||
|
for i,(sid,ts) in enumerate(staking_sources):
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT resource.id,name,init_supply
|
||||||
|
FROM resource_well
|
||||||
|
INNER JOIN resource ON resource.id = resource_well.resource_id
|
||||||
|
WHERE staking_source_id = ?;
|
||||||
|
""", (sid,))
|
||||||
|
wells = [(i[0],i[1].capitalize(),i[2]) for i in cursor.fetchall()]
|
||||||
|
staking_sources[i] = (sid,ts,wells)
|
||||||
|
|
||||||
|
for i,(sid,ts,wells) in enumerate(staking_sources):
|
||||||
|
cursor.execute("""
|
||||||
|
SELECT resoure_id,
|
||||||
|
FROM resource_well
|
||||||
|
INNER JOIN resource ON resource.id = resource_well.resource_id
|
||||||
|
WHERE staking_source_id = ?;
|
||||||
|
""", (sid,))
|
||||||
|
wells = [(i[0],i[1].capitalize(),i[2]) for i in cursor.fetchall()]
|
||||||
|
staking_sources[i] = (sid,ts,wells)
|
||||||
|
|
||||||
|
def mint():
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute("SELECT id FROM users WHERE name = ?", (current_user,))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if result and result[0]:
|
||||||
|
user_id = result[0]
|
||||||
|
else:
|
||||||
|
raise Exception("User not found: " + user_name)
|
||||||
|
|
||||||
|
rand_hash = "%010x" % random.randrange(16 ** 16)
|
||||||
|
print(rand_hash, " ", user_id)
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO staking_source (user_id, address)
|
||||||
|
VALUES (?, ?)
|
||||||
|
""", (user_id, f"0x{rand_hash}"))
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
def mine(a,b,user_data):
|
||||||
|
print(user_data)
|
||||||
|
source_id,well_id = user_data
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute("""
|
||||||
|
INSERT INTO staking_event (source_id, well_id)
|
||||||
|
VALUES (?, ?)
|
||||||
|
""", (source_id, well_id))
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
width, height, channels, data = dpg.load_image("moon-small.jpg")
|
||||||
|
|
||||||
|
with dpg.texture_registry(show=False):
|
||||||
|
dpg.add_static_texture(width=width, height=height, default_value=data, tag="moon")
|
||||||
|
|
||||||
|
with dpg.window(label="Example Window", tag="Primary", width=1200, height=800):
|
||||||
|
dpg.add_text("User: Joe")
|
||||||
|
with dpg.group(horizontal=True):
|
||||||
|
for res in resources:
|
||||||
|
dpg.add_text(f"{res}: 0 |")
|
||||||
|
|
||||||
|
dpg.add_button(label="Mint Moon", callback=mint)
|
||||||
|
dpg.add_separator()
|
||||||
|
|
||||||
|
for source in staking_sources:
|
||||||
|
dpg.add_image("moon")
|
||||||
|
with dpg.group(horizontal=True):
|
||||||
|
dpg.add_button(label="Upgrade")
|
||||||
|
dpg.add_button(label="Claim")
|
||||||
|
with dpg.group(horizontal=True):
|
||||||
|
for well in source[2]:
|
||||||
|
lbl = f"Mine {well[1]} ({well[2]})"
|
||||||
|
data = (source[0],well[0])
|
||||||
|
dpg.add_button(label=lbl, callback=mine, user_data=data)
|
||||||
|
|
||||||
|
dpg.show_viewport()
|
||||||
|
dpg.set_primary_window("Primary", True)
|
||||||
|
dpg.start_dearpygui()
|
||||||
|
|
||||||
|
|
||||||
|
# if gui_button(Rectangle(10,10,150,50), "#154#Mint"):
|
||||||
|
# mint()
|
||||||
|
# if current_source:
|
||||||
|
# now = datetime.datetime.utcnow()
|
||||||
|
# timespan = str(now - staked_timestamp).split('.')[0]
|
||||||
|
# draw_text(f"Mining start time: {timespan}", 200, 20, 30, text_color)
|
||||||
|
# btn_pos = 100
|
||||||
|
# spacing = 145
|
||||||
|
# for i,res in enumerate(resources):
|
||||||
|
# draw_text(f"{res}", 20, i * spacing + btn_pos, 27, text_color)
|
||||||
|
# draw_text(f"Amount", 20, i * spacing + btn_pos + 40, 20, text_color)
|
||||||
|
# if gui_button(Rectangle(20,i * spacing + btn_pos + 70,110,40), "#78#Upgrade"):
|
||||||
|
# mint()
|
||||||
|
# if gui_button(Rectangle(160,i * spacing + btn_pos + 70,110,40), "#78#Claim"):
|
||||||
|
# mint()
|
||||||
|
|
||||||
|
# end_drawing()
|
||||||
|
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
dpg.destroy_context()
|
BIN
moon-small.jpg
Normal file
BIN
moon-small.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.9 KiB |
67
tables.sql
67
tables.sql
@ -1,58 +1,71 @@
|
|||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
id serial not null primary key,
|
id integer primary key autoincrement,
|
||||||
name varchar(32) not null,
|
name varchar(32) not null
|
||||||
|
);
|
||||||
|
|
||||||
|
-- DROP TABLE users;
|
||||||
|
|
||||||
|
CREATE TABLE bank_account(
|
||||||
|
id integer primary key autoincrement,
|
||||||
|
user_id int not null,
|
||||||
|
resource_id int not null,
|
||||||
|
balance int not null default 0 CHECK (balance >= 0),
|
||||||
|
created_at timestamp DEFAULT (current_timestamp),
|
||||||
|
CONSTRAINT fk_user FOREIGN KEY(user_id)
|
||||||
|
REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_resource FOREIGN KEY(resource_id)
|
||||||
|
REFERENCES resource(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE resource(
|
CREATE TABLE resource(
|
||||||
id serial not null primary key,
|
id integer primary key autoincrement,
|
||||||
name varchar(32) not null,
|
name varchar(32) not null
|
||||||
);
|
);
|
||||||
|
|
||||||
INSERT INTO resource(name) VALUES
|
|
||||||
('NEBULANCE'),
|
|
||||||
('SHADOWSTONE'),
|
|
||||||
('AZURIUM'),
|
|
||||||
('NOVAFOR'),
|
|
||||||
('SOLLUX');
|
|
||||||
|
|
||||||
CREATE TABLE staking_source(
|
CREATE TABLE staking_source(
|
||||||
id serial not null primary key,
|
id integer primary key autoincrement,
|
||||||
user_id int not null,
|
user_id int not null,
|
||||||
|
address varchar(128) not null,
|
||||||
|
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)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE resource_well(
|
CREATE TABLE resource_well(
|
||||||
id serial not null primary key,
|
id integer primary key autoincrement,
|
||||||
staking_source_id int not null,
|
staking_source_id int not null,
|
||||||
resource_id int not null,
|
resource_id int not null,
|
||||||
init_supply int not null default 0,
|
init_supply int not null,
|
||||||
CONSTRAINT fk_resource FOREIGN KEY(resource_id)
|
CONSTRAINT fk_resource FOREIGN KEY(resource_id)
|
||||||
REFERENCES resource(id),
|
REFERENCES resource(id),
|
||||||
CONSTRAINT fk_ssource FOREIGN KEY(staking_source_id)
|
CONSTRAINT fk_ssource FOREIGN KEY(staking_source_id)
|
||||||
REFERENCES staking_source(id),
|
REFERENCES staking_source(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE staking_event(
|
CREATE TABLE staking_event(
|
||||||
id serial primary key not null,
|
id integer primary key autoincrement,
|
||||||
staking_source_id int not null,
|
well_id int not null,
|
||||||
created_at timestamp without time zone default (now() at time zone 'utc'),
|
source_id int not null,
|
||||||
CONSTRAINT fk_ures FOREIGN KEY(staking_source_id)
|
created_at timestamp DEFAULT (current_timestamp),
|
||||||
REFERENCES staking_source(id),
|
CONSTRAINT fk_sid FOREIGN KEY(source_id)
|
||||||
|
REFERENCES staking_source(id)
|
||||||
|
CONSTRAINT fk_wid FOREIGN KEY(well_id)
|
||||||
|
REFERENCES resource_well(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE upgrade_event(
|
CREATE TABLE upgrade_event(
|
||||||
id serial primary key not null,
|
id integer primary key autoincrement,
|
||||||
staking_event_id int not null,
|
staking_event_id int not null,
|
||||||
created_at timestamp without time zone default (now() at time zone 'utc'),
|
created_at timestamp DEFAULT (current_timestamp),
|
||||||
CONSTRAINT fk_mevent FOREIGN KEY(staking_event_id)
|
CONSTRAINT fk_mevent FOREIGN KEY(staking_event_id)
|
||||||
REFERENCES staking_event(id),
|
REFERENCES staking_event(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE claim_event(
|
CREATE TABLE claim_event(
|
||||||
id serial not null primary key,
|
id integer primary key autoincrement,
|
||||||
staking_source_id int not null,
|
staking_source_id int not null,
|
||||||
created_at timestamp without time zone default (now() at time zone 'utc'),
|
claim_type text CHECK ( claim_type IN ('BASE','BONUS') ),
|
||||||
|
created_at timestamp DEFAULT (current_timestamp),
|
||||||
CONSTRAINT fk_ures FOREIGN KEY(staking_source_id)
|
CONSTRAINT fk_ures FOREIGN KEY(staking_source_id)
|
||||||
REFERENCES staking_source(id),
|
REFERENCES staking_source(id)
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user