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(gestaltv7-eventsystem): Migration Event and @ReceiveEvent to gestalt's #18

Merged
merged 3 commits into from Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,18 +1,5 @@
/*
* 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.journal;

import org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData;
Expand Down Expand Up @@ -43,7 +30,7 @@ public Collection<ParagraphData> resolveJournalEntryParts(String entryId, long d
return entryMap.get(entryId).produceParagraph(date);
}

private static class StaticJournalEntryProducer implements JournalEntryProducer {
private static final class StaticJournalEntryProducer implements JournalEntryProducer {
private Collection<ParagraphData> paragraphs;

private StaticJournalEntryProducer(Collection<ParagraphData> paragraphs) {
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/terasology/journal/DefaultDocumentData.java
@@ -1,4 +1,4 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.journal;

Expand All @@ -18,22 +18,20 @@
import java.util.List;

public class DefaultDocumentData implements DocumentData {
private DocumentRenderStyle documentRenderStyle;
private List<DefaultParagraphData> paragraphs = new LinkedList<>();
private static final Logger logger = LoggerFactory.getLogger(DefaultDocumentData.class);

private static final Color UNREAD_COLOR = new Color(255,255,225);
private static final Color UNREAD_COLOR = new Color(255, 255, 225);

public DefaultDocumentData(DocumentRenderStyle documentRenderStyle) {
this.documentRenderStyle = documentRenderStyle;
}
private DocumentRenderStyle documentRenderStyle;
private List<DefaultParagraphData> paragraphs = new LinkedList<>();


private ParagraphRenderStyle unreadParagraph = new ParagraphRenderStyle() {
@Override
public Color getParagraphBackground() {
return UNREAD_COLOR;
}

@Override
public HorizontalAlign getHorizontalAlignment() {
return HorizontalAlign.CENTER;
Expand All @@ -47,6 +45,10 @@ public HorizontalAlign getHorizontalAlignment() {
}
};

public DefaultDocumentData(DocumentRenderStyle documentRenderStyle) {
this.documentRenderStyle = documentRenderStyle;
}

@Override
public DocumentRenderStyle getDocumentRenderStyle() {
return documentRenderStyle;
Expand Down
@@ -1,25 +1,9 @@
/*
* 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.journal;

import org.terasology.engine.entitySystem.event.Event;
import org.terasology.gestalt.entitysystem.event.Event;

/**
* @author Marcin Sciesinski <marcins78@gmail.com>
*/
public class DiscoveredNewJournalEntry implements Event {
private String chapterId;
private String entryId;
Expand Down
Expand Up @@ -9,9 +9,6 @@
import java.util.List;
import java.util.Map;

/**
* @author Marcin Sciesinski <marcins78@gmail.com>
*/
public class JournalAccessComponent implements Component<JournalAccessComponent> {
@Replicate
public Map<String, List<String>> discoveredJournalEntries = new LinkedHashMap<>();
Expand Down
22 changes: 3 additions & 19 deletions src/main/java/org/terasology/journal/JournalAuthoritySystem.java
@@ -1,35 +1,19 @@
/*
* 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.journal;

import org.terasology.engine.core.Time;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.entitySystem.event.ReceiveEvent;
import org.terasology.engine.entitySystem.systems.BaseComponentSystem;
import org.terasology.engine.entitySystem.systems.RegisterMode;
import org.terasology.engine.entitySystem.systems.RegisterSystem;
import org.terasology.engine.registry.In;
import org.terasology.gestalt.entitysystem.event.ReceiveEvent;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
* @author Marcin Sciesinski <marcins78@gmail.com>
*/
@RegisterSystem(RegisterMode.AUTHORITY)
public class JournalAuthoritySystem extends BaseComponentSystem {
@In
Expand Down
19 changes: 2 additions & 17 deletions src/main/java/org/terasology/journal/JournalButton.java
@@ -1,18 +1,5 @@
/*
* 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.journal;

import org.terasology.engine.input.BindButtonEvent;
Expand All @@ -21,8 +8,6 @@
import org.terasology.input.InputType;
import org.terasology.input.Keyboard;

/**
*/
@RegisterBindButton(id = "openJournal", description = "Open journal", category = "interaction")
@DefaultBinding(type = InputType.KEY, id = Keyboard.KeyId.J)
public class JournalButton extends BindButtonEvent {
Expand Down
17 changes: 2 additions & 15 deletions src/main/java/org/terasology/journal/JournalChapterHandler.java
@@ -1,18 +1,5 @@
/*
* 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.journal;

import org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData;
Expand Down
33 changes: 9 additions & 24 deletions src/main/java/org/terasology/journal/JournalClientSystem.java
@@ -1,54 +1,39 @@
/*
* 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.journal;

import org.terasology.engine.core.Time;
import org.terasology.engine.entitySystem.entity.EntityRef;
import org.terasology.engine.entitySystem.event.ReceiveEvent;
import org.terasology.engine.entitySystem.systems.BaseComponentSystem;
import org.terasology.engine.entitySystem.systems.RegisterMode;
import org.terasology.engine.entitySystem.systems.RegisterSystem;
import org.terasology.engine.entitySystem.systems.UpdateSubscriberSystem;
import org.terasology.engine.network.ClientComponent;
import org.terasology.engine.registry.In;
import org.terasology.engine.rendering.nui.NUIManager;
import org.terasology.gestalt.entitysystem.event.ReceiveEvent;
import org.terasology.input.ButtonState;
import org.terasology.journal.ui.JournalNUIWindow;
import org.terasology.journal.ui.NewEntryWindow;

/**
* @author Marcin Sciesinski <marcins78@gmail.com>
*/
@RegisterSystem(RegisterMode.CLIENT)
public class JournalClientSystem extends BaseComponentSystem implements UpdateSubscriberSystem {
private static final long FULL_ALPHA_TIME = 3000;
private static final long DIM_ALPHA_TIME = 1500;

@In
private NUIManager nuiManager;
@In
private Time time;

private final static long FULL_ALPHA_TIME = 3000;
private final static long DIM_ALPHA_TIME = 1500;

private long lastNotificationReceived;

@Override
public void update(float delta) {
long currentTime = time.getGameTimeInMs();
float alpha = (currentTime > lastNotificationReceived + FULL_ALPHA_TIME + DIM_ALPHA_TIME) ? 0f :
currentTime > lastNotificationReceived + FULL_ALPHA_TIME ? 1f - ((currentTime - lastNotificationReceived - FULL_ALPHA_TIME) / (1f * DIM_ALPHA_TIME)) : 1f;
float alpha = (currentTime > lastNotificationReceived + FULL_ALPHA_TIME + DIM_ALPHA_TIME) ? 0f
: currentTime > lastNotificationReceived + FULL_ALPHA_TIME
? 1f - ((currentTime - lastNotificationReceived - FULL_ALPHA_TIME) / (1f * DIM_ALPHA_TIME)) : 1f;

NewEntryWindow window = ((NewEntryWindow) nuiManager.getScreen("Journal:NewEntryWindow"));
if (alpha == 0f && window != null) {
Expand Down
17 changes: 2 additions & 15 deletions src/main/java/org/terasology/journal/JournalEntryProducer.java
@@ -1,18 +1,5 @@
/*
* 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.journal;

import org.terasology.engine.rendering.nui.widgets.browser.data.ParagraphData;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/org/terasology/journal/JournalManager.java
@@ -1,4 +1,4 @@
// Copyright 2020 The Terasology Foundation
// Copyright 2021 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0
package org.terasology.journal;

Expand All @@ -11,9 +11,6 @@

import java.util.Map;

/**
* @author Marcin Sciesinski <marcins78@gmail.com>
*/
public interface JournalManager {
void registerJournalChapter(String chapterId, TextureRegion icon, String name, JournalChapterHandler browserJournalChapterHandler);

Expand Down
20 changes: 2 additions & 18 deletions src/main/java/org/terasology/journal/JournalManagerImpl.java
@@ -1,18 +1,5 @@
/*
* 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.journal;

import org.terasology.engine.entitySystem.entity.EntityRef;
Expand All @@ -27,9 +14,6 @@
import java.util.List;
import java.util.Map;

/**
* @author Marcin Sciesinski <marcins78@gmail.com>
*/
@RegisterSystem
@Share(JournalManager.class)
public class JournalManagerImpl extends BaseComponentSystem implements JournalManager {
Expand Down
@@ -1,26 +1,10 @@
/*
* 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.journal;

import org.terasology.engine.network.NetworkEvent;
import org.terasology.engine.network.OwnerEvent;

/**
* @author Marcin Sciesinski <marcins78@gmail.com>
*/
@OwnerEvent
public class NewJournalEntryDiscoveredEvent extends NetworkEvent {
private String chapterId;
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/org/terasology/journal/RemoveJournalEntry.java
@@ -1,21 +1,8 @@
/*
* 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.journal;

import org.terasology.engine.entitySystem.event.Event;
import org.terasology.gestalt.entitysystem.event.Event;

public class RemoveJournalEntry implements Event {
private String chapterId;
Expand Down