public Object interpretRecursive(Sprite sprite) { Object returnValue = 0d; switch (type) { case BRACKET: returnValue = rightChild.interpretRecursive(sprite); break; case NUMBER: returnValue = value; break; case OPERATOR: Operators operator = Operators.getOperatorByValue(value); returnValue = interpretOperator(operator, sprite); break; case FUNCTION: Functions function = Functions.getFunctionByValue(value); returnValue = interpretFunction(function, sprite); break; case SENSOR: returnValue = interpretSensor(sprite); break; case USER_VARIABLE: returnValue = interpretUserVariable(sprite); break; case USER_LIST: returnValue = interpretUserList(sprite); break; case STRING: returnValue = value; break; case COLLISION_FORMULA: try { returnValue = interpretCollision(value); } catch (Exception exception) { returnValue = 0d; Log.e(getClass().getSimpleName(), Log.getStackTraceString(exception)); } } return normalizeDegeneratedDoubleValues(returnValue); }
public int getRequiredResources() { int resources = Brick.NO_RESOURCES; if (leftChild != null) { resources |= leftChild.getRequiredResources(); } if (rightChild != null) { resources |= rightChild.getRequiredResources(); } if (type == ElementType.FUNCTION) { Functions functions = Functions.getFunctionByValue(value); switch (functions) { case ARDUINOANALOG: case ARDUINODIGITAL: resources |= Brick.BLUETOOTH_SENSORS_ARDUINO; break; case RASPIDIGITAL: resources |= Brick.SOCKET_RASPI; break; } } if (type == ElementType.SENSOR) { Sensors sensor = Sensors.getSensorByValue(value); switch (sensor) { case X_ACCELERATION: case Y_ACCELERATION: case Z_ACCELERATION: resources |= Brick.SENSOR_ACCELERATION; break; case X_INCLINATION: case Y_INCLINATION: resources |= Brick.SENSOR_INCLINATION; break; case COMPASS_DIRECTION: resources |= Brick.SENSOR_COMPASS; break; case LATITUDE: case LONGITUDE: case LOCATION_ACCURACY: case ALTITUDE: resources |= Brick.SENSOR_GPS; break; case FACE_DETECTED: case FACE_SIZE: case FACE_X_POSITION: case FACE_Y_POSITION: resources |= Brick.FACE_DETECTION; break; case NXT_SENSOR_1: case NXT_SENSOR_2: case NXT_SENSOR_3: case NXT_SENSOR_4: resources |= Brick.BLUETOOTH_LEGO_NXT; break; case PHIRO_FRONT_LEFT: case PHIRO_FRONT_RIGHT: case PHIRO_SIDE_LEFT: case PHIRO_SIDE_RIGHT: case PHIRO_BOTTOM_LEFT: case PHIRO_BOTTOM_RIGHT: resources |= Brick.BLUETOOTH_PHIRO; break; case DRONE_BATTERY_STATUS: case DRONE_CAMERA_READY: case DRONE_EMERGENCY_STATE: case DRONE_FLYING: case DRONE_INITIALIZED: case DRONE_NUM_FRAMES: case DRONE_RECORD_READY: case DRONE_RECORDING: case DRONE_USB_ACTIVE: case DRONE_USB_REMAINING_TIME: resources |= Brick.ARDRONE_SUPPORT; break; case NFC_TAG_ID: resources |= Brick.NFC_ADAPTER; break; default: } } if (type == ElementType.COLLISION_FORMULA) { resources |= Brick.COLLISION; } return resources; }