Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

game: Refactor gate scripting #1231

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions assets/global/game.prefabs
Original file line number Diff line number Diff line change
Expand Up @@ -665,30 +665,28 @@
"name": "PropGate",
"traits": [
{ "$type": "AssetPrefabTrait_Renderable", "graphic": "graphics/game/prop_gate.graphic" },
{ "$type": "AssetPrefabTrait_SetMember", "sets": [ "gate" ] },
{ "$type": "AssetPrefabTrait_Script", "scripts": [ "scripts/scene/logic/gate.script" ] },
{
"$type": "AssetPrefabTrait_Property",
"properties": [
{ "$name": "cfgGateOpen", "$type": "AssetProperty_Bool", "$data": false }
]
}
{ "$type": "AssetPrefabTrait_Script", "scripts": [ "scripts/scene/logic/gate.script" ] }
]
},
{
"name": "PropPressurePlate",
"traits": [
{ "$type": "AssetPrefabTrait_Renderable", "graphic": "graphics/game/prop_pressure_plate.graphic" },
{ "$type": "AssetPrefabTrait_SetMember", "sets": [ "switch" ] },
{ "$type": "AssetPrefabTrait_Script", "scripts": [ "scripts/scene/logic/pressure_plate.script" ] }
]
},
{
"name": "PropFloorLight",
"traits": [
{ "$type": "AssetPrefabTrait_Renderable", "graphic": "graphics/game/prop_floor_light.graphic" },
{ "$type": "AssetPrefabTrait_SetMember", "sets": [ "light" ] },
{ "$type": "AssetPrefabTrait_Script", "scripts": [ "scripts/scene/logic/light.script" ] }
{ "$type": "AssetPrefabTrait_Script", "scripts": [ "scripts/scene/logic/light.script" ] },
{
"$type": "AssetPrefabTrait_Property",
"properties": [
{ "$type": "AssetProperty_Color", "$name": "cfgColor", "r": 1, "g": 0, "b": 0, "a": 1 },
{ "$type": "AssetProperty_Color", "$name": "cfgColorTrigger", "r": 0, "g": 1, "b": 0, "a": 1 }
]
}
]
},
{
Expand Down Expand Up @@ -1018,12 +1016,6 @@
}
]
},
{
"name": "LogicSwitch",
"traits": [
{ "$type": "AssetPrefabTrait_Script", "scripts": [ "scripts/scene/logic/gate_switch.script" ] }
]
},
{
"name": "ExplosionMedium", "isVolatile": true,
"traits": [
Expand Down
62 changes: 37 additions & 25 deletions assets/levels/default.level
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,6 @@
"position": { "x": 105.8384, "y": 1.2627, "z": 21.6802 },
"rotation": { "y": 0.347, "w": 0.9379 }
},
{
"id": 150723686,
"prefab": "PropFence",
"faction": "A",
"position": { "x": 26, "y": 0.7378, "z": -9 },
"rotation": { "y": -1 }
},
{
"id": 151812269,
"prefab": "PropWreck",
Expand Down Expand Up @@ -828,7 +821,7 @@
"id": 520161433,
"prefab": "PropFence",
"faction": "A",
"position": { "x": 26, "y": 0.9584, "z": -15 },
"position": { "x": 26, "y": 0.9584, "z": -14 },
"rotation": { "y": -1 }
},
{
Expand Down Expand Up @@ -2009,6 +2002,16 @@
"position": { "x": -47.0865, "y": 0.5053, "z": 69.9943 },
"rotation": { "y": -0.6059, "w": 0.7956 }
},
{
"id": 1264308031,
"prefab": "PropFloorLight",
"faction": "A",
"position": { "x": 26.959, "y": 0.9148, "z": -10.6213 },
"rotation": { "x": -4.2147e-8, "y": 6.2023e-23, "z": -4.2147e-8, "w": 1 },
"properties": [
{ "$type": "AssetProperty_LevelEntity", "$name": "cfgTrigger", "$data": 4128576319 }
]
},
{
"id": 1265083432,
"prefab": "PropTree",
Expand Down Expand Up @@ -2667,7 +2670,10 @@
"prefab": "PropFloorLight",
"faction": "A",
"position": { "x": 7.4015, "y": 1.4299, "z": -19.8512 },
"rotation": { "x": -0.5, "y": -0.5, "z": 0.5, "w": 0.5 }
"rotation": { "x": -0.5, "y": -0.5, "z": 0.5, "w": 0.5 },
"properties": [
{ "$type": "AssetProperty_LevelEntity", "$name": "cfgTrigger", "$data": 2176869707 }
]
},
{
"id": 1733453794,
Expand Down Expand Up @@ -3195,13 +3201,6 @@
"position": { "x": -98.2251, "y": 0.3578, "z": 27.0506 },
"rotation": { "y": 0.4087, "w": 0.9127 }
},
{
"id": 2093996692,
"prefab": "LogicSwitch",
"faction": "A",
"position": { "x": 0.448, "y": 0.7636, "z": -21.5103 },
"rotation": { "w": 1 }
},
{
"id": 2094852526,
"prefab": "PropPlant",
Expand Down Expand Up @@ -4376,7 +4375,10 @@
"prefab": "PropGate",
"faction": "A",
"position": { "x": 4.5412, "y": 0.4629, "z": -19.3119 },
"rotation": { "y": -0.7071, "w": 0.7071 }
"rotation": { "y": -0.7071, "w": 0.7071 },
"properties": [
{ "$type": "AssetProperty_LevelEntity", "$name": "cfgTrigger", "$data": 2176869707 }
]
},
{
"id": 2734812485,
Expand Down Expand Up @@ -4634,13 +4636,6 @@
"position": { "x": 58.3341, "y": 0.5484, "z": -94.8163 },
"rotation": { "y": -0.0048, "w": 1 }
},
{
"id": 2883209089,
"prefab": "PropFence",
"faction": "A",
"position": { "x": 26, "y": 0.582, "z": -6 },
"rotation": { "y": -1 }
},
{
"id": 2894832916,
"prefab": "PropPlant",
Expand Down Expand Up @@ -4712,7 +4707,7 @@
"id": 2930954255,
"prefab": "PropFence",
"faction": "A",
"position": { "x": 26, "y": 0.9307, "z": -12 },
"position": { "x": 26, "y": 0.9307, "z": -11 },
"rotation": { "y": -1 }
},
{
Expand Down Expand Up @@ -6648,6 +6643,13 @@
"position": { "x": -124.6901, "y": 0.6854, "z": -134.849 },
"rotation": { "y": 0.4005, "w": 0.9163 }
},
{
"id": 4128576319,
"prefab": "PropPressurePlate",
"faction": "A",
"position": { "x": 29.8577, "y": 1.0537, "z": -10.8405 },
"rotation": { "x": 0.0078, "y": 0.0001, "z": -0.0107, "w": 0.9999 }
},
{
"id": 4132670301,
"prefab": "PropPlant",
Expand Down Expand Up @@ -6790,6 +6792,16 @@
"position": { "x": -18, "y": 0.5225, "z": -3 },
"rotation": { "w": 1 }
},
{
"id": 4205311062,
"prefab": "PropGate",
"faction": "A",
"position": { "x": 25.8489, "y": 0.72, "z": -7.0346 },
"rotation": { "y": -1, "w": -4.3711e-8 },
"properties": [
{ "$type": "AssetProperty_LevelEntity", "$name": "cfgTrigger", "$data": 4128576319 }
]
},
{
"id": 4209259987,
"prefab": "PropPlant",
Expand Down
17 changes: 8 additions & 9 deletions assets/levels/test/gate.level
Original file line number Diff line number Diff line change
Expand Up @@ -2612,7 +2612,10 @@
"prefab": "PropGate",
"faction": "A",
"position": { "x": 18.4996, "y": 0.7126, "z": -30.0693 },
"rotation": { "y": -0.7674, "w": 0.6411 }
"rotation": { "y": -0.7674, "w": 0.6411 },
"properties": [
{ "$type": "AssetProperty_LevelEntity", "$name": "cfgTrigger", "$data": 3585854945 }
]
},
{
"id": 1681329994,
Expand Down Expand Up @@ -3587,7 +3590,10 @@
"prefab": "PropFloorLight",
"faction": "A",
"position": { "x": 21.569, "y": 1.3476, "z": -30.1002 },
"rotation": { "x": -0.5417, "y": -0.5417, "z": 0.4545, "w": 0.4545 }
"rotation": { "x": -0.5417, "y": -0.5417, "z": 0.4545, "w": 0.4545 },
"properties": [
{ "$type": "AssetProperty_LevelEntity", "$name": "cfgTrigger", "$data": 3585854945 }
]
},
{
"id": 2299812967,
Expand Down Expand Up @@ -4466,13 +4472,6 @@
"position": { "x": 134.376, "y": 0.6725, "z": 125.6214 },
"rotation": { "y": 0.1074, "w": 0.9942 }
},
{
"id": 2785665147,
"prefab": "LogicSwitch",
"faction": "A",
"position": { "x": 16.8337, "y": 0.756, "z": -35.0054 },
"rotation": { "w": 1 }
},
{
"id": 2795933875,
"prefab": "PropPlant",
Expand Down
9 changes: 7 additions & 2 deletions assets/scripts/scene/logic/gate.script
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Openable gate.
*
* Supports the following input properties:
* - "cfgGateOpen": Should the gate be currently open?
* - "cfgGateOpen": Should the gate be opened by default.
* - "cfgTrigger": Entity to ask if we are triggered (will be asked for a 'triggered' property).
*/

var me = self()
Expand All @@ -20,8 +21,12 @@ if (!$colGate) {
$colGate = colEntity
}

if ($cfgTrigger) {
ask(me, $cfgTrigger, "triggered")
}

var openSpeed = 2.5
var shouldOpen = $cfgGateOpen ?? false
var shouldOpen = $triggered ? (!$cfgGateOpen ?? true) : ($cfgGateOpen ?? false)

if (capable(me, "Animation")) {
anim_param(me, "open", "Active", true)
Expand Down
15 changes: 0 additions & 15 deletions assets/scripts/scene/logic/gate_switch.script

This file was deleted.

18 changes: 14 additions & 4 deletions assets/scripts/scene/logic/light.script
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
* Light that can dynamically change colors.
*
* Supports the following input properties:
* - "cfgColor": Current color.
* - "cfgColor": Normal color.
* - "cfgColorTrigger": Triggered color.
* - "cfgTrigger": Entity to ask if we are triggered (will be asked for a 'triggered' property).
*/

var fixture = self()
Expand All @@ -12,11 +14,19 @@ var lightRadius = 5
var lightIntensity = 3.5
var lightOffset = vec3(0.25, 0.5, 0)

renderable_param(fixture, "Emissive", $cfgColor ? fixtureEmissive : 0.0)
renderable_param(fixture, "Color", $cfgColor ?? white)
if ($cfgTrigger) {
ask(fixture, $cfgTrigger, "triggered")
}
var activeColor = $triggered ? $cfgColorTrigger : $cfgColor

var radiance = (activeColor ?? black) * lightIntensity
var radianceRgb = color(color_r(radiance), color_g(radiance), color_b(radiance), 0.0)

renderable_param(fixture, "Emissive", magnitude(radianceRgb) > 0.01 ? fixtureEmissive : 0.0)
renderable_param(fixture, "Color", activeColor ?? white)

if ($light) {
light_param($light, "Radiance", ($cfgColor ?? black) * lightIntensity)
light_param($light, "Radiance", radiance)
} else {
var e = light_point_spawn(vec3(0, 0, 0), black, lightRadius)
attach(e, fixture, null, lightOffset)
Expand Down
9 changes: 5 additions & 4 deletions libs/rend/src/instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ static RendMat3x4 rend_transpose_to_3x4(const GeoMatrix* m) {
}

static u32 rend_color_pack(const GeoColor color) {
const u32 r = (u8)(color.r * 255.999f);
const u32 g = (u8)(color.g * 255.999f);
const u32 b = (u8)(color.b * 255.999f);
const u32 a = (u8)(color.a * 255.999f);
const GeoColor clamped = geo_color_clamp01(color); // HDR colors are not supported atm.
const u32 r = (u8)(clamped.r * 255.999f);
const u32 g = (u8)(clamped.g * 255.999f);
const u32 b = (u8)(clamped.b * 255.999f);
const u32 a = (u8)(clamped.a * 255.999f);
return r | (g << 8) | (b << 16) | (a << 24);
}

Expand Down