Spaces:
Sleeping
Sleeping
# portfolio/app.py | |
from flask import Flask, render_template, url_for, redirect | |
from npc_social_network.routes.npc_route import npc_bp | |
# from stock.routes.stock_route import stock_bp | |
import os | |
import subprocess | |
# ์๋ฎฌ๋ ์ด์ ํ๋ก์ธ์ค๋ฅผ ๊ด๋ฆฌํ ์ ์ญ ๋ณ์ | |
simulation_process = None | |
def create_app(): | |
app = Flask(__name__) # static/template ๊ฒฝ๋ก๋ฅผ ๊ธฐ๋ณธ๊ฐ | |
# ๊ฐ ํ๋ก์ ํธ๋ Blueprint์์ ์๊ธฐ static/template ๊ด๋ฆฌ | |
app.register_blueprint(npc_bp) | |
# app.register_blueprint(stock_bp) | |
def index(): | |
return render_template("main.html") | |
def run_npc_simulation(): | |
global simulation_process | |
# ์ด๋ฏธ ์คํ ์ค์ธ ํ๋ก์ธ์ค๊ฐ ์๋ค๋ฉด ์ข ๋ฃ | |
if simulation_process and simulation_process.poll() is None: | |
simulation_process.terminate() | |
simulation_process.wait() | |
# ํ์ด์ฌ ๊ฐ์ํ๊ฒฝ์ ์คํ ํ์ผ ๊ฒฝ๋ก๋ฅผ ๋ช ์์ ์ผ๋ก ์ง์ ํ ์ ์์ | |
python_exec = "python" | |
# ๋น๋๊ธฐ๋ก Pygame ์๋ฎฌ๋ ์ด์ ์คํ | |
subprocess.Popen([python_exec, "-m", "npc_social_network.maps.villages.town_hall"]) # ๋น๋๊ธฐ๋ก ์คํ (์ฐฝ ๋์) | |
# ์คํ ํ ์ฌ์ฉ์ ์๋ด ํ์ด์ง ํ์ | |
return redirect(url_for('npc_social.home')) | |
return app | |
if __name__ == '__main__': | |
app = create_app() | |
print("[MAIN] Starting Flask app only (Background NPC interactions handled by separate runner).", flush=True) | |
app.run(debug=True, use_reloader=False) |