[{"data":1,"prerenderedAt":1229},["ShallowReactive",2],{"doc-global_essentials\u002Fitems\u002Fapply":3},{"id":4,"title":5,"body":6,"description":1219,"extension":1220,"meta":1221,"navigation":179,"path":1225,"seo":1226,"stem":1227,"__hash__":1228},"docs\u002Fdocs\u002Fglobal_essentials\u002Fitems\u002Fapply.md","Apply",{"type":7,"value":8,"toc":1201},"minimark",[9,14,27,30,35,38,86,89,103,105,109,115,118,123,244,246,250,253,258,332,336,368,370,374,381,414,419,449,451,455,458,507,510,512,516,519,565,568,570,574,577,626,629,640,642,646,652,896,898,902,905,926,931,970,973,975,979,1025,1027,1031,1104,1106,1110,1174,1176,1180,1197],[10,11,13],"h1",{"id":12},"apply-system","Apply System",[15,16,17,18,22,23,26],"p",{},"The apply system handles the \"Apply\" button in inventories. This powers ",[19,20,21],"strong",{},"crafting"," (combining items into new items) and ",[19,24,25],{},"custom interactions"," (puzzle mechanics, item insertion, etc.).",[28,29],"hr",{},[31,32,34],"h2",{"id":33},"how-it-works","How It Works",[15,36,37],{},"When a player clicks the Apply button:",[39,40,41,54],"table",{},[42,43,44],"thead",{},[45,46,47,51],"tr",{},[48,49,50],"th",{},"Step",[48,52,53],{},"What happens",[55,56,57,70,78],"tbody",{},[45,58,59,63],{},[60,61,62],"td",{},"1",[60,64,65,69],{},[66,67,68],"code",{},"inventory_apply"," event fires",[45,71,72,75],{},[60,73,74],{},"2",[60,76,77],{},"If event returns false, stop",[45,79,80,83],{},[60,81,82],{},"3",[60,84,85],{},"Otherwise, run crafting logic",[15,87,88],{},"The Apply button appears when an inventory has either:",[90,91,92,96],"ul",{},[93,94,95],"li",{},"Recipes assigned to it",[93,97,98,99,102],{},"A custom ",[66,100,101],{},"interactive"," value set",[28,104],{},[31,106,108],{"id":107},"the-apply-button","The Apply Button",[15,110,111,112,114],{},"The ",[66,113,101],{}," field on inventory templates controls the Apply button:",[15,116,117],{},"The value also becomes a CSS class on the button, allowing custom styling per inventory.",[15,119,120],{},[19,121,122],{},"Styling the Apply button:",[124,125,130],"pre",{"className":126,"code":127,"language":128,"meta":129,"style":129},"language-css shiki shiki-themes github-light github-dark","\u002F* Base styling for \"combine\" button *\u002F\n.apply-button.combine {\n  background-color: #4a90d9;\n}\n\n.apply-button.combine:hover {\n  background-color: #3a70b9;\n}\n\n\u002F* Set button text using ::before *\u002F\n.apply-button.combine::before {\n  content: \"Combine\";\n}\n","css","",[66,131,132,141,152,168,174,181,189,201,206,211,217,225,239],{"__ignoreMap":129},[133,134,137],"span",{"class":135,"line":136},"line",1,[133,138,140],{"class":139},"sJ8bj","\u002F* Base styling for \"combine\" button *\u002F\n",[133,142,144,148],{"class":135,"line":143},2,[133,145,147],{"class":146},"sScJk",".apply-button.combine",[133,149,151],{"class":150},"sVt8B"," {\n",[133,153,155,159,162,165],{"class":135,"line":154},3,[133,156,158],{"class":157},"sj4cs","  background-color",[133,160,161],{"class":150},": ",[133,163,164],{"class":157},"#4a90d9",[133,166,167],{"class":150},";\n",[133,169,171],{"class":135,"line":170},4,[133,172,173],{"class":150},"}\n",[133,175,177],{"class":135,"line":176},5,[133,178,180],{"emptyLinePlaceholder":179},true,"\n",[133,182,184,187],{"class":135,"line":183},6,[133,185,186],{"class":146},".apply-button.combine:hover",[133,188,151],{"class":150},[133,190,192,194,196,199],{"class":135,"line":191},7,[133,193,158],{"class":157},[133,195,161],{"class":150},[133,197,198],{"class":157},"#3a70b9",[133,200,167],{"class":150},[133,202,204],{"class":135,"line":203},8,[133,205,173],{"class":150},[133,207,209],{"class":135,"line":208},9,[133,210,180],{"emptyLinePlaceholder":179},[133,212,214],{"class":135,"line":213},10,[133,215,216],{"class":139},"\u002F* Set button text using ::before *\u002F\n",[133,218,220,223],{"class":135,"line":219},11,[133,221,222],{"class":146},".apply-button.combine::before",[133,224,151],{"class":150},[133,226,228,231,233,237],{"class":135,"line":227},12,[133,229,230],{"class":157},"  content",[133,232,161],{"class":150},[133,234,236],{"class":235},"sZZnC","\"Combine\"",[133,238,167],{"class":150},[133,240,242],{"class":135,"line":241},13,[133,243,173],{"class":150},[28,245],{},[31,247,249],{"id":248},"recipes","Recipes",[15,251,252],{},"Recipes define how items transform into other items.",[254,255,257],"h3",{"id":256},"recipe-template-fields","Recipe Template Fields",[39,259,260,270],{},[42,261,262],{},[45,263,264,267],{},[48,265,266],{},"Field",[48,268,269],{},"Description",[55,271,272,282,292,302,312,322],{},[45,273,274,279],{},[60,275,276],{},[66,277,278],{},"id",[60,280,281],{},"Recipe identifier",[45,283,284,289],{},[60,285,286],{},[66,287,288],{},"name",[60,290,291],{},"Display name",[45,293,294,299],{},[60,295,296],{},[66,297,298],{},"description",[60,300,301],{},"Recipe description (supports rich text)",[45,303,304,309],{},[60,305,306],{},[66,307,308],{},"input_items",[60,310,311],{},"Required ingredients",[45,313,314,319],{},[60,315,316],{},[66,317,318],{},"output_items",[60,320,321],{},"Items produced",[45,323,324,329],{},[60,325,326],{},[66,327,328],{},"tags",[60,330,331],{},"For categorizing recipes",[254,333,335],{"id":334},"inputoutput-format","Input\u002FOutput Format",[39,337,338,346],{},[42,339,340],{},[45,341,342,344],{},[48,343,266],{},[48,345,269],{},[55,347,348,358],{},[45,349,350,355],{},[60,351,352],{},[66,353,354],{},"item_id",[60,356,357],{},"The item template ID",[45,359,360,365],{},[60,361,362],{},[66,363,364],{},"quantity",[60,366,367],{},"How many (default: 1)",[28,369],{},[31,371,373],{"id":372},"learning-recipes","Learning Recipes",[15,375,376,377,380],{},"Recipes must be ",[19,378,379],{},"learned"," before they can be used.",[39,382,383,392],{},[42,384,385],{},[45,386,387,390],{},[48,388,389],{},"Action",[48,391,269],{},[55,393,394,404],{},[45,395,396,401],{},[60,397,398],{},[66,399,400],{},"{learn_recipe: \"recipe_id\"}",[60,402,403],{},"Learn a single recipe",[45,405,406,411],{},[60,407,408],{},[66,409,410],{},"{learn_recipe: \"recipe1, recipe2\"}",[60,412,413],{},"Learn multiple recipes (comma-separated)",[15,415,416],{},[19,417,418],{},"Example - Learning from a book:",[39,420,421,430],{},[42,422,423],{},[45,424,425,427],{},[48,426,266],{},[48,428,429],{},"Value",[55,431,432,440],{},[45,433,434,437],{},[60,435,436],{},"Trigger",[60,438,439],{},"Player uses \"Blacksmith Manual\" item",[45,441,442,444],{},[60,443,389],{},[60,445,446],{},[66,447,448],{},"{learn_recipe: \"iron_sword_recipe, steel_sword_recipe\"}",[28,450],{},[31,452,454],{"id":453},"crafting-flow","Crafting Flow",[15,456,457],{},"When the player clicks Apply with a selected recipe:",[39,459,460,468],{},[42,461,462],{},[45,463,464,466],{},[48,465,50],{},[48,467,53],{},[55,469,470,477,484,491,499],{},[45,471,472,474],{},[60,473,62],{},[60,475,476],{},"Check if recipe is learned",[45,478,479,481],{},[60,480,74],{},[60,482,483],{},"Check if ingredients exist (unequipped items only)",[45,485,486,488],{},[60,487,82],{},[60,489,490],{},"Check if inventory has space for outputs",[45,492,493,496],{},[60,494,495],{},"4",[60,497,498],{},"Remove input items",[45,500,501,504],{},[60,502,503],{},"5",[60,505,506],{},"Create output items",[15,508,509],{},"If any check fails, an appropriate notification is shown.",[28,511],{},[31,513,515],{"id":514},"recipe-selection-ui","Recipe Selection UI",[15,517,518],{},"When an inventory has recipes:",[39,520,521,531],{},[42,522,523],{},[45,524,525,528],{},[48,526,527],{},"UI Element",[48,529,530],{},"Behavior",[55,532,533,541,549,557],{},[45,534,535,538],{},[60,536,537],{},"Recipe list",[60,539,540],{},"Shows only learned recipes",[45,542,543,546],{},[60,544,545],{},"Recipe button",[60,547,548],{},"Disabled if ingredients missing",[45,550,551,554],{},[60,552,553],{},"Click recipe",[60,555,556],{},"Transfers needed ingredients from party inventory",[45,558,559,562],{},[60,560,561],{},"Click Apply",[60,563,564],{},"Crafts using selected recipe",[15,566,567],{},"Clicking a recipe automatically moves the required ingredients from party inventory to the crafting inventory.",[28,569],{},[31,571,573],{"id":572},"stacking-rules","Stacking Rules",[15,575,576],{},"Crafting respects item stacking:",[39,578,579,591],{},[42,580,581],{},[45,582,583,589],{},[48,584,585,588],{},[66,586,587],{},"max_stack"," Value",[48,590,530],{},[55,592,593,606,616],{},[45,594,595,603],{},[60,596,597,600,601],{},[66,598,599],{},"0"," or ",[66,602,62],{},[60,604,605],{},"Each item takes one slot",[45,607,608,613],{},[60,609,610],{},[66,611,612],{},"99",[60,614,615],{},"Up to 99 items per slot",[45,617,618,623],{},[60,619,620],{},[66,621,622],{},"-1",[60,624,625],{},"Unlimited stacking",[15,627,628],{},"The system calculates available space by considering:",[90,630,631,634,637],{},[93,632,633],{},"Slots freed by consuming ingredients",[93,635,636],{},"Existing partial stacks that can be filled",[93,638,639],{},"Max stack values from item templates",[28,641],{},[31,643,645],{"id":644},"custom-apply-logic","Custom Apply Logic",[15,647,648,649,651],{},"Use the ",[66,650,68],{}," event for custom behavior:",[124,653,657],{"className":654,"code":655,"language":656,"meta":129,"style":129},"language-javascript shiki shiki-themes github-light github-dark","game.on(\"inventory_apply\", (inventory) => {\n  if (inventory.id === \"puzzle_altar\") {\n    \u002F\u002F Check if correct items are placed\n    const gem = inventory.getFirstItemById(\"red_gem\");\n    const key = inventory.getFirstItemById(\"ancient_key\");\n\n    if (gem && key) {\n      \u002F\u002F Consume items\n      inventory.removeItem(gem);\n      inventory.removeItem(key);\n\n      \u002F\u002F Store result and notify\n      game.getStore(\"puzzle\").set(\"altar_activated\", true);\n      game.showNotification(\"The altar glows with ancient power!\");\n    }\n\n    \u002F\u002F Prevent other calls, including default crafting(if the inventory has any recipes assigned to it)\n    return false; \n  }\n});\n","javascript",[66,658,659,689,706,711,736,756,760,774,779,790,799,803,808,840,855,861,866,872,884,890],{"__ignoreMap":129},[133,660,661,664,667,670,673,676,680,683,687],{"class":135,"line":136},[133,662,663],{"class":150},"game.",[133,665,666],{"class":146},"on",[133,668,669],{"class":150},"(",[133,671,672],{"class":235},"\"inventory_apply\"",[133,674,675],{"class":150},", (",[133,677,679],{"class":678},"s4XuR","inventory",[133,681,682],{"class":150},") ",[133,684,686],{"class":685},"szBVR","=>",[133,688,151],{"class":150},[133,690,691,694,697,700,703],{"class":135,"line":143},[133,692,693],{"class":685},"  if",[133,695,696],{"class":150}," (inventory.id ",[133,698,699],{"class":685},"===",[133,701,702],{"class":235}," \"puzzle_altar\"",[133,704,705],{"class":150},") {\n",[133,707,708],{"class":135,"line":154},[133,709,710],{"class":139},"    \u002F\u002F Check if correct items are placed\n",[133,712,713,716,719,722,725,728,730,733],{"class":135,"line":170},[133,714,715],{"class":685},"    const",[133,717,718],{"class":157}," gem",[133,720,721],{"class":685}," =",[133,723,724],{"class":150}," inventory.",[133,726,727],{"class":146},"getFirstItemById",[133,729,669],{"class":150},[133,731,732],{"class":235},"\"red_gem\"",[133,734,735],{"class":150},");\n",[133,737,738,740,743,745,747,749,751,754],{"class":135,"line":176},[133,739,715],{"class":685},[133,741,742],{"class":157}," key",[133,744,721],{"class":685},[133,746,724],{"class":150},[133,748,727],{"class":146},[133,750,669],{"class":150},[133,752,753],{"class":235},"\"ancient_key\"",[133,755,735],{"class":150},[133,757,758],{"class":135,"line":183},[133,759,180],{"emptyLinePlaceholder":179},[133,761,762,765,768,771],{"class":135,"line":191},[133,763,764],{"class":685},"    if",[133,766,767],{"class":150}," (gem ",[133,769,770],{"class":685},"&&",[133,772,773],{"class":150}," key) {\n",[133,775,776],{"class":135,"line":203},[133,777,778],{"class":139},"      \u002F\u002F Consume items\n",[133,780,781,784,787],{"class":135,"line":208},[133,782,783],{"class":150},"      inventory.",[133,785,786],{"class":146},"removeItem",[133,788,789],{"class":150},"(gem);\n",[133,791,792,794,796],{"class":135,"line":213},[133,793,783],{"class":150},[133,795,786],{"class":146},[133,797,798],{"class":150},"(key);\n",[133,800,801],{"class":135,"line":219},[133,802,180],{"emptyLinePlaceholder":179},[133,804,805],{"class":135,"line":227},[133,806,807],{"class":139},"      \u002F\u002F Store result and notify\n",[133,809,810,813,816,818,821,824,827,829,832,835,838],{"class":135,"line":241},[133,811,812],{"class":150},"      game.",[133,814,815],{"class":146},"getStore",[133,817,669],{"class":150},[133,819,820],{"class":235},"\"puzzle\"",[133,822,823],{"class":150},").",[133,825,826],{"class":146},"set",[133,828,669],{"class":150},[133,830,831],{"class":235},"\"altar_activated\"",[133,833,834],{"class":150},", ",[133,836,837],{"class":157},"true",[133,839,735],{"class":150},[133,841,843,845,848,850,853],{"class":135,"line":842},14,[133,844,812],{"class":150},[133,846,847],{"class":146},"showNotification",[133,849,669],{"class":150},[133,851,852],{"class":235},"\"The altar glows with ancient power!\"",[133,854,735],{"class":150},[133,856,858],{"class":135,"line":857},15,[133,859,860],{"class":150},"    }\n",[133,862,864],{"class":135,"line":863},16,[133,865,180],{"emptyLinePlaceholder":179},[133,867,869],{"class":135,"line":868},17,[133,870,871],{"class":139},"    \u002F\u002F Prevent other calls, including default crafting(if the inventory has any recipes assigned to it)\n",[133,873,875,878,881],{"class":135,"line":874},18,[133,876,877],{"class":685},"    return",[133,879,880],{"class":157}," false",[133,882,883],{"class":150},"; \n",[133,885,887],{"class":135,"line":886},19,[133,888,889],{"class":150},"  }\n",[133,891,893],{"class":135,"line":892},20,[133,894,895],{"class":150},"});\n",[28,897],{},[31,899,901],{"id":900},"assigning-recipes-to-inventories","Assigning Recipes to Inventories",[15,903,904],{},"In the inventory template:",[39,906,907,915],{},[42,908,909],{},[45,910,911,913],{},[48,912,266],{},[48,914,269],{},[55,916,917],{},[45,918,919,923],{},[60,920,921],{},[66,922,248],{},[60,924,925],{},"List of recipe IDs available at this inventory",[15,927,928],{},[19,929,930],{},"Example - Blacksmith inventory:",[39,932,933,941],{},[42,934,935],{},[45,936,937,939],{},[48,938,266],{},[48,940,429],{},[55,942,943,952,961],{},[45,944,945,949],{},[60,946,947],{},[66,948,278],{},[60,950,951],{},"blacksmith_forge",[45,953,954,958],{},[60,955,956],{},[66,957,288],{},[60,959,960],{},"\"Blacksmith's Forge\"",[45,962,963,967],{},[60,964,965],{},[66,966,248],{},[60,968,969],{},"iron_sword_recipe, steel_sword_recipe, repair_armor",[15,971,972],{},"The Apply button defaults to \"craft\" when recipes are assigned.",[28,974],{},[31,976,978],{"id":977},"events","Events",[39,980,981,994],{},[42,982,983],{},[45,984,985,988,991],{},[48,986,987],{},"Event",[48,989,990],{},"When it fires",[48,992,993],{},"Parameters",[55,995,996,1010],{},[45,997,998,1002,1005],{},[60,999,1000],{},[66,1001,68],{},[60,1003,1004],{},"Apply button clicked",[60,1006,1007],{},[66,1008,1009],{},"(inventory)",[45,1011,1012,1017,1020],{},[60,1013,1014],{},[66,1015,1016],{},"recipe_learned",[60,1018,1019],{},"Recipe is learned",[60,1021,1022],{},[66,1023,1024],{},"(recipeId)",[28,1026],{},[31,1028,1030],{"id":1029},"methods","Methods",[39,1032,1033,1042],{},[42,1034,1035],{},[45,1036,1037,1040],{},[48,1038,1039],{},"Method",[48,1041,269],{},[55,1043,1044,1054,1064,1074,1084,1094],{},[45,1045,1046,1051],{},[60,1047,1048],{},[66,1049,1050],{},"inventory.getApplyButton()",[60,1052,1053],{},"Get the apply button label",[45,1055,1056,1061],{},[60,1057,1058],{},[66,1059,1060],{},"inventory.addRecipe(id)",[60,1062,1063],{},"Add recipe to inventory",[45,1065,1066,1071],{},[60,1067,1068],{},[66,1069,1070],{},"inventory.getRecipes()",[60,1072,1073],{},"Get all recipe IDs",[45,1075,1076,1081],{},[60,1077,1078],{},[66,1079,1080],{},"inventory.craft()",[60,1082,1083],{},"Execute crafting",[45,1085,1086,1091],{},[60,1087,1088],{},[66,1089,1090],{},"game.addLearnedRecipe(id)",[60,1092,1093],{},"Learn a recipe",[45,1095,1096,1101],{},[60,1097,1098],{},[66,1099,1100],{},"game.getLearnedRecipes()",[60,1102,1103],{},"Get all learned recipes",[28,1105],{},[31,1107,1109],{"id":1108},"quick-reference","Quick Reference",[39,1111,1112,1122],{},[42,1113,1114],{},[45,1115,1116,1119],{},[48,1117,1118],{},"I want to...",[48,1120,1121],{},"Do this",[55,1123,1124,1135,1144,1155,1164],{},[45,1125,1126,1129],{},[60,1127,1128],{},"Create a crafting station",[60,1130,1131,1132,1134],{},"Set ",[66,1133,248],{}," on inventory template",[45,1136,1137,1139],{},[60,1138,1093],{},[60,1140,1141,1143],{},[66,1142,400],{}," action",[45,1145,1146,1149],{},[60,1147,1148],{},"Custom apply behavior",[60,1150,1151,1152,1154],{},"Listen to ",[66,1153,68],{}," event",[45,1156,1157,1160],{},[60,1158,1159],{},"Change button label",[60,1161,1131,1162,1134],{},[66,1163,101],{},[45,1165,1166,1169],{},[60,1167,1168],{},"Check if recipe learned",[60,1170,1171],{},[66,1172,1173],{},"game.getLearnedRecipes().has(id)",[28,1175],{},[31,1177,1179],{"id":1178},"next-steps","Next Steps",[90,1181,1182,1190],{},[93,1183,1184,1189],{},[1185,1186,1188],"a",{"href":1187},"\u002Fdocs\u002Fglobal_essentials\u002Fitems\u002Fitems_overview","Overview"," - Item basics and templates",[93,1191,1192,1196],{},[1185,1193,1195],{"href":1194},"\u002Fdocs\u002Fglobal_essentials\u002Fitems\u002Fexchange","Exchange"," - Trading and shops",[1198,1199,1200],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}",{"title":129,"searchDepth":143,"depth":143,"links":1202},[1203,1204,1205,1209,1210,1211,1212,1213,1214,1215,1216,1217,1218],{"id":33,"depth":143,"text":34},{"id":107,"depth":143,"text":108},{"id":248,"depth":143,"text":249,"children":1206},[1207,1208],{"id":256,"depth":154,"text":257},{"id":334,"depth":154,"text":335},{"id":372,"depth":143,"text":373},{"id":453,"depth":143,"text":454},{"id":514,"depth":143,"text":515},{"id":572,"depth":143,"text":573},{"id":644,"depth":143,"text":645},{"id":900,"depth":143,"text":901},{"id":977,"depth":143,"text":978},{"id":1029,"depth":143,"text":1030},{"id":1108,"depth":143,"text":1109},{"id":1178,"depth":143,"text":1179},"The apply system handles the \"Apply\" button in inventories. This powers crafting (combining items into new items) and custom interactions (puzzle mechanics, item insertion, etc.).","md",{"plugin":1222,"category":1223,"page":1224},"global_essentials","items","apply","\u002Fdocs\u002Fglobal_essentials\u002Fitems\u002Fapply",{"title":5,"description":1219},"docs\u002Fglobal_essentials\u002Fitems\u002Fapply","6IvRPexNdgruESlbrtomHWYIBG2RwWJXF1DNkzV49_4",1779582261336]