Skip to content

Commit

Permalink
fix(ecs-gestalt): Migrate Components to gestalt's Components. (#35)
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 b2c3d42 commit f49230b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 68 deletions.
27 changes: 10 additions & 17 deletions src/main/java/org/terasology/fluid/component/FluidComponent.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.fluid.component;

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

/**
* This component indicates that an entity is a fluid, and contains basic attributes of the fluid.
*/
public class FluidComponent implements Component {
public class FluidComponent implements Component<FluidComponent> {
/** The type of the fluid */
@Replicate
public String fluidType;

/** The volume of the fluid */
@Replicate
public float volume;

@Override
public void copyFrom(FluidComponent other) {
this.fluidType = other.fluidType;
this.volume = other.volume;
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
/*
* Copyright 2015 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.fluid.component;

import org.joml.Vector2f;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.network.Replicate;
import org.terasology.engine.rendering.assets.texture.TextureRegionAsset;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.module.inventory.components.ItemDifferentiating;

/**
* This component indicates that an entity is a container capable of holding fluids.
*/
public class FluidContainerItemComponent implements Component, ItemDifferentiating {
public class FluidContainerItemComponent implements Component<FluidContainerItemComponent>, ItemDifferentiating {

/** The type of the fluid it can contain */
@Replicate
Expand Down Expand Up @@ -86,4 +73,15 @@ public boolean equals(Object o) {

return true;
}

@Override
public void copyFrom(FluidContainerItemComponent other) {
this.fluidType = other.fluidType;
this.volume = other.volume;
this.maxVolume = other.maxVolume;
this.fluidMinPerc = new Vector2f(other.fluidMinPerc);
this.fluidSizePerc = new Vector2f(other.fluidSizePerc);
this.textureWithHole = other.textureWithHole;
this.emptyTexture = other.emptyTexture;
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
/*
* Copyright 2015 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.fluid.component;

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

import java.util.Map;

/**
* A component for integration with a Computer module.
*/
public class FluidInventoryAccessComponent implements Component {
public class FluidInventoryAccessComponent implements Component<FluidInventoryAccessComponent> {
public Map<String, IntegerRange> input;
public Map<String, IntegerRange> output;

@Override
public void copyFrom(FluidInventoryAccessComponent other) {
this.input.clear();
for (Map.Entry<String, IntegerRange> entry : other.input.entrySet()) {
this.input.put(entry.getKey(), entry.getValue().copy());
}
this.output.clear();
for (Map.Entry<String, IntegerRange> entry : other.output.entrySet()) {
this.output.put(entry.getKey(), entry.getValue().copy());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
/*
* Copyright 2014 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.fluid.component;

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

import java.util.List;

/**
* Represents the fluid inventory of an entity which the entity uses to store fluids.
*/
public class FluidInventoryComponent implements Component {
public class FluidInventoryComponent implements Component<FluidInventoryComponent> {

/** A list of fluid slots which fluids can occupy */
@Replicate
Expand Down Expand Up @@ -55,4 +42,10 @@ public FluidInventoryComponent(int numSlots, float maximumVolume) {
maximumVolumes.add(maximumVolume);
}
}

@Override
public void copyFrom(FluidInventoryComponent other) {
this.fluidSlots = Lists.newLinkedList(this.fluidSlots);
this.maximumVolumes = Lists.newLinkedList(maximumVolumes);
}
}

0 comments on commit f49230b

Please sign in to comment.