mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-17 13:53:57 -07:00
Up to now `eslint-plugin-brace-rules` was used to enforce a common brace style for JavaScript code. This plugin was however updated the last time over 9 years ago and will be incompatible with ESLint v10, as that [removes `context.getSourceCode()`][1], the plugin relies on. To keep the eslint config working with ESLint v10, this replaces `eslint-plugin-brace-rules` with the [`@stylistic/brace-style`][2] rule from `@stylistic/eslint-plugin`, a package we already use. While `@stylistic/brace-style` doesn't offer an option to format braces in exactly the same way as before, the "allman" style seems to be the one closest to the existing code. [1]: https://eslint.org/blog/2025/11/eslint-v10.0.0-alpha.0-released/#removed-deprecated-rule-context-members [2]: https://eslint.style/rules/brace-style
37 lines
910 B
JavaScript
37 lines
910 B
JavaScript
function MotionBallScripted() {}
|
|
|
|
MotionBallScripted.prototype.Schema =
|
|
"<a:component type='test'/><empty/>";
|
|
|
|
MotionBallScripted.prototype.Init = function()
|
|
{
|
|
this.speedX = 0;
|
|
this.speedZ = 0;
|
|
};
|
|
|
|
MotionBallScripted.prototype.OnUpdate = function(msg)
|
|
{
|
|
var dt = msg.turnLength;
|
|
|
|
var cmpPos = Engine.QueryInterface(this.entity, IID_Position);
|
|
var cmpTerrain = Engine.QueryInterface(SYSTEM_ENTITY, IID_Terrain);
|
|
|
|
var pos = cmpPos.GetPosition();
|
|
|
|
var normal = cmpTerrain.CalcNormal(pos.x, pos.z);
|
|
|
|
var g = 10;
|
|
var forceX = normal.x * g;
|
|
var forceZ = normal.z * g;
|
|
|
|
this.speedX += forceX * dt;
|
|
this.speedZ += forceZ * dt;
|
|
|
|
var drag = 0.5; // fractional decay per second
|
|
this.speedX *= Math.pow(drag, dt);
|
|
this.speedZ *= Math.pow(drag, dt);
|
|
|
|
cmpPos.MoveTo(pos.x + this.speedX * dt, pos.z + this.speedZ * dt);
|
|
};
|
|
|
|
Engine.RegisterComponentType(IID_Motion, "MotionBallScripted", MotionBallScripted);
|