From 88a58fbcca13a905932481c267fc4a8ec54cf618 Mon Sep 17 00:00:00 2001 From: DarkWeird Date: Fri, 9 Jul 2021 16:53:15 +0300 Subject: [PATCH 1/2] fix(ecs-gestalt): Migrate Components to gestalt's Components. --- .../components/FluidSubstanceComponent.java | 21 +++---------- .../MaterialCompositionComponent.java | 30 +++++++------------ .../components/MaterialItemComponent.java | 26 ++++++---------- .../components/SubstanceComponent.java | 30 ++++++++----------- .../InjectSubstancesComponent.java | 26 ++++++---------- .../TransferSubstancesComponent.java | 27 +++++++---------- 6 files changed, 56 insertions(+), 104 deletions(-) diff --git a/src/main/java/org/terasology/substanceMatters/components/FluidSubstanceComponent.java b/src/main/java/org/terasology/substanceMatters/components/FluidSubstanceComponent.java index 5facba9..0a35f2e 100644 --- a/src/main/java/org/terasology/substanceMatters/components/FluidSubstanceComponent.java +++ b/src/main/java/org/terasology/substanceMatters/components/FluidSubstanceComponent.java @@ -1,21 +1,8 @@ -/* - * 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.substanceMatters.components; -import org.terasology.engine.entitySystem.Component; +import org.terasology.gestalt.entitysystem.component.EmptyComponent; -public class FluidSubstanceComponent implements Component { +public class FluidSubstanceComponent extends EmptyComponent { } diff --git a/src/main/java/org/terasology/substanceMatters/components/MaterialCompositionComponent.java b/src/main/java/org/terasology/substanceMatters/components/MaterialCompositionComponent.java index 3d88399..10929ff 100644 --- a/src/main/java/org/terasology/substanceMatters/components/MaterialCompositionComponent.java +++ b/src/main/java/org/terasology/substanceMatters/components/MaterialCompositionComponent.java @@ -1,31 +1,18 @@ -/* - * 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.substanceMatters.components; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import org.terasology.engine.entitySystem.Component; import org.terasology.engine.entitySystem.entity.EntityRef; import org.terasology.engine.entitySystem.prefab.Prefab; import org.terasology.engine.entitySystem.prefab.PrefabManager; -import org.terasology.module.inventory.systems.InventoryUtils; -import org.terasology.module.inventory.components.ItemDifferentiating; import org.terasology.engine.network.Replicate; import org.terasology.engine.registry.CoreRegistry; import org.terasology.engine.utilities.Assets; +import org.terasology.gestalt.entitysystem.component.Component; +import org.terasology.module.inventory.components.ItemDifferentiating; +import org.terasology.module.inventory.systems.InventoryUtils; import java.util.Collections; import java.util.Comparator; @@ -35,7 +22,7 @@ /** * A list of the contents of an item. Not intended to be added directly to a prefab with json. */ -public class MaterialCompositionComponent implements Component, ItemDifferentiating { +public class MaterialCompositionComponent implements Component, ItemDifferentiating { /** * A map of the substance prefab and how much is contained */ @@ -178,4 +165,9 @@ public String toDisplayString() { display = display.trim(); return display; } + + @Override + public void copy(MaterialCompositionComponent other) { + this.contents = Maps.newHashMap(other.contents); + } } diff --git a/src/main/java/org/terasology/substanceMatters/components/MaterialItemComponent.java b/src/main/java/org/terasology/substanceMatters/components/MaterialItemComponent.java index 1b30e36..cacaa90 100644 --- a/src/main/java/org/terasology/substanceMatters/components/MaterialItemComponent.java +++ b/src/main/java/org/terasology/substanceMatters/components/MaterialItemComponent.java @@ -1,27 +1,14 @@ -/* - * 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.substanceMatters.components; -import org.terasology.engine.entitySystem.Component; +import org.terasology.gestalt.entitysystem.component.Component; import org.terasology.module.inventory.components.ItemDifferentiating; /** * Attach this to items that are made of a particular substance. The icon will be tinted to the substance's definition. */ -public class MaterialItemComponent implements Component, ItemDifferentiating { +public class MaterialItemComponent implements Component, ItemDifferentiating { public String icon; @Override @@ -46,4 +33,9 @@ public boolean equals(Object o) { public int hashCode() { return icon != null ? icon.hashCode() : 0; } + + @Override + public void copy(MaterialItemComponent other) { + this.icon = other.icon; + } } diff --git a/src/main/java/org/terasology/substanceMatters/components/SubstanceComponent.java b/src/main/java/org/terasology/substanceMatters/components/SubstanceComponent.java index fdf2c0d..c0d69c6 100644 --- a/src/main/java/org/terasology/substanceMatters/components/SubstanceComponent.java +++ b/src/main/java/org/terasology/substanceMatters/components/SubstanceComponent.java @@ -1,29 +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.substanceMatters.components; -import org.terasology.engine.entitySystem.Component; +import org.terasology.gestalt.entitysystem.component.Component; /** * A definition for a substance. Color values are for generated icons. */ -public class SubstanceComponent implements Component { +public class SubstanceComponent implements Component { public String name; public String description = ""; public int hue; public float saturationScale = 1f; public float brightnessScale = 1f; + + @Override + public void copy(SubstanceComponent other) { + this.name = other.name; + this.description = other.description; + this.hue = other.hue; + this.saturationScale = other.saturationScale; + this.brightnessScale = other.brightnessScale; + } } diff --git a/src/main/java/org/terasology/substanceMatters/processParts/InjectSubstancesComponent.java b/src/main/java/org/terasology/substanceMatters/processParts/InjectSubstancesComponent.java index ea9af3a..585d127 100644 --- a/src/main/java/org/terasology/substanceMatters/processParts/InjectSubstancesComponent.java +++ b/src/main/java/org/terasology/substanceMatters/processParts/InjectSubstancesComponent.java @@ -1,26 +1,13 @@ -/* - * 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.substanceMatters.processParts; import com.google.common.collect.Maps; -import org.terasology.engine.entitySystem.Component; +import org.terasology.gestalt.entitysystem.component.Component; import java.util.Map; -public class InjectSubstancesComponent implements Component { +public class InjectSubstancesComponent implements Component { /** * A map of substance prefab and how much is added */ @@ -31,4 +18,9 @@ public class InjectSubstancesComponent implements Component { */ public Map replace = Maps.newHashMap(); + @Override + public void copy(InjectSubstancesComponent other) { + this.add = Maps.newHashMap(other.add); + this.replace = Maps.newHashMap(other.replace); + } } diff --git a/src/main/java/org/terasology/substanceMatters/processParts/TransferSubstancesComponent.java b/src/main/java/org/terasology/substanceMatters/processParts/TransferSubstancesComponent.java index a18d8c4..aa36819 100644 --- a/src/main/java/org/terasology/substanceMatters/processParts/TransferSubstancesComponent.java +++ b/src/main/java/org/terasology/substanceMatters/processParts/TransferSubstancesComponent.java @@ -1,26 +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.substanceMatters.processParts; -import org.terasology.engine.entitySystem.Component; +import org.terasology.gestalt.entitysystem.component.Component; /** * Creates an material item containing the materials that it is composed of based on the original input items. The item will appear like the largest amount of substance. */ -public class TransferSubstancesComponent implements Component { +public class TransferSubstancesComponent implements Component { boolean extract = true; boolean inject = true; + + @Override + public void copy(TransferSubstancesComponent other) { + this.extract = other.extract; + this.inject = other.inject; + } } From cf61831f4f8736f6ca7bde84c0308fb6d9e52aad Mon Sep 17 00:00:00 2001 From: Tobias Nett Date: Sat, 14 Aug 2021 12:18:58 +0200 Subject: [PATCH 2/2] chore: rename copy >>> copyFrom (as per MovingBlocks/gestalt#123) --- .../components/MaterialCompositionComponent.java | 2 +- .../substanceMatters/components/MaterialItemComponent.java | 2 +- .../substanceMatters/components/SubstanceComponent.java | 2 +- .../processParts/InjectSubstancesComponent.java | 2 +- .../processParts/TransferSubstancesComponent.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/terasology/substanceMatters/components/MaterialCompositionComponent.java b/src/main/java/org/terasology/substanceMatters/components/MaterialCompositionComponent.java index 10929ff..312b234 100644 --- a/src/main/java/org/terasology/substanceMatters/components/MaterialCompositionComponent.java +++ b/src/main/java/org/terasology/substanceMatters/components/MaterialCompositionComponent.java @@ -167,7 +167,7 @@ public String toDisplayString() { } @Override - public void copy(MaterialCompositionComponent other) { + public void copyFrom(MaterialCompositionComponent other) { this.contents = Maps.newHashMap(other.contents); } } diff --git a/src/main/java/org/terasology/substanceMatters/components/MaterialItemComponent.java b/src/main/java/org/terasology/substanceMatters/components/MaterialItemComponent.java index cacaa90..1efdce0 100644 --- a/src/main/java/org/terasology/substanceMatters/components/MaterialItemComponent.java +++ b/src/main/java/org/terasology/substanceMatters/components/MaterialItemComponent.java @@ -35,7 +35,7 @@ public int hashCode() { } @Override - public void copy(MaterialItemComponent other) { + public void copyFrom(MaterialItemComponent other) { this.icon = other.icon; } } diff --git a/src/main/java/org/terasology/substanceMatters/components/SubstanceComponent.java b/src/main/java/org/terasology/substanceMatters/components/SubstanceComponent.java index c0d69c6..aa6fbbc 100644 --- a/src/main/java/org/terasology/substanceMatters/components/SubstanceComponent.java +++ b/src/main/java/org/terasology/substanceMatters/components/SubstanceComponent.java @@ -15,7 +15,7 @@ public class SubstanceComponent implements Component { public float brightnessScale = 1f; @Override - public void copy(SubstanceComponent other) { + public void copyFrom(SubstanceComponent other) { this.name = other.name; this.description = other.description; this.hue = other.hue; diff --git a/src/main/java/org/terasology/substanceMatters/processParts/InjectSubstancesComponent.java b/src/main/java/org/terasology/substanceMatters/processParts/InjectSubstancesComponent.java index 585d127..4503bc0 100644 --- a/src/main/java/org/terasology/substanceMatters/processParts/InjectSubstancesComponent.java +++ b/src/main/java/org/terasology/substanceMatters/processParts/InjectSubstancesComponent.java @@ -19,7 +19,7 @@ public class InjectSubstancesComponent implements Component replace = Maps.newHashMap(); @Override - public void copy(InjectSubstancesComponent other) { + public void copyFrom(InjectSubstancesComponent other) { this.add = Maps.newHashMap(other.add); this.replace = Maps.newHashMap(other.replace); } diff --git a/src/main/java/org/terasology/substanceMatters/processParts/TransferSubstancesComponent.java b/src/main/java/org/terasology/substanceMatters/processParts/TransferSubstancesComponent.java index aa36819..71d6907 100644 --- a/src/main/java/org/terasology/substanceMatters/processParts/TransferSubstancesComponent.java +++ b/src/main/java/org/terasology/substanceMatters/processParts/TransferSubstancesComponent.java @@ -12,7 +12,7 @@ public class TransferSubstancesComponent implements Component