Skip to content

Commit f71675d

Browse files
committed
feat: add support for labels in projections
1 parent 3b29663 commit f71675d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1418
-1306
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.ftl linguist-vendored
2+
*.json linguist-vendored

Cargo.lock

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ features = ["alloc", "std", "clock", "serde", "unstable-locales"]
6666
[workspace.dependencies.diesel]
6767
version = "2"
6868
# Figure out how to make `without-deprecated` compile
69-
features = ["uuid", "chrono"]
69+
features = ["uuid", "chrono", "serde_json"]
7070

7171
[workspace.dependencies.diesel-async]
7272
version = "0.3"

api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "api"
3-
version = "0.25.0"
3+
version = "0.26.0"
44
edition = "2021"
55
license = "GPL-3.0"
66
authors = ["Matthew Polak <[email protected]>"]

api/macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "macros"
3-
version = "0.25.0"
3+
version = "0.26.0"
44
edition = "2021"
55
license = "GPL-3.0"
66
authors = ["Matthew Polak <[email protected]>"]
File renamed without changes.

api/macros/src/game/impls/mode.rs

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
7777
let mode_blocks = mode.blocks();
7878
let game_blocks = state.receiver.blocks();
7979

80+
let game_labels = state.receiver.labels();
81+
let game_labels = game_labels
82+
.iter()
83+
.filter(|l| l.tr() != "level")
84+
.collect::<Vec<_>>();
85+
8086
let diff_log = game_blocks
8187
.iter()
8288
.chain(mode_blocks.iter())
@@ -119,7 +125,7 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
119125
quote! {
120126
#extra
121127

122-
field.push_str(#translate::tr!(ctx, Self::tr()).as_ref());
128+
field.push_str(#translate::tr(ctx, Self::tr()).as_ref());
123129
field.push_str(": **");
124130
field.push_str(#v.as_ref());
125131
field.push_str("**\n");
@@ -139,6 +145,20 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
139145
f64::from(#value)
140146
})
141147
}, b.tr(), b.var_id())))
148+
.chain(
149+
game_labels
150+
.iter()
151+
.filter_map(|l| Some(({
152+
let value = l.value(Side::None, Access::ModeDiff(mode))?;
153+
154+
quote!({
155+
let stats = &data.stats.#path_to_game.#id;
156+
let game = &data.stats.#path_to_game;
157+
158+
f64::from(#value)
159+
})
160+
}, l.tr(), l.var_id())))
161+
)
142162
.chain(std::iter::once((
143163
quote!({
144164
let stats = &data.stats.#path_to_game.#id;
@@ -181,7 +201,7 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
181201
let mut buffer = #api::canvas::project::f64::create(
182202
ctx,
183203
::std::vec![(
184-
#translate::tr!(ctx, #tr),
204+
#translate::tr(ctx, #tr),
185205
snapshots
186206
.iter()
187207
.map(|(time, data)| (*time, #value))
@@ -190,13 +210,7 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
190210
predict_y,
191211
)],
192212
first.0..predict_x.map_or(last.0, |x| x.max(last.0)),
193-
({
194-
let data = &first.1;
195-
#value
196-
} * (7. / 8.))..(predict_y.max({
197-
let data = &last.1;
198-
#value
199-
}) * (8. / 7.)),
213+
(low * (7. / 8.))..(predict_y.max(high) * (8. / 7.)),
200214
None,
201215
background,
202216
)?;
@@ -211,7 +225,7 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
211225
#api::canvas::project::apply_bubbles(
212226
&mut surface,
213227
ctx,
214-
#translate::tr!(ctx, #tr).as_ref(),
228+
#translate::tr(ctx, #tr).as_ref(),
215229
&predict_y,
216230
&r,
217231
&x,
@@ -221,10 +235,10 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
221235
#api::canvas::project::apply_bubbles(
222236
&mut surface,
223237
ctx,
224-
#translate::tr!(ctx, #tr).as_ref(),
238+
#translate::tr(ctx, #tr).as_ref(),
225239
&predict_y,
226240
&r,
227-
&#translate::tr!(ctx, "never").as_ref(),
241+
&#translate::tr(ctx, "never").as_ref(),
228242
background,
229243
);
230244
}
@@ -283,7 +297,7 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
283297

284298
title.push_str(PLAIN);
285299
title.push(' ');
286-
title.push_str(#translate::tr!(ctx, Self::tr()).as_ref());
300+
title.push_str(#translate::tr(ctx, Self::tr()).as_ref());
287301

288302
embed.fields.push(#poise::serenity_prelude::EmbedField::new(title, log, true));
289303
embed
@@ -311,7 +325,7 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
311325

312326
#(#embed)*
313327

314-
embed.field(#translate::tr!(ctx, Self::tr()), field, true)
328+
embed.field(#translate::tr(ctx, Self::tr()), field, true)
315329
}
316330

317331
pub fn embed_diff(
@@ -328,7 +342,7 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
328342

329343
#(#embed_diff)*
330344

331-
embed.field(#translate::tr!(ctx, Self::tr()), field, true)
345+
embed.field(#translate::tr(ctx, Self::tr()), field, true)
332346
}
333347

334348
pub fn project(
@@ -355,11 +369,17 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
355369
let first = snapshots.first().unwrap();
356370
let last = snapshots.last().unwrap();
357371

358-
let lower = Self::min_fields(&first.1.stats.#path_to_game.#id, &first.1);
359-
let upper = ::std::cmp::max(Self::max_fields(&last.1.stats.#path_to_game.#id, &last.1), 100);
372+
let mut lower = Self::min_fields(&first.1.stats.#path_to_game.#id, &first.1);
373+
let mut upper = ::std::cmp::max(Self::max_fields(&first.1.stats.#path_to_game.#id, &first.1), 100);
374+
375+
for (_, data) in snapshots.iter().skip(1) {
376+
let stats = &data.stats.#path_to_game.#id;
377+
378+
lower = lower.min(Self::min_fields(stats, data));
379+
upper = upper.max(Self::max_fields(stats, data));
380+
}
360381

361382
let x_range = first.0.clone()..last.0.clone();
362-
let last_data = last.1.clone();
363383

364384
let v = ::std::vec![
365385
#(#chart,)*
@@ -376,7 +396,7 @@ pub(crate) fn impl_mode(tokens: &mut proc_macro2::TokenStream, state: &State, mo
376396

377397
let mut surface = #api::canvas::chart::canvas(&mut buffer)?;
378398

379-
#api::canvas::chart::apply_title(ctx, &mut surface, &last_data, &LABEL, background);
399+
#api::canvas::chart::apply_title(ctx, &mut surface, &last.1, &LABEL, background);
380400
#api::canvas::chart::round_corners(&mut surface);
381401

382402
Ok(#api::canvas::to_png(&mut surface))

0 commit comments

Comments
 (0)