mirror of
https://github.com/ethanrusz/scouter.git
synced 2024-11-23 20:27:45 -05:00
Add creature database layer
This commit is contained in:
parent
31ff9e346b
commit
bd1c3732c2
2 changed files with 85 additions and 11 deletions
10
app.py
10
app.py
|
@ -30,13 +30,9 @@ def main():
|
||||||
st.write(run.moon)
|
st.write(run.moon)
|
||||||
|
|
||||||
# Begin column layout
|
# Begin column layout
|
||||||
left_column, right_column = st.columns(2)
|
creatures = db.get_spawnable_inside_creature_ids(run.moon.moon_id)
|
||||||
|
for creature in creatures:
|
||||||
with left_column:
|
st.write(db.get_creature_by_id(creature))
|
||||||
st.markdown("### Outside")
|
|
||||||
|
|
||||||
with right_column:
|
|
||||||
st.markdown("### Inside")
|
|
||||||
|
|
||||||
st.markdown('## Scrap Lookup')
|
st.markdown('## Scrap Lookup')
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,24 @@ import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
|
class Creature:
|
||||||
|
def __init__(self, creature_id: int, creature_name: str, creature_nickname: str, health: int, power_level: int,
|
||||||
|
max_spawn: int, stunnable: int, stun_multiplier: float or None, door_open_speed: float or None,
|
||||||
|
hostile: int, creature_type: str, favorite_moon: str):
|
||||||
|
self.creature_id: int = creature_id
|
||||||
|
self.creature_name: str = creature_name
|
||||||
|
self.creature_nickname: str = creature_nickname
|
||||||
|
self.health: int = health
|
||||||
|
self.power_level: int = power_level
|
||||||
|
self.max_spawn: int = max_spawn
|
||||||
|
self.stunnable: bool = bool(stunnable)
|
||||||
|
self.stun_multiplier: float = stun_multiplier
|
||||||
|
self.door_open_speed: float or None = door_open_speed
|
||||||
|
self.hostile: bool = bool(hostile)
|
||||||
|
self.creature_type: str = creature_type
|
||||||
|
self.favorite_moon: str = favorite_moon
|
||||||
|
|
||||||
|
|
||||||
class Moon:
|
class Moon:
|
||||||
def __init__(self, moon_id: int, name: str, risk_level: str, cost: int, default_layout: str,
|
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,
|
map_size_multiplier: float, min_scrap: int, max_scrap: int, outside_max_power: int,
|
||||||
|
@ -20,8 +38,8 @@ class Moon:
|
||||||
|
|
||||||
|
|
||||||
class Scrap:
|
class Scrap:
|
||||||
def __init__(self, scrap_id: int, name: str, min_value: int,
|
def __init__(self, scrap_id: int, name: str, min_value: int, max_value: int, weight: int, conductive: int,
|
||||||
max_value: int, weight: int, conductive: int, two_handed: int):
|
two_handed: int):
|
||||||
self.scrap_id: int = scrap_id
|
self.scrap_id: int = scrap_id
|
||||||
self.name: str = name
|
self.name: str = name
|
||||||
self.min_value: int = min_value
|
self.min_value: int = min_value
|
||||||
|
@ -43,6 +61,41 @@ def get_connection() -> sqlite3.Connection:
|
||||||
return sqlite3.connect("./scouter.db")
|
return sqlite3.connect("./scouter.db")
|
||||||
|
|
||||||
|
|
||||||
|
def get_creature_by_id(creature_id: int) -> Creature or None:
|
||||||
|
with get_connection() as connection:
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
query = """
|
||||||
|
select c.creature_id,
|
||||||
|
c.creature_name,
|
||||||
|
c.creature_nickname,
|
||||||
|
c.health,
|
||||||
|
c.power_level,
|
||||||
|
c.max_spawn,
|
||||||
|
c.stunnable,
|
||||||
|
c.stun_multiplier,
|
||||||
|
c.door_open_speed,
|
||||||
|
c.hostile,
|
||||||
|
ct.type_name,
|
||||||
|
m.moon_name
|
||||||
|
from creature as c
|
||||||
|
join main.creature_type ct on c.creature_type_id = ct.creature_type_id
|
||||||
|
join main.moon m on c.favorite_moon_id = m.moon_id
|
||||||
|
where creature_id = ?
|
||||||
|
limit 1;
|
||||||
|
"""
|
||||||
|
|
||||||
|
creature = cursor.execute(
|
||||||
|
query,
|
||||||
|
(creature_id,)
|
||||||
|
).fetchone()
|
||||||
|
|
||||||
|
if creature:
|
||||||
|
return Creature(*creature)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_moon_id_by_name(moon_name: str) -> int | None:
|
def get_moon_id_by_name(moon_name: str) -> int | None:
|
||||||
"""Queries the database for a moon ID that matches the given name.
|
"""Queries the database for a moon ID that matches the given name.
|
||||||
|
|
||||||
|
@ -79,8 +132,7 @@ def get_moon_list() -> list[str] | None:
|
||||||
).fetchall()
|
).fetchall()
|
||||||
|
|
||||||
if moon_names:
|
if moon_names:
|
||||||
moon_names = [moon[0] for moon in moon_names]
|
return [moon[0] for moon in moon_names]
|
||||||
return moon_names
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -191,3 +243,29 @@ limit 1;
|
||||||
return Scrap(*scrap)
|
return Scrap(*scrap)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def get_spawnable_inside_creature_ids(moon_id: int) -> list[int] | None:
|
||||||
|
with get_connection() as connection:
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
query = """
|
||||||
|
select c.creature_id as Creature
|
||||||
|
from spawn_chance as s
|
||||||
|
join main.creature c on s.creature_id = c.creature_id
|
||||||
|
join main.moon m on m.moon_id = s.moon_id
|
||||||
|
join main.creature_type ct on ct.creature_type_id = c.creature_type_id
|
||||||
|
where s.moon_id like ?
|
||||||
|
and (ct.type_name = 'Inside' or 'Hybrid')
|
||||||
|
and s.spawn_chance > 0
|
||||||
|
order by s.spawn_chance desc;
|
||||||
|
"""
|
||||||
|
creature_ids = cursor.execute(
|
||||||
|
query,
|
||||||
|
(moon_id,)
|
||||||
|
).fetchall()
|
||||||
|
|
||||||
|
if creature_ids:
|
||||||
|
return [creature_id[0] for creature_id in creature_ids]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
Loading…
Reference in a new issue