Files
nick 8041286a9d
CI / build-and-test (push) Successful in 2m4s
feat: tool tips and groups for editable properties
2026-03-09 13:51:45 +13:00

50 lines
1.3 KiB
ActionScript 3

// Class-based entity script: one `EntityScript` instance per entity.
// Implements Init/Update/Shutdown so the engine will instantiate it per-entity.
class EntityScript
{
float baseX;
float baseY;
float baseZ;
[group["Movement"]][desc["Phase accumulator for the sine wave"]][editable][range[0,1]]float phase;
// per-instance movement parameters (can be tuned per-entity)
[group["Movement"]][desc["Bounce height"]][editable][range[0,10]]float amplitude = 2.5f;
[group["Movement"]][desc["Cycles per second"]][editable][range[0,10]]float speed = 2.5f;
[group["State"]][desc["Debug animation state"]][editable][options[Idle,Walk,Run]] int state = 0;
EntityScript()
{
baseX = 0.0f;
baseY = 0.0f;
baseZ = 0.0f;
phase = 0.0f;
}
void Init(uint entity)
{
if (!ECS::IsValid(entity)) return;
if (!ECS::HasTransform(entity))
ECS::AddTransform(entity, 0.0f, 0.0f, 0.0f);
ECS::GetPosition(entity, baseX, baseY, baseZ);
phase = 0.0f;
}
void Update(uint entity, float dt)
{
if (!ECS::IsValid(entity)) return;
if (!ECS::HasTransform(entity)) return;
phase += dt;
float offset = Math::Sin(phase * speed + float(entity) * 0.1f) * amplitude;
ECS::SetPosition(entity, baseX, baseY + offset, baseZ);
}
void Shutdown(uint entity)
{
// nothing to clean up per-instance for this simple example
}
}