Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ecs-gestalt): Migrate Components to gestalt's Components. #115

Merged
merged 3 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.simpleFarming.components;

import com.google.common.collect.Maps;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.world.block.ForceBlockActive;
import org.terasology.gestalt.entitysystem.component.Component;

import java.util.Arrays;
import java.util.List;
Expand All @@ -29,7 +29,7 @@
* @see org.terasology.simpleFarming.systems.BushAuthoritySystem
*/
@ForceBlockActive
public class BushDefinitionComponent implements Component {
public class BushDefinitionComponent implements Component<BushDefinitionComponent> {

/**
* Map associating prefabs with growth stages. Generally specified by a prefab.
Expand Down Expand Up @@ -86,4 +86,19 @@ public class BushDefinitionComponent implements Component {
* Used by vine buds to refer to the parent stem.
*/
public EntityRef parent;

@Override
public void copyFrom(BushDefinitionComponent other) {
this.growthStages.clear();
for (Map.Entry<String, BushGrowthStage> entry : other.growthStages.entrySet()) {
BushGrowthStage newStage = new BushGrowthStage(entry.getValue());
this.growthStages.put(entry.getKey(), newStage);
}
this.sustainable = other.sustainable;
this.seed = other.seed;
this.seedDropChances = other.seedDropChances;
this.produce = other.produce;
this.currentStage = other.currentStage;
this.parent = other.parent;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.simpleFarming.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.Component;

public class CheatGrowthComponent implements Component {
public class CheatGrowthComponent implements Component<CheatGrowthComponent> {
public boolean causesUnGrowth = false;

@Override
public void copyFrom(CheatGrowthComponent other) {
this.causesUnGrowth = other.causesUnGrowth;
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.simpleFarming.components;

import org.joml.Vector3i;
import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.Component;

import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Defines the structure of leaves in a tree.
*
* @see TreeGrowthStage
*/
public class LeafStructureComponent implements Component {
public class LeafStructureComponent implements Component<LeafStructureComponent> {
/**
* Locations of each leaf in this structure, relative to the top log block.
*/
public Set<Vector3i> leaves = new HashSet<>();

@Override
public void copyFrom(LeafStructureComponent other) {
this.leaves = other.leaves.stream()
.map(Vector3i::new)
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.simpleFarming.components;

import org.joml.Vector3i;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.world.block.ForceBlockActive;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.simpleFarming.systems.TreeAuthoritySystem;

/**
Expand All @@ -15,7 +15,7 @@
* @see RootComponent
*/
@ForceBlockActive
public class LogComponent implements Component {
public class LogComponent implements Component<LogComponent> {

/**
* The location of this log in the world.
Expand All @@ -28,4 +28,10 @@ public class LogComponent implements Component {
* events to the root so that the whole tree can react.
*/
public EntityRef root;

@Override
public void copyFrom(LogComponent other) {
this.location = new Vector3i(other.location);
this.root = other.root;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.simpleFarming.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.entitySystem.prefab.Prefab;
import org.terasology.engine.world.block.Block;
import org.terasology.engine.world.block.ForceBlockActive;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.simpleFarming.systems.TreeAuthoritySystem;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* Represents the root (lowest log block) of a tree.
Expand All @@ -22,7 +23,7 @@
* to a single block in specific.
*/
@ForceBlockActive
public class RootComponent implements Component {
public class RootComponent implements Component<RootComponent> {

/**
* The block to use for the sapling in the world.
Expand Down Expand Up @@ -78,4 +79,17 @@ public RootComponent(SaplingDefinitionComponent base) {
leaf = base.leaf;
growthStages = base.growthStages;
}

@Override
public void copyFrom(RootComponent other) {
this.sapling = other.sapling;
this.log = other.log;
this.leaf = other.leaf;
this.growthStages = other.growthStages.stream()
.map(TreeGrowthStage::new)
.collect(Collectors.toList());
this.growthStage = other.growthStage;
this.leaves = other.leaves;
this.alive = other.alive;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.simpleFarming.components;

import org.joml.Vector3i;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.prefab.Prefab;
import org.terasology.engine.world.block.Block;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.simpleFarming.systems.TreeAuthoritySystem;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
* Stores the necessary data for defining a tree.
Expand All @@ -24,7 +25,7 @@
* {@link RootComponent} of a tree is created based on the sapling's
* definition component.
*/
public class SaplingDefinitionComponent implements Component {
public class SaplingDefinitionComponent implements Component<SaplingDefinitionComponent> {

/**
* The location of the sapling. This does not need to be provided with the
Expand Down Expand Up @@ -75,4 +76,15 @@ public SaplingDefinitionComponent(RootComponent base, Vector3i location) {
leaf = base.leaf;
growthStages = base.growthStages;
}

@Override
public void copyFrom(SaplingDefinitionComponent other) {
this.location = new Vector3i(other.location);
sapling = other.sapling;
log = other.log;
leaf = other.leaf;
this.growthStages = other.growthStages.stream()
.map(TreeGrowthStage::new)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.simpleFarming.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Indicates the item is a seed and links to the prefab to be used to create the plant.
Expand All @@ -12,7 +12,7 @@
*
* @see org.terasology.simpleFarming.systems.PlantAuthoritySystem
*/
public class SeedDefinitionComponent implements Component {
public class SeedDefinitionComponent implements Component<SeedDefinitionComponent> {
/**
* The prefab name for the plant that grows from this seed.
* <p>
Expand All @@ -23,4 +23,9 @@ public class SeedDefinitionComponent implements Component {
* to be found on the same entity.
*/
public String prefab;

@Override
public void copyFrom(SeedDefinitionComponent other) {
this.prefab = other.prefab;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.simpleFarming.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.prefab.Prefab;
import org.terasology.engine.world.block.Block;
import org.terasology.engine.world.block.ForceBlockActive;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Stores all data needed to grow a vine.
Expand All @@ -24,7 +24,7 @@
* @see org.terasology.simpleFarming.systems.VineAuthoritySystem
*/
@ForceBlockActive
public class VineDefinitionComponent implements Component {
public class VineDefinitionComponent implements Component<VineDefinitionComponent> {

/**
* The block to use for a stem.
Expand Down Expand Up @@ -56,4 +56,13 @@ public class VineDefinitionComponent implements Component {
* The maximum length a vine can grow
*/
public int maxLength = 20;

@Override
public void copyFrom(VineDefinitionComponent other) {
this.stem = other.stem;
this.bud = other.bud;
this.minGrowTime = other.minGrowTime;
this.maxGrowTime = other.maxGrowTime;
this.maxLength = other.maxLength;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.simpleFarming.components;

import org.joml.Vector3i;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.world.block.ForceBlockActive;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Component used to store information about the current state of a particular vine.
Expand All @@ -17,7 +17,7 @@
* @see org.terasology.simpleFarming.systems.VineAuthoritySystem
*/
@ForceBlockActive
public class VineNodeComponent implements Component {
public class VineNodeComponent implements Component<VineNodeComponent> {

/**
* The position of this stem block.
Expand Down Expand Up @@ -71,4 +71,13 @@ public VineNodeComponent(EntityRef parent, Vector3i position) {
this.parent = parent;
this.position = position;
}

@Override
public void copyFrom(VineNodeComponent other) {
this.position = new Vector3i(other.position);
this.bud = other.bud;
this.child = other.child;
this.parent = other.parent;
this.length = other.length;
}
}