Skip to content

Commit e277fe0

Browse files
BeyondMagicMillenaQueirozNanashii76
committed
refactor(python): restructure everything into a modern python project
Co-authored-by: Millena Queiroz <[email protected]> Co-authored-by: Paulo H. Lamounier <[email protected]>
1 parent 1efe3f1 commit e277fe0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+152
-98
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
__pycache__/
44
.env
55
.junk
6+
/src/Unimancer_Interface.egg-info

makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
.PHONY: config build start stop rmv interface
22

3-
VENV_DIR := ./.venv
3+
VENV_DIR := $(CURDIR)/.venv
4+
PYTHONPATH=$(CURDIR)/source
45

56
config:
67
@cp .env.template .env
78
@test -d $(VENV_DIR) || python3 -m venv $(VENV_DIR)
89
@echo "Python virtual environment criado em $(VENV_DIR)"
910
@$(VENV_DIR)/bin/pip install --upgrade pip
10-
@$(VENV_DIR)/bin/pip install -r requirements.txt
1111
@echo "Dependencias instaladas com sucesso."
12+
@python -m pip install .
1213

1314
build:
1415
@sudo docker compose up --build

pyproject.toml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "Unimancer-Interface"
7+
version = "4.0.0"
8+
description = "A game interface for Unimancer."
9+
readme = "README.md"
10+
requires-python = ">=3.9"
11+
license = { file = "LICENSE" }
12+
keywords = ["setuptools", "interface", "game", "unimancer"]
13+
14+
authors = [
15+
{name = "A. Random Developer", email = "[email protected]" },
16+
]
17+
18+
maintainers = [
19+
{ name = "A. Great Maintainer", email = "[email protected]" },
20+
]
21+
22+
classifiers = []
23+
dependencies = [
24+
"psycopg2",
25+
"colorama"
26+
]
27+
28+
[project.urls]
29+
"Homepage" = "https://github.com/SBD1/2024.2-unimancer"
30+
"Bug Reports" = "https://github.com/SBD1/2024.2-unimancer/issues"
31+
"Source" = "https://github.com/SBD1/2024.2-unimancer"
32+
33+
[project.scripts]
34+
sample = "sample:main"
35+
36+
37+
[tool.setuptools]
38+
package-data = { }

requirements.txt

-2
This file was deleted.

source/main.py

-48
This file was deleted.

src/__init__.py

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from database.Database import Database
2+
from default import populate_database
3+
import sys
4+
import logic
5+
import utils
6+
7+
def main():
8+
9+
sqls = {
10+
"./source/database/ddl/types.sql",
11+
"./source/database/ddl/tables.sql",
12+
"./source/database/dml/procedures.sql",
13+
"./source/database/dml/triggers.sql"
14+
}
15+
16+
db = Database("localhost", "postgres", "postgres", "123456")
17+
18+
def table_length() -> list:
19+
db.cur.execute("SELECT table_name FROM information_schema.tables WHERE table_schema='public'")
20+
tables = db.cur.fetchall()
21+
return len(tables)
22+
23+
def init_database():
24+
for sql in sqls:
25+
db.execute_file(sql)
26+
utils.debug("")
27+
populate_database(db)
28+
29+
# Process command line arguments.
30+
if len(sys.argv) > 1:
31+
arg = sys.argv[1]
32+
if arg == "delete" or arg == "reset":
33+
db.delete_tables()
34+
if arg == "reset":
35+
init_database()
36+
exit(0)
37+
38+
if table_length() == 0:
39+
utils.debug("Nenhuma tabela encontrada. Criando banco de dados...")
40+
utils.debug("Banco de dados e tabelas criados com sucesso!")
41+
init_database()
42+
43+
while True:
44+
character = logic.main_menu(db.conn)
45+
if not character:
46+
utils.debug("Nenhum personagem retornado, saindo.")
47+
exit(0)
48+
49+
while logic.game(db.conn, character):
50+
pass
File renamed without changes.
File renamed without changes.

source/combat.py src/combat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import random
22
from colorama import Fore, Style
33
import time
4-
import logic as logic
4+
import src.logic as logic
55
from utils import debug, error
66
import interface.display as display
77
from character import Character
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

source/database/defaults/npc/citizen/questers.py src/database/data/npc/citizen/questers.py

+5-19
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,11 @@ def questers(db: Database):
1212
"Ancião",
1313
3,
1414
"Velho homem aborrecido com a vida.",
15-
"Bem-vindo, jovem. Você deseja embarcar em uma jornada?"
16-
),
17-
(
18-
"Elysia",
19-
2,
20-
"descr",
21-
"Eu vi algo estranho nas montanhas... Está disposto a investigar?"
22-
),
23-
(
24-
"Isolde",
25-
1,
26-
"Você está pronto para enfrentar o que há de mais perigoso neste mundo?",
27-
"...Dialogo..."
28-
),
29-
(
30-
"Kael",
31-
4,
32-
"Tenho algumas pistas para você, mas isso vai exigir coragem.",
33-
"...Dialogo..."
15+
"""Tsk! Malditas pragas... esses ratos estão por toda parte!
16+
Entram nos celeiros, roem nossos suprimentos e nem os templos escaparam deles!
17+
Se ninguém fizer nada, logo estaremos dividindo nossas camas com essa praga!
18+
Se você puder nos ajudar a exterminá-los, seremos imensamente gratos. Mate-os e lhe darei uma recompensa justa!
19+
"""
3420
),
3521
]
3622

source/database/defaults/storage/quest.py src/database/data/storage/quest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from database import Database
2-
from database.defaults.storage.storage import storage
2+
from database.data.storage.storage import storage
33
from utils import debug, error
44
from colorama import Style
55

File renamed without changes.

source/database/ddl/tables.sql src/database/ddl/tables.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CREATE TABLE item (
33
tipo TIPO_ITEM NOT NULL,
44
descricao TEXT NOT NULL,
55
-- É o numero de inimigos que você tem que matar para conseguir o item.
6-
-- Chance de drop: O cálculo é: 1 / enemies_average.
6+
-- Chance de drop: O cálculo é: 1 / drop_inimigos_media.
77
drop_inimigos_media INT NOT NULL CHECK (drop_inimigos_media >= 0),
88
nome VARCHAR(200) NOT NULL,
99
peso INT NOT NULL CHECK (peso >= 0),
File renamed without changes.
File renamed without changes.
File renamed without changes.

source/queries/query.py src/database/dql/query.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,31 @@ def get_civilian_info(conn, npc_name):
150150
result = cur.fetchone()
151151
return {
152152
'nome': result[0],
153-
'descricao': result[1]
153+
'descricao': result[1],
154+
'npc_id': result[2]
154155
}
155156

157+
# get quest given a quester id
158+
def get_quest(conn, quester_id):
159+
with conn.cursor() as cur:
160+
cur.execute(
161+
"""
162+
SELECT q.titulo, q.descricao, qu.dialogo, q.id, q.recompensa
163+
FROM quest q
164+
LEFT JOIN quester qu ON qu.id = q.quester_id
165+
WHERE q.quester_id = %s;
166+
""", (quester_id,)
167+
)
168+
result = cur.fetchall()
169+
return {
170+
'title': result[0][0],
171+
'description': result[0][1],
172+
'dialog': result[0][2],
173+
'quest_id': result[0][3],
174+
'reward': result[0][4]
175+
}
176+
177+
156178
# Function to get all spells
157179
def get_spells(conn, character_id):
158180
with conn.cursor() as cur:
File renamed without changes.

source/default.py src/default.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
2-
from database.defaults.item.acessory import bracelet, buckle, cane, cloack, collar, gloves, hat, ring, pants, socks, boots, key
31
from utils import debug, error
42
from database.Database import Database
53

6-
from database.defaults.npc.enemy import enemies, enemies_instances
7-
8-
from database.defaults.npc.citizen import citizens, merchants, questers
9-
10-
from database.defaults.storage import quest, storage, enemie_storage
11-
12-
from database.defaults.map import regions as r, sub_regions as sr, sub_regions_connections as src
13-
14-
from database.defaults.item.scroll import area_damage, cure, damage, scroll, writted_scroll, requirements
15-
16-
from database.defaults.item import effects, potions, potion_effect
4+
from database.data.item.acessory import bracelet, buckle, cane, cloack, collar, gloves, hat, ring, pants, socks, boots, key
5+
from database.data.npc.enemy import enemies, enemies_instances
6+
from database.data.npc.citizen import citizens, merchants, questers
7+
from database.data.storage import quest, storage, enemie_storage
8+
from database.data.map import regions as r, sub_regions as sr, sub_regions_connections as src
9+
from database.data.item.scroll import area_damage, cure, damage, scroll, writted_scroll, requirements
10+
from database.data.item import effects, potions, potion_effect
1711

1812
def populate_database(db: Database):
1913

source/interface/display.py src/interface/display.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import platform
33
from colorama import Fore, Style
44
import time
5-
import queries.query as query
65

76
# Clean the terminal screen
87
def clear_screen():
@@ -52,13 +51,27 @@ def display_npc_info(npc_nome, npc_tipo, conn):
5251
time.sleep(1)
5352

5453
if npc_tipo == "Quester":
55-
get_quest(npc_nome)
54+
show_quest(conn, npc_nome, descricao['npc_id'], character)
5655
input("Pressione Enter para continuar...")
5756
else:
5857
print(Fore.RED + f"{npc_nome} não tem nada a dizer." + Style.RESET_ALL)
5958
print(Fore.MAGENTA + "Pressione 0 para voltar ao menu." + Style.RESET_ALL)
6059
input()
6160

62-
def get_quest(npc_nome):
63-
print(f"Você recebeu uma missão de {npc_nome}.")
64-
# Adicione mais lógica conforme necessário
61+
def show_quest(conn, npc_name, npc_id, character):
62+
quest = get_quest(conn, npc_id)
63+
print(Fore.CYAN + f"\n Missão: {quest['title']}" + Style.RESET_ALL)
64+
print(Fore.CYAN + f"{quest['description']}" + Style.RESET_ALL)
65+
print('..')
66+
time.sleep(1)
67+
for line in quest['dialog'].split('\n'):
68+
print(f"{npc_name} diz: {line}")
69+
input("Pressione Enter para continuar...")
70+
71+
accept_quest(conn, character.id, quest['quest_id'])
72+
73+
print(Fore.GREEN + "\n--- COMPLETE A MISSÃO ---" + Style.RESET_ALL)
74+
print(Fore.YELLOW + f"Descrição: {quest['description']}" + Style.RESET_ALL)
75+
print(Fore.YELLOW + f"Recompensa: {quest['reward']}" + Style.RESET_ALL)
76+
print(Fore.MAGENTA + "Pressione Enter para continuar..." + Style.RESET_ALL)
77+
input()

source/interface/inventory.py src/interface/inventory.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from colorama import Style, Fore
2-
from interface.display import clear_screen
3-
from queries.query import list_item_inventory
2+
import database.dql.query as query
43
from character import Character
54

65
def display(character, conn):
76
print(f"Inventário de === {character.nome} ===")
87
print("-" * 40)
98

10-
items = list_item_inventory(conn, character.id)
9+
items = query.list_item_inventory(conn, character.id)
1110

1211
if not items:
1312
print("O inventário está vazio.")

source/interface/world_info.py src/interface/world_info.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from colorama import Fore, Style
22
import psycopg2
3-
from queries.query import get_subregions_character, list_npcs_subregion, list_enemys_subregion
3+
from database.dql.query import get_subregions_character, list_npcs_subregion, list_enemys_subregion
44
from character import Character
55

66
# Function to get subregion description

source/logic.py src/logic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import interface.display as display
22
import interface.inventory as inventory
33
import interface.world_info as world_info
4-
import queries.query as query
4+
import database.dql.query as query
55
import combat as combat
66
from colorama import Fore, Style
77
from character import Character

source/utils.py src/utils.py

File renamed without changes.

0 commit comments

Comments
 (0)