Skip to content

Commit

Permalink
fix(ecs-gestalt): Migrate Components to gestalt's Components. (#68)
Browse files Browse the repository at this point in the history
Ref: MovingBlocks/Terasology#4753

Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
  • Loading branch information
DarkWeird and skaldarnar committed Aug 25, 2021
1 parent 36755d4 commit 946d9b7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0


package org.terasology.potions.component;

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

/**
* This component is only used as an identifier to identify if the entity is an empty potion container.
*/
@Replicate
public final class EmptyPotionComponent implements Component {
public final class EmptyPotionComponent extends EmptyComponent<EmptyPotionComponent> {
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0


package org.terasology.potions.component;

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

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

/**
* This component is used for storing information about a potion. Specifically, what potion bottle it came from, the
* durability cost per drink, whether it has a genome, and all of the potion's effects.
*/
public final class PotionComponent implements Component {
public final class PotionComponent implements Component<PotionComponent> {
/** Can this potion bottle be reused indefinitely. */
@Replicate
public boolean hasInfDurability = false;
Expand All @@ -36,4 +37,15 @@ public final class PotionComponent implements Component {
/** List of PotionEffects that this potion has. */
@Replicate
public List<PotionEffect> effects = Lists.newArrayList();

@Override
public void copyFrom(PotionComponent other) {
this.hasInfDurability = other.hasInfDurability;
this.bottlePrefab = other.bottlePrefab;
this.costPerDrink = other.costPerDrink;
this.hasGenome = other.hasGenome;
this.effects = other.effects.stream()
.map(PotionEffect::copy)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.potions.component;
Expand All @@ -20,4 +20,12 @@ public class PotionEffect {
/** Duration of the potion's effect in milliseconds. */
@Replicate
public long duration;

public PotionEffect copy() {
PotionEffect newPE = new PotionEffect();
newPE.effect = this.effect;
newPE.magnitude = this.magnitude;
newPE.duration = this.duration;
return newPE;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.potions.component;

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

import java.util.HashMap;
import java.util.Map;
Expand All @@ -16,8 +16,14 @@
*
* Note: Make sure that the entity you are attaching this to has a PhysicalStatsComponent.
*/
public class PotionEffectsListComponent implements Component {
public class PotionEffectsListComponent implements Component<PotionEffectsListComponent> {
/** A map of potion-based effects being applied to an entity. */
@Replicate
public Map<String, PotionEffect> effects = new HashMap<String, PotionEffect>();

@Override
public void copyFrom(PotionEffectsListComponent other) {
effects.clear();
other.effects.forEach((k, v) -> this.effects.put(k, v.copy()));
}
}

0 comments on commit 946d9b7

Please sign in to comment.