mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 21:34:08 -07:00
Use prototype = Object.create(parent) instead of prototype = new parent(...) to avoid calling the constructor needlessly (as it is redundant with the base constructor call in the constructor calls the parent constructor). Testfile reference comes from7c2e9027c2, "initial terrible AI player scripts" had it since57e5bb878a, jubot copied it since02ed11ac54, qbot copied it sinceb146f53d7bqbot-wc (later aegis) copied it since45ee419171, aegis copied it sincebcf7115b5c, petra copied it since97afd25171.d23b7deb98used Object.create correctly for new code in aegis that was adopted for petra too in97afd25171. Differential Revision: https://code.wildfiregames.com/D2238 Patch By: Krinkle This was SVN commit r22834.
45 lines
869 B
JavaScript
45 lines
869 B
JavaScript
function TestScript1A() {}
|
|
|
|
TestScript1A.prototype.Init = function() {
|
|
this.x = 101000;
|
|
};
|
|
|
|
TestScript1A.prototype.GetX = function() {
|
|
return this.x;
|
|
};
|
|
|
|
TestScript1A.prototype.OnTurnStart = function(msg) {
|
|
this.x += 1;
|
|
};
|
|
|
|
Engine.RegisterComponentType(IID_Test1, "TestScript1A", TestScript1A);
|
|
|
|
// -------- //
|
|
|
|
function TestScript1B() {}
|
|
|
|
TestScript1B.prototype = Object.create(TestScript1A.prototype);
|
|
|
|
TestScript1B.prototype.Init = function() {
|
|
this.x = 102000;
|
|
};
|
|
|
|
Engine.RegisterComponentType(IID_Test1, "TestScript1B", TestScript1B);
|
|
|
|
// -------- //
|
|
|
|
function TestScript2A() {}
|
|
|
|
TestScript2A.prototype.Init = function() {
|
|
this.x = 201000;
|
|
};
|
|
|
|
TestScript2A.prototype.GetX = function() {
|
|
return this.x;
|
|
};
|
|
|
|
TestScript2A.prototype.OnUpdate = function(msg) {
|
|
this.x += msg.turnLength;
|
|
};
|
|
|
|
Engine.RegisterComponentType(IID_Test2, "TestScript2A", TestScript2A);
|