Skip to content

Commit

Permalink
feat(gestaltv7-eventsystem): Migration Event and @ReceiveEvent to ges…
Browse files Browse the repository at this point in the history
…talt's (#9)
  • Loading branch information
DarkWeird committed Dec 9, 2021
1 parent f8cc5c3 commit 2298b71
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 323 deletions.
@@ -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.fluid.computer.module.inventory;

import com.gempukku.lang.CustomObject;
Expand All @@ -24,17 +11,19 @@

import java.util.Map;

public class FluidFunctionParamValidationUtil {
public final class FluidFunctionParamValidationUtil {
private FluidFunctionParamValidationUtil() { }

public static InventoryBinding.InventoryWithSlots validateFluidInventoryBinding(
int line, ComputerCallback computer, Map<String, Variable> parameters,
String parameterName, String functionName, Boolean input) throws ExecutionException {
Variable inventoryBinding = FunctionParamValidationUtil.validateParameter(line, parameters, parameterName, functionName, Variable.Type.CUSTOM_OBJECT);
Variable inventoryBinding =
FunctionParamValidationUtil.validateParameter(line, parameters, parameterName, functionName, Variable.Type.CUSTOM_OBJECT);
CustomObject customObject = (CustomObject) inventoryBinding.getValue();
if (!customObject.getType().contains("FLUID_INVENTORY_BINDING")
|| (input != null && input != ((InventoryBinding) customObject).isInput()))
|| (input != null && input != ((InventoryBinding) customObject).isInput())) {
throw new ExecutionException(line, "Invalid " + parameterName + " in " + functionName + "()");
}

InventoryBinding binding = (InventoryBinding) inventoryBinding.getValue();
return binding.getInventoryEntity(line, computer);
Expand Down
@@ -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.fluid.computer.module.inventory;

import com.gempukku.lang.ExecutionException;
Expand Down Expand Up @@ -42,7 +29,10 @@ public int getCpuCycleDuration() {
}

@Override
public Object onFunctionEnd(int line, ComputerCallback computer, Map<String, Variable> parameters, Object onFunctionStartResult) throws ExecutionException {
public Object onFunctionEnd(int line,
ComputerCallback computer,
Map<String, Variable> parameters,
Object onFunctionStartResult) throws ExecutionException {
InventoryBinding.InventoryWithSlots inventory = FluidFunctionParamValidationUtil.validateFluidInventoryBinding(line, computer,
parameters, "fluidInventoryBinding", methodName, null);

Expand Down
@@ -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.fluid.computer.module.inventory;

import com.gempukku.lang.ExecutionException;
Expand All @@ -21,7 +8,6 @@
import org.terasology.computer.context.ComputerCallback;
import org.terasology.computer.module.inventory.InventoryBinding;
import org.terasology.computer.system.server.lang.AbstractModuleMethodExecutable;
import org.terasology.fluid.component.FluidInventoryComponent;
import org.terasology.fluid.system.FluidUtils;

import java.util.Map;
Expand All @@ -43,7 +29,10 @@ public int getCpuCycleDuration() {
}

@Override
public Object onFunctionEnd(int line, ComputerCallback computer, Map<String, Variable> parameters, Object onFunctionStartResult) throws ExecutionException {
public Object onFunctionEnd(int line,
ComputerCallback computer,
Map<String, Variable> parameters,
Object onFunctionStartResult) throws ExecutionException {
InventoryBinding.InventoryWithSlots inventory = FluidFunctionParamValidationUtil.validateFluidInventoryBinding(line, computer,
parameters, "fluidInventoryBinding", methodName, null);

Expand Down
@@ -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.fluid.computer.module.inventory;

import com.gempukku.lang.ExecutionException;
Expand Down Expand Up @@ -44,7 +31,10 @@ public int getCpuCycleDuration() {
}

@Override
public Object onFunctionEnd(int line, ComputerCallback computer, Map<String, Variable> parameters, Object onFunctionStartResult) throws ExecutionException {
public Object onFunctionEnd(int line,
ComputerCallback computer,
Map<String, Variable> parameters,
Object onFunctionStartResult) throws ExecutionException {
InventoryBinding.InventoryWithSlots inventory = FluidFunctionParamValidationUtil.validateFluidInventoryBinding(line, computer,
parameters, "fluidInventoryBinding", methodName, null);

Expand Down
@@ -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.fluid.computer.module.inventory;

import com.gempukku.lang.ExecutionException;
Expand All @@ -32,13 +19,15 @@ public class FluidInventoryAndChangedConditionMethod extends AbstractModuleMetho
private final String methodName;
private FluidManipulatorConditionsRegister fluidManipulatorConditionsRegister;

public FluidInventoryAndChangedConditionMethod(String methodName, FluidManipulatorConditionsRegister fluidManipulatorConditionsRegister) {
public FluidInventoryAndChangedConditionMethod(String methodName,
FluidManipulatorConditionsRegister fluidManipulatorConditionsRegister) {
super("Gets the information about fluids stored in the inventory as well as a Condition " +
"that allows to wait for the inventory's contents to be changed.", "Map",
"Map containing to entries:<l>" +
"- \"inventory\" - containing a List of Maps, with each entry in the list corresponding to one slot " +
"in the fluid inventory, and each entry Map containing two keys - \"type\" with String value of fluid type, " +
"as specified in the getFluidType() method, and \"volume\" with Number value, specifying volume of the fluid in that slot<l>" +
"as specified in the getFluidType() method, and \"volume\" with Number value, specifying volume of the fluid in " +
"that slot<l>" +
"- \"condition\" - containing condition you could wait on to listen on a change of the fluid inventory from " +
"the state described in the \"inventory\" key. Please note, that the condition might be fulfilled even though " +
"the fluid inventory state has not changed.");
Expand All @@ -54,7 +43,10 @@ public int getCpuCycleDuration() {
}

@Override
public Object onFunctionEnd(int line, ComputerCallback computer, Map<String, Variable> parameters, Object onFunctionStartResult) throws ExecutionException {
public Object onFunctionEnd(int line,
ComputerCallback computer,
Map<String, Variable> parameters,
Object onFunctionStartResult) throws ExecutionException {
InventoryBinding.InventoryWithSlots inventory = FluidFunctionParamValidationUtil.validateFluidInventoryBinding(line, computer,
parameters, "fluidInventoryBinding", methodName, null);

Expand All @@ -70,7 +62,8 @@ public Object onFunctionEnd(int line, ComputerCallback computer, Map<String, Var
@Override
public boolean checkRelease() {
try {
InventoryBinding.InventoryWithSlots inventory = FluidFunctionParamValidationUtil.validateFluidInventoryBinding(line, computer,
InventoryBinding.InventoryWithSlots inventory =
FluidFunctionParamValidationUtil.validateFluidInventoryBinding(line, computer,
parameters, "fluidInventoryBinding", methodName, null);
List<Variable> currentInventory = getInventory(inventory);
if (!currentInventory.equals(inventoryCopyResult)) {
Expand Down
@@ -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.fluid.computer.module.inventory;

import com.gempukku.lang.ExecutionException;
Expand All @@ -32,8 +19,8 @@ public class FluidInventoryBindingMethod extends AbstractModuleMethodExecutable<

public FluidInventoryBindingMethod(String methodName, BlockEntityRegistry blockEntityRegistry, boolean input) {
super(input ? "Creates the input fluid inventory binding for the storage specified in the direction. " +
"This binding allows to insert fluids into the inventory only." :
"Creates the output fluid inventory binding for the storage specified in the direction. " +
"This binding allows to insert fluids into the inventory only."
: "Creates the output fluid inventory binding for the storage specified in the direction. " +
"This binding allows to remove fluids from the inventory only.", "FluidInventoryBinding",
input ? "Input binding for the direction specified." : "Output binding for the direction specified.");
this.blockEntityRegistry = blockEntityRegistry;
Expand All @@ -43,18 +30,22 @@ public FluidInventoryBindingMethod(String methodName, BlockEntityRegistry blockE
addParameter("direction", "Direction", "Direction in which the fluid manipulator is bound to.");

if (input) {
addExample("This example creates input fluid inventory binding to an inventory above it and prints out the slot count for it. Please make sure " +
addExample("This example creates input fluid inventory binding to an inventory above it and prints out the slot count for it." +
" Please make sure " +
"this computer has a module of Fluid Manipulator type in any of its slots.",
"var invBind = computer.bindModuleOfType(\"" + FluidManipulatorCommonSystem.COMPUTER_FLUID_MODULE_TYPE + "\");\n" +
"var topInv = invBind."+methodName+"(\"up\");\n" +
"console.append(\"Inventory above has \" + invBind.getInventorySlotCount(topInv) + \" number of slots available for input.\");"
"var topInv = invBind." + methodName + "(\"up\");\n" +
"console.append(\"Inventory above has \" + invBind.getInventorySlotCount(topInv) + \" number of slots " +
"available for input.\");"
);
} else {
addExample("This example creates output fluid inventory binding to an inventory above it and prints out the slot count for it. Please make sure " +
addExample("This example creates output fluid inventory binding to an inventory above it and prints out the slot count for it" +
". Please make sure " +
"this computer has a module of Fluid Manipulator type in any of its slots.",
"var invBind = computer.bindModuleOfType(\"" + FluidManipulatorCommonSystem.COMPUTER_FLUID_MODULE_TYPE + "\");\n" +
"var topInv = invBind."+methodName+"(\"up\");\n" +
"console.append(\"Inventory above has \" + invBind.getInventorySlotCount(topInv) + \" number of slots available for output.\");"
"var topInv = invBind." + methodName + "(\"up\");\n" +
"console.append(\"Inventory above has \" + invBind.getInventorySlotCount(topInv) + \" number of slots " +
"available for output.\");"
);
}
}
Expand All @@ -65,7 +56,10 @@ public int getCpuCycleDuration() {
}

@Override
public Object onFunctionEnd(int line, ComputerCallback computer, Map<String, Variable> parameters, Object onFunctionStartResult) throws ExecutionException {
public Object onFunctionEnd(int line,
ComputerCallback computer,
Map<String, Variable> parameters,
Object onFunctionStartResult) throws ExecutionException {
Direction direction = FunctionParamValidationUtil.validateDirectionParameter(line, parameters,
"direction", methodName);

Expand Down
@@ -1,26 +1,11 @@
/*
* 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.fluid.computer.module.inventory;

import com.gempukku.lang.ExecutionException;
import com.gempukku.lang.Variable;
import org.terasology.computer.FunctionParamValidationUtil;
import org.terasology.computer.context.ComputerCallback;
import org.terasology.computer.module.inventory.InventoryBinding;
import org.terasology.computer.module.inventory.InventoryModuleCommonSystem;
import org.terasology.computer.system.server.lang.AbstractModuleMethodExecutable;

import java.util.Map;
Expand All @@ -36,11 +21,13 @@ public FluidInventorySlotCountMethod(String methodName) {

addParameter("fluidInventoryBinding", "FluidInventoryBinding", "Fluid inventory it should query for number of slots.");

addExample("This example creates output fluid inventory binding to an inventory above it and prints out the slot count for it. Please make sure " +
"this computer has a module of Fluid Manipulator type in any of its slots.",
"var invBind = computer.bindModuleOfType(\"" + FluidManipulatorCommonSystem.COMPUTER_FLUID_MODULE_TYPE + "\");\n" +
addExample("This example creates output fluid inventory binding to an inventory above it and prints out the slot count for it. " +
"Please make sure this computer has a module of Fluid Manipulator type in any of its slots.",
"var invBind = computer.bindModuleOfType(\"" +
FluidManipulatorCommonSystem.COMPUTER_FLUID_MODULE_TYPE + "\");\n" +
"var topInv = invBind.getOutputInventoryBinding(\"up\");\n" +
"console.append(\"Inventory above has \" + invBind.getInventorySlotCount(topInv) + \" number of slots available for output.\");"
"console.append(" +
"\"Inventory above has \" + invBind.getInventorySlotCount(topInv) + \" number of slots available for output.\");"
);
}

Expand All @@ -50,7 +37,10 @@ public int getCpuCycleDuration() {
}

@Override
public Object onFunctionEnd(int line, ComputerCallback computer, Map<String, Variable> parameters, Object onFunctionStartResult) throws ExecutionException {
public Object onFunctionEnd(int line,
ComputerCallback computer,
Map<String, Variable> parameters,
Object onFunctionStartResult) throws ExecutionException {
InventoryBinding.InventoryWithSlots inventory = FluidFunctionParamValidationUtil.validateFluidInventoryBinding(line, computer,
parameters, "fluidInventoryBinding", methodName, null);

Expand Down

0 comments on commit 2298b71

Please sign in to comment.