Skip to content

Commit 0c6dfee

Browse files
gajopclaude
andcommitted
Order every file public-before-private
Clear the pre-existing lint-rust-step-down backlog: within each module and impl block, public items now come before private helpers. Pure reordering of existing functions — no behaviour change. `just lint` is now fully green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b8ea7df commit 0c6dfee

11 files changed

Lines changed: 424 additions & 424 deletions

File tree

native/src/sbc/map_settings/ui/water/model.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,6 @@ pub(crate) enum WaterField {
3333

3434
use WaterField::*;
3535

36-
fn num(name: &'static str, title: &'static str) -> Box<NumericField> {
37-
Box::new(NumericField::new(name, title, 0.0).decimals(2))
38-
}
39-
40-
/// Water textures live under the engine VFS's `bitmaps/`, as in
41-
/// `water_editor.lua` — that is engine content, not an asset pack, so the
42-
/// picker browses the VFS directly.
43-
fn tex(name: &'static str, title: &'static str) -> Box<AssetField> {
44-
Box::new(
45-
AssetField::new(name, title, "vfs:bitmaps")
46-
.extensions(&[".png", ".jpg", ".tga", ".dds", ".bmp"]),
47-
)
48-
}
49-
5036
/// Every field here is a key of `SetWaterParamsCommand`'s options, so the
5137
/// dispatch is uniform: send the one field that changed.
5238
///
@@ -104,3 +90,17 @@ pub(crate) fn water_model() -> TableModel<WaterField> {
10490
entry(Texture, tex("texture", "Texture")),
10591
])
10692
}
93+
94+
fn num(name: &'static str, title: &'static str) -> Box<NumericField> {
95+
Box::new(NumericField::new(name, title, 0.0).decimals(2))
96+
}
97+
98+
/// Water textures live under the engine VFS's `bitmaps/`, as in
99+
/// `water_editor.lua` — that is engine content, not an asset pack, so the
100+
/// picker browses the VFS directly.
101+
fn tex(name: &'static str, title: &'static str) -> Box<AssetField> {
102+
Box::new(
103+
AssetField::new(name, title, "vfs:bitmaps")
104+
.extensions(&[".png", ".jpg", ".tga", ".dds", ".bmp"]),
105+
)
106+
}

native/src/sbc/objects/ui/properties/model.rs

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ impl Position {
4343
})
4444
}
4545

46+
pub(super) fn json(self) -> serde_json::Value {
47+
serde_json::json!({ "x": self.x, "y": self.y, "z": self.z })
48+
}
49+
4650
fn from_fields(model: &PropertiesModel, field: &str) -> Self {
4751
Self {
4852
x: model.number(&component_name(field, "x")),
@@ -66,10 +70,6 @@ impl Position {
6670
z: self.z - other.z,
6771
}
6872
}
69-
70-
pub(super) fn json(self) -> serde_json::Value {
71-
serde_json::json!({ "x": self.x, "y": self.y, "z": self.z })
72-
}
7373
}
7474

7575
#[derive(Clone)]
@@ -84,15 +84,28 @@ pub(super) fn is_angle(field: &str) -> bool {
8484
field == "rot"
8585
}
8686

87+
pub(super) fn sub_parts(name: &str) -> Option<(&str, &str)> {
88+
name.split_once('.')
89+
}
90+
91+
pub(super) fn number_f(value: &serde_json::Value) -> f32 {
92+
value.as_f64().unwrap_or(0.0) as f32
93+
}
94+
95+
pub(super) fn component_name(field: &str, axis: &str) -> String {
96+
format!("{field}_{axis}")
97+
}
98+
99+
pub(super) fn component(name: &str) -> Option<(&str, &str)> {
100+
let (field, axis) = name.rsplit_once('_')?;
101+
matches!(axis, "x" | "y" | "z").then_some((field, axis))
102+
}
103+
87104
/// A sub-object's field, named `parent.key` (Lua's `name .. tkey`).
88105
fn sub_name(parent: &str, key: &str) -> String {
89106
format!("{parent}.{key}")
90107
}
91108

92-
pub(super) fn sub_parts(name: &str) -> Option<(&str, &str)> {
93-
name.split_once('.')
94-
}
95-
96109
/// Lua sends only the changed key for these, rather than the whole table: the
97110
/// setters apply the keys they are given, and resending the rest would fight
98111
/// with the engine's own bookkeeping.
@@ -143,27 +156,12 @@ impl PropertiesModel {
143156
}
144157
}
145158

146-
fn value(&self, name: &str) -> FieldValue {
147-
self.fields
148-
.iter()
149-
.find(|field| field.name() == name)
150-
.map(|field| field.value())
151-
.unwrap_or(FieldValue::Text(String::new()))
152-
}
153-
154159
pub(super) fn set(&mut self, name: &str, value: FieldValue) {
155160
if let Some(field) = self.fields.iter_mut().find(|field| field.name() == name) {
156161
field.set_value(&value);
157162
}
158163
}
159164

160-
fn number(&self, name: &str) -> f32 {
161-
match self.value(name) {
162-
FieldValue::Number(n) => n,
163-
_ => 0.0,
164-
}
165-
}
166-
167165
/// Build the fields for one object.
168166
///
169167
/// Generic sub-objects (`states`, `resources`, ...) and the rules map have
@@ -370,6 +368,55 @@ impl PropertiesModel {
370368
.collect()
371369
}
372370

371+
pub(super) fn set_json_field(&mut self, name: &str, value: &serde_json::Value) {
372+
// The team choice shows names, so the stored id has to be mapped back.
373+
if name == "team" {
374+
if let Some(team) = value.as_i64().and_then(|id| self.team_name(id as i32)) {
375+
self.set(name, FieldValue::Text(team));
376+
}
377+
return;
378+
}
379+
if let Some(value) = value.as_bool() {
380+
self.set(name, FieldValue::Bool(value));
381+
} else if let Some(value) = value.as_str() {
382+
self.set(name, FieldValue::Text(value.to_string()));
383+
} else if value.is_number() {
384+
self.set(name, number(value));
385+
}
386+
}
387+
388+
/// The reverse of `sub_value`: put a sub-object key into its field.
389+
pub(super) fn set_sub_field(&mut self, name: &str, key: &str, value: &serde_json::Value) {
390+
let captions = match key {
391+
"fireState" => Some(FIRE_STATES),
392+
"moveState" => Some(MOVE_STATES),
393+
_ => None,
394+
};
395+
if let Some(captions) = captions {
396+
let index = value.as_i64().unwrap_or(0) as usize;
397+
if let Some(caption) = captions.get(index) {
398+
self.set(name, FieldValue::Text((*caption).to_string()));
399+
}
400+
return;
401+
}
402+
self.set_json_field(name, value);
403+
}
404+
405+
fn value(&self, name: &str) -> FieldValue {
406+
self.fields
407+
.iter()
408+
.find(|field| field.name() == name)
409+
.map(|field| field.value())
410+
.unwrap_or(FieldValue::Text(String::new()))
411+
}
412+
413+
fn number(&self, name: &str) -> f32 {
414+
match self.value(name) {
415+
FieldValue::Number(n) => n,
416+
_ => 0.0,
417+
}
418+
}
419+
373420
fn sub_fields_of(&self, parent: &str) -> Vec<String> {
374421
self.layout
375422
.iter()
@@ -413,40 +460,6 @@ impl PropertiesModel {
413460
.find(|(team_id, _)| *team_id == id)
414461
.map(|(_, name)| name.clone())
415462
}
416-
417-
pub(super) fn set_json_field(&mut self, name: &str, value: &serde_json::Value) {
418-
// The team choice shows names, so the stored id has to be mapped back.
419-
if name == "team" {
420-
if let Some(team) = value.as_i64().and_then(|id| self.team_name(id as i32)) {
421-
self.set(name, FieldValue::Text(team));
422-
}
423-
return;
424-
}
425-
if let Some(value) = value.as_bool() {
426-
self.set(name, FieldValue::Bool(value));
427-
} else if let Some(value) = value.as_str() {
428-
self.set(name, FieldValue::Text(value.to_string()));
429-
} else if value.is_number() {
430-
self.set(name, number(value));
431-
}
432-
}
433-
434-
/// The reverse of `sub_value`: put a sub-object key into its field.
435-
pub(super) fn set_sub_field(&mut self, name: &str, key: &str, value: &serde_json::Value) {
436-
let captions = match key {
437-
"fireState" => Some(FIRE_STATES),
438-
"moveState" => Some(MOVE_STATES),
439-
_ => None,
440-
};
441-
if let Some(captions) = captions {
442-
let index = value.as_i64().unwrap_or(0) as usize;
443-
if let Some(caption) = captions.get(index) {
444-
self.set(name, FieldValue::Text((*caption).to_string()));
445-
}
446-
return;
447-
}
448-
self.set_json_field(name, value);
449-
}
450463
}
451464

452465
impl EditorModel for PropertiesModel {
@@ -488,10 +501,6 @@ fn number(value: &serde_json::Value) -> FieldValue {
488501
FieldValue::Number(number_f(value))
489502
}
490503

491-
pub(super) fn number_f(value: &serde_json::Value) -> f32 {
492-
value.as_f64().unwrap_or(0.0) as f32
493-
}
494-
495504
fn index_of(captions: &[&str], value: &str) -> i32 {
496505
captions
497506
.iter()
@@ -552,15 +561,6 @@ fn sub_field(name: &str, key: &str, value: &serde_json::Value) -> Option<Box<dyn
552561
None
553562
}
554563

555-
pub(super) fn component_name(field: &str, axis: &str) -> String {
556-
format!("{field}_{axis}")
557-
}
558-
559-
pub(super) fn component(name: &str) -> Option<(&str, &str)> {
560-
let (field, axis) = name.rsplit_once('_')?;
561-
matches!(axis, "x" | "y" | "z").then_some((field, axis))
562-
}
563-
564564
fn title(name: &str) -> String {
565565
let mut out = String::new();
566566
for (i, ch) in name.chars().enumerate() {

native/src/sbc/panels/controls/asset_picker.rs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -59,53 +59,6 @@ impl AssetPicker {
5959
self.field.as_deref()
6060
}
6161

62-
fn markup_rml(&self) -> String {
63-
format!(
64-
concat!(
65-
r#"<div id="asset-picker" class="picker-backdrop hidden">"#,
66-
r#"<div class="dialog picker-dialog asset-dialog">"#,
67-
r#"<div class="dialog-header"><span class="dialog-title">Pick Asset</span></div>"#,
68-
r#"<div class="dialog-content">"#,
69-
r#"<div class="asset-path-nav">"#,
70-
r#"<button id="asset-up" class="dialog-button">Up</button>"#,
71-
r#"<span id="asset-path" class="asset-path"></span></div>"#,
72-
r#"{grid}"#,
73-
r#"</div>"#,
74-
r#"<div class="dialog-footer">"#,
75-
r#"<button id="asset-ok" class="dialog-button primary">OK</button>"#,
76-
r#"<button id="asset-cancel" class="dialog-button">Cancel</button>"#,
77-
r#"</div></div></div>"#,
78-
),
79-
grid = self.grid.container_rml(),
80-
)
81-
}
82-
83-
fn bind_listeners(
84-
&mut self,
85-
interface: &NativeInterfaceRef,
86-
document: u64,
87-
) -> Result<(), Error> {
88-
if self.bound {
89-
return Ok(());
90-
}
91-
let rml = interface.rml_ui();
92-
for (id, event) in [
93-
("asset-ok", PickerEvent::Accept),
94-
("asset-cancel", PickerEvent::Cancel),
95-
("asset-up", PickerEvent::Up),
96-
] {
97-
let Some(e) = element_by_id(interface, document, id) else {
98-
continue;
99-
};
100-
let q = self.events.clone();
101-
rml.element_add_event_listener(e, "click", false, move || {
102-
q.borrow_mut().push(event);
103-
})?;
104-
}
105-
self.bound = true;
106-
Ok(())
107-
}
108-
10962
pub(crate) fn open(
11063
&mut self,
11164
interface: &NativeInterfaceRef,
@@ -193,6 +146,53 @@ impl AssetPicker {
193146
Ok(None)
194147
}
195148

149+
fn markup_rml(&self) -> String {
150+
format!(
151+
concat!(
152+
r#"<div id="asset-picker" class="picker-backdrop hidden">"#,
153+
r#"<div class="dialog picker-dialog asset-dialog">"#,
154+
r#"<div class="dialog-header"><span class="dialog-title">Pick Asset</span></div>"#,
155+
r#"<div class="dialog-content">"#,
156+
r#"<div class="asset-path-nav">"#,
157+
r#"<button id="asset-up" class="dialog-button">Up</button>"#,
158+
r#"<span id="asset-path" class="asset-path"></span></div>"#,
159+
r#"{grid}"#,
160+
r#"</div>"#,
161+
r#"<div class="dialog-footer">"#,
162+
r#"<button id="asset-ok" class="dialog-button primary">OK</button>"#,
163+
r#"<button id="asset-cancel" class="dialog-button">Cancel</button>"#,
164+
r#"</div></div></div>"#,
165+
),
166+
grid = self.grid.container_rml(),
167+
)
168+
}
169+
170+
fn bind_listeners(
171+
&mut self,
172+
interface: &NativeInterfaceRef,
173+
document: u64,
174+
) -> Result<(), Error> {
175+
if self.bound {
176+
return Ok(());
177+
}
178+
let rml = interface.rml_ui();
179+
for (id, event) in [
180+
("asset-ok", PickerEvent::Accept),
181+
("asset-cancel", PickerEvent::Cancel),
182+
("asset-up", PickerEvent::Up),
183+
] {
184+
let Some(e) = element_by_id(interface, document, id) else {
185+
continue;
186+
};
187+
let q = self.events.clone();
188+
rml.element_add_event_listener(e, "click", false, move || {
189+
q.borrow_mut().push(event);
190+
})?;
191+
}
192+
self.bound = true;
193+
Ok(())
194+
}
195+
196196
fn set_visible(
197197
&self,
198198
interface: &NativeInterfaceRef,

0 commit comments

Comments
 (0)