compilation fixes
Guide for compilation fixes
Compilation Fixes - UI Phase 1 Completion
Purpose
This document tracks the compilation errors encountered after the initial Skills UI revamp and their resolutions.
Errors Fixed (Steps 655-661)
Error 1: Duplicate Field in UiAssets
Problem:
error[E0124]: field `farming_icon` is already declared
--> src/systems/ui/mod.rs:131:5Cause: The
farming_icon field was declared twice in the UiAssets struct.Fix:
// src/systems/ui/mod.rs (line 131)
// REMOVED: pub farming_icon: Handle<Image>,
// (kept only the first declaration at line 130)Error 2: Invalid Derive on Type Alias
Problem:
error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s
--> src/systems/ui/mod.rs:194:1Cause: Attempted to use
#[derive] macro on a pub use type alias.Original Code:
#[derive(Default, PartialEq, Eq, Clone, Copy, Debug, Resource)]
pub use crate::systems::combat::Style as AttackStyle;Fix:
// src/systems/ui/mod.rs (line 194)
// REMOVED: #[derive(Default, PartialEq, Eq, Clone, Copy, Debug, Resource)]
pub use crate::systems::combat::Style as AttackStyle;Explanation: Type aliases inherit traits from the original type. The derives must be on the source
Style enum, not the alias.Error 3: Color32::black() Not Found
Problem:
error[E0599]: no function or associated item named `black` found for struct `Color32`
--> src/systems/ui/skills_ui.rs:99:55Cause:
egui::Color32::black() is not a valid method in egui 0.28.Original Code:
.stroke(egui::Stroke::new(1.0, egui::Color32::black()))Fix:
// src/systems/ui/skills_ui.rs (line 99)
.stroke(egui::Stroke::new(1.0, egui::Color32::BLACK))Explanation: Use the
BLACK constant instead of a black() method.Error 4: Missing Default Trait on Style Enum
Problem:
error[E0277]: the trait bound `Style: Default` is not satisfied
--> src/systems/ui/mod.rs:169:5Cause:
UiState struct has a field selected_attack_style: AttackStyle (which is an alias to Style), and UiState derives Default, but Style didn't implement Default.Fix:
// src/systems/combat/mod.rs (lines 114-121)
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Style {
#[default]
Accurate, // +3 Attack
Aggressive, // +3 Strength
Defensive, // +3 Defense
Controlled, // +1 to all
Longrange, // [NEW] Ranged/Magic defensive
}Changes:
- Added
PartialEqandEqderives (needed for comparison) - Added
Defaultderive with#[default]attribute onAccuratevariant
Verification
After these fixes, the project compiled successfully:
$ cargo run --bin legends_client
Compiling legends_client v0.1.0 (/home/ecom-nithinm/Documents/loh/loh-game)
warning: unused import: `ItemId`
--> src/systems/skills/mining.rs:7:55
|
7 | ...AddItemEvent, ItemId, item_id};
| ^^^^^^
# ... (other warnings, but no errors)
Building [==================> ] 760/762Lessons Learned
- Type Aliases Don't Accept Derives: Always add trait implementations to the original type, not the alias.
- egui API Changes:
Color32::BLACK(constant) vsColor32::black()(non-existent method). - Default Trait Requirements: When using
#[derive(Default)]on a struct, all fields must implementDefault. - Duplicate Field Detection: Rust's error messages clearly identify duplicate struct fields with line numbers.
Phase 2 Compilation Fixes (Menu Toggle Implementation)
Error 5: Missing menu_open Field
Problem:
Attempted to use
ui_state.menu_open but the field didn't exist in UiState struct.Cause: Menu toggle functionality was added without updating the
UiState struct definition.Fix:
// src/systems/ui/mod.rs (lines 166-181)
#[derive(Resource)]
pub struct UiState {
pub active_tab: UiTab,
pub selected_attack_style: AttackStyle,
pub active_menu: Option<ActiveMenu>,
pub menu_open: bool, // [NEW]
}
impl Default for UiState {
fn default() -> Self {
Self {
active_tab: UiTab::default(),
selected_attack_style: AttackStyle::default(),
active_menu: None,
menu_open: true, // Start with menu open
}
}
}Explanation:
- Removed
#[derive(Default)]from struct because we need custom default logic - Implemented
Defaulttrait manually to setmenu_open: trueby default - This allows the menu to be visible on startup
Error 6: Missing ActiveQuests Import
Problem:
error[E0412]: cannot find type `ActiveQuests` in this scope
--> src/systems/ui/mod.rs:363:111Cause: Attempted to use
ActiveQuests type without importing it.Fix:
// src/systems/ui/mod.rs (line 5)
use crate::systems::quests::quest_system::ActiveQuests;Note: This import was added but ultimately not used in the final implementation. The Quests tab was simplified to just show "No active quests" placeholder text instead of attempting to access quest data through egui context.
Error 7: Undefined render_combat_tab Function
Problem:
Attempted to call
render_combat_tab(ui, ¶ms, &mut ui_state, &mut combat_style_writer) but function didn't exist.Cause: Placeholder function call from incomplete refactoring.
Fix:
Inlined the combat tab rendering logic directly in the match statement instead of extracting to a separate function:
// src/systems/ui/mod.rs (lines 366-422)
UiTab::Combat => {
ui.heading("Combat");
ui.separator();
if let Ok((player_entity, _, _)) = player_q.get_single() {
let mut combat_level = 3;
if let Ok(skills) = skills_q.get(player_entity) {
combat_level = skills.get_combat_level();
}
// ... full combat UI implementation ...
}
}Explanation: Extracting to a separate function would require passing many parameters, so keeping it inline is simpler for now.
Verification (Phase 2)
After Phase 2 fixes, the project compiled successfully:
$ cargo check --bin legends_client
Checking legends_client v0.1.0 (/home/ecom-nithinm/Documents/loh/loh-game)
warning: unused import: `crate::systems::quests::quest_system::ActiveQuests`
--> src/systems/ui/mod.rs:5:5
# ... (other warnings, but no errors)
Finished `dev` profile [optimized + debuginfo] target(s) in 8.04sRelated Documents
- egui API Changes - Comprehensive guide to egui 0.28 API changes
- Skills UI Revamp - The UI changes that triggered these errors