From 85ce6c60d5ccaacc311b3b312ffa54ddd47658b0 Mon Sep 17 00:00:00 2001 From: DarkWeird Date: Wed, 9 Sep 2020 17:06:45 +0300 Subject: [PATCH] feature(reintegrate-gestaltv7): gestalt-v7 compability (package) --- .../internal/CaveDetectorSystem.java | 30 ++----- .../internal/EasterEggDetectorSystem.java | 32 +++----- .../systems/BlockDetectorSystemImpl.java | 82 +++++++------------ .../blockdetector/utilities/DetectorData.java | 28 ++----- .../utilities/LinearAudioDetectorImpl.java | 40 ++++----- .../systems/BlockDetectorSystemTest.java | 69 +++++++--------- 6 files changed, 100 insertions(+), 181 deletions(-) diff --git a/src/main/java/org/terasology/blockdetector/internal/CaveDetectorSystem.java b/src/main/java/org/terasology/blockdetector/internal/CaveDetectorSystem.java index 6d41817..e0e421f 100644 --- a/src/main/java/org/terasology/blockdetector/internal/CaveDetectorSystem.java +++ b/src/main/java/org/terasology/blockdetector/internal/CaveDetectorSystem.java @@ -1,30 +1,17 @@ -/* - * Copyright 2016 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.blockdetector.internal; import com.google.common.collect.Sets; -import org.terasology.audio.AudioManager; import org.terasology.blockdetector.systems.BlockDetectorSystem; import org.terasology.blockdetector.utilities.DetectorData; import org.terasology.blockdetector.utilities.LinearAudioDetectorImpl; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterSystem; -import org.terasology.math.Region3i; +import org.terasology.engine.audio.AudioManager; +import org.terasology.engine.entitySystem.systems.BaseComponentSystem; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.math.Region3i; +import org.terasology.engine.registry.In; import org.terasology.math.geom.Vector3i; -import org.terasology.registry.In; /** * A detector for caves, i.e. air located below the player. @@ -42,7 +29,8 @@ public class CaveDetectorSystem extends BaseComponentSystem { @Override public void initialise() { Region3i range = Region3i.createFromMinMax(new Vector3i(-1, -55, -1), new Vector3i(1, -5, 1)); - data = new LinearAudioDetectorImpl("BlockDetector:caveDetector", Sets.newHashSet("engine:air"), range, audioManager, "BlockDetector:ScannerBeep", 250, 1000); + data = new LinearAudioDetectorImpl("BlockDetector:caveDetector", Sets.newHashSet("engine:air"), range, + audioManager, "BlockDetector:ScannerBeep", 250, 1000); Region3i nonAerialRange = Region3i.createFromMinMax(new Vector3i(-3, -3, -3), new Vector3i(3, 3, 3)); data.setNonAerialRange(nonAerialRange); diff --git a/src/main/java/org/terasology/blockdetector/internal/EasterEggDetectorSystem.java b/src/main/java/org/terasology/blockdetector/internal/EasterEggDetectorSystem.java index 39440fc..5ce26f9 100644 --- a/src/main/java/org/terasology/blockdetector/internal/EasterEggDetectorSystem.java +++ b/src/main/java/org/terasology/blockdetector/internal/EasterEggDetectorSystem.java @@ -1,32 +1,19 @@ -/* - * Copyright 2016 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.blockdetector.internal; import com.google.common.collect.Sets; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.terasology.audio.AudioManager; import org.terasology.blockdetector.systems.BlockDetectorSystem; import org.terasology.blockdetector.utilities.DetectorData; import org.terasology.blockdetector.utilities.LinearAudioDetectorImpl; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterSystem; -import org.terasology.math.Region3i; +import org.terasology.engine.audio.AudioManager; +import org.terasology.engine.entitySystem.systems.BaseComponentSystem; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.math.Region3i; +import org.terasology.engine.registry.In; import org.terasology.math.geom.Vector3i; -import org.terasology.registry.In; /** * A festive implementation example! @@ -55,7 +42,8 @@ public class EasterEggDetectorSystem extends BaseComponentSystem { @Override public void initialise() { Region3i range = Region3i.createFromMinMax(new Vector3i(-40, -40, -40), new Vector3i(40, 40, 40)); - data = new LinearAudioDetectorImpl("BlockDetector:easterEggDetector", Sets.newHashSet("CoreAssets:Snow"), range, audioManager, "BlockDetector:ScannerBeep", 200, 2000); + data = new LinearAudioDetectorImpl("BlockDetector:easterEggDetector", Sets.newHashSet("CoreAssets:Snow"), + range, audioManager, "BlockDetector:ScannerBeep", 200, 2000); blockDetectorSystem.addDetector(data); } @@ -65,4 +53,4 @@ public void initialise() { public void shutdown() { blockDetectorSystem.removeDetector(data.getDetectorUri()); } -} \ No newline at end of file +} diff --git a/src/main/java/org/terasology/blockdetector/systems/BlockDetectorSystemImpl.java b/src/main/java/org/terasology/blockdetector/systems/BlockDetectorSystemImpl.java index d5eeec3..623a6e9 100644 --- a/src/main/java/org/terasology/blockdetector/systems/BlockDetectorSystemImpl.java +++ b/src/main/java/org/terasology/blockdetector/systems/BlockDetectorSystemImpl.java @@ -1,38 +1,25 @@ -/* - * Copyright 2016 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.blockdetector.systems; import com.google.common.collect.Maps; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.terasology.blockdetector.utilities.DetectorData; -import org.terasology.entitySystem.entity.EntityRef; -import org.terasology.entitySystem.systems.BaseComponentSystem; -import org.terasology.entitySystem.systems.RegisterSystem; -import org.terasology.entitySystem.systems.UpdateSubscriberSystem; -import org.terasology.logic.inventory.InventoryManager; -import org.terasology.logic.inventory.SelectedInventorySlotComponent; -import org.terasology.logic.players.LocalPlayer; +import org.terasology.engine.entitySystem.entity.EntityRef; +import org.terasology.engine.entitySystem.systems.BaseComponentSystem; +import org.terasology.engine.entitySystem.systems.RegisterSystem; +import org.terasology.engine.entitySystem.systems.UpdateSubscriberSystem; +import org.terasology.engine.logic.players.LocalPlayer; +import org.terasology.engine.registry.In; +import org.terasology.engine.registry.Share; +import org.terasology.engine.world.WorldProvider; +import org.terasology.engine.world.block.Block; +import org.terasology.engine.world.block.BlockManager; +import org.terasology.engine.world.block.BlockUri; +import org.terasology.inventory.logic.InventoryManager; +import org.terasology.inventory.logic.SelectedInventorySlotComponent; import org.terasology.math.geom.Vector3i; -import org.terasology.registry.In; -import org.terasology.registry.Share; -import org.terasology.world.WorldProvider; -import org.terasology.world.block.Block; -import org.terasology.world.block.BlockManager; -import org.terasology.world.block.BlockUri; import java.math.RoundingMode; import java.util.HashSet; @@ -46,67 +33,58 @@ */ @RegisterSystem @Share(value = BlockDetectorSystem.class) -public class BlockDetectorSystemImpl extends BaseComponentSystem implements UpdateSubscriberSystem, BlockDetectorSystem { +public class BlockDetectorSystemImpl extends BaseComponentSystem implements UpdateSubscriberSystem, + BlockDetectorSystem { private static final Logger logger = LoggerFactory.getLogger(BlockDetectorSystemImpl.class); - + private final Set detectedBlocks = new HashSet<>(); /** * Used to retrieve the {@code AIR_ID} and {@code UNLOADED_ID} Urns. */ @In private BlockManager blockManager; - /** * Used to get the block located at the specified position. */ @In private WorldProvider worldProvider; - /** * Used to get the player's current position. */ @In private LocalPlayer localPlayer; - /** * Used to get the player's current selected item. */ @In private InventoryManager inventoryManager; - /** * The map of detector-detectable bindings. */ private Map detectors; - private float timeSinceLastUpdate; - /** * The period at which the detectBlocks() function should be called. */ private float updatePeriod; - /** * The current timer task associated with the timer. */ private TimerTask timerTask; - /** * The timer object calling timerTask periodically. */ private Timer timer; - /** * The current task period, in ms. */ private Integer taskPeriod; - private Set detectedBlocks = new HashSet<>(); - /** - * Sets the local player for the test - * The dummy local player will make the system work and does not throw a null exception - * @param set A local player whose location component is used - */ + * Sets the local player for the test The dummy local player will make the system work and does not throw a null + * exception + * + * @param set A local player whose location component is used + */ public void setLocalPlayer(LocalPlayer set) { this.localPlayer = set; } @@ -116,16 +94,17 @@ public float getTimeSinceLastUpdate() { } /** - * This sets the timeSinceLastUpdate value for the tests - */ + * This sets the timeSinceLastUpdate value for the tests + */ public void setTimeSinceLastUpdate(float value) { this.timeSinceLastUpdate = value; } /** - * This provides the DetectorData for the tests - * @return a Map of DetectorData - */ + * This provides the DetectorData for the tests + * + * @return a Map of DetectorData + */ public Map getDetectors() { return this.detectors; } @@ -337,7 +316,8 @@ public void detectBlocks() { int newPeriod = data.getPeriod(minDistance); if (taskPeriod == null || taskPeriod != newPeriod) { - logger.info("Detector {} rescheduling task at taskPeriod {} (minimal block distance: {})", data.getDetectorUri(), newPeriod, minDistance); + logger.info("Detector {} rescheduling task at taskPeriod {} (minimal block distance: {})", + data.getDetectorUri(), newPeriod, minDistance); // Reset the timer. shutdownTimer(); diff --git a/src/main/java/org/terasology/blockdetector/utilities/DetectorData.java b/src/main/java/org/terasology/blockdetector/utilities/DetectorData.java index 651da24..6f34f42 100644 --- a/src/main/java/org/terasology/blockdetector/utilities/DetectorData.java +++ b/src/main/java/org/terasology/blockdetector/utilities/DetectorData.java @@ -1,21 +1,8 @@ -/* - * Copyright 2016 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.blockdetector.utilities; -import org.terasology.math.Region3i; +import org.terasology.engine.math.Region3i; import java.util.Set; @@ -28,21 +15,20 @@ public abstract class DetectorData { /** * The Uri of the detector item. */ - private String detectorUri; + private final String detectorUri; /** * A set of detectable item Uris represented as strings. */ - private Set detectableUris; + private final Set detectableUris; /** * The range of the detector. */ - private Region3i range; + private final Region3i range; /** - * If this variable is not null, all blocks within the specified range - * must not be AIR or UNLOADED. + * If this variable is not null, all blocks within the specified range must not be AIR or UNLOADED. */ private Region3i nonAerialRange; diff --git a/src/main/java/org/terasology/blockdetector/utilities/LinearAudioDetectorImpl.java b/src/main/java/org/terasology/blockdetector/utilities/LinearAudioDetectorImpl.java index cbc4507..12ea04c 100644 --- a/src/main/java/org/terasology/blockdetector/utilities/LinearAudioDetectorImpl.java +++ b/src/main/java/org/terasology/blockdetector/utilities/LinearAudioDetectorImpl.java @@ -1,33 +1,20 @@ -/* - * Copyright 2016 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.blockdetector.utilities; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.terasology.audio.AudioManager; -import org.terasology.math.Region3i; -import org.terasology.utilities.Assets; +import org.terasology.engine.audio.AudioManager; +import org.terasology.engine.math.Region3i; +import org.terasology.engine.utilities.Assets; import java.util.Set; /** * A DetectorData implementation containing information about an audio asset. *

- * Plays the asset with a frequency scaling depending on the distance to the closest block, - * ranging from frequencyLow to frequencyHigh with four possible values. + * Plays the asset with a frequency scaling depending on the distance to the closest block, ranging from frequencyLow to + * frequencyHigh with four possible values. */ public class LinearAudioDetectorImpl extends DetectorData { private static final Logger logger = LoggerFactory.getLogger(LinearAudioDetectorImpl.class); @@ -35,19 +22,20 @@ public class LinearAudioDetectorImpl extends DetectorData { /** * The audio manager. Should be injected in the custom system implementation. */ - private AudioManager audioManager; + private final AudioManager audioManager; /** * The audio asset Uri, represented as a string. */ - private String audioUri; + private final String audioUri; - private int frequencyLow; - private int frequencyHigh; + private final int frequencyLow; + private final int frequencyHigh; - private int scaleCount = 4; + private final int scaleCount = 4; - public LinearAudioDetectorImpl(String detectorUri, Set detectableUris, Region3i range, AudioManager audioManager, String audioUri, int frequencyLow, int frequencyHigh) { + public LinearAudioDetectorImpl(String detectorUri, Set detectableUris, Region3i range, + AudioManager audioManager, String audioUri, int frequencyLow, int frequencyHigh) { super(detectorUri, detectableUris, range); this.audioManager = audioManager; this.audioUri = audioUri; diff --git a/src/test/java/org/terasology/blockdetector/systems/BlockDetectorSystemTest.java b/src/test/java/org/terasology/blockdetector/systems/BlockDetectorSystemTest.java index 5dac6b6..74ee0ee 100644 --- a/src/test/java/org/terasology/blockdetector/systems/BlockDetectorSystemTest.java +++ b/src/test/java/org/terasology/blockdetector/systems/BlockDetectorSystemTest.java @@ -1,47 +1,33 @@ -/* - * Copyright 2017 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 2020 The Terasology Foundation +// SPDX-License-Identifier: Apache-2.0 package org.terasology.blockdetector.systems; import com.google.common.collect.Sets; import org.junit.Assert; import org.junit.Test; -import org.terasology.audio.AudioManager; import org.terasology.blockdetector.utilities.DetectorData; import org.terasology.blockdetector.utilities.LinearAudioDetectorImpl; -import org.terasology.context.Context; -import org.terasology.logic.players.LocalPlayer; -import org.terasology.logic.players.event.ResetCameraEvent; -import org.terasology.math.Region3i; +import org.terasology.engine.audio.AudioManager; +import org.terasology.engine.context.Context; +import org.terasology.engine.logic.players.LocalPlayer; +import org.terasology.engine.logic.players.event.ResetCameraEvent; +import org.terasology.engine.math.Region3i; +import org.terasology.engine.registry.In; +import org.terasology.engine.world.WorldProvider; +import org.terasology.engine.world.block.BlockManager; import org.terasology.math.geom.Vector3i; import org.terasology.moduletestingenvironment.ModuleTestingEnvironment; -import org.terasology.registry.In; -import org.terasology.world.WorldProvider; -import org.terasology.world.block.BlockManager; public class BlockDetectorSystemTest extends ModuleTestingEnvironment { + BlockDetectorSystemImpl blockDetectorSystem = new BlockDetectorSystemImpl(); @In private AudioManager audioManager; - private DetectorData data; - BlockDetectorSystemImpl blockDetectorSystem = new BlockDetectorSystemImpl(); - /* This updateTest is created to test if the timeSinceLastUpdate is increased by delta. - To make the system runs, we create a dummy local player so that the localPlayer data is not null and does not throw a null exception + To make the system runs, we create a dummy local player so that the localPlayer data is not null and does not + throw a null exception */ @Test public void updateTest() { @@ -55,22 +41,23 @@ public void updateTest() { Assert.assertEquals(8, blockDetectorSystem.getTimeSinceLastUpdate(), 3); } - // This method should return the Detectors in not null condition. It's just running the method and check if Detectors is not null + // This method should return the Detectors in not null condition. It's just running the method and check if + // Detectors is not null @Test public void initialiseTest() { blockDetectorSystem.initialise(); Assert.assertNotNull(blockDetectorSystem.getDetectors()); } - /* These test method is to test whether the method addDetector is functioning or not. - We use the same method CaveDetectorSystem to add. - Then we want to assert if the map contains the same data we want to be stored there. - When we try to get the values, it is started and ended with '[' and ']'. - Therefore, we use string data type so we can use substring to remove them. - Then we assert that both values (expected which is the data and actual which is the map value substring) are equal - */ + /* These test method is to test whether the method addDetector is functioning or not. + We use the same method CaveDetectorSystem to add. + Then we want to assert if the map contains the same data we want to be stored there. + When we try to get the values, it is started and ended with '[' and ']'. + Therefore, we use string data type so we can use substring to remove them. + Then we assert that both values (expected which is the data and actual which is the map value substring) are equal + */ @Test - public void detectedBlockTest(){ + public void detectedBlockTest() { WorldProvider worldProvider = getHostContext().get(WorldProvider.class); BlockManager blockManager = getHostContext().get(BlockManager.class); @@ -91,12 +78,14 @@ public void detectedBlockTest(){ /* Inside this method, the detectedBlocks set will be added with a block if a block is detected. First, we create a dummy local player to make the system runs and does not throw null exception. - Next is we place a block with worldprovider.setBlock -- and then we run the method and check if the detectedBlocks set is not null (filled with our block) + Next is we place a block with worldprovider.setBlock -- and then we run the method and check if the + detectedBlocks set is not null (filled with our block) */ @Test - public void detectorTest(){ + public void detectorTest() { Region3i range = Region3i.createFromMinMax(new Vector3i(-1, -55, -1), new Vector3i(1, -5, 1)); - data = new LinearAudioDetectorImpl("BlockDetector:caveDetector", Sets.newHashSet("engine:air"), range, audioManager, "BlockDetector:ScannerBeep", 250, 1000); + data = new LinearAudioDetectorImpl("BlockDetector:caveDetector", Sets.newHashSet("engine:air"), range, + audioManager, "BlockDetector:ScannerBeep", 250, 1000); Region3i nonAerialRange = Region3i.createFromMinMax(new Vector3i(-3, -3, -3), new Vector3i(3, 3, 3)); data.setNonAerialRange(nonAerialRange); @@ -108,6 +97,6 @@ public void detectorTest(){ String dataToCompare = this.data.toString(); //we use substring because we don't want the '[' and ']' to be asserted - Assert.assertEquals(dataToCompare, value.substring(1, value.length()-1)); + Assert.assertEquals(dataToCompare, value.substring(1, value.length() - 1)); } }