Available Feats Support
This commit is contained in:
@@ -279,7 +279,7 @@ func (ctx *wikiContext) wikiTableSourceRows(def wikiTableDefinition, page wikiTe
|
||||
if page.Category != "classes" {
|
||||
return nil, nil
|
||||
}
|
||||
return ctx.classProgressionRows(def, page.Row)
|
||||
return ctx.classProgressionRows(def.Rows.Levels, nil, page.Row)
|
||||
case "class_feats":
|
||||
if page.Category != "classes" {
|
||||
return nil, nil
|
||||
@@ -303,8 +303,8 @@ func (ctx *wikiContext) wikiTableSourceRows(def wikiTableDefinition, page wikiTe
|
||||
}
|
||||
}
|
||||
|
||||
func (ctx *wikiContext) classProgressionRows(def wikiTableDefinition, classRow map[string]any) ([]map[string]any, error) {
|
||||
start, end, err := parseLevelRange(def.Rows.Levels)
|
||||
func (ctx *wikiContext) classProgressionRows(levels string, projections map[string]wikiDataProviderProjectionField, classRow map[string]any) ([]map[string]any, error) {
|
||||
start, end, err := parseLevelRange(levels)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -317,7 +317,15 @@ func (ctx *wikiContext) classProgressionRows(def wikiTableDefinition, classRow m
|
||||
}
|
||||
}
|
||||
}
|
||||
granted := map[int][]string{}
|
||||
if len(projections) == 0 {
|
||||
projections = map[string]wikiDataProviderProjectionField{
|
||||
"GrantedFeats": {When: "{{GrantedOnLevel > 0}}"},
|
||||
}
|
||||
}
|
||||
classFeatFields := map[string]map[int][]string{}
|
||||
for field := range projections {
|
||||
classFeatFields[field] = map[int][]string{}
|
||||
}
|
||||
if table := ctx.tableForValue(fieldValue(classRow, "FeatsTable"), ctx.classFeatTables); table != nil {
|
||||
for _, featRow := range table.Rows {
|
||||
level, err := strconv.Atoi(stringValue(featRow, "GrantedOnLevel"))
|
||||
@@ -325,8 +333,18 @@ func (ctx *wikiContext) classProgressionRows(def wikiTableDefinition, classRow m
|
||||
continue
|
||||
}
|
||||
name := ctx.renderReference(fieldValue(featRow, "FeatIndex"), ctx.featIDToKey, ctx.resolveFeatName)
|
||||
if name != "" {
|
||||
granted[level] = append(granted[level], name)
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
renderCtx := wikiTableRenderContext{TableName: "class_progression", Path: ctx.wikiDataPath}
|
||||
for field, projection := range projections {
|
||||
value, err := ctx.evalWikiTableTemplate(projection.When, featRow, renderCtx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("class progression field %s condition %q: %w", field, projection.When, err)
|
||||
}
|
||||
if truthyWikiTableValue(value) {
|
||||
classFeatFields[field][level] = append(classFeatFields[field][level], name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,7 +369,9 @@ func (ctx *wikiContext) classProgressionRows(def wikiTableDefinition, classRow m
|
||||
row[key] = value
|
||||
}
|
||||
}
|
||||
row["GrantedFeats"] = granted[level]
|
||||
for field, values := range classFeatFields {
|
||||
row[field] = values[level]
|
||||
}
|
||||
row["BonusFeat"] = bonusByLevel[level]
|
||||
row["HPMin"] = level
|
||||
if hitDie > 0 {
|
||||
|
||||
Reference in New Issue
Block a user