private void setField (Field field, Task<E> task, Object value) { field.setAccessible(true); Object valueObject = castValue(field, value); if (valueObject == null) throwAttributeTypeException(getCurrentTask().name, field.getName(), field.getType().getSimpleName()); try { field.set(task, valueObject); } catch (ReflectionException e) { throw new GdxRuntimeException(e); } }
private StackedTask<E> createStackedTask (String name, Task<E> task) { Metadata metadata = findMetadata(task.getClass()); if (metadata == null) throw new RuntimeException(name + ": @TaskConstraint annotation not found in '" + task.getClass().getSimpleName() + "' class hierarchy"); return new StackedTask<E>(lineNumber, name, task, metadata); }
void addImport (String alias, String task) { if (task == null) throw new RuntimeException("import: missing task class name."); if (alias == null) { Class<?> clazz = null; try { clazz = ClassReflection.forName(task); } catch (ReflectionException e) { throw new RuntimeException("import: class not found '" + task + "'"); } alias = clazz.getSimpleName(); } String className = getImport(alias); if (className != null) throw new RuntimeException("import: alias '" + alias + "' previously defined already."); userImports.put(alias, task); }
if (ret == null) throwAttributeTypeException(getCurrentTask().name, field.getName(), type.getSimpleName()); return ret;
if (ret == null) throwAttributeTypeException(getCurrentTask().name, field.getName(), type.getSimpleName()); return ret;
Task<E> task; if (isSubtreeRef) { task = subtreeRootTaskInstance(name); String className = getImport(name); if (className == null) className = name; @SuppressWarnings("unchecked") initCurrentTree(task, indent); indent = 0; } else if (!isGuard) { StackedTask<E> stackedTask = getPrevTask(); popAndCheckMinChildren(stack.size - i); int maxChildren = stackedParent.metadata.maxChildren; if (stackedParent.task.getChildCount() >= maxChildren) throw stackedTaskException(stackedParent, "max number of children exceeded (" + (stackedParent.task.getChildCount() + 1) + " > " + maxChildren + ")"); updateCurrentTask(createStackedTask(name, task), indent, isGuard); } catch (ReflectionException e) { throw new GdxRuntimeException("Cannot parse behavior tree!!!", e);
Task<E> task; if (isSubtreeRef) { task = subtreeRootTaskInstance(name); String className = getImport(name); if (className == null) className = name; @SuppressWarnings("unchecked") initCurrentTree(task, indent); indent = 0; } else if (!isGuard) { StackedTask<E> stackedTask = getPrevTask(); popAndCheckMinChildren(stack.size() - i); int maxChildren = stackedParent.metadata.maxChildren; if (stackedParent.task.getChildCount() >= maxChildren) throw stackedTaskException(stackedParent, "max number of children exceeded (" + (stackedParent.task.getChildCount() + 1) + " > " + maxChildren + ")"); updateCurrentTask(createStackedTask(name, task), indent, isGuard); } catch (ReflectionException e) { throw new RuntimeException("Cannot parse behavior tree!!!", e);
void addImport (String alias, String task) { if (task == null) throw new GdxRuntimeException("import: missing task class name."); if (alias == null) { Class<?> clazz = null; try { clazz = ClassReflection.forName(task); } catch (ReflectionException e) { throw new GdxRuntimeException("import: class not found '" + task + "'"); } alias = clazz.getSimpleName(); } String className = getImport(alias); if (className != null) throw new GdxRuntimeException("import: alias '" + alias + "' previously defined already."); userImports.put(alias, task); }
@Override public void parse (char[] data, int offset, int length) { debug = btParser.debugLevel > BehaviorTreeParser.DEBUG_NONE; root = null; clear(); super.parse(data, offset, length); // Pop all task from the stack and check their minimum number of children popAndCheckMinChildren(0); Subtree<E> rootTree = subtrees.get(""); if (rootTree == null) throw new RuntimeException("Missing root tree"); root = rootTree.rootTask; if (root == null) throw new RuntimeException("The tree must have at least the root task"); clear(); }
@Override public void parse (char[] data, int offset, int length) { debug = btParser.debugLevel > BehaviorTreeParser.DEBUG_NONE; root = null; clear(); super.parse(data, offset, length); // Pop all task from the stack and check their minimum number of children popAndCheckMinChildren(0); Subtree<E> rootTree = subtrees.get(""); if (rootTree == null) throw new GdxRuntimeException("Missing root tree"); root = rootTree.rootTask; if (root == null) throw new GdxRuntimeException("The tree must have at least the root task"); clear(); }
@Override protected void attribute (String name, Object value) { if (btParser.debugLevel > BehaviorTreeParser.DEBUG_LOW) GdxAI.getLogger().debug(TAG + lineNumber + ": attribute '" + name + " : " + value + "'"); boolean validAttribute = statement.attribute(this, name, value); if (!validAttribute) { if (statement == Statement.TreeTask) { throw stackedTaskException(getCurrentTask(), "unknown attribute '" + name + "'"); } else { throw new RuntimeException(statement.name + ": unknown attribute '" + name + "'"); } } }
@Override protected void attribute (String name, Object value) { if (btParser.debugLevel > BehaviorTreeParser.DEBUG_LOW) GdxAI.getLogger().debug(TAG, lineNumber + ": attribute '" + name + " : " + value + "'"); boolean validAttribute = statement.attribute(this, name, value); if (!validAttribute) { if (statement == Statement.TreeTask) { throw stackedTaskException(getCurrentTask(), "unknown attribute '" + name + "'"); } else { throw new GdxRuntimeException(statement.name + ": unknown attribute '" + name + "'"); } } }
private void setField (Field field, Task<E> task, Object value) { field.setAccessible(true); Object valueObject = castValue(field, value); try { field.set(task, valueObject); } catch (ReflectionException e) { throw new GdxRuntimeException(e); } }
@Override protected void startStatement (String name, boolean isSubtreeReference, boolean isGuard) { if (btParser.debugLevel > BehaviorTreeParser.DEBUG_LOW) GdxAI.getLogger().debug(TAG, (isGuard? " guard" : " task") + " name '" + name + "'"); this.isSubtreeRef = isSubtreeReference; this.statement = isSubtreeReference ? Statement.TreeTask : checkStatement(name); if (isGuard) { if (statement != Statement.TreeTask) throw new GdxRuntimeException(name + ": only tree's tasks can be guarded"); } statement.enter(this, name, isGuard); }
@Override protected <E> boolean attribute (DefaultBehaviorTreeReader<E> reader, String name, Object value) { if (!(value instanceof String)) reader.throwAttributeTypeException(this.name, name, "String"); reader.addImport(name, (String)value); return true; }
@Override protected <E> void exit (DefaultBehaviorTreeReader<E> reader) { if (!reader.isSubtreeRef) { reader.checkRequiredAttributes(reader.getCurrentTask()); reader.encounteredAttributes.clear(); } } };
private void popAndCheckMinChildren (int upToFloor) { // Check the minimum number of children in prevTask if (prevTask != null) checkMinChildren(prevTask); // Check the minimum number of children while popping up to the specified floor while (stack.size > upToFloor) { StackedTask<E> stackedTask = stack.pop(); checkMinChildren(stackedTask); } }
public BehaviorTreeParser (DistributionAdapters distributionAdapters, int debugLevel, DefaultBehaviorTreeReader<E> reader) { this.distributionAdapters = distributionAdapters; this.debugLevel = debugLevel; btReader = reader == null ? new DefaultBehaviorTreeReader<E>() : reader; btReader.setParser(this); }
@Override protected <E> void exit (DefaultBehaviorTreeReader<E> reader) { if (!reader.isSubtreeRef) { reader.checkRequiredAttributes(reader.getCurrentTask()); reader.encounteredAttributes.clear(); } } };
@Override protected <E> boolean attribute (DefaultBehaviorTreeReader<E> reader, String name, Object value) { if (!(value instanceof String)) reader.throwAttributeTypeException(this.name, name, "String"); reader.addImport(name, (String)value); return true; }