Skip to content

Commit

Permalink
Part Browser Changes: Added 'Add Part' button for new parts, tech req…
Browse files Browse the repository at this point in the history
…uired is now autofilled.

Tech required autofilled based on a mapping file of of year and category fields.

Standardized the line endings on generated files. (to LF only)

Updated the year field on the NK-9 (2009) to match its tech year.
mattwrobel committed Dec 28, 2018
1 parent f80ac23 commit f28c610
Showing 12 changed files with 2,382 additions and 202 deletions.
2 changes: 1 addition & 1 deletion Source/Tech Tree/Parts Browser/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RP-0-Parts-Browser
This is a browser/editor application for the RP-0 parts list (converted to json files per mod) that can also generate the needed configs from it.
This is a browser/editor application for the RP-0 parts list (converted to json files per mod) that can also generate the needed configs from it, created by [@mattwrobel](https://github.com/mattwrobel)

To get it working:
1. It uses Python 3, so that needs to be installed.
34 changes: 29 additions & 5 deletions Source/Tech Tree/Parts Browser/app.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

from flask import jsonify
from part_data import PartData
from tech_mapping import TechMapping
from flask import Flask, g
from flask import Blueprint, abort, g, render_template, redirect, request, url_for
from slugify import slugify
@@ -13,6 +14,9 @@
from identical_parts_cfg_generator import generate_identical_parts

part_data = PartData()
tech_mapping = TechMapping()

tech_mapping.validate_current(part_data.parts)

def create_app(test_config=None):

@@ -49,18 +53,26 @@ def unique_values_for_column(column_name):
sorted_values = list(part_data.unique_values_for_columns[column_name])
sorted_values.sort()
return jsonify({"data": sorted_values})
@app.route('/api/tech_mapping/<category>/<year>')
def get_tech_mapping(category, year):
return tech_mapping.get_tech_by_category_and_year(category, year)
@app.route('/api/combo_options/<column_name>')
def combo_options(column_name):
sorted_values = list(part_data.unique_values_for_columns[column_name])
sorted_values.sort()
return jsonify({"data": list(map(lambda x: {column_name: x}, sorted_values))})
if column_name != 'year':
sorted_values = list(part_data.unique_values_for_columns[column_name])
sorted_values.sort()
return jsonify({"data": list(map(lambda x: {column_name: x}, sorted_values))})
else:
sorted_values = list(tech_mapping.unique_years)
sorted_values.sort()
return jsonify({"data": list(map(lambda x: {column_name: x}, sorted_values))})

@app.route('/api/export_to_json')
def export_to_json():
for mod in part_data.unique_values_for_columns['mod']:
parts_for_mod = list(filter(lambda x: x['mod'] == mod, part_data.parts))
parts_for_mod.sort(key=lambda x: x['name'] if x['name'] is not None and len(x['name']) > 0 else x['title'] )
text_file = open("data/" + make_safe_filename(mod) + ".json", "w")
text_file = open("data/" + make_safe_filename(mod) + ".json", "w", newline='\n')
text_file.write(json.dumps(parts_for_mod, indent=4, separators=(',', ': ')))
text_file.close()
return "true"
@@ -102,9 +114,21 @@ def generate_all_configs():
def commit_changes():
queued_changes = request.get_json()
for row_id in queued_changes['queued_changes']:
new_part = False
part = part_data.get_part_by_name(queued_changes['queued_changes'][row_id]['name'])
# if the part can't be found, we assume it's a new part
if part is None:
part = {}
new_part = True
# if the mod isn't set, that is almost certainly because we're
# adding to a new mod, need to set it from the new_mod field
if 'mod' in queued_changes['queued_changes'][row_id]['changes'] and queued_changes['queued_changes'][row_id]['changes']['mod']['new'] == "":
queued_changes['queued_changes'][row_id]['changes']['mod']['new'] = queued_changes['queued_changes'][row_id]['changes']['new_mod']['new']
for field_name in queued_changes['queued_changes'][row_id]['changes']:
part[field_name] = queued_changes['queued_changes'][row_id]['changes'][field_name]['new']
if field_name not in ['mod_type', 'new_mod']:
part[field_name] = queued_changes['queued_changes'][row_id]['changes'][field_name]['new']
if new_part:
part_data.add_new_part(part)
export_to_json()
return "true"

4 changes: 2 additions & 2 deletions Source/Tech Tree/Parts Browser/data/Engine_Config.json
Original file line number Diff line number Diff line change
@@ -4315,7 +4315,7 @@
"entry_cost": "0",
"category": "STAGED",
"info": "",
"year": "1969",
"year": "2009",
"technology": "stagedCombustion2009",
"era": "04-ADV",
"ro": true,
@@ -8343,4 +8343,4 @@
"identical_part_name": "",
"module_tags": []
}
]
]
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ def generate_ecm_engines(parts):
# for purposes I don't full understand, we replace all '.' and '_' characters with '-'
# and '?' with ' '. That's what the downstream code expects for whatever reason.
ecm_configs += module_part_config_template.substitute(name=part['name'].replace('_','-').replace('.','-').replace('?',' '), ecm=part['entry_cost_mods'])
text_file = open("output/ECM-Engines.cfg", "w")
text_file = open("output/ECM-Engines.cfg", "w", newline='\n')
text_file.write(tree_ecm_engines_header)
text_file.write(ecm_configs)
text_file.write(tree_ecm_engines_footer)
2 changes: 1 addition & 1 deletion Source/Tech Tree/Parts Browser/ecm_parts_cfg_generator.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ def generate_ecm_parts(parts):
# for purposes I don't full understand, we replace all '.' and '_' characters with '-'
# and '?' with ' ' in the part names. That's what the downstream code expects for whatever reason.
ecm_configs += module_part_config_template.substitute(name=part['name'].replace('_','-').replace('.','-').replace('?',' '), ecm=part['entry_cost_mods'])
text_file = open("output/ECM-Parts.cfg", "w")
text_file = open("output/ECM-Parts.cfg", "w", newline='\n')
text_file.write(tree_ecm_parts_header)
text_file.write(ecm_configs)
text_file.write(tree_ecm_parts_footer)
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ def generate_identical_parts(parts):
sorted_parts.sort()
identical_part_configs += identical_part_template.substitute(name=name, identical_parts=",".join(sorted_parts))

text_file = open("output/identicalParts.cfg", "w")
text_file = open("output/identicalParts.cfg", "w", newline='\n')
text_file.write(identical_parts_header)
text_file.write(identical_part_configs)
text_file.close()
Loading

0 comments on commit f28c610

Please sign in to comment.