diff --git a/dev_stuff/python_helpers/main.py b/dev_stuff/python_helpers/main.py index 7745fb7..4bdc60d 100644 --- a/dev_stuff/python_helpers/main.py +++ b/dev_stuff/python_helpers/main.py @@ -37,7 +37,7 @@ def generate_clothing_item(name, model, texture_choices): tree = gfg.ElementTree(root) - path = r'python_helpers/outputs/output_clothing/' + name + ".xml" + path = r'outputs/output_clothing/' + name + ".xml" with open(path, "wb") as file: tree.write(file, encoding='utf-8', xml_declaration=True, pretty_print=True ) @@ -63,31 +63,35 @@ def generate_clothing_item(name, model, texture_choices): - path_idtable = r'python_helpers/outputs/fileGuidTable.xml' + path_idtable = r'outputs/fileGuidTable.xml' with open(path_idtable, "ab") as file: tree_guid.write(file, encoding='utf-8', pretty_print=True) -def generate_recipe(recipe_name, recipe_items, result_name, time, skill_required, tooltip): +def generate_recipe(recipe_name, recipe_items, on_create_func, time, skill_required, tooltip): root_element = f"recipe {recipe_name}\n" root_element += "\t{\n" for item in recipe_items: root_element += f"\t\t{item},\n" - root_element += f"\n\n\t\tResult: {result_name},\n" + root_element += "\n\n" + + # if result != "": + # root_element += f"\t\tResult: {result_name},\n" root_element += f"\t\tTime: {time:.2f},\n" root_element += "\t\tNeedToBeLearn: true,\n" root_element += "\t\tCanBeDoneFromFloor: false,\n" root_element += "\t\tOnGiveXP: NoXP_OnGiveXP,\n" root_element += f"\t\tSkillRequired: {skill_required[0]}={skill_required[1]},\n" root_element += "\t\tCategory: Surgeon,\n" + root_element += f"\t\tOnCreate:{on_create_func},\n" root_element += f"\t\tTooltip: {tooltip},\n" root_element += "\t}\n" - path = r'python_helpers/outputs/output_recipe/script.txt' + path = r'outputs/output_recipe/script.txt' with open(path, "at") as file: file.write(root_element) @@ -114,7 +118,7 @@ def generate_item(item_name, weight, item_type, display_category, display_name, root_element += "\t}\n" - path = r'python_helpers/outputs/output_item/script.txt' + path = r'outputs/output_item/script.txt' with open(path, "at") as file: file.write(root_element) @@ -123,24 +127,24 @@ def generate_item(item_name, weight, item_type, display_category, display_name, ########################################################################################### def read_table(file_name: str, table_name: str) -> pd.DataFrame: - wb = openpyxl.load_workbook(file_name, read_only= False, data_only = True) # openpyxl does not have table info if read_only is True; data_only means any functions will pull the last saved value instead of the formula - for sheetname in wb.sheetnames: # pulls as strings - sheet = wb[sheetname] # get the sheet object instead of string - if table_name in sheet.tables: # tables are stored within sheets, not within the workbook, although table names are unique in a workbook - tbl = sheet.tables[table_name] # get table object instead of string - tbl_range = tbl.ref #something like 'C4:F9' - break # we've got our table, bail from for-loop - data = sheet[tbl_range] # returns a tuple that contains rows, where each row is a tuple containing cells - content = [[cell.value for cell in row] for row in data] # loop through those row/cell tuples - header = content[0] # first row is column headers - rest = content[1:] # every row that isn't the first is data - df = pd.DataFrame(rest, columns = header) + wb = openpyxl.load_workbook(file_name, read_only=False, data_only=True) # openpyxl does not have table info if read_only is True; data_only means any functions will pull the last saved value instead of the formula + for sheetname in wb.sheetnames: # pulls as strings + sheet = wb[sheetname] # get the sheet object instead of string + if table_name in sheet.tables: # tables are stored within sheets, not within the workbook, although table names are unique in a workbook + tbl = sheet.tables[table_name] # get table object instead of string + tbl_range = tbl.ref #something like 'C4:F9' + break # we've got our table, bail from for-loop + data = sheet[tbl_range] # returns a tuple that contains rows, where each row is a tuple containing cells + content = [[cell.value for cell in row] for row in data] # loop through those row/cell tuples + header = content[0] # first row is column headers + rest = content[1:] # every row that isn't the first is data + df = pd.DataFrame(rest, columns=header) wb.close() return df ########################################################################################### -excel_path = r'python_helpers/modules_prost.xlsx' +excel_path = r'modules_prost.xlsx' df_base = read_table(excel_path, "BaseTable") df_top = read_table(excel_path, "TopTable") @@ -182,37 +186,65 @@ for base_row in df_base.iterrows(): icon = "metalLeg" generate_item(item_id, weight, item_type, display_category, display_name, icon, "TempTooltip", "false", clothing_item_name, bl, "Hands") + # ITEM GENERATION PASS - Single item to assemble stuff -def generate_normal_items(df, type): +def generate_normal_items(df, part_type): for row in df.iterrows(): - item_id = "ProstPart_" + row[1][type] + item_id = "ProstPart_" + row[1][part_type] item_type = "Normal" weight = "{0:.2f}".format(float(row[1]["Weight"])) display_category = "Prosthesis" display_name = row[1]["Display Name"] - icon = "ProstTest" + type + icon = "ProstTest" + part_type generate_item(item_id, weight, item_type, display_category, display_name, icon, "TempTooltip", "false") + generate_normal_items(df_base, "Base") generate_normal_items(df_top, "Top") -# RECIPE GENERATION PASS +# RECIPE GENERATION PASS - Assembly +for base_row in df_base.iterrows(): + for top_row in df_top.iterrows(): + + base_name = base_row[1]["Base"] + top_name = top_row[1]["Top"] + base_display_name = base_row[1]["Display Name"] + top_display_name = top_row[1]["Display Name"] + + recipe_name = f"Craft prosthesis with {base_display_name} and {top_display_name}" + + first_item = "ProstPart_" + base_row[1]["Base"] + second_item = "ProstPart_" + top_row[1]["Top"] + # TODO add screwdriver and some screws to the items + + + recipe_items = [first_item, second_item] + on_create_func = "ProsthesisRecipes.OnCreateProsthesis" + time = 10 # TODO Change this + skill_required = ["FirstAid", "2"] # TODO Change this + tooltip = "Tooltip_test" + generate_recipe(recipe_name, recipe_items, on_create_func, time, skill_required, tooltip) + + +# RECIPE GENERATION PASS - Disassembly for base_row in df_base.iterrows(): for top_row in df_top.iterrows(): base_name = base_row[1]["Base"] top_name = top_row[1]["Top"] + base_display_name = base_row[1]["Display Name"] + top_display_name = top_row[1]["Display Name"] - recipe_name = f"Craft prosthesis with {base_name} and {top_name}" - - first_item = "ProstPart_" + base_row[1]["Base"] - second_item = "ProstPart_" + top_row[1]["Top"] - - recipe_items = [first_item, second_item] - result = "Prost_" + base_name + "_" + top_name + recipe_name = f"Disassemble prosthesis with {base_display_name} and {top_display_name}" + recipe_item = [f"Prost_{base_name}_{top_name}"] + on_create_func = "ProsthesisRecipes.OnDisassembleProsthesis" time = 10 # TODO Change this - skill_required = ["FirstAid","2"] # TODO Change this + skill_required = ["FirstAid", "2"] # TODO Change this tooltip = "Tooltip_test" - generate_recipe(recipe_name, recipe_items, result, time, skill_required, tooltip) + generate_recipe(recipe_name, recipe_item, on_create_func, time, skill_required, tooltip) + + +# RECIPE GENERATION PASS - Single parts - Base +# TODO do this diff --git a/media/lua/client/TOC_ProsthesisHandler.lua b/media/lua/client/TOC_ProsthesisHandler.lua index 4b257d1..4a56e69 100644 --- a/media/lua/client/TOC_ProsthesisHandler.lua +++ b/media/lua/client/TOC_ProsthesisHandler.lua @@ -17,8 +17,6 @@ local base_table = { } - - local top_table = { MetalHook = { durability = 1, @@ -53,7 +51,7 @@ end ---@param prosthesis_item any Normal item ---@param inventory any player inventory ---@param limb any ----@return unknown equipped_prosthesis clothing item equipped prosthesis +---@return any equipped_prosthesis clothing item equipped prosthesis function GenerateEquippedProsthesis(prosthesis_item, inventory, limb) -- TODO Durability should be decided from the clothing item xml. Same thing for disassembling stuff -- TODO some stuff should be defined by the limb, like -10 if forearm in speed @@ -63,8 +61,6 @@ function GenerateEquippedProsthesis(prosthesis_item, inventory, limb) local prosthesis_name = prosthesis_item:getFullType() local item_mod_data = prosthesis_item:getModData() - - local durability_base = 0 local speed_base = 0 @@ -100,8 +96,13 @@ end ProsthesisRecipes = {} +-- Parts should have a default condition max set at creation +-- When we create a prosthesis, we carry the condition from the parts +-- If we disassemble the prosthesis, the condition will be carried back to the parts +-- Speed stat should be managed in another way, so change it -local function GetProshetsisPartName(array_stats, prosthesis_name) + +local function GetProsthesisPartName(array_stats, prosthesis_name) for name, _ in pairs(array_stats) do if string.find(prosthesis_name, name) then return name @@ -151,8 +152,8 @@ function ProsthesisRecipes.OnDisassembleProsthesis(item, result_items, player, s -- Check name of the item local prosthesis_item_name = item:getFullType() - local base_name = GetProshetsisPartName(base_table, prosthesis_item_name) - local top_name = GetProshetsisPartName(top_table, prosthesis_item_name) + local base_name = GetProsthesisPartName(base_table, prosthesis_item_name) + local top_name = GetProsthesisPartName(top_table, prosthesis_item_name) print("TOC: " .. base_name .. " and " .. top_name) @@ -179,9 +180,3 @@ end - --- Parts should have a default condition max set at creation --- When we create a prosthesis, we carry the condition from the parts --- If we disassemble the prosthesis, the condition will be carried back to the parts - --- Speed stat should be managed in another way, so change it \ No newline at end of file