Skip to content

Commit

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

Co-authored-by: Michael Pollind <mpollind@gmail.com>
Co-authored-by: Tobias Nett <skaldarnar@googlemail.com>
  • Loading branch information
3 people committed Aug 25, 2021
1 parent 0775f00 commit 95a4f20
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 56 deletions.
27 changes: 9 additions & 18 deletions src/main/java/org/terasology/staticCities/SettlementComponent.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
/*
* Copyright 2013 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.staticCities;

import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.staticCities.settlements.Settlement;

/**
* Indicates a settlement.
*/
public final class SettlementComponent implements Component {
public final class SettlementComponent implements Component<SettlementComponent> {

public Settlement settlement;

Expand All @@ -32,4 +18,9 @@ public SettlementComponent() {
public SettlementComponent(Settlement settlement) {
this.settlement = settlement;
}

@Override
public void copyFrom(SettlementComponent other) {
this.settlement = other.settlement;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.staticCities.parcels;

import com.google.common.cache.Cache;
Expand All @@ -11,7 +10,6 @@
import org.slf4j.LoggerFactory;
import org.terasology.commonworld.Orientation;
import org.terasology.commonworld.geom.CircleUtility;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.utilities.random.FastRandom;
import org.terasology.engine.utilities.random.Random;
import org.terasology.engine.world.block.BlockArea;
Expand All @@ -21,6 +19,7 @@
import org.terasology.engine.world.generation.GeneratingRegion;
import org.terasology.engine.world.generation.Produces;
import org.terasology.engine.world.generation.Requires;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.joml.geom.Circlef;
import org.terasology.joml.geom.Rectanglef;
import org.terasology.math.TeraMath;
Expand Down Expand Up @@ -100,7 +99,7 @@ private Set<RectStaticParcel> generateParcels(Settlement settlement, BlockedArea
result.addAll(generateParcels(settlement, rng, 25, 40, 1, Zone.GOVERNMENTAL, blockedAreaFacet, terrainFacet));
result.addAll(generateParcels(settlement, rng, 20, 30, 1, Zone.COMMERCIAL, blockedAreaFacet, terrainFacet));
result.addAll(generateParcels(settlement, rng, config.minSize, config.maxSize, config.maxLots,
Zone.RESIDENTIAL, blockedAreaFacet, terrainFacet));
Zone.RESIDENTIAL, blockedAreaFacet, terrainFacet));
return result;
}

Expand Down Expand Up @@ -224,7 +223,7 @@ public void setConfiguration(Component configuration) {
}
}

private static class ParcelConfiguration implements Component {
private static class ParcelConfiguration implements Component<ParcelConfiguration> {

@Range(min = 5f, max = 50f, increment = 1f, precision = 0, description = "The min. parcel length")
private float minSize = 10;
Expand All @@ -237,5 +236,13 @@ private static class ParcelConfiguration implements Component {

@Range(min = 5, max = 250, increment = 1, precision = 0, description = "The max. number of parcels")
private int maxLots = 100;

@Override
public void copyFrom(ParcelConfiguration other) {
this.minSize = other.minSize;
this.maxSize = other.maxSize;
this.maxTries = other.maxTries;
this.maxLots = other.maxLots;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
/*
* 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.staticCities.sites;

import org.joml.RoundingMode;
import org.joml.Vector2i;
import org.joml.Vector2ic;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.utilities.procedural.Noise;
import org.terasology.engine.utilities.procedural.WhiteNoise;
import org.terasology.engine.world.block.BlockArea;
Expand All @@ -31,6 +17,7 @@
import org.terasology.engine.world.generation.GeneratingRegion;
import org.terasology.engine.world.generation.Produces;
import org.terasology.engine.world.generation.Requires;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.math.TeraMath;
import org.terasology.nui.properties.Range;
import org.terasology.staticCities.terrain.BuildableTerrainFacet;
Expand Down Expand Up @@ -155,7 +142,7 @@ private boolean ensureMinDistance(List<Site> sites, double minDist) {
return true;
}

private static class SiteConfiguration implements Component {
private static class SiteConfiguration implements Component<SiteConfiguration> {

@Range(label = "Minimal town size", description = "Minimal town size in blocks", min = 1, max = 150, increment = 10, precision = 1)
private int minRadius = 50;
Expand All @@ -165,5 +152,12 @@ private static class SiteConfiguration implements Component {

@Range(label = "Minimum distance between towns", min = 10, max = 1000, increment = 10, precision = 1)
private int minDistance = 128;

@Override
public void copyFrom(SiteConfiguration other) {
this.minRadius = other.minRadius;
this.maxRadius = other.maxRadius;
this.minDistance = other.minDistance;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
/*
* 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.staticCities.surface;

import org.terasology.commonworld.heightmap.HeightMap;
import org.terasology.commonworld.heightmap.HeightMaps;
import org.terasology.commonworld.heightmap.NoiseHeightMap;
import org.terasology.commonworld.symmetry.Symmetries;
import org.terasology.commonworld.symmetry.Symmetry;
import org.terasology.engine.entitySystem.Component;
import org.terasology.engine.world.generation.ConfigurableFacetProvider;
import org.terasology.engine.world.generation.GeneratingRegion;
import org.terasology.engine.world.generation.Produces;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.nui.properties.OneOf.Enum;

@Produces(InfiniteSurfaceHeightFacet.class)
Expand Down Expand Up @@ -103,8 +90,13 @@ public Symmetry getInstance() {
}
}

private static class InfiniteSurfaceConfiguration implements Component {
private static class InfiniteSurfaceConfiguration implements Component<InfiniteSurfaceConfiguration> {
@Enum(label = "Symmetric World", description = "Check to create an axis-symmetric world")
private SymmetryType symmetry = SymmetryType.NONE;

@Override
public void copyFrom(InfiniteSurfaceConfiguration other) {
this.symmetry = other.symmetry;
}
}
}

0 comments on commit 95a4f20

Please sign in to comment.