-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: expose settlement events #31
Conversation
Neat! Throwing some reviewers at this, and pinging @Vizaxo who weirdly for some reason still doesn't auto-complete for reviews etc here. |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.*; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.*; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
No (technical) reason, just a matter of personal taste. I've put it back in and removed the star imports, etc. |
Re-bump just to see if we should merge yet :-) Pinging @skaldarnar @Vizaxo @msteiger @CptCrispyCrunchy |
There was a problem hiding this 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 🤓
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 ofworldProvider
orblockBufferSystem
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 newSet
andBuffer
block events and handlers can be removed.