From d032840763fb396f85dcdf112da98a8238a58716 Mon Sep 17 00:00:00 2001 From: Tim Corbly Date: Thu, 17 Oct 2024 23:32:40 -0600 Subject: [PATCH] Update exports and add JBC 10 and 11 with a couple bugs --- src/simulator/ScriptManager.ts | 27 +-- src/simulator/babylonBindings/RobotBinding.ts | 53 +++--- .../challenges/jbc10-Chopped-New.ts | 79 +++++++++ .../challenges/jbc11-Making-Waves-New.ts | 147 +++++++++++++++++ .../challenges/jbc12-Add-It-Up-New.ts | 10 +- .../challenges/jbc14-Dance-Party.ts | 6 +- .../challenges/jbc17-Mountain-Rescue-New.ts | 14 +- .../challenges/jbc18-Stackerz-New.ts | 12 +- .../challenges/jbc24-Walk-the-Line-New.ts | 8 +- .../challenges/jbc4-Serpentine-New.ts | 10 +- .../challenges/jbc6-Figure-Eight-New.ts | 8 +- .../challenges/jbc7-Load-Em-Up-New.ts | 6 +- .../challenges/jbc8-Bulldozer-Mania-New.ts | 6 +- .../challenges/jbc9-Cover-Your-Bases-New.ts | 6 +- src/simulator/definitions/scenes/index.ts | 28 ++-- src/simulator/definitions/scenes/jbc0.ts | 6 + .../definitions/scenes/jbc10-Chopped-New.ts | 133 +++++++++++++++ .../scenes/jbc11-Making-Waves-New.ts | 156 ++++++++++++++++++ .../definitions/scenes/jbc12-Add-It-Up-New.ts | 108 +++++++++++- .../definitions/scenes/jbc14-Dance-Party.ts | 18 +- .../scenes/jbc17-Mountain-Rescue-New.ts | 6 +- .../definitions/scenes/jbc18-Stackerz-New.ts | 6 +- .../scenes/jbc24-Walk-the-Line-New.ts | 6 +- .../definitions/scenes/jbc4-Serpentine-New.ts | 10 +- .../scenes/jbc6-Figure-Eight-New.ts | 10 +- .../definitions/scenes/jbc7-Load-Em-Up-New.ts | 6 +- .../scenes/jbc8-Bulldozer-Mania-New.ts | 6 +- .../scenes/jbc9-Cover-Your-Bases-New.ts | 6 +- src/state/reducer/challenges.ts | 63 +++++-- src/state/reducer/scenes.ts | 11 +- 30 files changed, 813 insertions(+), 158 deletions(-) create mode 100644 src/simulator/definitions/challenges/jbc10-Chopped-New.ts create mode 100644 src/simulator/definitions/challenges/jbc11-Making-Waves-New.ts create mode 100644 src/simulator/definitions/scenes/jbc10-Chopped-New.ts create mode 100644 src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts diff --git a/src/simulator/ScriptManager.ts b/src/simulator/ScriptManager.ts index 95ec08f5..d01496e1 100644 --- a/src/simulator/ScriptManager.ts +++ b/src/simulator/ScriptManager.ts @@ -32,7 +32,7 @@ export interface ScriptSceneBinding { readonly geometry: Dict; addGeometry(geometry: Geometry, id?: string): string; removeGeometry(id: string): void; - + gravity: Vector3wUnits; camera: Camera; @@ -148,7 +148,7 @@ class ScriptManager { refCounts.set(filterId, 1); } } - + // eslint-disable-next-line @typescript-eslint/no-unsafe-call if (this[onChangedKey]) this[onChangedKey](listener.nodeId, new Set(refCounts.keys())); }; @@ -209,7 +209,7 @@ namespace ScriptManager { } export const collision = construct(Type.Collision); - + export interface IntersectionStart { type: Type.IntersectionStart; nodeId: string; @@ -256,7 +256,7 @@ namespace ScriptManager { } export const render = construct(Type.Render); - + export interface Collision { type: Type.Collision; nodeId: string; @@ -265,7 +265,7 @@ namespace ScriptManager { } export const collision = construct(Type.Collision); - + export interface Intersection { type: Type.Intersection; nodeId: string; @@ -330,7 +330,7 @@ namespace ScriptManager { constructor(script: Script, manager: ScriptManager) { this.script_ = script; this.manager_ = manager; - + this.spawnFunc_({ scene: this, RotationwUnits, @@ -342,6 +342,7 @@ namespace ScriptManager { Distance, Mass, Angle, + Date, }, this.script_.code); } @@ -415,7 +416,7 @@ namespace ScriptManager { if (this.onUnbind) this.onUnbind(nodeId); this.boundNodeIds_.delete(nodeId); } - + dispose() { // TODO: This code could be more efficient. We need to unregister the collision and intersection listeners // from the parent, but doing it as a single operation would be better. @@ -439,7 +440,7 @@ namespace ScriptManager { if (resolvedId in this.manager_.scene.nodes) { throw new Error(`Node with id ${resolvedId} already exists`); } - + onNodeAdd(resolvedId, node); return resolvedId; @@ -455,7 +456,7 @@ namespace ScriptManager { onNodeRemove(id); } - + setNode(id: string, node: Node): void { const { onNodeChange } = this.manager_; if (!onNodeChange) return; @@ -496,7 +497,7 @@ namespace ScriptManager { onGeometryRemove(id); } - + get gravity(): Vector3wUnits { return this.manager_.scene.gravity; } @@ -568,7 +569,7 @@ namespace ScriptManager { this.manager_.removeIntersectionRefCounts_(listener); break; } - + delete this.listeners_[handle]; } @@ -584,13 +585,13 @@ namespace ScriptManager { setChallengeEventValue(eventId: string, value: boolean) { if (!this.manager_.onChallengeSetEventValue) return; this.manager_.onChallengeSetEventValue(eventId, value); - this.getChallengeEventValue(eventId,value); + this.getChallengeEventValue(eventId, value); } getChallengeEventValue(eventId: string, value: boolean) { if (!this.manager_.onChallengeGetEventValue) return; return value; - this.getChallengeEventValue(eventId,value); + this.getChallengeEventValue(eventId, value); } } diff --git a/src/simulator/babylonBindings/RobotBinding.ts b/src/simulator/babylonBindings/RobotBinding.ts index fbdc365a..4e279731 100644 --- a/src/simulator/babylonBindings/RobotBinding.ts +++ b/src/simulator/babylonBindings/RobotBinding.ts @@ -1,7 +1,8 @@ -import { Scene as babylonScene, TransformNode, PhysicsViewer, Vector3, IPhysicsEnabledObject, - Mesh, PhysicsJoint, IPhysicsEnginePluginV2, PhysicsConstraintAxis, Physics6DoFConstraint, - PhysicsConstraintMotorType, PhysicsConstraintAxisLimitMode, +import { + Scene as babylonScene, TransformNode, PhysicsViewer, Vector3, IPhysicsEnabledObject, + Mesh, PhysicsJoint, IPhysicsEnginePluginV2, PhysicsConstraintAxis, Physics6DoFConstraint, + PhysicsConstraintMotorType, PhysicsConstraintAxisLimitMode, } from '@babylonjs/core'; import '@babylonjs/core/Physics/physicsEngineComponent'; @@ -101,7 +102,7 @@ class RobotBinding { private createSensor_ = >(s: { new(parameters: SensorParameters): S }) => (id: string, definition: T): S => { const parent = this.links_[definition.parentId]; - + return new s({ id, definition, @@ -138,7 +139,7 @@ class RobotBinding { private bParentChild_ = (id: string, parentId: string): { bParent: Mesh; bChild: Mesh; childId: string; } => { if (!parentId) throw new Error(`Missing parent: "${parentId}" for node "${id}"`); - + const children = this.childrenNodeIds_[id]; if (children.length !== 1) throw new Error(`"${id}" must have exactly one child`); @@ -184,7 +185,7 @@ class RobotBinding { const maxForce = 50000; bMotor.setAxisFriction(PhysicsConstraintAxis.ANGULAR_Z, 0); - bMotor.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, maxForce); + bMotor.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, maxForce); bMotor.setAxisMode(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintAxisLimitMode.FREE); bMotor.setAxisMotorTarget(PhysicsConstraintAxis.ANGULAR_Z, velocity); @@ -227,7 +228,7 @@ class RobotBinding { */ for (let port = 0; port < 4; ++port) { const motorId = this.motorPorts_[port]; - + // If no motor is bound to the port, skip it. if (!motorId) continue; @@ -286,9 +287,9 @@ class RobotBinding { // If the motor is in pwm mode and the direction is idle, set the motor target to 0. if (mode === Motor.Mode.Pwm && (direction === Motor.Direction.Idle || direction === Motor.Direction.Brake)) { this.setMotorVelocity_(bMotor, 0); - if (Math.abs(velocity) < 10) { - bMotor.setAxisMode(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintAxisLimitMode.LOCKED); - } + // if (Math.abs(velocity) < 10) { + // bMotor.setAxisMode(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintAxisLimitMode.LOCKED); + // } continue; } @@ -319,11 +320,11 @@ class RobotBinding { // this.brakeAt_[port] = undefined; // } - + let pwm_adj = 0; // If the motor is not in pwm mode, and we are not done, calculate the pwm value. if (mode !== Motor.Mode.Pwm && !done) { - + // This code is taken from Wombat-Firmware for parity. const pErr = speedGoal - velocity; const dErr = pErr - this.lastPErrs_[port]; @@ -353,7 +354,7 @@ class RobotBinding { pwm = plug * clamp(-400, pwm, 400); if (writePwm) writeCommands.push(WriteCommand.motorPwm({ port, pwm })); - + const normalizedPwm = pwm / 400; const nextAngularVelocity = normalizedPwm * velocityMax * 2 * Math.PI / ticksPerRevolution; // console.log("nextAngularVelocity", nextAngularVelocity); @@ -400,7 +401,7 @@ class RobotBinding { } } - const currentAngle = this.hingeAngle_(servoId, servo.parentId); + const currentAngle = this.hingeAngle_(servoId, servo.parentId); const targetAangle = this.lastServoEnabledAngle_[i]; let cur_angle = 0; @@ -413,7 +414,7 @@ class RobotBinding { if (cur_angle.toFixed(5) !== targetAangle.toFixed(5)) { if (cur_angle < targetAangle) { - bServo.setAxisMaxLimit(PhysicsConstraintAxis.ANGULAR_Z, targetAangle); + bServo.setAxisMaxLimit(PhysicsConstraintAxis.ANGULAR_Z, targetAangle); bServo.setAxisMotorTarget(PhysicsConstraintAxis.ANGULAR_Z, Math.PI * .4); } if (cur_angle > targetAangle) { @@ -559,10 +560,10 @@ class RobotBinding { weight.physicsBody.setAngularVelocity(Vector3.Zero()); weight.physicsBody.setLinearVelocity(Vector3.Zero()); } - + rootTransformNode.position = RawVector3.toBabylon(rawOrigin.position || RawVector3.ZERO) .add(RawVector3.toBabylon(rawInternalOrigin.position || RawVector3.ZERO)); - + rootTransformNode.rotationQuaternion = RawQuaternion.toBabylon(RawEuler.toQuaternion(UpdatedEulerOrigin)); for (const link of Object.values(this.links_)) { @@ -618,7 +619,7 @@ class RobotBinding { if (node.type !== Node.Type.Link) continue; const bNode = await createLink(nodeId, node, this.bScene_, this.robot_, this.colliders_); - if (this.physicsViewer_ && bNode.physicsBody) this.physicsViewer_.showBody(bNode.physicsBody); + if (this.physicsViewer_ && bNode.physicsBody) this.physicsViewer_.showBody(bNode.physicsBody); bNode.metadata = { id: this.robotSceneId_, selected: false } as SceneMeshMetadata; this.links_[nodeId] = bNode; @@ -628,7 +629,7 @@ class RobotBinding { for (const nodeId of nodeIds) { const node = robot.nodes[nodeId]; if (node.type === Node.Type.Link || node.type === Node.Type.IRobotCreate) continue; - + switch (node.type) { case Node.Type.Weight: { const bNode = createWeight(nodeId, node, this.bScene_, this.robot_, this.links_); @@ -639,7 +640,7 @@ class RobotBinding { const { bParent, bChild } = this.bParentChild_(nodeId, node.parentId); const bJoint = createHinge(nodeId, node, this.bScene_, bParent, bChild); - bJoint.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, 1000000000); + bJoint.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, 1000000000); bJoint.setAxisMotorType(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintMotorType.VELOCITY); // Start motor in locked position so the wheels don't slide bJoint.setAxisMode(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintAxisLimitMode.LOCKED); @@ -657,10 +658,10 @@ class RobotBinding { // -90 is upright and closed; 0 is forward and open const { bParent, bChild } = this.bParentChild_(nodeId, node.parentId); const bJoint = createHinge(nodeId, node, this.bScene_, bParent, bChild); - bJoint.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, 10000000); - bJoint.setAxisMotorType(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintMotorType.VELOCITY); + bJoint.setAxisMotorMaxForce(PhysicsConstraintAxis.ANGULAR_Z, 10000000); + bJoint.setAxisMotorType(PhysicsConstraintAxis.ANGULAR_Z, PhysicsConstraintMotorType.VELOCITY); // Start the servos at 0 - bJoint.setAxisMaxLimit(PhysicsConstraintAxis.ANGULAR_Z, Angle.toRadiansValue(Angle.degrees(0))); + bJoint.setAxisMaxLimit(PhysicsConstraintAxis.ANGULAR_Z, Angle.toRadiansValue(Angle.degrees(0))); bJoint.setAxisMinLimit(PhysicsConstraintAxis.ANGULAR_Z, Angle.toRadiansValue(Angle.degrees(-1))); this.servos_[nodeId] = bJoint; @@ -715,9 +716,9 @@ class RobotBinding { const node = robot.nodes[nodeId]; if (node.type !== Node.Type.IRobotCreate) continue; this.createBinding_ = new CreateBinding( - workerInstance.createSerial, - this.createMotors_, - this.createAnalogSensors_, + workerInstance.createSerial, + this.createMotors_, + this.createAnalogSensors_, this.createDigitalSensors_ ); } diff --git a/src/simulator/definitions/challenges/jbc10-Chopped-New.ts b/src/simulator/definitions/challenges/jbc10-Chopped-New.ts new file mode 100644 index 00000000..f55c9163 --- /dev/null +++ b/src/simulator/definitions/challenges/jbc10-Chopped-New.ts @@ -0,0 +1,79 @@ +import Author from "../../../db/Author"; +import Challenge from "../../../state/State/Challenge"; +import Expr from "../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../util/LocalizedString"; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: "JBC Challenge 10" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 10: Chopped`, + }, + author: { + type: Author.Type.Organization, + id: "kipr", + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: "c", + events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, + }, + waitedToChop: { + name: { [LocalizedString.EN_US]: "Waited to Chop" }, + description: { [LocalizedString.EN_US]: "Robot waited to chop" }, + }, + can7Upright: { + name: { [LocalizedString.EN_US]: "Can 7 Upright" }, + description: { [LocalizedString.EN_US]: "Can 7 upright" }, + }, + }, + success: { + exprs: { + // Start Box Events + notInStartBox: { + type: Expr.Type.Event, + eventId: "notInStartBox", + }, + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", + }, + + //Chop Events + waitedToChop: { + type: Expr.Type.Event, + eventId: "waitedToChop", + }, + can7Upright: { + type: Expr.Type.Event, + eventId: "can7Upright", + }, + can7NotUpright: { + type: Expr.Type.Not, + argId: "can7Upright", + }, + + // Success Logic = Can 7 not upright, waited to chop, and began in start box + completion: { + type: Expr.Type.And, + argIds: [ + "inStartBoxOnce", + "waitedToChop", + "can7NotUpright", + ], + }, + }, + rootId: "completion", + }, + sceneId: "jbc10", +} as Challenge; diff --git a/src/simulator/definitions/challenges/jbc11-Making-Waves-New.ts b/src/simulator/definitions/challenges/jbc11-Making-Waves-New.ts new file mode 100644 index 00000000..db6c2b32 --- /dev/null +++ b/src/simulator/definitions/challenges/jbc11-Making-Waves-New.ts @@ -0,0 +1,147 @@ +import Author from "../../../db/Author"; +import Challenge from "../../../state/State/Challenge"; +import Expr from "../../../state/State/Challenge/Expr"; +import LocalizedString from "../../../util/LocalizedString"; +import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; + +export default { + name: { [LocalizedString.EN_US]: "JBC Challenge 11" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 11: Making Waves`, + }, + author: { + type: Author.Type.Organization, + id: "kipr", + }, + code: { + 'c': ProgrammingLanguage.DEFAULT_CODE.c, + 'cpp': ProgrammingLanguage.DEFAULT_CODE.cpp, + 'python': ProgrammingLanguage.DEFAULT_CODE.python, + }, + defaultLanguage: "c", + events: { + notInStartBox: { + name: { [LocalizedString.EN_US]: "Robot not in Start Box" }, + description: { [LocalizedString.EN_US]: "Robot not in start box" }, + }, + wave: { + name: { [LocalizedString.EN_US]: "Robot Waved" }, + description: { [LocalizedString.EN_US]: "Robot waved" }, + }, + circle3Touched: { + name: { [LocalizedString.EN_US]: "Circle 3 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 3 touched" }, + }, + circle6Touched: { + name: { [LocalizedString.EN_US]: "Circle 6 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 6 touched" }, + }, + circle9Touched: { + name: { [LocalizedString.EN_US]: "Circle 9 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 9 touched" }, + }, + circle12Touched: { + name: { [LocalizedString.EN_US]: "Circle 12 Touched" }, + description: { [LocalizedString.EN_US]: "Circle 12 touched" }, + }, + }, + success: { + exprs: { + // Start Box Events + notInStartBox: { + type: Expr.Type.Event, + eventId: "notInStartBox", + }, + inStartBox: { + type: Expr.Type.Not, + argId: "notInStartBox", + }, + inStartBoxOnce: { + type: Expr.Type.Once, + argId: "inStartBox", + }, + + //Wave Events + wave: { + type: Expr.Type.Event, + eventId: "wave", + }, + + //Circle Events + circle3Touched: { + type: Expr.Type.Event, + eventId: "circle3Touched", + }, + circle3Waved: { + type: Expr.Type.And, + argIds: [ + "circle3Touched", + "wave", + ], + }, + circle3WavedOnce: { + type: Expr.Type.Once, + argId: "circle3Waved", + }, + circle6Touched: { + type: Expr.Type.Event, + eventId: "circle6Touched", + }, + circle6Waved: { + type: Expr.Type.And, + argIds: [ + "circle6Touched", + "wave", + ], + }, + circle6WavedOnce: { + type: Expr.Type.Once, + argId: "circle6Waved", + }, + circle9Touched: { + type: Expr.Type.Event, + eventId: "circle9Touched", + }, + circle9Waved: { + type: Expr.Type.And, + argIds: [ + "circle9Touched", + "wave", + ], + }, + circle9WavedOnce: { + type: Expr.Type.Once, + argId: "circle9Waved", + }, + circle12Touched: { + type: Expr.Type.Event, + eventId: "circle12Touched", + }, + circle12Waved: { + type: Expr.Type.And, + argIds: [ + "circle12Touched", + "wave", + ], + }, + circle12WavedOnce: { + type: Expr.Type.Once, + argId: "circle12Waved", + }, + + // Success Logic = All circles waved at least once and began in start box + completion: { + type: Expr.Type.And, + argIds: [ + "inStartBoxOnce", + "circle3WavedOnce", + "circle6WavedOnce", + "circle9WavedOnce", + "circle12WavedOnce", + ], + }, + }, + rootId: "completion", + }, + sceneId: "jbc11", +} as Challenge; diff --git a/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts b/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts index 728a4c7a..5f3d25fc 100644 --- a/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts +++ b/src/simulator/definitions/challenges/jbc12-Add-It-Up-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 5' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 12' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 5: Add It Up', + [LocalizedString.EN_US]: 'Junior Botball Challenge 12: Add It Up', }, author: { type: Author.Type.Organization, @@ -135,11 +135,11 @@ export default { type: Expr.Type.Once, argId: 'passed8', }, - + passedSerpentine: { type: Expr.Type.And, - argIds: ["passed1Once", "passed2Once","passed3Once", "passed4Once", "passed5Once", "passed6Once", "passed7Once", "passed8Once"], + argIds: ["passed1Once", "passed2Once", "passed3Once", "passed4Once", "passed5Once", "passed6Once", "passed7Once", "passed8Once"], }, // Success logic @@ -150,5 +150,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc8', + sceneId: 'jbc12', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc14-Dance-Party.ts b/src/simulator/definitions/challenges/jbc14-Dance-Party.ts index 4e2a1123..ec611dd4 100644 --- a/src/simulator/definitions/challenges/jbc14-Dance-Party.ts +++ b/src/simulator/definitions/challenges/jbc14-Dance-Party.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 5' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 14' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 5: Dance Party`, + [LocalizedString.EN_US]: `Junior Botball Challenge 14: Dance Party`, }, author: { type: Author.Type.Organization, @@ -129,5 +129,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc5', + sceneId: 'jbc14', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts b/src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts index 5f203b61..16efbef9 100644 --- a/src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts +++ b/src/simulator/definitions/challenges/jbc17-Mountain-Rescue-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 19' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 17' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 19: Mountain Rescue`, + [LocalizedString.EN_US]: `Junior Botball Challenge 17: Mountain Rescue`, }, author: { type: Author.Type.Organization, @@ -114,24 +114,24 @@ export default { // Intersecting and Upright IntersectingUpright1: { type: Expr.Type.And, - argIds: ['can1UprightOnce','can1IntersectsOnce'], + argIds: ['can1UprightOnce', 'can1IntersectsOnce'], }, IntersectingUpright2: { type: Expr.Type.And, - argIds: ['can2UprightOnce','can2IntersectsOnce'], + argIds: ['can2UprightOnce', 'can2IntersectsOnce'], }, IntersectingUpright3: { type: Expr.Type.And, - argIds: ['can3UprightOnce','can3IntersectsOnce'], + argIds: ['can3UprightOnce', 'can3IntersectsOnce'], }, completion: { type: Expr.Type.And, - argIds: ['IntersectingUpright1','IntersectingUpright2','IntersectingUpright3'], + argIds: ['IntersectingUpright1', 'IntersectingUpright2', 'IntersectingUpright3'], }, }, rootId: 'completion', }, - sceneId: 'jbc19', + sceneId: 'jbc17', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc18-Stackerz-New.ts b/src/simulator/definitions/challenges/jbc18-Stackerz-New.ts index 09230b55..c6e4dfe0 100644 --- a/src/simulator/definitions/challenges/jbc18-Stackerz-New.ts +++ b/src/simulator/definitions/challenges/jbc18-Stackerz-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 22' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 18' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 22: Stackerz`, + [LocalizedString.EN_US]: `Junior Botball Challenge 18: Stackerz`, }, author: { type: Author.Type.Organization, @@ -21,7 +21,7 @@ export default { defaultLanguage: 'c', events: { - + leaveStartBox: { name: { [LocalizedString.EN_US]: 'Robot Left Start' }, description: { [LocalizedString.EN_US]: 'Robot left starting box' }, @@ -31,7 +31,7 @@ export default { name: { [LocalizedString.EN_US]: 'One Can Stacked' }, description: { [LocalizedString.EN_US]: 'One can is stacked on another' }, }, - + robotTouchCan: { name: { [LocalizedString.EN_US]: 'Robot Touching Can' }, description: { [LocalizedString.EN_US]: 'Robot is touching a can' }, @@ -66,7 +66,7 @@ export default { argId: 'robotTouchCan', }, - + completion: { type: Expr.Type.And, argIds: ['leaveStartBoxOnce', 'canStacked', 'robotTouchCanNot'], @@ -74,5 +74,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc22', + sceneId: 'jbc18', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts b/src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts index 648c2220..85f7e80a 100644 --- a/src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts +++ b/src/simulator/definitions/challenges/jbc24-Walk-the-Line-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 17' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 24' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 17: Walk the Line`, + [LocalizedString.EN_US]: `Junior Botball Challenge 24: Walk the Line`, }, author: { type: Author.Type.Organization, @@ -35,7 +35,7 @@ export default { type: Expr.Type.Event, eventId: 'lineFollow', }, - + completion: { type: Expr.Type.And, @@ -46,5 +46,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc17', + sceneId: 'jbc24', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc4-Serpentine-New.ts b/src/simulator/definitions/challenges/jbc4-Serpentine-New.ts index 27346a77..fc187aec 100644 --- a/src/simulator/definitions/challenges/jbc4-Serpentine-New.ts +++ b/src/simulator/definitions/challenges/jbc4-Serpentine-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 8' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 4' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 8: Serpentine', + [LocalizedString.EN_US]: 'Junior Botball Challenge 4: Serpentine', }, author: { type: Author.Type.Organization, @@ -135,11 +135,11 @@ export default { type: Expr.Type.Once, argId: 'passed8', }, - + passedSerpentine: { type: Expr.Type.And, - argIds: ["passed1Once", "passed2Once","passed3Once", "passed4Once", "passed5Once", "passed6Once", "passed7Once", "passed8Once"], + argIds: ["passed1Once", "passed2Once", "passed3Once", "passed4Once", "passed5Once", "passed6Once", "passed7Once", "passed8Once"], }, // Success logic @@ -150,5 +150,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc8', + sceneId: 'jbc4', } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts b/src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts index b39ec0ad..e4dcaa56 100644 --- a/src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts +++ b/src/simulator/definitions/challenges/jbc6-Figure-Eight-New.ts @@ -5,9 +5,9 @@ import LocalizedString from "../../../util/LocalizedString"; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: "JBC Challenge 4" }, + name: { [LocalizedString.EN_US]: "JBC Challenge 6" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 4: Figure Eight`, + [LocalizedString.EN_US]: `Junior Botball Challenge 6: Figure Eight`, }, author: { type: Author.Type.Organization, @@ -122,10 +122,10 @@ export default { // Success Logic = Can A upright, intersects and touched completion: { type: Expr.Type.And, - argIds: ["IntersectsUpright4", "IntersectsUpright9", "startingBox","figureEightOnce"], + argIds: ["IntersectsUpright4", "IntersectsUpright9", "startingBox", "figureEightOnce"], }, }, rootId: "completion", }, - sceneId: "jbc4", + sceneId: "jbc6", } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts b/src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts index 935907aa..94d0a953 100644 --- a/src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts +++ b/src/simulator/definitions/challenges/jbc7-Load-Em-Up-New.ts @@ -5,9 +5,9 @@ import LocalizedString from "../../../util/LocalizedString"; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: "JBC Challenge 6" }, + name: { [LocalizedString.EN_US]: "JBC Challenge 7" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 6: Load 'Em Up`, + [LocalizedString.EN_US]: `Junior Botball Challenge 7: Load 'Em Up`, }, author: { type: Author.Type.Organization, @@ -94,5 +94,5 @@ export default { }, rootId: "completion", }, - sceneId: "jbc6", + sceneId: "jbc7", } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts b/src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts index cf79b231..3bcf1d61 100644 --- a/src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts +++ b/src/simulator/definitions/challenges/jbc8-Bulldozer-Mania-New.ts @@ -5,9 +5,9 @@ import LocalizedString from "../../../util/LocalizedString"; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: "JBC Challenge 7" }, + name: { [LocalizedString.EN_US]: "JBC Challenge 8" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 7: Bulldozer Mania`, + [LocalizedString.EN_US]: `Junior Botball Challenge 8: Bulldozer Mania`, }, author: { type: Author.Type.Organization, @@ -143,5 +143,5 @@ export default { }, rootId: "completion", }, - sceneId: "jbc7", + sceneId: "jbc8", } as Challenge; diff --git a/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts b/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts index ee145b12..891c61cb 100644 --- a/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts +++ b/src/simulator/definitions/challenges/jbc9-Cover-Your-Bases-New.ts @@ -5,9 +5,9 @@ import LocalizedString from '../../../util/LocalizedString'; import ProgrammingLanguage from "../../../programming/compiler/ProgrammingLanguage"; export default { - name: { [LocalizedString.EN_US]: 'JBC Challenge 7B' }, + name: { [LocalizedString.EN_US]: 'JBC Challenge 9' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 7B: Cover Your Bases`, + [LocalizedString.EN_US]: `Junior Botball Challenge 9: Cover Your Bases`, }, author: { type: Author.Type.Organization, @@ -198,5 +198,5 @@ export default { }, rootId: 'completion', }, - sceneId: 'jbc7b', + sceneId: 'jbc9', } as Challenge; diff --git a/src/simulator/definitions/scenes/index.ts b/src/simulator/definitions/scenes/index.ts index 62295fa6..6c3af999 100644 --- a/src/simulator/definitions/scenes/index.ts +++ b/src/simulator/definitions/scenes/index.ts @@ -3,38 +3,42 @@ export * from './jbcSandboxB'; export * from './jbc0'; export * from './jbc1'; export * from './jbc2'; +export * from './jbc3-Precision-Parking-New'; +export * from './jbc4-Serpentine-New'; +export * from './jbc5'; +export * from './jbc6-Figure-Eight-New'; +export * from './jbc7-Load-Em-Up-New'; +export * from './jbc8-Bulldozer-Mania-New'; +export * from './jbc9-Cover-Your-Bases-New'; +export * from './jbc10-Chopped-New'; +export * from './jbc11-Making-Waves-New'; +export * from './jbc12-Add-It-Up-New'; +export * from './jbc14-Dance-Party'; +export * from './jbc17-Mountain-Rescue-New'; +export * from './jbc18-Stackerz-New'; +export * from './jbc24-Walk-the-Line-New'; +export * from './moonSandbox'; // export * from './jbc2b-Ring-Around-the-Cans-Sr'; // export * from './jbc2c-Back-It-Up'; // export * from './jbc2d-Ring-Around-the-Can-and-Back-It-Up'; -export * from './jbc3-Precision-Parking-New'; // export * from './jbc3b-Parallel-Parking'; // export * from './jbc3c-Quick-Get-Away'; -export * from './jbc5'; -export * from './jbc6-Figure-Eight-New'; // export * from './jbc4b-Barrel-Racing'; // export * from './jbc14-Dance-Party'; // export * from './jbc5b-Line-Dance'; // export * from './jbc5c-Synchronized-Dancing'; -export * from './jbc7-Load-Em-Up-New'; // export * from './jbc6b-Pick-Em-Up'; // export * from './jbc6c-Empty-the-Garage'; -export * from './jbc8-Bulldozer-Mania-New'; // export * from './jbc7b-Cover-Your-Bases'; -export * from './jbc4-Serpentine-New'; // export * from './jbc8b-Serpentine-Jr'; -export * from './jbc12-Add-It-Up-New'; // export * from './jbc9b-Balancing-Act'; // export * from './jbc10-Solo-Joust'; // export * from './jbc10b-Solo-Joust-Jr'; // export * from './jbc12-Unload-Em'; // export * from './jbc13-Clean-the-Mat'; // export * from './jbc15b-Bump-Bump'; -export * from './jbc24-Walk-the-Line-New'; // export * from './jbc17b-Walk-the-Line-2'; -export * from './jbc17-Mountain-Rescue-New'; // export * from './jbc20-Rescue-the-Cans'; // export * from './jbc21-Foot-Tall'; -export * from './jbc18-Stackerz-New'; // export * from './scriptPlayground'; -// export * from './lightSensorTest'; -export * from './moonSandbox'; \ No newline at end of file +// export * from './lightSensorTest'; \ No newline at end of file diff --git a/src/simulator/definitions/scenes/jbc0.ts b/src/simulator/definitions/scenes/jbc0.ts index 5e56246f..31ebeda3 100644 --- a/src/simulator/definitions/scenes/jbc0.ts +++ b/src/simulator/definitions/scenes/jbc0.ts @@ -5,6 +5,8 @@ import LocalizedString from '../../../util/LocalizedString'; import Script from '../../../state/State/Scene/Script'; import { createBaseSceneSurfaceB, createCanNode } from './jbcBase'; import { Color } from '../../../state/State/Scene/Color'; +import Robot from 'state/State/Robot'; +import Node from 'state/State/Scene/Node'; const baseScene = createBaseSceneSurfaceB(); @@ -96,6 +98,10 @@ const ROBOT_ORIGIN: ReferenceFramewUnits = { }, }; +const robotNode: Node.Robot = baseScene.nodes['robot'] as Node.Robot; + + + export const JBC_0: Scene = { ...baseScene, name: { [LocalizedString.EN_US]: 'JBC 0' }, diff --git a/src/simulator/definitions/scenes/jbc10-Chopped-New.ts b/src/simulator/definitions/scenes/jbc10-Chopped-New.ts new file mode 100644 index 00000000..0f12f285 --- /dev/null +++ b/src/simulator/definitions/scenes/jbc10-Chopped-New.ts @@ -0,0 +1,133 @@ +import Scene from "../../../state/State/Scene"; +import LocalizedString from "../../../util/LocalizedString"; +import { createBaseSceneSurfaceA, createCanNode } from "./jbcBase"; +import { Color } from "../../../state/State/Scene/Color"; +import { Distance } from "../../../util"; +import Script from "../../../state/State/Scene/Script"; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const waitToChop = ` +// Need to wait 5 seconds before the can can be chopped +let currentDate; +let stopTime = 0; +scene.addOnRenderListener(() => { + const robotNode = scene.nodes['robot']; + if (robotNode.state.getMotor(0).speedGoal <= 15 && robotNode.state.getMotor(3).speedGoal <= 15) { + if (stopTime == 0) { + currentDate = new Date(); + stopTime = currentDate.getTime(); + console.log('Waiting at ', stopTime); + } + else { + currentDate = new Date(); + if (currentDate.getTime() - stopTime > 5000) { + scene.setChallengeEventValue('waitedToChop', true); + console.log("Waited 5 seconds"); + } + } + } + else { + stopTime = 0; + } +}); +`; + +const uprightCan = ` +// When a can is standing upright, the upright condition is met. + +const EULER_IDENTITY = RotationwUnits.EulerwUnits.identity(); +const yAngle = (nodeId) => 180 / Math.PI * Math.acos(Vector3wUnits.dot(Vector3wUnits.applyQuaternion(Vector3wUnits.Y, RotationwUnits.toRawQuaternion(scene.nodes[nodeId].origin.orientation || EULER_IDENTITY)), Vector3wUnits.Y)); + + +scene.addOnRenderListener(() => { + const upright7 = yAngle('can7') > 5; + scene.setChallengeEventValue('can7Upright', upright7); +}); +`; + +export const JBC_10: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: "JBC 10" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 10: Chopped`, + }, + scripts: { + inStartBox: Script.ecmaScript("In Start Box", notInStartBox), + waitToChop: Script.ecmaScript("Wait to Chop", waitToChop), + uprightCan: Script.ecmaScript("Upright Can", uprightCan), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + }, + nodes: { + ...baseScene.nodes, + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + can7: createCanNode(7), + }, +}; + diff --git a/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts b/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts new file mode 100644 index 00000000..0620806a --- /dev/null +++ b/src/simulator/definitions/scenes/jbc11-Making-Waves-New.ts @@ -0,0 +1,156 @@ +import Scene from "../../../state/State/Scene"; +import LocalizedString from "../../../util/LocalizedString"; +import { createBaseSceneSurfaceA, createCanNode, createCircleNode } from "./jbcBase"; +import { Color } from "../../../state/State/Scene/Color"; +import { Distance } from "../../../util"; +import Script from "../../../state/State/Scene/Script"; +import Node from "state/State/Scene/Node"; + +const baseScene = createBaseSceneSurfaceA(); + +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +const wave = ` + // Check if robot waves + let waveStart = -1; + let waveMax = 0; + + scene.addOnRenderListener(() => { + const robotNode = scene.nodes['robot']; + + if (scene.programStatus === 'running') { + if (robotNode.state.getMotor(0).speedGoal == 0 && robotNode.state.getMotor(3).speedGoal == 0) { + console.log('Robot stopped, motors at: ', robotNode.state.getMotor(0).speedGoal, ' ', robotNode.state.getMotor(3).speedGoal); + if (waveStart == -1) { + waveStart = robotNode.state.getServo(0).position; + console.log('Wave start at ', waveStart); + } + else { + console.log('Wave diff at ', Math.abs(robotNode.state.getServo(0).position - waveStart)); + if (Math.abs(robotNode.state.getServo(0).position - waveStart) >= waveMax) { + waveMax = Math.abs(robotNode.state.getServo(0).position - waveStart); + console.log('Wave max at ', waveMax, 'Wave start at ', waveStart); + } + else { + if (waveMax != 0) { + scene.setChallengeEventValue('wave', true); + console.log('Robot waved!'); + } + } + } + } + else { + console.log('Robot moving, motors at: ', robotNode.state.getMotor(0).pwm, ' ', robotNode.state.getMotor(3).pwm); + waveStart =-1; + waveMax = 0; + scene.setChallengeEventValue('wave', false); + } + } + else { + waveStart =-1; + waveMax = 0; + } + }); +`; + +const circleIntersects = ` +const setNodeVisible = (nodeId, visible) => scene.setNode(nodeId, { + ...scene.nodes[nodeId], + visible +}); + +let circles = new Set(['circle3', 'circle6', 'circle9', 'circle12']); + +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot intersects!', type, otherNodeId); + scene.setChallengeEventValue(otherNodeId + 'Touched', true); + setNodeVisible(otherNodeId, true); +}, ...circles); +`; + +export const JBC_11: Scene = { + ...baseScene, + name: { [LocalizedString.EN_US]: "JBC 11" }, + description: { + [LocalizedString.EN_US]: `Junior Botball Challenge 11: Making Waves`, + }, + scripts: { + inStartBox: Script.ecmaScript("In Start Box", notInStartBox), + waitToChop: Script.ecmaScript("Wave", wave), + circleIntersects: Script.ecmaScript("Circle Intersects", circleIntersects), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + }, + nodes: { + ...baseScene.nodes, + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + circle3: createCircleNode(3, undefined, false, false), + circle6: createCircleNode(6, undefined, false, false), + circle9: createCircleNode(9, undefined, false, false), + circle12: createCircleNode(12, undefined, false, false), + }, +}; + diff --git a/src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts b/src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts index de5b748d..daf116f3 100644 --- a/src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts +++ b/src/simulator/definitions/scenes/jbc12-Add-It-Up-New.ts @@ -1,14 +1,110 @@ import Scene from "../../../state/State/Scene"; -import LocalizedString from '../../../util/LocalizedString'; - -import { createBaseSceneSurfaceA } from './jbcBase'; +import LocalizedString from "../../../util/LocalizedString"; +import { createBaseSceneSurfaceA, createCanNode, createCircleNode } from "./jbcBase"; +import { Color } from "../../../state/State/Scene/Color"; +import { Distance } from "../../../util"; +import Script from "../../../state/State/Scene/Script"; +import Node from "state/State/Scene/Node"; import tr from '@i18n'; const baseScene = createBaseSceneSurfaceA(); -export const JBC_9: Scene = { +const notInStartBox = ` +scene.addOnIntersectionListener('robot', (type, otherNodeId) => { + console.log('Robot not started in start box!', type, otherNodeId); + if(scene.programStatus === 'running'){ + scene.setChallengeEventValue('notInStartBox', type === 'start'); + } +}, 'notStartBox'); +`; + +// const addItUp = { +// scene.addOnIntersectionListener('robot', (type, otherNodeId) => { +// } + + + + +export const JBC_12: Scene = { ...baseScene, - name: tr('JBC 9'), - description: tr('Junior Botball Challenge 9: Add It Up'), + name: tr('JBC 12'), + description: tr('Junior Botball Challenge 12: Add It Up'), + scripts: { + inStartBox: Script.ecmaScript("In Start Box", notInStartBox), + }, + geometry: { + ...baseScene.geometry, + mainSurface_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(0.1), + z: Distance.meters(3.54), + }, + }, + notStartBox_geom: { + type: "box", + size: { + x: Distance.meters(3.54), + y: Distance.centimeters(10), + z: Distance.meters(2.13), + }, + }, + }, + nodes: { + ...baseScene.nodes, + mainSurface: { + type: "object", + geometryId: "mainSurface_geom", + name: { [LocalizedString.EN_US]: "Mat Surface" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-6.9), + z: Distance.inches(19.75), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(0, 0, 0), + }, + }, + }, + notStartBox: { + type: "object", + geometryId: "notStartBox_geom", + name: { [LocalizedString.EN_US]: "Not Start Box" }, + visible: false, + origin: { + position: { + x: Distance.centimeters(0), + y: Distance.centimeters(-1.9), + z: Distance.meters(1.208), + }, + }, + material: { + type: "basic", + color: { + type: "color3", + color: Color.rgb(255, 0, 0), + }, + }, + }, + circle1: createCircleNode(1, undefined, false, false), + circle2: createCircleNode(2, undefined, false, false), + circle3: createCircleNode(3, undefined, false, false), + circle4: createCircleNode(4, undefined, false, false), + circle5: createCircleNode(5, undefined, false, false), + circle6: createCircleNode(6, undefined, false, false), + circle7: createCircleNode(7, undefined, false, false), + circle8: createCircleNode(8, undefined, false, false), + circle9: createCircleNode(9, undefined, false, false), + circle10: createCircleNode(10, undefined, false, false), + circle11: createCircleNode(11, undefined, false, false), + circle12: createCircleNode(12, undefined, false, false), + }, }; \ No newline at end of file diff --git a/src/simulator/definitions/scenes/jbc14-Dance-Party.ts b/src/simulator/definitions/scenes/jbc14-Dance-Party.ts index 7126dbe9..b6461e3b 100644 --- a/src/simulator/definitions/scenes/jbc14-Dance-Party.ts +++ b/src/simulator/definitions/scenes/jbc14-Dance-Party.ts @@ -1,9 +1,9 @@ -import Scene from '../../../../state/State/Scene'; -import LocalizedString from '../../../../util/LocalizedString'; -import Script from '../../../../state/State/Scene/Script'; -import { createCanNode, createBaseSceneSurfaceA } from '../jbcBase'; -import { Color } from '../../../../state/State/Scene/Color'; -import { Distance } from '../../../../util'; +import Scene from '../../../state/State/Scene'; +import LocalizedString from '../../../util/LocalizedString'; +import Script from '../../../state/State/Scene/Script'; +import { createCanNode, createBaseSceneSurfaceA } from './jbcBase'; +import { Color } from '../../../state/State/Scene/Color'; +import { Distance } from '../../../util'; const baseScene = createBaseSceneSurfaceA(); @@ -51,11 +51,11 @@ scene.addOnRenderListener(() => { `; -export const JBC_5: Scene = { +export const JBC_14: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 5' }, + name: { [LocalizedString.EN_US]: 'JBC 14' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 5: Dance Party', + [LocalizedString.EN_US]: 'Junior Botball Challenge 14: Dance Party', }, scripts: { goingBackwards: Script.ecmaScript('Going Backwards', goingBackwards), diff --git a/src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts b/src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts index b91a078a..b3a1f0df 100644 --- a/src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts +++ b/src/simulator/definitions/scenes/jbc17-Mountain-Rescue-New.ts @@ -54,11 +54,11 @@ const REAM_ORIGIN: ReferenceFramewUnits = { }), }; -export const JBC_19: Scene = { +export const JBC_17: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 19' }, + name: { [LocalizedString.EN_US]: 'JBC 17' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 19: Mountain Rescue`, + [LocalizedString.EN_US]: `Junior Botball Challenge 17: Mountain Rescue`, }, scripts: { uprightCans: Script.ecmaScript('Upright Cans', uprightCans), diff --git a/src/simulator/definitions/scenes/jbc18-Stackerz-New.ts b/src/simulator/definitions/scenes/jbc18-Stackerz-New.ts index 4fc5252a..18c316f7 100644 --- a/src/simulator/definitions/scenes/jbc18-Stackerz-New.ts +++ b/src/simulator/definitions/scenes/jbc18-Stackerz-New.ts @@ -63,11 +63,11 @@ scene.onBind = nodeId => { }; `; -export const JBC_22: Scene = { +export const JBC_18: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 22' }, + name: { [LocalizedString.EN_US]: 'JBC 18' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 22: Stackerz`, + [LocalizedString.EN_US]: `Junior Botball Challenge 18: Stackerz`, }, scripts: { leftStartBox: Script.ecmaScript('Robot Left Start', leftStartBox), diff --git a/src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts b/src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts index f2794375..22b15f0c 100644 --- a/src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts +++ b/src/simulator/definitions/scenes/jbc24-Walk-the-Line-New.ts @@ -52,11 +52,11 @@ const ROBOT_ORIGIN: ReferenceFramewUnits = { x: Distance.centimeters(-15), }, }; -export const JBC_17: Scene = { +export const JBC_24: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 17' }, + name: { [LocalizedString.EN_US]: 'JBC 24' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 17: Walk the Line', + [LocalizedString.EN_US]: 'Junior Botball Challenge 24: Walk the Line', }, scripts: { lineFollow: Script.ecmaScript('Line Follow', lineFollow), diff --git a/src/simulator/definitions/scenes/jbc4-Serpentine-New.ts b/src/simulator/definitions/scenes/jbc4-Serpentine-New.ts index 08db3a07..f41a8e26 100644 --- a/src/simulator/definitions/scenes/jbc4-Serpentine-New.ts +++ b/src/simulator/definitions/scenes/jbc4-Serpentine-New.ts @@ -109,12 +109,12 @@ scene.onBind = nodeId => { }; `; -// 'n2','n3','n4','n5','n6','n7','n8' -export const JBC_8: Scene = { + +export const JBC_4: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 8' }, + name: { [LocalizedString.EN_US]: 'JBC 4' }, description: { - [LocalizedString.EN_US]: 'Junior Botball Challenge 8: Serpentine', + [LocalizedString.EN_US]: 'Junior Botball Challenge 4: Serpentine', }, scripts: { passedSide: Script.ecmaScript('Passed Side', passedSide), @@ -516,7 +516,7 @@ export const JBC_8: Scene = { x: Distance.centimeters(-26), // can 8 y: Distance.centimeters(-6.9), z: Distance.centimeters(65.5), - },false,false), + }, false, false), scriptIds: ['passedSide'], }, }, diff --git a/src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts b/src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts index 766ad535..8a63e20f 100644 --- a/src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts +++ b/src/simulator/definitions/scenes/jbc6-Figure-Eight-New.ts @@ -117,11 +117,11 @@ scene.addOnRenderListener(() => { }); `; -export const JBC_4: Scene = { +export const JBC_6: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: "JBC 4" }, + name: { [LocalizedString.EN_US]: "JBC 6" }, description: { - [LocalizedString.EN_US]: "Junior Botball Challenge 4: Figure Eight", + [LocalizedString.EN_US]: "Junior Botball Challenge 6: Figure Eight", }, scripts: { circleIntersects: Script.ecmaScript("Circle Intersects", circleIntersects), @@ -305,7 +305,7 @@ export const JBC_4: Scene = { }, }, }, - + n2: { type: "object", geometryId: "topCan9_geom", @@ -327,7 +327,7 @@ export const JBC_4: Scene = { }, }, - + can4: { ...createCanNode(4) }, can9: { ...createCanNode(9), scriptIds: ["passedSide"] }, }, diff --git a/src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts b/src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts index 3528862f..422c2f5f 100644 --- a/src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts +++ b/src/simulator/definitions/scenes/jbc7-Load-Em-Up-New.ts @@ -68,11 +68,11 @@ scene.addOnRenderListener(() => { }); `; -export const JBC_6: Scene = { +export const JBC_7: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: "JBC 6" }, + name: { [LocalizedString.EN_US]: "JBC 7" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 6: Load 'Em Up`, + [LocalizedString.EN_US]: `Junior Botball Challenge 7: Load 'Em Up`, }, scripts: { uprightCans: Script.ecmaScript("Upright Cans", uprightCans), diff --git a/src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts b/src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts index 57cd7c3e..0258a2e3 100644 --- a/src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts +++ b/src/simulator/definitions/scenes/jbc8-Bulldozer-Mania-New.ts @@ -138,11 +138,11 @@ scene.onBind = nodeId => { }; `; -export const JBC_7: Scene = { +export const JBC_8: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: "JBC 7" }, + name: { [LocalizedString.EN_US]: "JBC 8" }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 7: Bulldozer Mania`, + [LocalizedString.EN_US]: `Junior Botball Challenge 8: Bulldozer Mania`, }, scripts: { startBoxIntersects: Script.ecmaScript( diff --git a/src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts b/src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts index ebf88a45..082da976 100644 --- a/src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts +++ b/src/simulator/definitions/scenes/jbc9-Cover-Your-Bases-New.ts @@ -200,11 +200,11 @@ const ROBOT_ORIGIN: ReferenceFramewUnits = { }, }; -export const JBC_7B: Scene = { +export const JBC_9: Scene = { ...baseScene, - name: { [LocalizedString.EN_US]: 'JBC 7B' }, + name: { [LocalizedString.EN_US]: 'JBC 9' }, description: { - [LocalizedString.EN_US]: `Junior Botball Challenge 7B: Cover Your Bases`, + [LocalizedString.EN_US]: `Junior Botball Challenge 9: Cover Your Bases`, }, scripts: { startBoxIntersects: Script.ecmaScript( diff --git a/src/state/reducer/challenges.ts b/src/state/reducer/challenges.ts index 9404ea4f..19656952 100644 --- a/src/state/reducer/challenges.ts +++ b/src/state/reducer/challenges.ts @@ -19,26 +19,29 @@ import jbc2 from "../../simulator/definitions/challenges/jbc2"; // import jbc2c from "../../simulator/definitions/challenges/archived/jbc2c-Back-It-Up"; // import jbc2d from "../../simulator/definitions/challenges/archived/jbc2d-Ring-Around-the-Can-and-Back-It-Up"; import jbc3 from "../../simulator/definitions/challenges/jbc3-Precision-Parking-New"; -import jbc4 from "../../simulator/definitions/challenges/jbc6-Figure-Eight-New"; +import jbc4 from "../../simulator/definitions/challenges/jbc4-Serpentine-New"; // import jbc4b from "../../simulator/definitions/challenges/archived/jbc4b-Barrel-Racing"; import jbc5 from "../../simulator/definitions/challenges/jbc5"; -import jbc6 from "../../simulator/definitions/challenges/jbc7-Load-Em-Up-New"; +import jbc6 from "../../simulator/definitions/challenges/jbc6-Figure-Eight-New"; // import jbc6c from "../../simulator/definitions/challenges/archived/jbc6c-Empty-the-Garage"; -import jbc7 from "../../simulator/definitions/challenges/jbc8-Bulldozer-Mania-New"; +import jbc7 from "../../simulator/definitions/challenges/jbc7-Load-Em-Up-New"; // import jbc7b from "../../simulator/definitions/challenges/archived/jbc7b-Cover-Your-Bases"; -import jbc8 from "../../simulator/definitions/challenges/jbc4-Serpentine-New"; +import jbc8 from "../../simulator/definitions/challenges/jbc8-Bulldozer-Mania-New"; +import jbc9 from "../../simulator/definitions/challenges/jbc9-Cover-Your-Bases-New"; // import jbc8b from "../../simulator/definitions/challenges/archived/jbc8b-Serpentine-Jr"; -// import jbc10 from "../../simulator/definitions/challenges/archived/jbc10-Solo-Joust"; +import jbc10 from "../../simulator/definitions/challenges/jbc10-Chopped-New"; // import jbc10b from "../../simulator/definitions/challenges/archived/jbc10b-Solo-Joust-Jr"; +import jbc11 from "../../simulator/definitions/challenges/jbc11-Making-Waves-New"; // import jbc12 from "../../simulator/definitions/challenges/archived/jbc12-Unload-Em"; // import jbc13 from "../../simulator/definitions/challenges/archived/jbc13-Clean-the-Mat"; +import jbc14 from "../../simulator/definitions/challenges/jbc14-Dance-Party"; // import jbc15b from "../../simulator/definitions/challenges/archived/jbc15b-Bump-Bump"; -import jbc17 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; +import jbc17 from "../../simulator/definitions/challenges/jbc17-Mountain-Rescue-New"; // import jbc17b from "../../simulator/definitions/challenges/archived/jbc17b-Walk-the-Line-2"; -import jbc19 from "../../simulator/definitions/challenges/jbc17-Mountain-Rescue-New"; +import jbc18 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; // import jbc20 from "../../simulator/definitions/challenges/archived/jbc20-Rescue-the-Cans"; // import jbc21 from "../../simulator/definitions/challenges/archived/jbc21-Foot-Tall"; -import jbc22 from "../../simulator/definitions/challenges/jbc18-Stackerz-New"; +import jbc24 from "../../simulator/definitions/challenges/jbc24-Walk-the-Line-New"; // import test from '../../simulator/definitions/challenges/archived/test'; export namespace ChallengesAction { @@ -216,14 +219,22 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc8b, // brief: ChallengeBrief.fromChallenge(jbc8b), // }), - // 'jbc10': Async.loaded({ - // value: jbc10, - // brief: ChallengeBrief.fromChallenge(jbc10), - // }), + 'jbc9': Async.loaded({ + value: jbc9, + brief: ChallengeBrief.fromChallenge(jbc9), + }), + 'jbc10': Async.loaded({ + value: jbc10, + brief: ChallengeBrief.fromChallenge(jbc10), + }), // 'jbc10b': Async.loaded({ // value: jbc10b, // brief: ChallengeBrief.fromChallenge(jbc10b), // }), + 'jbc11': Async.loaded({ + value: jbc11, + brief: ChallengeBrief.fromChallenge(jbc11), + }), // 'jbc12': Async.loaded({ // value: jbc12, // brief: ChallengeBrief.fromChallenge(jbc12), @@ -232,6 +243,10 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc13, // brief: ChallengeBrief.fromChallenge(jbc13), // }), + 'jbc14': Async.loaded({ + value: jbc14, + brief: ChallengeBrief.fromChallenge(jbc14), + }), // 'jbc15b': Async.loaded({ // value: jbc15b, // brief: ChallengeBrief.fromChallenge(jbc15b), @@ -244,10 +259,14 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc17b, // brief: ChallengeBrief.fromChallenge(jbc17b), // }), - 'jbc19': Async.loaded({ - value: jbc19, - brief: ChallengeBrief.fromChallenge(jbc19), + 'jbc18': Async.loaded({ + value: jbc18, + brief: ChallengeBrief.fromChallenge(jbc18), }), + // 'jbc19': Async.loaded({ + // value: jbc19, + // brief: ChallengeBrief.fromChallenge(jbc19), + // }), // 'jbc20': Async.loaded({ // value: jbc20, // brief: ChallengeBrief.fromChallenge(jbc20), @@ -256,9 +275,17 @@ const DEFAULT_CHALLENGES: Challenges = { // value: jbc21, // brief: ChallengeBrief.fromChallenge(jbc21), // }), - 'jbc22': Async.loaded({ - value: jbc22, - brief: ChallengeBrief.fromChallenge(jbc22), + // 'jbc22': Async.loaded({ + // value: jbc22, + // brief: ChallengeBrief.fromChallenge(jbc22), + // }), + // 'jbc23': Async.loaded({ + // value: jbc23, + // brief: ChallengeBrief.fromChallenge(jbc23), + // }), + 'jbc24': Async.loaded({ + value: jbc24, + brief: ChallengeBrief.fromChallenge(jbc24), }), }; diff --git a/src/state/reducer/scenes.ts b/src/state/reducer/scenes.ts index 32d572bb..3bb18c57 100644 --- a/src/state/reducer/scenes.ts +++ b/src/state/reducer/scenes.ts @@ -312,17 +312,22 @@ const DEFAULT_SCENES: Scenes = { // jbc8b: Async.loaded({ value: JBC_SCENES.JBC_8B }), jbc9: Async.loaded({ value: JBC_SCENES.JBC_9 }), // jbc9b: Async.loaded({ value: JBC_SCENES.JBC_9B }), - // jbc10: Async.loaded({ value: JBC_SCENES.JBC_10 }), + jbc10: Async.loaded({ value: JBC_SCENES.JBC_10 }), // jbc10b: Async.loaded({ value: JBC_SCENES.JBC_10B }), + jbc11: Async.loaded({ value: JBC_SCENES.JBC_11 }), // jbc12: Async.loaded({ value: JBC_SCENES.JBC_12 }), // jbc13: Async.loaded({ value: JBC_SCENES.JBC_13 }), + jbc14: Async.loaded({ value: JBC_SCENES.JBC_14 }), // jbc15b: Async.loaded({ value: JBC_SCENES.JBC_15B }), jbc17: Async.loaded({ value: JBC_SCENES.JBC_17 }), // jbc17b: Async.loaded({ value: JBC_SCENES.JBC_17B }), - jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), + jbc18: Async.loaded({ value: JBC_SCENES.JBC_18 }), + // jbc19: Async.loaded({ value: JBC_SCENES.JBC_19 }), // jbc20: Async.loaded({ value: JBC_SCENES.JBC_20 }), // jbc21: Async.loaded({ value: JBC_SCENES.JBC_21 }), - jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), + // jbc22: Async.loaded({ value: JBC_SCENES.JBC_22 }), + // jbc23: Async.loaded({ value: JBC_SCENES.JBC_23 }), + jbc24: Async.loaded({ value: JBC_SCENES.JBC_24 }), // scriptPlayground: Async.loaded({ value: JBC_SCENES.scriptPlayground }), // lightSensorTest: Async.loaded({ value: JBC_SCENES.lightSensorTest }), };