Skip to content

Commit

Permalink
feat: ✨ add debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Wivik committed Apr 15, 2023
1 parent f407f49 commit 14856a1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 12 deletions.
36 changes: 30 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
repository_owner = 'Wivik'
repository_name = 'pyp-boy'

PYP_BOY_LOG_LEVEL = os.environ.get('PYP_BOY_LOG_LEVEL')
PYP_BOY_MODE = os.environ.get('PYP_BOY_MODE')

if PYP_BOY_LOG_LEVEL is not None and PYP_BOY_LOG_LEVEL == 'DEBUG':
log_level = 'DEBUG'
else:
log_level = 'INFO'
if PYP_BOY_MODE is not None and PYP_BOY_MODE == 'DEBUG':
print('debug mode on')
global_vars.update(
pyp_boy_debug_mode=True,
)

## Create dir
if not os.path.isdir(log_path):
Expand Down Expand Up @@ -81,7 +82,7 @@ def root():
if not os.path.exists(game_file):
# get the latest release
get_release = f.get_latest_release(repository_owner, repository_name, game_file, logger=logger)
return render_template('db.html', footer_vars=footer_vars, global_vars=v.global_vars, get_release=get_release, new=False)
return render_template('db.html', footer_vars=footer_vars, global_vars=global_vars, get_release=get_release, new=False)
else:
## check new version
db_version = db.get_game_db_version(game_file)
Expand All @@ -91,6 +92,7 @@ def root():
if check_version:
return render_template('db.html', footer_vars=footer_vars, global_vars=global_vars, new=True)
else:
global_vars.update(app_version=db_version)
return redirect(url_for('sys'))

@app.route("/newfile")
Expand Down Expand Up @@ -143,6 +145,26 @@ def sys_new():
else:
return render_template('sys/new.html', global_vars=global_vars)

@app.route("/sys/debug")
@check_session
def sys_debug():

url_params = request.args
if len(url_params) > 0:
if url_params['action'] == 'add_all_items':
item_type = url_params['type']
if item_type not in ['weapon', 'aid', 'apparel', 'misc']:
error_number = f.gen_random_hex_number()
flash(error_number + ' DEBUG_ITEMS '+str(ret))
return redirect(url_for('sys_debug'))
items = db.run_db_select_all_query(game_file, 'SELECT id FROM '+ item_type, '', logger=logger)
for item in items:
db.add_item(save_file, session['save_id'], item['id'], item_type, logger=logger)
flash('Item '+ item_type +' id ' + str(item['id']) +' added')
return render_template('sys/debug.html', global_vars=global_vars)
else:
return render_template('sys/debug.html', global_vars=global_vars)

@app.route("/stat")
def stat():
test_save_file = f.test_save_file(save_file, logger=logger)
Expand Down Expand Up @@ -252,3 +274,5 @@ def data_log():
story_step = db.get_chapter_step(game_file, story_row['chapter'], story_row['step'], logger=logger)
story.append(story_step['text'])
return render_template('data/log.html', global_vars=global_vars, story=story)


6 changes: 1 addition & 5 deletions templates/flashed_messages.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{% if get_flashed_messages() %}
<div class="flash">
0x0042 - Disk Read Error<br />
0x5555 - Bus Error <br />
{% for message in get_flashed_messages() %}
{{ message }}
{{ message }}<br />
{% endfor %}
<br />Subroutine interrupted
<br />Press any key to continue...
</div>
{% endif %}
25 changes: 25 additions & 0 deletions templates/sys/debug.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% extends 'base.html' %}

{% block content %}

{% include 'sys/sys_submenu.html' %}

<div id="container">

<div id="container_left">
<p>Debug section</p>

<a href="{{ url_for('sys_debug', action='add_all_items', type='weapon') }}">Add all weapons items to inventory</a>
<a href="{{ url_for('sys_debug', action='add_all_items', type='apparel') }}">Add all apparel items to inventory</a>
<a href="{{ url_for('sys_debug', action='add_all_items', type='aid') }}">Add all aid items to inventory</a>
<a href="{{ url_for('sys_debug', action='add_all_items', type='misc') }}">Add all misc items to inventory</a>
</div>
<div id="container_right" style="background-image: url({{ url_for('static', filename='img/back/debug.png') }});" class="pixel-art">
&nbsp;
</div>

</div>



{% endblock %}
3 changes: 3 additions & 0 deletions templates/sys/sys_submenu.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<li><a href="/sys"{% if request.path == '/' or request.path == '/sys' or request.path == '/sys/' or request.path.startswith("/sys/load") %} class="active"{% endif %}>Open</a></li>
<li><a href="/sys/new"{% if request.path == '/sys/new' %} class="active"{% endif %}>New</a></li>
<li><a href="/sys/manage"{% if request.path == '/sys/manage' %} class="active"{% endif %}>Manage</a></li>
{%if global_vars.pyp_boy_debug_mode %}
<li><a href="/sys/debug"{% if request.path == '/sys/debug' %} class="active"{% endif %}>Debug</a></li>
{% endif %}
</ul>

</nav>
Expand Down
2 changes: 1 addition & 1 deletion utils/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
global_vars = {
'app_name': 'Pyp-boy',
'app_version': '0.1.0',
'pyp_boy_debug_mode': False,
}

global footer_vars
Expand All @@ -14,4 +15,3 @@
session = {}

global app_version

0 comments on commit 14856a1

Please sign in to comment.