Skip to content

Commit

Permalink
Fix up the randomizer function for tests.
Browse files Browse the repository at this point in the history
It isn't used in tests yet (and will need to change if it is
used) but compiles now.

Added more preview images. Tweaked some log lines.
  • Loading branch information
ceejbot committed Jan 5, 2024
1 parent eb57df9 commit a63e8bb
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions docs/article-layouts-v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ color = {r = 160, g = 240, b = 2, a = 255 }
size = { x = 10.0, y = 10.0 }
```

Soulsy ships with the indicator used above. It looks like a water droplet.

### Meter elements

Slot layouts can optionally include a *meter* display, for graphically showing enchantment charge or torch burn time. The meaning of the meter depends on the item being shown, and SoulsyHUD does its best to guess what should be shown for an item. For example, a meter on the shouts and powers HUD slot would show shout cooldown time if that's relevant.
Expand All @@ -172,7 +174,6 @@ Right now SoulsyHUD supports three flavors of meters:

1. A rectangular meter built from two SVGs, one for the background and one to show fill level.
2. A rectangular meter built from one background SVG and a fill color.
3. __NOT YET FINISHED:__ Circular meters, with a background SVG, a fill color, and angles for 0% and 100%. You can draw a full circle around a slot or a partial arc. Elliptical curves aren't supported yet. (Sending cookies or coffee to the mod author might help with this feature request.)

Rectangular meters are drawn as _horizontal_ bars filling from left to right, then rotated by the angle you specify. All angles are given in degrees. 0° means no rotation. 90° is a vertical meter, with full being at the top. You can specify any degree of rotation you want: if your layout uses equilateral triangles, you can rotate a meter 60° to make it align with an edge.

Expand All @@ -191,12 +192,13 @@ size = { x = 100.0, y = 20.0 }
color = { r = 255, g = 255, b = 255, a = 255 }
[left.meter.fill]
# the svg drawn to show the fill
# set this to empty string to re-use the empty svg
svg = "meter_bar_filled.svg"
size = { x = 98.0, y = 16.0 }
color = { r = 59, g = 106, b = 249, a = 200 }
```

Meter elements are rotated around their centers. You will likely need to play with the offset until a rotated meter is positioned exactly where you want. Remember to specify sizes as if the meter were *horizontal*, filling from left to right. Then rotate it to match your other layout elements.
Meter elements are rotated around their centers. You will likely need to play with the offset until a rotated meter is positioned exactly where you want. Remember to specify sizes as if the meter were *horizontal*, filling from left to right. Then rotate it to match your other layout elements. Look at the layouts that come with Soulsy to see examples of meters with different rotations and fills.

## Slot elements

Expand Down
Binary file modified installer/images/layouts-default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified installer/images/layouts-minimal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added installer/images/layouts-text-only.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/controller/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ impl Controller {
let kind = item.kind();
cxx::let_cxx_string!(form_spec = item.form_string());
cxx::let_cxx_string!(name = item.name());
log::info!("about to equip this item: slot={:?}; {}", which, item);
log::debug!("about to equip this item: slot={:?}; {}", which, item);

if kind.is_magic() || kind.left_hand_ok() || kind.right_hand_ok() {
equipWeapon(&form_spec, which, &name);
Expand Down Expand Up @@ -1167,7 +1167,7 @@ impl Controller {
self.update_slot(HudElement::Left, &HudItem::default());
return changed;
} else if treat_as_two_hander && left {
log::info!("treat_as_two_hander + left detected; item={item}");
log::debug!("treat_as_two_hander + left detected; item={item}");
// TODO The left hud slot should be cleared and the left hand unequipped.
// but I'm also not sure we ever get here.
return false;
Expand Down
21 changes: 19 additions & 2 deletions src/data/huditem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,20 @@ impl RelevantExtraData {
pub fn randomize() -> Self {
let has_charge = rand::random::<f32>() > 0.5;
let max_charge = if has_charge {
rand::random::<f32>() * 3000.0
} else {
0.0
};
let charge = rand::random::<f32>() * max_charge;

let has_time_left = rand::random::<f32>() > 0.5;
let max_time = if has_charge {
rand::random::<f32>() * 120.0
} else {
0.0
};
let time_left = rand::random::<f32>() * max_time;

let is_poisoned = rand::random::<f32>() > 0.5;

Self {
Expand Down Expand Up @@ -304,10 +313,18 @@ impl HudItem {
self.shout_cooldown = extra.time_left;
self.meter_level = 0.0;
} else {
self.meter_level = extra.time_left * 100.0 / self.shout_cooldown;
if self.shout_cooldown == 0.0 {
self.meter_level = 0.0;
} else {
self.meter_level = extra.time_left * 100.0 / self.shout_cooldown;
}
}
} else {
self.meter_level = extra.time_left * 100.0 / extra.max_time;
if extra.max_time == 0.0 {
self.meter_level = 0.0;
} else {
self.meter_level = extra.time_left * 100.0 / extra.max_time;
}
}
}

Expand Down

0 comments on commit a63e8bb

Please sign in to comment.