Path: blob/main/public/games/files/algaes-escapade/js/lib/gates/notGate.js
1039 views
/**1* Simulates a NOT gate in JavaScript. As an io object this can be used to2* chain together logic operators and objects3*4* @author David North5*/6function notGate()7{8notGate.prototype.constructor.call(this);910/**11* Overrides the addInput method of the parent so that only a single12* input can be added to this object. This is because the NOT gate can only13* operate by setting itself to a modified state of it's single input14*15* @param io input The input to add16*17* @return io18*/19this.addInput = function( input ){20notGate.prototype.addInput.call(this, input);2122if ( this.getInputs().length > 1 )23{24throw 'You may only have one input assigned to a Not gate';25}2627return this;28}2930/**31* Overrides the setState method of the parent so that the state that this32* object is set to is the opposite to that provided33*34* @param boolean state The state to apply35*36* @return notGate37*/38this.setState = function( state ){39return notGate.prototype.setState.call(this, !state);40}41}4243//Set the parent of the notGate to io44include_once(['lib/io.js']);45notGate.prototype = new io();464748