Skip to content

Commit 953e13e

Browse files
committed
Generate translations + clean up old generation code
1 parent 633ea4f commit 953e13e

File tree

4 files changed

+38
-55
lines changed

4 files changed

+38
-55
lines changed

gm4_furniture/beet.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ data_pack:
88
resource_pack:
99
load: .
1010

11+
require:
12+
- bolt
13+
1114
pipeline:
1215
- gm4_furniture.generate
1316
- gm4.plugins.extend.module

gm4_furniture/data/gm4_furniture/template/function/crafting_template.mcfunction

Lines changed: 0 additions & 12 deletions
This file was deleted.

gm4_furniture/generate.py

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,65 @@
1-
from beet import Context, subproject, Cache
1+
from beet import Context, subproject, Cache, Language, Function
22
from pathlib import Path
33
from typing import Any
44
from gm4.utils import CSV
55
from gm4.plugins.resource_pack import ContainerGuiOptions, GuiFont
66

77
def beet_default(ctx: Context):
88

9-
trades_init = []
10-
trades_list = []
11-
trades_append = []
12-
13-
furniture_sets = {}
9+
trades_init: list[str] = []
10+
trades_list: list[str] = []
11+
trades_append: list[str] = []
12+
13+
furniture_sets: dict[str,CSV] = {}
1414

1515
for path in sorted(Path('gm4_furniture/raw_data/furniture_set').glob('*.csv')):
1616
furniture_sets[path.stem] = CSV.from_file(path)
1717

1818
# loop through the different sheets, each sheet hold a different 'set_name'
1919
# of furniture which need to be sorted in the furniture_station storage
20-
for set_name,furniture_set in furniture_sets.items():
20+
for set_name, furniture_set in furniture_sets.items():
2121

2222
# call generate_trade_data to build the commands
2323
new_trades_init,new_trades_list,new_trades_append = generate_trade_data(ctx, furniture_set, set_name)
2424
# append the trade data to the total list
2525
trades_init.append(new_trades_init)
26-
trades_list.append(new_trades_list)
26+
trades_list += new_trades_list
2727
trades_append.append(new_trades_append)
2828

2929
# read furniture data from this sheet, and then create the placement function
3030
# and loot table for each furniture
3131
generate_furniture_data(ctx, furniture_set, set_name)
3232

33-
34-
# build the trade data commands
35-
trades_init = '\n'.join(trades_init)
36-
trades_list = '\n'.join(trades_list)
37-
trades_append = '\n'.join(trades_append)
38-
# build the trade data function from crafting_template
39-
subproject_config = {
40-
"data_pack": {
41-
"load": [
42-
{
43-
f"data/gm4_furniture/function/generate_trades.mcfunction": "data/gm4_furniture/template/function/crafting_template.mcfunction",
44-
}
45-
],
46-
"render": {
47-
"function": "*"
48-
}
49-
},
50-
"meta": {
51-
"trades_init": trades_init,
52-
"trades_list": trades_list,
53-
"trades_append": trades_append,
54-
}
55-
}
56-
57-
ctx.require(subproject(subproject_config))
58-
59-
60-
61-
def generate_trade_data(ctx, furniture_set, set_name):
33+
# generate trades function
34+
function_strings: list[str] = [
35+
"# create storage to hold the trade data for furniture items in furniture station",
36+
"# @s = unspecified",
37+
"# at unspecified",
38+
"# run from init",
39+
"# generated by generate.py\n"
40+
]
41+
for string in trades_init + trades_list + trades_append:
42+
function_strings.append(string)
43+
function_strings.append("\ndata remove storage gm4_furniture:temp new_trades")
44+
ctx.data.functions['gm4_furniture:generate_trades'] = Function(function_strings)
45+
46+
def generate_trade_data(ctx: Context, furniture_set: CSV, set_name: str):
6247

6348
# create a command to make an empty storage called new_trades that holds the set_name name and tool cmd
6449
new_trades_init = "data modify storage gm4_furniture:temp new_trades." + set_name + " set value {\"minecraft:item_model\":\"gm4_furniture:set_tool/" + set_name + "\",trades:[]}"
6550

6651
# iterate over the rows in the spreadsheet and add the trade data for each furniture to the storage
67-
new_trades_list = []
52+
new_trades_list: list[str] = []
6853
for row in furniture_set:
6954
new_trades_list.append("data modify storage gm4_furniture:temp new_trades." + set_name + ".trades append value {cost:[{id:" + row['craft_item_1_id'] + ",count:" + row['craft_item_1_count'] + "b},{id:" + row['craft_item_2_id'] + ",count:" + row['craft_item_2_count'] + "b}],result:{furniture_id:\"" + set_name + "/" + row['technical_id'] + "\",count:" + row['craft_result_count'] + "}}")
70-
new_trades_list = '\n'.join(new_trades_list)
7155

7256
# add command to append the main furniture_station storage with the newly created new_trades
7357
new_trades_append = "data modify storage gm4_furniture:data furniture_station prepend from storage gm4_furniture:temp new_trades." + set_name
7458

7559
# return the created commands
7660
return(new_trades_init,new_trades_list,new_trades_append)
7761

78-
79-
80-
def generate_furniture_data(ctx, furniture_set, set_name):
62+
def generate_furniture_data(ctx: Context, furniture_set: CSV, set_name: str):
8163

8264
# create furniture loot tables and placement functions for every furniture in this category
8365
for row in furniture_set:
@@ -121,7 +103,10 @@ def generate_furniture_data(ctx, furniture_set, set_name):
121103
}
122104

123105
ctx.require(subproject(subproject_config))
124-
106+
107+
ctx.generate("gm4_translations:en_us", merge=Language({
108+
f"block.gm4_furniture.{ set_name }.{ row['technical_id'] }": row['display_name']
109+
}))
125110

126111
class FurnitureStationGui(ContainerGuiOptions):
127112
container = "furniture_station"

gm4_furniture/translations.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
key,en_us
2+
container.gm4.furniture_station,"Furniture Station"
3+
item.gm4_furniture.furniture_station,"Furniture Station"
4+
item.gm4_furniture.furniture_station,"Furniture Station"
5+
item.gm4_furniture.paintbrush,"Paintbrush"
6+
item.gm4_furniture.paintbrush.description_1," to paint furniture"
7+
item.gm4_furniture.paintbrush.description_2," furniture to pick color"

0 commit comments

Comments
 (0)