Skip to content

Commit ca21e64

Browse files
committed
fix: implement condition inversion, fix json serialization for several conditions
1 parent 1c0d80c commit ca21e64

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

lang/constructs/worldgen/surface_rules/Condition_Biome.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (c BiomeCondition) ExportSymbol(symbol traversal.Symbol, rootDir *lib.FileT
5252
func (c BiomeCondition) MarshalJSON() ([]byte, error) {
5353
return json.MarshalIndent(struct {
5454
Type SurfaceConditionKind `json:"type"`
55-
Biomes []traversal.Reference `json:"biomes"`
55+
Biomes []traversal.Reference `json:"biome_is"`
5656
}{
5757
Type: BiomeConditionKind,
5858
Biomes: c.biomes,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package surface_rules
2+
3+
import (
4+
"encoding/json"
5+
6+
"github.com/minecraftmetascript/mms/lang/traversal"
7+
"github.com/minecraftmetascript/mms/lib"
8+
)
9+
10+
type NotCondition struct {
11+
traversal.Construct
12+
Invert traversal.Construct
13+
}
14+
15+
func (c NotCondition) ExportSymbol(symbol traversal.Symbol, rootDir *lib.FileTreeLike) error {
16+
return exportSurfaceCondition(symbol, rootDir, c)
17+
}
18+
19+
func (c NotCondition) MarshalJSON() ([]byte, error) {
20+
return json.MarshalIndent(struct {
21+
Type SurfaceConditionKind `json:"type"`
22+
Invert traversal.Construct `json:"invert"`
23+
}{
24+
Type: NotConditionKind,
25+
Invert: c.Invert,
26+
}, "", " ")
27+
}
28+
29+
func InvertCondition(c traversal.Construct) NotCondition {
30+
return NotCondition{Invert: c}
31+
}

lang/constructs/worldgen/surface_rules/Condition_VerticalGradient.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ func (c VerticalGradientCondition) ExportSymbol(symbol traversal.Symbol, rootDir
6161

6262
func (c VerticalGradientCondition) MarshalJSON() ([]byte, error) {
6363
return json.MarshalIndent(struct {
64-
Type SurfaceConditionKind `json:"type"`
64+
Type SurfaceConditionKind `json:"type"`
65+
TrueAtBelow primitives.VerticalAnchor `json:"true_at_and_below"`
66+
FalseAtAbove primitives.VerticalAnchor `json:"false_at_and_above"`
6567
}{
66-
Type: VerticalGradientConditionKind,
68+
Type: VerticalGradientConditionKind,
69+
TrueAtBelow: c.TrueAtAndBelow,
70+
FalseAtAbove: c.FalseAtAndAbove,
6771
}, "", " ")
6872
}

lang/constructs/worldgen/surface_rules/Condition_YAbove.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ func (c YAboveCondition) ExportSymbol(symbol traversal.Symbol, rootDir *lib.File
5555

5656
func (c YAboveCondition) MarshalJSON() ([]byte, error) {
5757
return json.MarshalIndent(struct {
58-
Type SurfaceConditionKind `json:"type"`
58+
Type SurfaceConditionKind `json:"type"`
59+
Anchor primitives.VerticalAnchor `json:"anchor"`
60+
Multiplier int `json:"multiplier"`
61+
Add bool `json:"add_stone_depth"`
5962
}{
60-
Type: YAboveConditionKind,
63+
Type: YAboveConditionKind,
64+
Anchor: c.Anchor,
65+
Multiplier: c.Multiplier,
66+
Add: c.Add,
6167
}, "", " ")
6268
}

lang/constructs/worldgen/surface_rules/SurfaceConditions.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
VerticalGradientConditionKind SurfaceConditionKind = "minecraft:vertical_gradient"
2525
AboveWaterConditionKind SurfaceConditionKind = "minecraft:water"
2626
YAboveConditionKind SurfaceConditionKind = "minecraft:y_above"
27+
NotConditionKind SurfaceConditionKind = "minecraft:not"
2728
ReferenceConditionKind SurfaceConditionKind = "mms:__reference"
2829
)
2930

@@ -36,11 +37,16 @@ func init() {
3637
if sc := def.SurfaceCondition(); sc != nil {
3738
if sc.GetChildCount() > 0 {
3839
if prc, ok := sc.GetChild(0).(antlr.ParserRuleContext); ok {
39-
return traversal.ConstructRegistry.Construct(
40+
cond := traversal.ConstructRegistry.Construct(
4041
prc,
4142
currentNamespace,
4243
scope,
4344
)
45+
if sc.Bang() != nil {
46+
return InvertCondition(cond)
47+
} else {
48+
return cond
49+
}
4450
}
4551
}
4652
}
@@ -64,10 +70,6 @@ func exportSurfaceCondition(symbol traversal.Symbol, rootDir *lib.FileTreeLike,
6470
return nil
6571
}
6672

67-
func InvertCondition(condition traversal.Construct) traversal.Construct {
68-
return condition
69-
}
70-
7173
type BaseSurfaceCondition struct {
7274
traversal.Construct
7375
Negate bool

0 commit comments

Comments
 (0)