Skip to content

Making new Equipment

Zachary-Ronayne edited this page Nov 1, 2020 · 7 revisions

Creation

Lets say we are making equipment Pencil.

First, create a file Pencil.js. This should be placed in the ExperimentObjects directory, or ExperimentObjects/.

Next, inside Pencil.js create two classes, Pencil and PencilController2D as follows: Note, if Pencil is a sub class of a different object than EquipmentObject, it should extend that object.

class Pencil extends Equipment{
}
class PencilController2D extends EquipmentController2D{
}

Next, add any fields to Pencil, as well as appropriate setters, specific to pencils.

Next implement any methods or fields in PencilController2D, specific to pencils.

Note, some of the following methods may be implemented by other sub classes, for example, if Pencil extended Container, then reset() would not necessarily need implementation.

Next, implement getID() in Pencil. This should return an integer representing the ID of Pencil. This ID should be defined in ObjectIDs.js, and should be a different integer from all other IDs. This ID should be added under the comment "Constants for IDs of Equipment".

Next, implement reset() in PencilController2D, which should bring the Pencil to a default state, as if it was taken directly off a shelf.

Next, implement idToFunc() and funcToId() in PencilController2D. These should convert an integer ID to a function and vice versa. All functions for these parameters should take exactly one parameter, another ExperimentObjectController2D, which will interact with the PencilController2D. The function IDs should be defined as constants in the top of the file. All function IDs should be integers greater than or equal to 1. See Container.js for an example.

Next, implement getFuncDescriptions() in PencilController2D. This should return a list of all of the descriptions for each function, based on the function IDs from idToFunc() and funcToId().

Finally, be sure to add Pencil.js script to the main simulator page, and test cases file, and to create unit tests for all methods in Pencil.

At this point, Pencil should be able to work in the simulation, however, for it to be stored and loaded by the database or Experiment parser, it must be added to idToEquipment in ObjectIDs.js. To do this, add a new case in the switch statement with the ID constant for Pencil, and return a new PencilController2D containing a new Pencil object.