Skip to main content

Crafting Sorting

Based on game build 714014 | Last updated: 2026-03-21

Overview

The crafting_sorting module provides a collection of sorting classes used to organize recipes within the crafting menu interface. It categorizes recipes based on filter definitions, craftability status (buffered, craftable, uncraftable), and user favorite settings. These classes are typically instantiated by the crafting HUD widget to determine the display order of recipe buttons.

Usage example

local Sorting = require("crafting_sorting")

-- Assume widget is a valid crafting HUD widget instance
local widget = ThePlayer.HUD.crafting
local sorter = Sorting.DefaultSort(widget)

-- Iterate through sorted recipes
for index, recipe_name in sorter:__ipairs() do
print(index, recipe_name)
end

-- Refresh sorting logic if recipes change
sorter:Refresh()

Dependencies & tags

Components used: None (UI utility class). Dependencies: metaclass Globals: CRAFTING_FILTERS, AllRecipes, TheCraftingMenuProfile, STRINGS Tags: None identified.

Properties

PropertyTypeDefault ValueDescription
widgettablenilReference to the parent crafting widget.
sortedtable{}List of recipes explicitly defined in the filter.
unsortedtable{}List of recipes not defined in the filter.
fullupdatebooleanfalseFlag indicating a full UI refresh is required.
craftabletable{}(CraftableSort) Recipes currently craftable by the player.
favoritetable{}(FavoriteSort) Recipes marked as favorites by the player.
alpha_sortedtable{}(AlphaSort) List of all recipes sorted alphabetically.

Main functions

Constructor(widget)

  • Description: Initializes the sorting instance. Specific behavior varies by class (DefaultSort, CraftableSort, FavoriteSort, AlphaSort).
  • Parameters: widget (table) - The crafting HUD widget instance managing the menu.
  • Returns: Self (instance).

Refresh()

  • Description: Updates internal sorting tables based on current game state (e.g., inventory changes, favorite toggles). Triggers a widget update if changes occurred.
  • Parameters: None.
  • Returns: boolean - true if the widget requires an update, false otherwise.

GetSorted()

  • Description: Retrieves the list of recipes that belong to the current filter's sorted definition.
  • Parameters: None.
  • Returns: table - List of sorted recipe names. Returns empty table if no filter is selected.

GetUnsorted()

  • Description: Retrieves the list of recipes that do not belong to the current filter's sorted definition.
  • Parameters: None.
  • Returns: table - List of unsorted recipe names.

__ipairs()

  • Description: Lua metamethod enabling iteration over the sorter instance. Yields indices and recipe names in the calculated order (sorted then unsorted, categorized by specific sort logic).
  • Parameters: None.
  • Returns: function - An iterator function compatible with for i, v in ipairs(sorter) do.

OnFavoriteChanged(recipe_name, is_favorite_recipe)

  • Description: Callback triggered when a recipe's favorite status changes. Updates internal favorite tables and marks for refresh.
  • Parameters: recipe_name (string) - The name of the recipe. is_favorite_recipe (boolean) - The new favorite status.
  • Returns: Nothing.

OnSelected()

  • Description: Called when the sorting mode or filter is selected. Rebuilds internal tables to reflect the new selection.
  • Parameters: None.
  • Returns: Nothing.

BuildCraftableTable()

  • Description: (CraftableSort) Scans valid recipes and categorizes them into buffered, craftable, or uncraftable tables based on build state.
  • Parameters: None.
  • Returns: boolean - true if any category table changed.

BuildFavoriteTable()

  • Description: (FavoriteSort / DefaultSort) Rebuilds the favorite vs non-favorite categorization based on TheCraftingMenuProfile.
  • Parameters: None.
  • Returns: Nothing.

Events & listeners

  • Listens to: None (Does not use inst:ListenForEvent).
  • Pushes: None (Does not use inst:PushEvent).
  • Widget Callbacks: Calls widget:ApplyFilters() internally when Refresh() detects changes.