diff --git a/src/core/meta.rs b/src/core/meta.rs index 5104abe..7987356 100644 --- a/src/core/meta.rs +++ b/src/core/meta.rs @@ -375,13 +375,12 @@ impl Meta { let context = Context { sync_rules: project.sync_rules.clone(), ignore_rules, - legacy_scripts: project.legacy_scripts, + legacy_scripts: project.legacy_scripts.unwrap_or(true), }; Self { - source: Source::new(), context, - keep_unknowns: project.keep_unknowns, + ..Self::default() } } } diff --git a/src/middleware/lua.rs b/src/middleware/lua.rs index 11fd89e..81a2f2c 100644 --- a/src/middleware/lua.rs +++ b/src/middleware/lua.rs @@ -3,7 +3,10 @@ use rbx_dom_weak::types::{Enum, Variant}; use std::{collections::HashMap, path::Path}; use super::FileType; -use crate::{core::snapshot::Snapshot, vfs::Vfs}; +use crate::{ + core::{meta::Context, snapshot::Snapshot}, + vfs::Vfs, +}; #[derive(Debug, Clone, PartialEq)] pub enum ScriptType { @@ -12,16 +15,6 @@ pub enum ScriptType { Module, } -impl ScriptType { - fn as_class(&self) -> &'static str { - match self { - ScriptType::Server => "Script", - ScriptType::Client => "LocalScript", - ScriptType::Module => "ModuleScript", - } - } -} - impl From for ScriptType { fn from(file_type: FileType) -> Self { match file_type { @@ -34,13 +27,23 @@ impl From for ScriptType { } #[profiling::function] -pub fn snapshot_lua(path: &Path, vfs: &Vfs, script_type: ScriptType) -> Result { - let mut snapshot = Snapshot::new().with_class(script_type.as_class()); +pub fn snapshot_lua(path: &Path, context: &Context, vfs: &Vfs, script_type: ScriptType) -> Result { + let (class_name, run_context) = match (context.use_legacy_scripts(), &script_type) { + (false, ScriptType::Server) => ("Script", Some(Variant::Enum(Enum::from_u32(1)))), + (false, ScriptType::Client) => ("Script", Some(Variant::Enum(Enum::from_u32(2)))), + (true, ScriptType::Server) => ("Script", Some(Variant::Enum(Enum::from_u32(0)))), + (true, ScriptType::Client) => ("LocalScript", None), + (_, ScriptType::Module) => ("ModuleScript", None), + }; + + let mut snapshot = Snapshot::new().with_class(class_name); let mut properties = HashMap::new(); let source = vfs.read_to_string(path)?; if script_type != ScriptType::Module { + let mut overridden = false; + if let Some(line) = source.lines().next() { if line.contains("--disable") { properties.insert(String::from("Disabled"), Variant::Bool(true)); @@ -49,13 +52,22 @@ pub fn snapshot_lua(path: &Path, vfs: &Vfs, script_type: ScriptType) -> Result Result { + fn middleware(&self, path: &Path, context: &Context, vfs: &Vfs) -> Result { let result = match self { FileType::Project => snapshot_project(path, vfs), FileType::InstanceData => unreachable!(), // FileType::ServerScript | FileType::ClientScript | FileType::ModuleScript => { - snapshot_lua(path, vfs, self.clone().into()) + snapshot_lua(path, context, vfs, self.clone().into()) } // FileType::StringValue => snapshot_txt(path, vfs), @@ -145,7 +145,7 @@ fn new_snapshot_file(path: &Path, context: &Context, vfs: &Vfs) -> Result