Compare commits

...

5 commits

4 changed files with 176 additions and 37 deletions

40
app.py
View file

@ -2,38 +2,32 @@ import streamlit as st
import database as db
class Creature:
def __init__(self, name, nickname, power, max_spawns, hits_to_kill):
self.name = name
self.nickname = nickname
self.power = power
self.max_spawns = max_spawns
self.hits_to_kill = hits_to_kill
class Run:
def __init__(self, moon):
self.moon = moon
self.inside_power = moon.inside_max_power
self.outside_power = moon.outside_max_power
def __init__(self, moon: db.Moon):
self.moon: db.Moon = moon
self.inside_power: int = moon.inside_max_power
self.outside_power: int = moon.outside_max_power
def main():
st.set_page_config("Lethal Company Scouter", "🛰️")
st.markdown("# :red[Lethal Company] Scouter")
st.markdown(":rainbow[What does the scouter say about this moon's power level?]")
moon_name = st.selectbox(
"Moon",
db.get_moon_list(),
placeholder="Moon! Pick a moon!",
help="Pick your current moon.",
)
moon_id = db.get_moon_id_by_name(moon_name)
run = Run(db.get_moon_by_id(moon_id))
moon_id: int = db.get_moon_id_by_name(moon_name)
run: Run = Run(db.get_moon_by_id(moon_id))
st.markdown(f"## {run.moon.name} ({run.moon.tier})")
st.info(f"Risk: {run.moon.risk_level} | Min scrap: {run.moon.min_scrap} "
f"| Max scrap: {run.moon.max_scrap} | Default layout: {run.moon.default_layout}")
st.write(run)
st.write(run.moon)
# Begin column layout
left_column, right_column = st.columns(2)
@ -44,6 +38,18 @@ def main():
with right_column:
st.markdown("### Inside")
st.markdown('## Scrap Lookup')
scrap_name = st.selectbox(
'Scrap',
db.get_scrap_list(),
placeholder='Select a scrap name!'
)
scrap_id: int = db.get_scrap_id_by_name(scrap_name)
scrap: db.Scrap = db.get_scrap_by_id(scrap_id)
st.write(scrap)
if __name__ == "__main__":
main()

View file

@ -1 +1,53 @@
;
insert into main.scrap (scrap_id, scrap_name, min_value, max_value, weight, conductive, two_handed)
values (1, 'Air Horn', 52, 72, 0, 0, 0),
(2, 'Apparatus', 80, 80, 31, 1, 1),
(3, 'Bee Hive', 50, 156, 0, 1, 1),
(4, 'Bottles', 44, 56, 19, 0, 1),
(5, 'Brass Bell', 48, 80, 24, 1, 0),
(6, 'Candy', 6, 36, 11, 0, 0),
(7, 'Cash Register', 80, 160, 84, 1, 1),
(8, 'Chemical Jug', 32, 84, 32, 0, 1),
(9, 'Clown Horn', 52, 72, 0, 1, 0),
(10, 'Coffee Mug', 24, 68, 5, 0, 0),
(11, 'Comedy Mask', 28, 52, 11, 0, 0),
(12, 'Cookie Mold Pan', 12, 40, 16, 0, 0),
(13, 'Dustpan', 12, 32, 0, 0, 0),
(14, 'Egg Beater', 12, 44, 11, 1, 0),
(15, 'Fancy Lamp', 60, 128, 21, 1, 1),
(16, 'Flask', 16, 44, 19, 1, 0),
(17, 'Gift', 12, 28, 19, 0, 0),
(18, 'Gold Bar', 102, 210, 77, 1, 0),
(19, 'Golden Cup', 40, 80, 16, 0, 0),
(20, 'Hair Brush', 8, 36, 11, 0, 0),
(21, 'Hairdryer', 60, 100, 7, 0, 0),
(22, 'Homemade Flashbang', 10, 28, 5, 0, 0),
(23, 'Jar of Pickles', 32, 60, 16, 0, 0),
(24, 'Large Axle', 36, 56, 16, 1, 1),
(25, 'Large Bolt', 20, 32, 19, 1, 0),
(26, 'Laser Pointer', 32, 100, 0, 0, 0),
(27, 'Magic 7 Ball', 36, 72, 16, 0, 0),
(28, 'Magnifying Glass', 44, 60, 11, 0, 0),
(29, 'Metal Sheet', 10, 22, 26, 1, 0),
(30, 'Old Phone', 48, 64, 5, 0, 0),
(31, 'Painting', 60, 124, 32, 0, 1),
(32, 'Perfume Bottle', 48, 104, 0, 0, 0),
(33, 'Pill Bottle', 16, 40, 0, 0, 0),
(34, 'Plastic Fish', 28, 40, 0, 0, 0),
(35, 'Player Body', 5, 5, 11, 0, 1),
(36, 'Red Soda', 18, 90, 7, 1, 0),
(37, 'Remote', 20, 48, 0, 0, 0),
(38, 'Robot Toy', 56, 88, 21, 1, 0),
(39, 'Rubber Duckie', 2, 100, 0, 0, 0),
(40, 'Shotgun', 30, 90, 16, 0, 0),
(41, 'Shotgun Shell', 0, 0, 0, 0, 0),
(42, 'Steering Wheel', 16, 32, 16, 0, 0),
(43, 'Stop Sign', 20, 52, 21, 1, 0),
(44, 'Tea Kettle', 32, 56, 21, 1, 0),
(45, 'Teeth', 60, 84, 0, 0, 0),
(46, 'Toothpaste', 14, 48, 0, 0, 0),
(47, 'Toy Cube', 24, 44, 0, 0, 0),
(48, 'Tragedy Mask', 28, 52, 11, 0, 0),
(49, 'V-Type Engine', 20, 56, 16, 1, 1),
(50, 'Wedding Ring', 52, 80, 16, 1, 0),
(51, 'Whoopie Cushion', 6, 20, 0, 1, 0),
(52, 'Yield Sign', 18, 36, 42, 1, 0);

View file

@ -3,19 +3,32 @@ import sqlite3
class Moon:
def __init__(self, moon_id, name, risk_level, cost, default_layout, map_size_multiplier, min_scrap, max_scrap,
outside_max_power, inside_max_power, tier):
self.id = moon_id
self.name = name
self.risk_level = risk_level
self.cost = cost
self.default_layout = default_layout,
self.map_size_multiplier = map_size_multiplier
self.min_scrap = min_scrap
self.max_scrap = max_scrap
self.outside_max_power = outside_max_power
self.inside_max_power = inside_max_power
self.tier = tier
def __init__(self, moon_id: int, name: str, risk_level: str, cost: int, default_layout: str,
map_size_multiplier: float, min_scrap: int, max_scrap: int, outside_max_power: int,
inside_max_power: int, tier: str):
self.moon_id: int = moon_id
self.name: str = name
self.risk_level: str = risk_level
self.cost: int = cost
self.default_layout: str = default_layout
self.map_size_multiplier: float = map_size_multiplier
self.min_scrap: int = min_scrap
self.max_scrap: int = max_scrap
self.outside_max_power: int = outside_max_power
self.inside_max_power: int = inside_max_power
self.tier: str = tier
class Scrap:
def __init__(self, scrap_id: int, name: str, min_value: int,
max_value: int, weight: int, conductive: int, two_handed: int):
self.scrap_id: int = scrap_id
self.name: str = name
self.min_value: int = min_value
self.max_value: int = max_value
self.weight: int = weight
self.conductive: bool = bool(conductive)
self.two_handed: bool = bool(two_handed)
def get_connection() -> sqlite3.Connection:
@ -59,13 +72,13 @@ def get_moon_list() -> list[str] | None:
"""
with get_connection() as connection:
cursor = connection.cursor()
moons = cursor.execute(
moon_names = cursor.execute(
"select moon_name from moon order by moon_id"
).fetchall()
if moons:
moons = [moon[0] for moon in moons]
return moons
if moon_names:
moon_names = [moon[0] for moon in moon_names]
return moon_names
else:
return None
@ -77,7 +90,6 @@ def get_moon_by_id(moon_id: int) -> Moon | None:
:return: A moon object or None if no moon is found
"""
with get_connection() as connection:
connection.text_factory = str
cursor = connection.cursor()
query = """
@ -97,7 +109,8 @@ from moon as m
join main.layout l on l.layout_id = m.default_layout_id
join main.moon_tier mt on mt.moon_tier_id = m.moon_tier_id
where m.moon_id = ?
limit 1;"""
limit 1;
"""
moon = cursor.execute(
query,
@ -108,3 +121,71 @@ limit 1;"""
return Moon(*moon)
else:
return None
def get_scrap_list() -> list[str] | None:
"""Provides a list of all scrap names from the database.
:return: All scrap names as a list of strings or None if no scrap is found
"""
with get_connection() as connection:
cursor = connection.cursor()
scrap_names = cursor.execute(
"select scrap_name from scrap order by scrap_id"
)
if scrap_names:
scrap_names = [scrap[0] for scrap in scrap_names]
return scrap_names
else:
return None
def get_scrap_id_by_name(scrap_name: str) -> int | None:
"""Queries the database for a scrap ID that matches the given name.
:param scrap_name: Moon name as a string
:return: The scrap's ID as an int or None if no scrap is found
"""
with get_connection() as connection:
cursor = connection.cursor()
scrap_id = cursor.execute(
"select scrap_id "
"from scrap "
"where scrap_name = ? "
"order by scrap_name "
"limit 1;",
(scrap_name,)
).fetchone()
if scrap_id:
return scrap_id[0]
else:
return None
def get_scrap_by_id(scrap_id: int) -> Scrap | None:
with get_connection() as connection:
cursor = connection.cursor()
query = """
select s.scrap_id,
s.scrap_name,
s.min_value,
s.max_value,
s.weight,
s.conductive,
s.two_handed
from scrap as s
where scrap_id = ?
limit 1;
"""
scrap = cursor.execute(
query,
(scrap_id,)
).fetchone()
if scrap:
return Scrap(*scrap)
else:
return None

Binary file not shown.