mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Refactor get_best_middleware function by removing static JSON model classes and simplifying middleware selection logic for improved clarity and maintainability.
This commit is contained in:
parent
2dfcac4ef7
commit
9e270bd847
1 changed files with 3 additions and 64 deletions
|
|
@ -303,57 +303,6 @@ pub struct SyncbackReturn<'sync> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_best_middleware(snapshot: &SyncbackSnapshot) -> Middleware {
|
pub fn get_best_middleware(snapshot: &SyncbackSnapshot) -> Middleware {
|
||||||
// At some point, we're better off using an O(1) method for checking
|
|
||||||
// equality for classes like this.
|
|
||||||
static JSON_MODEL_CLASSES: OnceLock<HashSet<&str>> = OnceLock::new();
|
|
||||||
let json_model_classes = JSON_MODEL_CLASSES.get_or_init(|| {
|
|
||||||
[
|
|
||||||
"Sound",
|
|
||||||
"SoundGroup",
|
|
||||||
"Sky",
|
|
||||||
"Atmosphere",
|
|
||||||
"BloomEffect",
|
|
||||||
"BlurEffect",
|
|
||||||
"ColorCorrectionEffect",
|
|
||||||
"DepthOfFieldEffect",
|
|
||||||
"SunRaysEffect",
|
|
||||||
"ParticleEmitter",
|
|
||||||
"TextChannel",
|
|
||||||
"TextChatCommand",
|
|
||||||
// TODO: Implement a way to use inheritance for this
|
|
||||||
"ChatWindowConfiguration",
|
|
||||||
"ChatInputBarConfiguration",
|
|
||||||
"BubbleChatConfiguration",
|
|
||||||
"ChannelTabsConfiguration",
|
|
||||||
// GUI elements
|
|
||||||
"Frame",
|
|
||||||
"TextLabel",
|
|
||||||
"ImageLabel",
|
|
||||||
"TextButton",
|
|
||||||
"ImageButton",
|
|
||||||
"TextBox",
|
|
||||||
"ScrollingFrame",
|
|
||||||
"ViewportFrame",
|
|
||||||
"VideoFrame",
|
|
||||||
"CanvasGroup",
|
|
||||||
// UI layout/constraint classes
|
|
||||||
"UIListLayout",
|
|
||||||
"UIGridLayout",
|
|
||||||
"UITableLayout",
|
|
||||||
"UIPageLayout",
|
|
||||||
"UIFlexItem",
|
|
||||||
"UIPadding",
|
|
||||||
"UICorner",
|
|
||||||
"UIStroke",
|
|
||||||
"UIGradient",
|
|
||||||
"UIScale",
|
|
||||||
"UISizeConstraint",
|
|
||||||
"UITextSizeConstraint",
|
|
||||||
"UIAspectRatioConstraint",
|
|
||||||
]
|
|
||||||
.into()
|
|
||||||
});
|
|
||||||
|
|
||||||
let old_middleware = snapshot
|
let old_middleware = snapshot
|
||||||
.old_inst()
|
.old_inst()
|
||||||
.and_then(|inst| inst.metadata().middleware);
|
.and_then(|inst| inst.metadata().middleware);
|
||||||
|
|
@ -365,9 +314,8 @@ pub fn get_best_middleware(snapshot: &SyncbackSnapshot) -> Middleware {
|
||||||
return override_middleware;
|
return override_middleware;
|
||||||
} else if let Some(old_middleware) = old_middleware {
|
} else if let Some(old_middleware) = old_middleware {
|
||||||
return old_middleware;
|
return old_middleware;
|
||||||
} else if json_model_classes.contains(inst.class.as_str()) {
|
|
||||||
middleware = Middleware::JsonModel;
|
|
||||||
} else {
|
} else {
|
||||||
|
// Specific classes that need special middleware, everything else defaults to JsonModel
|
||||||
middleware = match inst.class.as_str() {
|
middleware = match inst.class.as_str() {
|
||||||
"Folder" | "Configuration" | "Tool" | "ScreenGui" | "SurfaceGui" | "BillboardGui"
|
"Folder" | "Configuration" | "Tool" | "ScreenGui" | "SurfaceGui" | "BillboardGui"
|
||||||
| "AdGui" => Middleware::Dir,
|
| "AdGui" => Middleware::Dir,
|
||||||
|
|
@ -376,9 +324,8 @@ pub fn get_best_middleware(snapshot: &SyncbackSnapshot) -> Middleware {
|
||||||
"LocalScript" => Middleware::ClientScript,
|
"LocalScript" => Middleware::ClientScript,
|
||||||
"ModuleScript" => Middleware::ModuleScript,
|
"ModuleScript" => Middleware::ModuleScript,
|
||||||
"LocalizationTable" => Middleware::Csv,
|
"LocalizationTable" => Middleware::Csv,
|
||||||
// This isn't the ideal way to handle this but it works.
|
// Default: use JsonModel for everything else (becomes Dir if has children)
|
||||||
name if name.ends_with("Value") => Middleware::JsonModel,
|
_ => Middleware::JsonModel,
|
||||||
_ => Middleware::Rbxm,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,14 +340,6 @@ pub fn get_best_middleware(snapshot: &SyncbackSnapshot) -> Middleware {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if middleware == Middleware::Rbxm {
|
|
||||||
middleware = match env::var(DEBUG_MODEL_FORMAT_VAR) {
|
|
||||||
Ok(value) if value == "1" => Middleware::Rbxmx,
|
|
||||||
Ok(value) if value == "2" => Middleware::JsonModel,
|
|
||||||
_ => Middleware::Rbxm,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
middleware
|
middleware
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue