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

feat: expose settlement events #31

Merged

Conversation

kaen
Copy link
Contributor

@kaen kaen commented Aug 11, 2017

Exposes some events for site selection, building selection, and block rasterization to allow customization by client code. There are probably still more events to expose but it seems good to merge incrementally. Part of #29

As a side note, I think RasterTarget should be used in place of worldProvider or blockBufferSystem directly. I didn't want to make that change since it may be included in the major changes already underway. If that's implemented the new Set and Buffer block events and handlers can be removed.

@Cervator
Copy link
Member

Neat! Throwing some reviewers at this, and pinging @Vizaxo who weirdly for some reason still doesn't auto-complete for reviews etc here.

Copy link
Contributor

@skaldarnar skaldarnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good overall, the events definitely improve the API of dynamic cities. I left a few comments here and there requesting some minor changes.
Is there any (technical) reason why you removed the Optional?

@@ -180,7 +180,7 @@ public void postBegin() {
return Optional.empty();
}

public Optional<GenericBuildingComponent> getRandomBuildingOfZoneForCulture(String zone, Rect2i shape, CultureComponent cultureComponent) {
public GenericBuildingComponent getRandomBuildingOfZoneForCulture(String zone, Rect2i shape, CultureComponent cultureComponent) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this interface? I personally think that Optional conveys the intended interface way better than the Java's typical null pattern. I still find it counter-intuitive that a method public X getFoo() might return "nothing" as part of its interface.

@@ -38,8 +38,7 @@
import org.terasology.dynamicCities.buildings.components.ProductionChestComponent;
import org.terasology.dynamicCities.buildings.components.SettlementRefComponent;
import org.terasology.dynamicCities.buildings.events.OnSpawnDynamicStructureEvent;
import org.terasology.dynamicCities.construction.events.BuildingEntitySpawnedEvent;
import org.terasology.dynamicCities.construction.events.SpawnStructureBufferedEvent;
import org.terasology.dynamicCities.construction.events.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid star imports (in IntelliJ you have to set the number of classes for which start import is triggered to some very high number)

@@ -99,6 +100,7 @@
import org.terasology.world.block.entity.placement.PlaceBlocks;
import org.terasology.world.generation.Border3D;
import org.terasology.world.generation.facets.SurfaceHeightFacet;
import sun.misc.Request;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this import intended? I general, you should avoid the sun packages if possible.

import org.terasology.dynamicCities.settlements.events.CheckBuildingSpawnPreconditionsEvent;
import org.terasology.dynamicCities.settlements.events.SettlementGrowthEvent;
import org.terasology.dynamicCities.settlements.events.SettlementRegisterEvent;
import org.terasology.dynamicCities.settlements.events.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the start import.

&& checkBuildArea) {
CheckSiteSuitabilityEvent checkSiteSuitabilityEvent = new CheckSiteSuitabilityEvent();
siteRegion.send(checkSiteSuitabilityEvent);
if (checkSiteSuitabilityEvent.getResult() == SettlementFilterResult.SUITABLE) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to use a switch statement here (also helps to spot missed cases, etc.).

switch(checkSiteSuitabilityEvent.getResult()) {
    case SettlementFilterResult.SUITABLE:
      ...;
      break;
  case SettlementFilterResult.UNSUITABLE:
  case SettlementFilterResult.UNKOWN:
      ...;
      break;
}

*/
public class CheckBuildingForParcelEvent implements ConsumableEvent {
public DynParcel dynParcel;
public GenericBuildingComponent building;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, I'd like to have this as Optional

@kaen
Copy link
Contributor Author

kaen commented Aug 20, 2017

No (technical) reason, just a matter of personal taste. I've put it back in and removed the star imports, etc.

@Cervator
Copy link
Member

Cervator commented Sep 2, 2017

Re-bump just to see if we should merge yet :-) Pinging @skaldarnar @Vizaxo @msteiger @CptCrispyCrunchy

Copy link
Contributor

@skaldarnar skaldarnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While testing the medieval cities world with this PR I noticed a couple of building parcels overlapping each other. Not sure whether this is caused by this change or not.

Let's get this merged for now, can fix bugs later on 🤓

@skaldarnar skaldarnar added the Type: Improvement Request for or addition/enhancement of a feature label Apr 8, 2020
@skaldarnar skaldarnar changed the title Feature/pluggable settlement development feat: expose settlement events Apr 8, 2020
@skaldarnar skaldarnar merged commit ba5145b into Terasology:master Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement Request for or addition/enhancement of a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants