mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-25 13:30:10 +00:00
replace implementation arguments with context
This commit is contained in:
1 parent
373f6a5fe3
commit
c1232298b3
29 files changed
+102
-99
No files matched your search
+3
-3
@@ -23,15 +23,15 @@ public class Block implements Item<Block.ReturnInfo<?>> {
|
||||
return items;
|
||||
}
|
||||
|
||||
public ReturnInfo<?> apply(ImplementationArguments implementationArguments) {
|
||||
return apply(, implementationArguments, new HashMap<>());
|
||||
public ReturnInfo<?> apply(Context context) {
|
||||
return apply(context, new HashMap<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnInfo<?> apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
Map<String, Variable<?>> scope = new HashMap<>(variableMap);
|
||||
for(Item<?> item : items) {
|
||||
Object result = item.apply(, implementationArguments, scope);
|
||||
Object result = item.apply(context, scope);
|
||||
if(result instanceof ReturnInfo) {
|
||||
ReturnInfo<?> level = (ReturnInfo<?>) result;
|
||||
if(!level.getLevel().equals(ReturnLevel.NONE)) return level;
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ public class ForKeyword implements Keyword<Block.ReturnInfo<?>> {
|
||||
|
||||
@Override
|
||||
public Block.ReturnInfo<?> apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
for(initializer.apply(, implementationArguments, variableMap); statement.apply(, implementationArguments, variableMap); incrementer.apply(, implementationArguments, variableMap)) {
|
||||
Block.ReturnInfo<?> level = conditional.apply(, implementationArguments, variableMap);
|
||||
for(initializer.apply(context, variableMap); statement.apply(context, variableMap); incrementer.apply(context, variableMap)) {
|
||||
Block.ReturnInfo<?> level = conditional.apply(context, variableMap);
|
||||
if(level.getLevel().equals(Block.ReturnLevel.BREAK)) break;
|
||||
if(level.getLevel().isReturnFast()) return level;
|
||||
}
|
||||
|
||||
+4
-4
@@ -28,14 +28,14 @@ public class IfKeyword implements Keyword<Block.ReturnInfo<?>> {
|
||||
|
||||
@Override
|
||||
public Block.ReturnInfo<?> apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
if(statement.apply(, implementationArguments, variableMap)) return conditional.apply(, implementationArguments, variableMap);
|
||||
if(statement.apply(context, variableMap)) return conditional.apply(context, variableMap);
|
||||
else {
|
||||
for(Pair<Returnable<Boolean>, Block> pair : elseIf) {
|
||||
if(pair.getLeft().apply(, implementationArguments, variableMap)) {
|
||||
return pair.getRight().apply(, implementationArguments, variableMap);
|
||||
if(pair.getLeft().apply(context, variableMap)) {
|
||||
return pair.getRight().apply(context, variableMap);
|
||||
}
|
||||
}
|
||||
if(elseBlock != null) return elseBlock.apply(, implementationArguments, variableMap);
|
||||
if(elseBlock != null) return elseBlock.apply(context, variableMap);
|
||||
}
|
||||
return new Block.ReturnInfo<>(Block.ReturnLevel.NONE, null);
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,8 +22,8 @@ public class WhileKeyword implements Keyword<Block.ReturnInfo<?>> {
|
||||
|
||||
@Override
|
||||
public Block.ReturnInfo<?> apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
while(statement.apply(, implementationArguments, variableMap)) {
|
||||
Block.ReturnInfo<?> level = conditional.apply(, implementationArguments, variableMap);
|
||||
while(statement.apply(context, variableMap)) {
|
||||
Block.ReturnInfo<?> level = conditional.apply(context, variableMap);
|
||||
if(level.getLevel().equals(Block.ReturnLevel.BREAK)) break;
|
||||
if(level.getLevel().isReturnFast()) return level;
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,6 +27,6 @@ public abstract class BinaryOperation<I, O> implements Returnable<O> {
|
||||
|
||||
@Override
|
||||
public O apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return apply(left.apply(, implementationArguments, variableMap), right.apply(, implementationArguments, variableMap));
|
||||
return apply(left.apply(context, variableMap), right.apply(context, variableMap));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -20,7 +20,7 @@ public abstract class UnaryOperation<T> implements Returnable<T> {
|
||||
|
||||
@Override
|
||||
public T apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
return apply(input.apply(, implementationArguments, variableMap));
|
||||
return apply(input.apply(context, variableMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -21,8 +21,8 @@ public class Assignment<T> implements Item<T> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public synchronized T apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
T val = value.apply(, implementationArguments, variableMap);
|
||||
public T apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
T val = value.apply(context, variableMap);
|
||||
((Variable<T>) variableMap.get(identifier)).setValue(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class Declaration<T> implements Item<T> {
|
||||
|
||||
@Override
|
||||
public T apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
T result = value.apply(, implementationArguments, variableMap);
|
||||
T result = value.apply(context, variableMap);
|
||||
switch(type) {
|
||||
case NUMBER:
|
||||
variableMap.put(identifier, new NumberVariable((Number) result, position));
|
||||
|
||||
+9
-6
@@ -2,7 +2,7 @@ package com.dfsek.terra.addons.terrascript.script;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.api.FunctionBuilder;
|
||||
import com.dfsek.terra.addons.terrascript.api.StructureScript;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.api.TerraProperties;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.DirectBuffer;
|
||||
import com.dfsek.terra.addons.terrascript.api.buffer.StructureBuffer;
|
||||
import com.dfsek.terra.addons.terrascript.api.exception.ParseException;
|
||||
@@ -10,6 +10,7 @@ import com.dfsek.terra.addons.terrascript.parser.Parser;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Block;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.properties.Context;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.structure.LootTable;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
@@ -75,7 +76,7 @@ public class StructureScriptImpl implements StructureScript {
|
||||
try {
|
||||
return cache.get(location, () -> {
|
||||
StructureBuffer buf = new StructureBuffer(location);
|
||||
buf.setSucceeded(applyBlock(new TerraImplementationArguments(buf, rotation, random, world, 0)));
|
||||
buf.setSucceeded(applyBlock(new TerraProperties(buf, rotation, random, world, 0)));
|
||||
return buf;
|
||||
});
|
||||
} catch(ExecutionException e) {
|
||||
@@ -87,7 +88,7 @@ public class StructureScriptImpl implements StructureScript {
|
||||
@SuppressWarnings("try")
|
||||
public boolean generate(Buffer buffer, World world, Random random, Rotation rotation, int recursions) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_recursive:" + id)) {
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, recursions));
|
||||
return applyBlock(new TerraProperties(buffer, rotation, random, world, recursions));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ public class StructureScriptImpl implements StructureScript {
|
||||
public boolean generate(Vector3 location, World world, Random random, Rotation rotation) {
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_direct:" + id)) {
|
||||
DirectBuffer buffer = new DirectBuffer(location, world);
|
||||
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, world, 0));
|
||||
return applyBlock(new TerraProperties(buffer, rotation, random, world, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,9 +106,11 @@ public class StructureScriptImpl implements StructureScript {
|
||||
return id;
|
||||
}
|
||||
|
||||
private boolean applyBlock(TerraImplementationArguments arguments) {
|
||||
private boolean applyBlock(TerraProperties arguments) {
|
||||
try {
|
||||
return block.apply(arguments).getLevel() != Block.ReturnLevel.FAIL;
|
||||
Context context = new Context();
|
||||
context.put(arguments);
|
||||
return block.apply(context).getLevel() != Block.ReturnLevel.FAIL;
|
||||
} catch(RuntimeException e) {
|
||||
main.logger().severe("Failed to generate structure at " + arguments.getBuffer().getOrigin() + ": " + e.getMessage());
|
||||
main.getDebugLogger().stack(e);
|
||||
|
||||
@@ -54,9 +54,9 @@ public class ParserTest {
|
||||
long t = System.nanoTime() - l;
|
||||
System.out.println("Took " + (double) t / 1000000);
|
||||
|
||||
block.apply(, null, new HashMap<>());
|
||||
block.apply(null, new HashMap<>());
|
||||
|
||||
block.apply(, null, new HashMap<>());
|
||||
block.apply(null, new HashMap<>());
|
||||
}
|
||||
|
||||
private static class Test1 implements Function<Void> {
|
||||
@@ -72,7 +72,7 @@ public class ParserTest {
|
||||
|
||||
@Override
|
||||
public Void apply(Context context, Map<String, Variable<?>> variableMap) {
|
||||
System.out.println("string: " + a.apply(, implementationArguments, variableMap) + ", double: " + b.apply(, implementationArguments, variableMap));
|
||||
System.out.println("string: " + a.apply(context, variableMap) + ", double: " + b.apply(context, variableMap));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user