Skip to content

Commit

Permalink
Fix rep children z-fighting;
Browse files Browse the repository at this point in the history
Fix shape colors type;
Add Vampires;
Add AllOtherUnits expression;
  • Loading branch information
makscee committed Mar 12, 2024
1 parent c915636 commit 9863167
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 286 deletions.
2 changes: 1 addition & 1 deletion assets/ron/heroes/fertilizer.unit.ron
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
level: 1,
houses: "Druids",
description: "%trigger → %effect on %target",
trigger: Fire(trigger: BattleStart, target: AllyUnits, effect: UseAbility("Thorns", 0), period: 0),
trigger: Fire(trigger: BattleStart, target: AllAllyUnits, effect: UseAbility("Thorns", 0), period: 0),
representation: (
material: Shape(
shape: Rectangle,
Expand Down
2 changes: 1 addition & 1 deletion assets/ron/heroes/hag.unit.ron
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
level: 1,
houses: "Witches",
description: "%trigger → %effect on %target",
trigger: Fire(trigger: BattleStart, target: EnemyUnits, effect: UseAbility("Weakness", 0), period: 0),
trigger: Fire(trigger: BattleStart, target: AllEnemyUnits, effect: UseAbility("Weakness", 0), period: 0),
representation: (
material: Curve(
thickness: Float(0.3),
Expand Down
2 changes: 1 addition & 1 deletion assets/ron/heroes/priest.unit.ron
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
hp: 1,
atk: 1,
houses: "Holy",
trigger: Fire(trigger: BattleStart, target: AllyUnits, effect: UseAbility("Blessing", 0)),
trigger: Fire(trigger: BattleStart, target: AllAllyUnits, effect: UseAbility("Blessing", 0)),
representation: (
count: 4,
material: Shape(
Expand Down
2 changes: 1 addition & 1 deletion assets/ron/heroes/ruin.unit.ron
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
level: 1,
houses: "Death Knights",
description: "%trigger → %effect on %target",
trigger: Fire(trigger: BattleStart, target: EnemyUnits, effect: UseAbility("Decay", 0), period: 0),
trigger: Fire(trigger: BattleStart, target: AllEnemyUnits, effect: UseAbility("Decay", 0), period: 0),
representation: (
material: Shape(
shape: Rectangle,
Expand Down
2 changes: 1 addition & 1 deletion assets/ron/heroes/virus.unit.ron
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
level: 1,
houses: "Death Knights",
description: "%trigger → %effect on %target",
trigger: Fire(trigger: BattleStart, target: EnemyUnits, effect: UseAbility("Plague", 0), period: 0),
trigger: Fire(trigger: BattleStart, target: AllEnemyUnits, effect: UseAbility("Plague", 0), period: 0),
representation: (
material: Shape(
shape: Circle,
Expand Down
24 changes: 24 additions & 0 deletions assets/ron/houses/vampires.house.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#![enable(implicit_some)]
(
name: "Vampires",
color: ("#BA002F"),
statuses: [
(
name: "Siphoned Out",
description: "-{Charges} Hp",
trigger: Change(trigger: Var(Hp), expr: Sub(Int(0), Context(Charges))),
),
(
name: "Siphon Bonus",
description: "+{Charges} Hp",
trigger: Change(trigger: Var(Hp), expr: Context(Charges)),
),
],
abilities: [
(
name: "Siphon",
description: "Drain 1 HP from target",
effect: List([AddStatus("Siphoned Out"), WithTarget(Owner, AddStatus("Siphon Bonus")), Vfx("apply_status")]),
),
],
)
5 changes: 2 additions & 3 deletions assets/shaders/sdf_shape.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ struct ShapeMaterial {
size: vec2<f32>,
thickness: f32,
alpha: f32,
colors: array<vec4<f32>, 10>,
point1: vec2<f32>,
point2: vec2<f32>,
colors: array<vec4<f32>, 10>,
};

@group(1) @binding(0)
Expand Down Expand Up @@ -43,8 +43,7 @@ fn fragment(in: MeshVertexOutput) -> @location(0) vec4<f32> {
#ifdef LINE
v = min(v, smoothstep(0.0, AA, -sdf)) * v;
v = max(v, smoothstep(AA, 0.0, -sdf - thickness));
#endif
#ifdef OPAQUE
#else ifdef OPAQUE
v = f32(sdf < 0.0);
#endif
v = max(v, smoothstep(thickness + GLOW, thickness, -sdf) * 0.1);
Expand Down
10 changes: 6 additions & 4 deletions src/components/representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl RepresentationMaterial {
let mut materials = world.get_resource_mut::<Assets<ShapeMaterial>>().unwrap();
if let Some(mat) = materials.get_mut(&handle) {
for (i, color) in colors.into_iter().enumerate() {
mat.colors[i] = color;
mat.colors[i] = Color::from(color);
}
mat.thickness = thickness;
mat.alpha = alpha;
Expand Down Expand Up @@ -502,16 +502,18 @@ impl Representation {
let entity = world.spawn_empty().set_parent(entity).id();
self.material.unpack(entity, world);
VarState::new_with(VarName::Index, VarValue::Int(i as i32)).attach(entity, world);
world.get_mut::<Transform>(entity).unwrap().translation.z += 0.01 * i as f32;
world.get_mut::<Transform>(entity).unwrap().translation.z += 0.001 * i as f32;
self.material_entities.push(entity);
}
self.unpack_children(world);
*self.material_entities.first().unwrap()
}
fn unpack_children(&mut self, world: &mut World) {
let parent = *self.material_entities.first().unwrap();
for child in self.children.iter_mut() {
child.unpack_materials(world.spawn_empty().set_parent(parent).id(), world);
for (i, child) in self.children.iter_mut().enumerate() {
let entity = world.spawn_empty().set_parent(parent).id();
child.unpack_materials(entity, world);
world.get_mut::<Transform>(entity).unwrap().translation.z += (i + 1) as f32;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/materials/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ pub struct ShapeMaterial {
#[uniform(0)]
pub alpha: f32,
#[uniform(0)]
pub colors: [Vec4; 10],
#[uniform(0)]
pub point1: Vec2,
#[uniform(0)]
pub point2: Vec2,
#[uniform(0)]
pub colors: [Color; 10],
pub shape: Shape,
pub fill: Fill,
pub fill_color: FillColor,
Expand Down
Loading

0 comments on commit 9863167

Please sign in to comment.