<commit_before>MapEditor = MapEditor or class()
core:import("CoreEditorWidgets")

local Editor = MapEditor
local Utils = BLE.Utils
local m = {}
function Editor:init()
    managers.editor = self
    if not PackageManager:loaded("core/packages/editor") then
        PackageManager:load("core/packages/editor")
    end

    self._current_continent = "world"
    self._grid_size = 1
    self._current_pos = Vector3()
    self._spawn_position = Vector3()
    self._snap_rotation = 90
    self._screen_borders = Utils:GetConvertedResolution()
    self._mul = 80
	self._camera_object = World:create_camera()
    self._camera_object:set_near_range(20)
	self._camera_object:set_far_range(BLE.Options:GetValue("Map/CameraFarClip"))
    self._camera_object:set_fov(BLE.Options:GetValue("Map/CameraFOV"))
	self._camera_object:set_position(Vector3(864, -789, 458))
	self._camera_object:set_rotation(Rotation(54.8002, -21.7002, 8.53774e-007))
	self._vp = managers.viewport:new_vp(0, 0, 1, 1, "MapEditor", 10)
	self._vp:set_camera(self._camera_object)
	self._camera_pos = self._camera_object:position()
	self._camera_rot = self._camera_object:rotation()
    self._editor_all = World:make_slot_mask(1, 10, 11, 15, 19, 29, 34, 35, 36, 37, 38, 39)
	self._con = managers.menu._controller
    self._move_widget = CoreEditorWidgets.MoveWidget:new(self)
    self._rotate_widget = CoreEditorWidgets.RotationWidget:new(self)
    self._undo_handler = UndoUnitHandler:new()

    self:set_use_surface_move(BLE.Options:GetValue("Map/SurfaceMove"))
    self:check_has_fix()

    self._idstrings = {
        ["@ID4f01cba97e94239b@"] = "x",
        ["@IDce15c901d9af3e30@"] = "y",
        ["@ID1a99fc522e3faad0@"] = "z",
        ["@IDc126f12c99c8804d@"] = "xy",
        ["@ID5dac81a18d09497c@"] = "xz",
        ["@ID0602a12dbeee9c14@"] = "yz",
    }
    
    self._toggle_trigger = BeardLib.Utils.Input:TriggerDataFromString(BLE.Options:GetValue("Input/ToggleMapEditor"))
    local normal = not Global.editor_safe_mode
    self._menu = MenuUI:new({
        background_color = Color.transparent,
        accent_color = BLE.Options:GetValue("AccentColor"),
        mouse_press = normal and callback(self, self, "mouse_pressed"),
        mouse_release = normal and callback(self, self, "mouse_released"),
        create_items = callback(self, self, "post_init"),
    })
end

--Who doesn't like a short code :P
function Editor:m() return m end

function Editor:post_init(menu)
    self.parts = m
    m.menu = UpperMenu:new(self, menu)
    m.status = StatusMenu:new(self, menu)
    m.world = WorldDataEditor:new(self, menu)
    m.mission = MissionEditor:new(self, menu)
    m.static = StaticEditor:new(self, menu)
    m.opt = InEditorOptions:new(self, menu)
    m.console = EditorConsole:new(self, menu)
    m.env = EnvEditor:new(self, menu)
    m.instances = InstancesEditor:new(self, menu)
    for name, manager in pairs(m) do
        manager.manager_name = name
    end

    m.menu:build_tabs()
    m.world:Switch()

    menu.mouse_move = callback(m.static, m.static, "mouse_moved")
    if self._has_fix then
        m.menu:toggle_widget("move")
    end
end

--functions
function Editor:animate_bg_fade()
    if not self._menu then
        return
    end
    
    local bg = self._menu._panel:rect({
        name = "Background",
        layer = 10000,
        color = BLE.Options:GetValue("BackgroundColor"):with_alpha(1),
    })
    play_anim(bg, {
        set = {alpha = 0},
        callback = function(o)
            if alive(o) then
                o:parent():destroy(o)
            end
        end,
        wait = 0.5,
    })
end

function Editor:check_has_fix()
    local unit = World:spawn_unit(Idstring("core/units/move_widget/move_widget"), Vector3())
    self._has_fix = World:raycast("ray", unit:position(), unit:position():with_z(100), "ray_type", "widget", "target_unit", unit) ~= nil
    unit:set_enabled(false)
    unit:set_slot(0)
end

function Editor:update_grid_size(value)
    self._grid_size = tonumber(value)
    for _, manager in pairs(m) do
        if manager.update_grid_size then
            manager:update_grid_size()
        end
    end
end

local dis = mvector3.distance
function Editor:SetRulerPoints()
    local start_pos = self._current_pos    
	if not self._end_pos then
        self._start_pos = start_pos
        self:Log("[RULER]Start position: " .. tostring(start_pos))
    else
        self:Log(string.format("[RULER]Length: %.2fm", dis(self._start_pos, self._end_pos) / 100))
        self:Log("[RULER]End position: " .. tostring(self._end_pos))
        self._end_pos = nil
        self._start_pos = nil
	end
end

function Editor:reset_widget_values()
    self._using_move_widget = false
    self._using_rotate_widget = false
    self._move_widget:reset_values()
    self._rotate_widget:reset_values()
end

function Editor:OnWidgetGrabbed()
    self:StorePreviousPosRot()
    self._old_units = self:selected_units()
end

function Editor:StorePreviousPosRot()
    for _, unit in pairs(self:selected_units()) do
        unit:unit_data()._prev_pos = unit:position()
        unit:unit_data()._prev_rot = unit:rotation()
    end
end

function Editor:Undo()
    self._undo_handler:Undo()
end

function Editor:OnWidgetReleased()
    local unit = self:selected_unit()
    if alive(self:widget_unit()) then
        if unit:unit_data()._prev_pos ~= self:widget_unit():position() then
            self:OnUnitPosChanged()
        end

        if unit:unit_data()._prev_rot ~= self:widget_unit():rotation() then
            self:OnUnitRotChanged()
        end
    end
end

function Editor:OnUnitPosChanged()
    self._undo_handler:SaveUnitValues(self._old_units, "pos")
end

function Editor:OnUnitRotChanged()
    self._undo_handler:SaveUnitValues(self._old_units, "rot")
end

function Editor:OnUnitDeleted()
    self:Log("Unit deleted!")
end

function Editor:OnUnitSpawned()
    self:Log("Unit spawned!")
end
<commit_msg>just in case<commit_after>MapEditor = MapEditor or class()
core:import("CoreEditorWidgets")

local Editor = MapEditor
local Utils = BLE.Utils
local m = {}
function Editor:init()
    managers.editor = self
    if not PackageManager:loaded("core/packages/editor") then
        PackageManager:load("core/packages/editor")
    end

    self._current_continent = "world"
    self._grid_size = 1
    self._current_pos = Vector3()
    self._spawn_position = Vector3()
    self._snap_rotation = 90
    self._screen_borders = Utils:GetConvertedResolution()
    self._mul = 80
	self._camera_object = World:create_camera()
    self._camera_object:set_near_range(20)
	self._camera_object:set_far_range(BLE.Options:GetValue("Map/CameraFarClip"))
    self._camera_object:set_fov(BLE.Options:GetValue("Map/CameraFOV"))
	self._camera_object:set_position(Vector3(864, -789, 458))
	self._camera_object:set_rotation(Rotation(54.8002, -21.7002, 8.53774e-007))
	self._vp = managers.viewport:new_vp(0, 0, 1, 1, "MapEditor", 10)
	self._vp:set_camera(self._camera_object)
	self._camera_pos = self._camera_object:position()
	self._camera_rot = self._camera_object:rotation()
    self._editor_all = World:make_slot_mask(1, 10, 11, 15, 19, 29, 34, 35, 36, 37, 38, 39)
	self._con = managers.menu._controller
    self._move_widget = CoreEditorWidgets.MoveWidget:new(self)
    self._rotate_widget = CoreEditorWidgets.RotationWidget:new(self)
    self._undo_handler = UndoUnitHandler:new()

    self:set_use_surface_move(BLE.Options:GetValue("Map/SurfaceMove"))
    self:check_has_fix()

    self._idstrings = {
        ["@ID4f01cba97e94239b@"] = "x",
        ["@IDce15c901d9af3e30@"] = "y",
        ["@ID1a99fc522e3faad0@"] = "z",
        ["@IDc126f12c99c8804d@"] = "xy",
        ["@ID5dac81a18d09497c@"] = "xz",
        ["@ID<PASSWORD>@"] = "yz",
    }
    
    self._toggle_trigger = BeardLib.Utils.Input:TriggerDataFromString(BLE.Options:GetValue("Input/ToggleMapEditor"))
    local normal = not Global.editor_safe_mode
    self._menu = MenuUI:new({
        background_color = Color.transparent,
        accent_color = BLE.Options:GetValue("AccentColor"),
        mouse_press = normal and callback(self, self, "mouse_pressed"),
        mouse_release = normal and callback(self, self, "mouse_released"),
        create_items = callback(self, self, "post_init"),
    })
end

--Who doesn't like a short code :P
function Editor:m() return m end

function Editor:post_init(menu)
    self.parts = m
    m.menu = UpperMenu:new(self, menu)
    m.status = StatusMenu:new(self, menu)
    m.world = WorldDataEditor:new(self, menu)
    m.mission = MissionEditor:new(self, menu)
    m.static = StaticEditor:new(self, menu)
    m.opt = InEditorOptions:new(self, menu)
    m.console = EditorConsole:new(self, menu)
    m.env = EnvEditor:new(self, menu)
    m.instances = InstancesEditor:new(self, menu)
    for name, manager in pairs(m) do
        manager.manager_name = name
    end

    m.menu:build_tabs()
    m.world:Switch()

    menu.mouse_move = callback(m.static, m.static, "mouse_moved")
    if self._has_fix then
        m.menu:toggle_widget("move")
    end
end

--functions
function Editor:animate_bg_fade()
    if not self._menu then
        return
    end
    
    local bg = self._menu._panel:rect({
        name = "Background",
        layer = 10000,
        color = BLE.Options:GetValue("BackgroundColor"):with_alpha(1),
    })
    play_anim(bg, {
        set = {alpha = 0},
        callback = function(o)
            if alive(o) then
                o:parent():destroy(o)
            end
        end,
        wait = 0.5,
    })
end

function Editor:check_has_fix()
    local unit = World:spawn_unit(Idstring("core/units/move_widget/move_widget"), Vector3())
    self._has_fix = World:raycast("ray", unit:position(), unit:position():with_z(100), "ray_type", "widget", "target_unit", unit) ~= nil
    unit:set_enabled(false)
    unit:set_slot(0)
end

function Editor:update_grid_size(value)
    self._grid_size = tonumber(value)
    for _, manager in pairs(m) do
        if manager.update_grid_size then
            manager:update_grid_size()
        end
    end
end

local dis = mvector3.distance
function Editor:SetRulerPoints()
    local start_pos = self._current_pos    
	if not self._end_pos then
        self._start_pos = start_pos
        self:Log("[RULER]Start position: " .. tostring(start_pos))
    else
        self:Log(string.format("[RULER]Length: %.2fm", dis(self._start_pos, self._end_pos) / 100))
        self:Log("[RULER]End position: " .. tostring(self._end_pos))
        self._end_pos = nil
        self._start_pos = nil
	end
end

function Editor:reset_widget_values()
    self._using_move_widget = false
    self._using_rotate_widget = false
    self._move_widget:reset_values()
    self._rotate_widget:reset_values()
end

function Editor:OnWidgetGrabbed()
    self:StorePreviousPosRot()
    self._old_units = self:selected_units()
end

function Editor:StorePreviousPosRot()
    for _, unit in pairs(self:selected_units()) do
        unit:unit_data()._prev_pos = unit:position()
        unit:unit_data()._prev_rot = unit:rotation()
    end
end

function Editor:Undo()
    self._undo_handler:Undo()
    m.static:recalc_all_locals()
end

function Editor:OnWidgetReleased()
    local unit = self:selected_unit()
    if alive(self:widget_unit()) then
        if unit:unit_data()._prev_pos ~= self:widget_unit():position() then
            self:OnUnitPosChanged()
        end

        if unit:unit_data()._prev_rot ~= self:widget_unit():rotation() then
            self:OnUnitRotChanged()
        end
    end
end

function Editor:OnUnitPosChanged()
    self._undo_handler:SaveUnitValues(self._old_units, "pos")
end

function Editor:OnUnitRotChanged()
    self._undo_handler:SaveUnitValues(self._old_units, "rot")
end

function Editor:OnUnitDeleted()
    self:Log("Unit deleted!")
end

function Editor:OnUnitSpawned()
    self:Log("Unit spawned!")
end

{'fraction_non_alphanumeric': 0.12402969962875464, 'fraction_numerical': 0.023709078636517042, 'mean_word_length': 3.6537102473498235, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6070820', 'n_tokens_mistral': 4152, 'n_tokens_neox': 3956, 'n_words': 727}