Skip to content

Commit

Permalink
PlutoComponent cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AMNatty committed Jun 21, 2022
1 parent 27f4882 commit 6ba1dfa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions UPDATE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 22.3.0.0-alpha.1
* `[PlutoComponent]` Removing components using a token should have the same semantics as removing individual components
* `[PlutoComponent]` Made the addition and removal of components hookable before mount events are fired

## 22.3.0.0-alpha.0
* `[SDK]` **Combined `PlutoFramebuffer`, `PlutoMesher`, `PlutoShader` and `PlutoTexture`
into `PlutoRender`**
Expand Down
3 changes: 1 addition & 2 deletions buildSrc/src/main/kotlin/org/plutoengine/Versions.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.plutoengine

import org.gradle.internal.os.OperatingSystem
import org.gradle.api.JavaVersion

object Versions {
Expand Down Expand Up @@ -28,7 +27,7 @@ object Versions {

const val isPrerelease = true
const val prereleaseName = "alpha"
const val prerealeaseUpdate = 0
const val prerealeaseUpdate = 1

val versionFull =
if (isPrerelease)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.commons.collections4.multimap.ArrayListValuedHashMap;
import org.apache.commons.collections4.multimap.HashSetValuedHashMap;
import org.apache.commons.lang3.ClassUtils;
import org.jetbrains.annotations.MustBeInvokedByOverriders;
import org.jetbrains.annotations.NotNull;

import java.util.*;
Expand Down Expand Up @@ -74,6 +75,14 @@ public <T extends R> T addComponent(@NotNull ComponentToken<T> token)
this.components.put(token, component);
this.tokens.put(component, token);

this.onComponentAdded(component);

return component;
}

@MustBeInvokedByOverriders
protected void onComponentAdded(R component)
{
try
{
component.initialize(this);
Expand All @@ -82,8 +91,6 @@ public <T extends R> T addComponent(@NotNull ComponentToken<T> token)
{
throw new RuntimeException("An exception has occured while mounting the component", e);
}

return component;
}

public Class<R> getComponentBase()
Expand Down Expand Up @@ -130,6 +137,12 @@ public void removeComponent(@NotNull R component) throws IllegalArgumentExceptio

classes.forEach(clazz -> this.implementationProviders.removeMapping(clazz, component));

this.onComponentRemoved(component);
}

@MustBeInvokedByOverriders
protected void onComponentRemoved(R component)
{
try
{
component.destroy(this);
Expand All @@ -151,14 +164,7 @@ public <T extends R> void removeComponents(@NotNull ComponentToken<T> componentT

classes.forEach(clazz -> this.implementationProviders.removeMapping(clazz, component));

try
{
component.onUnmount();
}
catch (Exception e)
{
throw new RuntimeException("An exception has occured whiile unmounting the component", e);
}
this.onComponentRemoved(component);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void render()

var scoreFont = new TextStyleOptions(24)
.setPaint(LiPaint.solidColor(Color.WHITE));
ImmediateFontRenderer.drawString(5.0f, 5.0f, ("S %010.0f").formatted(this.entityPlayer.getScore()), SRCloneMod.srCloneFont, scoreFont);
ImmediateFontRenderer.drawString(5.0f, 5.0f, "S %010.0f".formatted(this.entityPlayer.getScore()), SRCloneMod.srCloneFont, scoreFont);

if (this.deathScreenAnimation > 1.0f)
{
Expand Down

0 comments on commit 6ba1dfa

Please sign in to comment.