Skip to content

Commit

Permalink
Mod scripting guide update (#356)
Browse files Browse the repository at this point in the history
* added bool to number function expression

* added group attribute to cell entities

* added neighbors attribute to group entities

* updated modding guide a bit more

* more modding guide updates

* Update entities_guide.md

* more guide updates

* more guide updates

* more modding guide updates

* final modding guide update
  • Loading branch information
Zematus authored Sep 25, 2022
1 parent 532d8bb commit ae3f8a3
Show file tree
Hide file tree
Showing 36 changed files with 905 additions and 843 deletions.
20 changes: 20 additions & 0 deletions Assets/Scripts/WorldEngine/Modding/Entities/CellEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class CellEntity : DelayedSetEntity<TerrainCell>
public const string BiomeTraitPresenceAttributeId = "biome_trait_presence";
public const string BiomeTypePresenceAttributeId = "biome_type_presence";
public const string NeighborsAttributeId = "neighbors";
public const string GroupAttributeId = "group";
public const string ArabilityAttributeId = "arability";
public const string AccessibilityAttributeId = "accessibility";
public const string HillinessAttributeId = "hilliness";
Expand All @@ -26,6 +27,7 @@ public virtual TerrainCell Cell
private ValueGetterEntityAttribute<float> _hillinessAttribute;
private ValueGetterEntityAttribute<float> _flowingWaterAttribute;

private GroupEntity _groupEntity = null;
private CellCollectionEntity _neighborsEntity = null;

private class BiomeTraitPresenceAttribute : ValueEntityAttribute<float>
Expand Down Expand Up @@ -115,10 +117,25 @@ public EntityAttribute GetNeighborsAttribute()
return _neighborsEntity.GetThisEntityAttribute();
}

public EntityAttribute GetGroupAttribute()
{
_groupEntity =
_groupEntity ?? new GroupEntity(
GetGroup,
Context,
BuildAttributeId(GroupAttributeId),
this);

return _groupEntity.GetThisEntityAttribute();
}

public override EntityAttribute GetAttribute(string attributeId, IExpression[] arguments = null)
{
switch (attributeId)
{
case GroupAttributeId:
return GetGroupAttribute();

case BiomeTraitPresenceAttributeId:
return new BiomeTraitPresenceAttribute(this, arguments);

Expand Down Expand Up @@ -180,6 +197,9 @@ protected override void ResetInternal()

if (_isReset) return;

_groupEntity?.Reset();
_neighborsEntity?.Reset();
}

private CellGroup GetGroup() => Cell.Group;
}
20 changes: 20 additions & 0 deletions Assets/Scripts/WorldEngine/Modding/Entities/GroupEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GroupEntity : CulturalEntity<CellGroup>
public const string AccessibilityModifierAttributeId = "accessibility_modifier";
public const string PropertiesAttributeId = "properties";
public const string PopulationAttributeId = "population";
public const string NeighborsAttributeId = "neighbors";

public virtual CellGroup Group
{
Expand All @@ -33,6 +34,7 @@ public virtual CellGroup Group
private PolityCollectionEntity _presentPolitiesEntity = null;
private FactionCollectionEntity _closestFactionsEntity = null;
private ModifiableGroupPropertyContainerEntity _propertiesEntity = null;
private GroupCollectionEntity _neighborsEntity = null;

protected override object _reference => Group;

Expand Down Expand Up @@ -162,10 +164,27 @@ private void UpdateAccessibilityModifier(float value)
Group.SetToUpdate(warnIfUnexpected: false);
}

public ICollection<CellGroup> GetNeighbors() => Group.Neighbors.Values;

public EntityAttribute GetNeighborsAttribute()
{
_neighborsEntity =
_neighborsEntity ?? new GroupCollectionEntity(
GetNeighbors,
Context,
BuildAttributeId(NeighborsAttributeId),
this);

return _neighborsEntity.GetThisEntityAttribute();
}

public override EntityAttribute GetAttribute(string attributeId, IExpression[] arguments = null)
{
switch (attributeId)
{
case NeighborsAttributeId:
return GetNeighborsAttribute();

case CellAttributeId:
return GetCellAttribute();

Expand Down Expand Up @@ -242,6 +261,7 @@ protected override void ResetInternal()
_presentPolitiesEntity?.Reset();
_closestFactionsEntity?.Reset();
_propertiesEntity?.Reset();
_neighborsEntity?.Reset();

base.ResetInternal();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ private static IExpression BuildIdentifierExpression(
return new ClampFunctionExpression(context, argExpressions);
case GetProbabilityAdjectiveFunctionExpression.FunctionId:
return new GetProbabilityAdjectiveFunctionExpression(context, argExpressions);
case NumberFunctionExpression.FunctionId:
return new NumberFunctionExpression(context, argExpressions);
}

if (string.IsNullOrWhiteSpace(arguments))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;

public class NumberFunctionExpression : FunctionExpressionWithOutput<float>
{
public const string FunctionId = "number";

private readonly IValueExpression<bool> _arg;

public NumberFunctionExpression(Context c, IExpression[] arguments) :
base(c, FunctionId, 1, arguments)
{
_arg = ValueExpressionBuilder.ValidateValueExpression<bool>(arguments[0]);
}

public override float Value => _arg.Value ? 1 : 0;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions Modding Guide/Guides/action_modding_guide.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Action Modding Guide

**Action** mod files are located within the *Actions* folder.
**Action** scripting mod files are located within the *Actions* folder.
To be valid, mod files must have the .json extension and have the following file structure:

#### File Structure
Note: *.json* files do not support comments. Remove texts enclosed within double dashes `--`

```
{
Expand All @@ -30,7 +31,7 @@ To be valid, mod files must have the .json extension and have the following file
to decide if action will be present on the list a available actions within the assigned category.
If any of the expressions evaluate to 'false', then
the action will not be present within the category
menu. Please read expressions_guide.txt for more
menu. Please read expressions_guide.md for more
details on how to define valid boolean
expressions.
Expand All @@ -46,9 +47,17 @@ To be valid, mod files must have the .json extension and have the following file
"effects": -- (required) List of EFFECT EXPRESSIONS to
evaluate after an action has been executed.
These can introduce changes to the target or any
related entity. Please read expressions_guide.txt
related entity. Please read expressions_guide.md
for more details on how to define valid effect
expressions.
"enableDebugLog": -- (optional) Can only have 'true' or 'false'
as value (default: 'false'). This an option
to assist in mod development. If this is
'true', and 'Debug Mode' is enabled within
the game, then debug information specific
to this action will be logged during the
game execution.
},
... -- additional actions --
]
Expand All @@ -66,12 +75,12 @@ if an action is available for execution, They also define the tooltips to be dis
{
"condition": -- (required) BOOLEAN EXPRESSION to be evaluated
to decide if action can be executed at a particular
time. Please read expressions_guide.txt for more
time. Please read expressions_guide.md for more
details on how to define valid boolean
expressions.
"info": -- (required) Text to generate when a tooltip needs
to be displayed. See string_values_guide.txt
to be displayed. See string_values_guide.md
to find more about how to define valid dynamic
text values.
}
Expand Down
2 changes: 1 addition & 1 deletion Modding Guide/Guides/adjective_modding_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@

## Notes
1. Remove any trailing commas or the file won't be parsed.
2. These are used to decide whether or not to associate the element with a particular **region**. If any of the constraints fails then the adjective won't be used when generating names of phrases within the region. Refer to *region_constraints_guide.txt* for more details on how to define and use region constraints.
2. These are used to decide whether or not to associate the element with a particular **region**. If any of the constraints fails then the adjective won't be used when generating names of phrases within the region. Refer to *region_constraints_guide.md* for more details on how to define and use region constraints.
8 changes: 0 additions & 8 deletions Modding Guide/Guides/attribute_flags.txt

This file was deleted.

121 changes: 0 additions & 121 deletions Modding Guide/Guides/conditions_guide.txt

This file was deleted.

4 changes: 2 additions & 2 deletions Modding Guide/Guides/cultural_preferences_modding_guide.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Cultural Preferences Modding Guide

Cultural Preferences modding files are located within the **Preferences** folder. To be valid, mod files must have the **.json** extension and have the following file structure:
Cultural Preferences scripting mod files are located within the **Preferences** folder. To be valid, mod files must have the **.json** extension and have the following file structure:

#### File Structure
Note: .json files do not support comments. Remove texts enclosed within double dashes '--'
Note: *.json* files do not support comments. Remove texts enclosed within double dashes `--`

```
{
Expand Down
Loading

0 comments on commit ae3f8a3

Please sign in to comment.