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. #68

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()));
}
}