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

feature(ecs-gestalt): Migrate Components to gestalt's Components #82

Merged
merged 7 commits into from
Aug 25, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import org.terasology.combatSystem.FactionList;
import org.terasology.combatSystem.PlanetFactionList;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.network.Replicate;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Makes the entity belong to a specific faction.
*/
public class FactionComponent implements Component{
public class FactionComponent implements Component<FactionComponent> {
@Replicate
public FactionList faction = PlanetFactionList.EARTH;

@Override
public void copy(FactionComponent other) {
this.faction = other.faction;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FactionList is just an interface 🤔 not sure how to do a deep copy of instances of that in the end ... not even sure what the design decision here was...

}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.combatSystem.hurting;

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

/**
* Damages an entity critically.
* <p>
* Damaging critically means multiplying the original damage by <b>critFactor</b>.
* The critical damage has <b>critChance</b>/100 probability of occurring.
*/
public class CritDamageComponent implements Component{
public class CritDamageComponent implements Component<CritDamageComponent> {

@Replicate
public int critChance = 10; // in percentage out of 100

@Replicate
public float critFactor = 2; // factor to multiply damage with

@Override
public void copy(CritDamageComponent other) {
this.critChance = other.critChance;
this.critFactor = other.critFactor;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.terasology.combatSystem.hurting;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.prefab.Prefab;
import org.terasology.engine.logic.health.EngineDamageTypes;
import org.terasology.engine.network.Replicate;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Specifies the amount and damage type that an entity will inflict on other entities.
* <p>
* {@link HurtEvent} is used to hurt other entity/entities.
*/
public class HurtingComponent implements Component{
public class HurtingComponent implements Component<HurtingComponent> {
/**
* The amount of damage the entity will inflict.
*/
Expand All @@ -23,4 +23,9 @@ public class HurtingComponent implements Component{
@Replicate
public Prefab damageType = EngineDamageTypes.DIRECT.get();

@Override
public void copy(HurtingComponent other) {
this.amount = other.amount;
this.damageType = other.damageType;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package org.terasology.combatSystem.hurting;

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

/**
* To generate a random damage amount between <b>minDamage</b> and <b>maxDamage</b> (both inclusive).
*/
public class RandomDamageComponent implements Component{
public class RandomDamageComponent implements Component<RandomDamageComponent> {
public RandomDamageComponent() {

}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add the default constructor here if there are no other constructors.

Suggested change
public RandomDamageComponent() {
}


//inclusive
@Replicate
public int minDamage = 2;

//inclusive
@Replicate
public int maxDamage = 4;

@Override
public void copy(RandomDamageComponent other) {
this.minDamage = other.minDamage;
this.maxDamage = other.maxDamage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@
package org.terasology.combatSystem.physics.components;

import com.google.common.collect.Lists;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.network.Replicate;
import org.terasology.gestalt.entitysystem.component.Component;

import java.util.List;

/**
* specifies the <b>Entities</b> that will not be collided with.
* <p>
* An {@link EntityRef} with this {@link Component} will not collide with <b>exceptions</b>.
* An {@link EntityRef} with this {@link Component} will not collide with <b>exceptions</b>.
*/
public class CollisionExceptionsComponent implements Component{
public class CollisionExceptionsComponent implements Component<CollisionExceptionsComponent> {
@Replicate
public List<EntityRef> exceptions = Lists.<EntityRef>newArrayList();

@Override
public void copy(CollisionExceptionsComponent other) {
this.exceptions = Lists.newArrayList(other.exceptions);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package org.terasology.combatSystem.physics.components;

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

/**
* Adds <b>friction</b>.
* <p>
* <b>this</b> can be used to implement <b>Fluid Viscosity</b> as well.
*
*
* TODO implement this component and its code.
*/
public class FrictionComponent implements Component{
public class FrictionComponent implements Component<FrictionComponent> {
@Replicate
float friction = 20.0f;

@Replicate
float velocity = 20.0f;

@Override
public void copy(FrictionComponent other) {
this.friction = other.friction;
this.velocity = other.velocity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.joml.Vector3f;
import org.terasology.combatSystem.physics.events.CombatForceEvent;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.network.Replicate;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Adds <b>Gravity</b> to the entity.
Expand All @@ -12,8 +12,12 @@
* That would result in removal of those forces too if <b>Gravity</b> is disabled as a whole.
* Instead use of {@link CombatForceEvent} is encouraged to add forces.
*/
public class GravityComponent implements Component{
public class GravityComponent implements Component<GravityComponent> {
@Replicate
public Vector3f gravityAccel = new Vector3f(0, -10.0f, 0);

@Override
public void copy(GravityComponent other) {
this.gravityAccel.set(other.gravityAccel);
skaldarnar marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.combatSystem.physics.components;

import org.joml.Vector3f;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.network.Replicate;
import org.terasology.engine.physics.components.RigidBodyComponent;
import org.terasology.engine.physics.components.TriggerComponent;
import org.terasology.gestalt.entitysystem.component.Component;

/**
* Adds <b>translational motion</b> feature to an entity.
* <p>
* <b>NOTE</b>: It does not add <b>collider</b> like {@link RigidBodyComponent}.
* {@link TriggerComponent} is used for collisions.
*/
public class MassComponent implements Component{
public class MassComponent implements Component<MassComponent> {
@Replicate(initialOnly = true)
public float mass = 10.0f;

Expand All @@ -23,4 +25,11 @@ public class MassComponent implements Component{
@Replicate
public Vector3f force = new Vector3f();

@Override
public void copy(MassComponent other) {
this.velocity.set(other.velocity);
this.acceleration.set(other.acceleration);
this.force.set(other.force);
this.mass = other.mass;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.combatSystem.traps.components;

import org.terasology.engine.entitySystem.Component;

public class ActivateOnPlaceComponent implements Component{

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

public class ActivateOnPlaceComponent implements Component<ActivateOnPlaceComponent> {

@Override
public void copy(ActivateOnPlaceComponent other) {

}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just extend EmptyComponent.

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.combatSystem.traps.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.prefab.Prefab;
import org.terasology.engine.network.Replicate;
import org.terasology.gestalt.entitysystem.component.Component;

public class BaseLauncherComponent implements Component{
public class BaseLauncherComponent implements Component<BaseLauncherComponent> {
@Replicate
public Prefab entityInBase;

@Replicate
public int amountOfEntityInBase;

@Replicate
public int coolDownTime = 1000;

@Replicate
public float lastLaunchTime = -1.0f;

@Override
public void copy(BaseLauncherComponent other) {
this.entityInBase = other.entityInBase;
this.amountOfEntityInBase = other.amountOfEntityInBase;
this.coolDownTime = other.coolDownTime;
this.lastLaunchTime = other.lastLaunchTime;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.combatSystem.traps.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.network.Replicate;
import org.terasology.gestalt.entitysystem.component.Component;

public class BeaconComponent implements Component{
public class BeaconComponent implements Component<BeaconComponent> {
@Replicate
public EntityRef base = EntityRef.NULL;

@Override
public void copy(BeaconComponent other) {
this.base = other.base;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.combatSystem.traps.components;

import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.network.Replicate;
import org.terasology.gestalt.entitysystem.component.Component;

public class HomingComponent implements Component{
public class HomingComponent implements Component<HomingComponent> {
@Replicate
public EntityRef target = EntityRef.NULL;

@Replicate
public int initialSleepTime = 500;

@Replicate
public int updationTime = 200;

@Replicate
public float lastUpdateTime = -1.0f;

@Replicate
public float launchedTime = -1.0f;

@Override
public void copy(HomingComponent other) {
this.target = other.target;
this.initialSleepTime = other.initialSleepTime;
this.updationTime = other.updationTime;
this.lastUpdateTime = other.lastUpdateTime;
this.launchedTime = other.launchedTime;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.combatSystem.traps.components;

import com.google.common.collect.Lists;
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.List;

@ForceBlockActive
public class SwitchComponent implements Component{
public class SwitchComponent implements Component<SwitchComponent> {
public List<EntityRef> doors = Lists.newArrayList();

@Override
public void copy(SwitchComponent other) {
this.doors = Lists.newArrayList(other.doors);
}
}
Loading