Skip to content

Commit

Permalink
fix(ecs-gestalt): Migrate Components to gestalt's Components. (#8)
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 d7ffdd1 commit c95bd29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.notifications.model;

import org.terasology.engine.entitySystem.Component;
import org.terasology.gestalt.entitysystem.component.Component;
import org.terasology.notifications.events.ExpireNotificationEvent;
import org.terasology.notifications.events.ShowNotificationEvent;

Expand All @@ -15,7 +15,7 @@
* <p>
* Please use {@link ShowNotificationEvent} and {@link ExpireNotificationEvent} to modify the displayed notifications.
*/
public class NotificationComponent implements Component {
public class NotificationComponent implements Component<NotificationComponent> {
/**
* The ordered list of notifications to show in the notification overlay.
*/
Expand All @@ -24,4 +24,10 @@ public class NotificationComponent implements Component {
public NotificationComponent() {
notifications = new ArrayList<>();
}

@Override
public void copyFrom(NotificationComponent other) {
notifications.clear();
notifications.addAll(other.notifications);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.terasology.nui.databinding.ReadOnlyBinding;
import org.terasology.nui.widgets.UIList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -43,9 +44,10 @@ public void initialise() {
@Override
public List<TimedNotification> get() {
EntityRef client = localPlayer.getClientEntity();
return Optional.ofNullable(client.getComponent(NotificationComponent.class))
List<TimedNotification> timedNotifications = Optional.ofNullable(client.getComponent(NotificationComponent.class))
.map(component -> component.notifications)
.orElse(Collections.emptyList());
return timedNotifications;
}
});
}
Expand Down

0 comments on commit c95bd29

Please sign in to comment.