fix assign
fixes #1037 (closed)
Merge request reports
Activity
331 331 /** Number of already hosted slaves 332 332 * @returns {number} */ 333 333 get hostedSlaves() { 334 return State.variables[this.desc.baseName + "Slaves"]; 334 switch (this.desc.baseName) { It's a bad design. This switch contradicts basic principles of the OOP model. Never ever a class should know about ancestor-related details, especially related to their implementation.
- Replace with
return State.variables[capFirstChar(this.desc.baseName) + "iIDs"].length;
- Provide overrides for the special cases (brother, cellblock, HGSuite, master suite, servants' quaters)
You may want to look at
App.Entity.Facilities.FacilitySingleJob._employeeIDsVariableName
.- Replace with
I'll add schoolroom. I'm not quite sure I follow what else you are saying. I'm sure it seems simple to you but it adds a lot of complexity. I can try though.
Edited by lowercasedonkey
331 331 /** Number of already hosted slaves 332 332 * @returns {number} */ 333 333 get hostedSlaves() { 334 return State.variables[this.desc.baseName + "Slaves"]; 334 switch (this.desc.baseName) { Given the available job classes and all definitions inside them,
get hostedSlaves()
can be implemented using the job objects:get hostedSlaves() { return this.job().employeesIds.length; }
You just need to split the first three lines out of
App.Entity.Facilities.FacilitySingleJob.employeesIndices()
into this new functionget employeesIds()
.Edited by ezshOk, so you want me to take
/** @returns {number[]} */ employeesIndices() { const V = State.variables; const si = V.slaveIndices; const ids = V[this._employeeIDsVariableName]; // updated by assignJob()/removeJob() return ids.map(id => si[id]); }
and either use or remove the first three lines. Then make a function called employeesIds and do something with it.
I can see how
/** @private */ get _employeeIDsVariableName() { return this.facility.genericName + "iIDs"; }
is helpful and could set up something automatic, but I'm not quite getting how this comes together. It's probably something with scope.
Edit: forked off what I think you are saying in !5281 (merged) for better discussion and to keep this ready to merge.
Edited by lowercasedonkey
mentioned in merge request !5281 (merged)