mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-16 22:19:25 +07:00
don't clone hidden fragments (while they are not explicit)
This commit is contained in:
@@ -5,7 +5,7 @@ local evo = require 'evolved'
|
|||||||
|
|
||||||
evo.debug_mode(true)
|
evo.debug_mode(true)
|
||||||
|
|
||||||
do
|
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == nil then
|
||||||
local i = evo.id()
|
local i = evo.id()
|
||||||
|
|
||||||
for _ = 1, 0xFFFFE do
|
for _ = 1, 0xFFFFE do
|
||||||
@@ -6156,3 +6156,82 @@ do
|
|||||||
assert(evo.has(e3g, f3) and evo.get(e3g, f3) == 33)
|
assert(evo.has(e3g, f3) and evo.get(e3g, f3) == 33)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local f1, f2, f3 = evo.id(3)
|
||||||
|
|
||||||
|
evo.set(f2, evo.HIDDEN)
|
||||||
|
evo.set(f3, evo.HIDDEN)
|
||||||
|
|
||||||
|
do
|
||||||
|
local p = evo.spawn { [f1] = 11, [f2] = 22 }
|
||||||
|
local e = evo.clone(p)
|
||||||
|
|
||||||
|
assert(evo.has(p, f1) and evo.get(p, f1) == 11)
|
||||||
|
assert(evo.has(p, f2) and evo.get(p, f2) == 22)
|
||||||
|
|
||||||
|
assert(evo.has(e, f1) and evo.get(e, f1) == 11)
|
||||||
|
assert(not evo.has(e, f2) and evo.get(e, f2) == nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local p = evo.spawn { [f1] = 11, [f2] = 22, [f3] = 33 }
|
||||||
|
local e = evo.clone(p)
|
||||||
|
|
||||||
|
assert(evo.has(p, f1) and evo.get(p, f1) == 11)
|
||||||
|
assert(evo.has(p, f2) and evo.get(p, f2) == 22)
|
||||||
|
assert(evo.has(p, f3) and evo.get(p, f3) == 33)
|
||||||
|
|
||||||
|
assert(evo.has(e, f1) and evo.get(e, f1) == 11)
|
||||||
|
assert(not evo.has(e, f2) and evo.get(e, f2) == nil)
|
||||||
|
assert(not evo.has(e, f3) and evo.get(e, f3) == nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local p = evo.spawn { [f2] = 22 }
|
||||||
|
local e = evo.clone(p)
|
||||||
|
|
||||||
|
assert(not evo.has(p, f1) and evo.get(p, f1) == nil)
|
||||||
|
assert(evo.has(p, f2) and evo.get(p, f2) == 22)
|
||||||
|
assert(not evo.has(p, f3) and evo.get(p, f3) == nil)
|
||||||
|
|
||||||
|
assert(not evo.has(e, f1) and evo.get(e, f1) == nil)
|
||||||
|
assert(not evo.has(e, f2) and evo.get(e, f2) == nil)
|
||||||
|
assert(not evo.has(e, f3) and evo.get(e, f3) == nil)
|
||||||
|
end
|
||||||
|
do
|
||||||
|
local p = evo.spawn { [f2] = 22, [f3] = 33 }
|
||||||
|
local e = evo.clone(p)
|
||||||
|
|
||||||
|
assert(not evo.has(p, f1) and evo.get(p, f1) == nil)
|
||||||
|
assert(evo.has(p, f2) and evo.get(p, f2) == 22)
|
||||||
|
assert(evo.has(p, f3) and evo.get(p, f3) == 33)
|
||||||
|
|
||||||
|
assert(not evo.has(e, f1) and evo.get(e, f1) == nil)
|
||||||
|
assert(not evo.has(e, f2) and evo.get(e, f2) == nil)
|
||||||
|
assert(not evo.has(e, f3) and evo.get(e, f3) == nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local p = evo.spawn { [f1] = 11, [f2] = 22 }
|
||||||
|
local e = evo.clone(p, { [f2] = 2 })
|
||||||
|
|
||||||
|
assert(evo.has(p, f1) and evo.get(p, f1) == 11)
|
||||||
|
assert(evo.has(p, f2) and evo.get(p, f2) == 22)
|
||||||
|
|
||||||
|
assert(evo.has(e, f1) and evo.get(e, f1) == 11)
|
||||||
|
assert(evo.has(e, f2) and evo.get(e, f2) == 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
do
|
||||||
|
local p = evo.spawn { [f1] = 11, [f2] = 22 }
|
||||||
|
local e = evo.clone(p, { [f2] = 2, [f3] = 3 })
|
||||||
|
|
||||||
|
assert(evo.has(p, f1) and evo.get(p, f1) == 11)
|
||||||
|
assert(evo.has(p, f2) and evo.get(p, f2) == 22)
|
||||||
|
|
||||||
|
assert(evo.has(e, f1) and evo.get(e, f1) == 11)
|
||||||
|
assert(evo.has(e, f2) and evo.get(e, f2) == 2)
|
||||||
|
assert(evo.has(e, f3) and evo.get(e, f3) == 3)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
98
evolved.lua
98
evolved.lua
@@ -1225,6 +1225,32 @@ local function __chunk_without_fragments(chunk, ...)
|
|||||||
return chunk
|
return chunk
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param chunk? evolved.chunk
|
||||||
|
---@return evolved.chunk?
|
||||||
|
---@nodiscard
|
||||||
|
local function __chunk_without_hidden_fragments(chunk)
|
||||||
|
if not chunk then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if not chunk.__has_hidden_fragments then
|
||||||
|
return chunk
|
||||||
|
end
|
||||||
|
|
||||||
|
local chunk_fragment_list = chunk.__fragment_list
|
||||||
|
local chunk_fragment_count = chunk.__fragment_count
|
||||||
|
|
||||||
|
for i = chunk_fragment_count, 1, -1 do
|
||||||
|
local fragment = chunk_fragment_list[i]
|
||||||
|
|
||||||
|
if __evolved_has(fragment, __HIDDEN) then
|
||||||
|
chunk = __chunk_without_fragment(chunk, fragment)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return chunk
|
||||||
|
end
|
||||||
|
|
||||||
---
|
---
|
||||||
---
|
---
|
||||||
---
|
---
|
||||||
@@ -1660,7 +1686,9 @@ local function __clone_entity(entity, prefab, components)
|
|||||||
local prefab_chunk = __entity_chunks[prefab_index]
|
local prefab_chunk = __entity_chunks[prefab_index]
|
||||||
local prefab_place = __entity_places[prefab_index]
|
local prefab_place = __entity_places[prefab_index]
|
||||||
|
|
||||||
local chunk = __chunk_with_components(prefab_chunk, components)
|
local chunk = __chunk_with_components(
|
||||||
|
__chunk_without_hidden_fragments(prefab_chunk),
|
||||||
|
components)
|
||||||
|
|
||||||
if not chunk then
|
if not chunk then
|
||||||
return
|
return
|
||||||
@@ -1694,46 +1722,50 @@ local function __clone_entity(entity, prefab, components)
|
|||||||
if prefab_chunk.__has_setup_hooks then
|
if prefab_chunk.__has_setup_hooks then
|
||||||
for prefab_component_index = 1, prefab_component_count do
|
for prefab_component_index = 1, prefab_component_count do
|
||||||
local fragment = prefab_component_fragments[prefab_component_index]
|
local fragment = prefab_component_fragments[prefab_component_index]
|
||||||
|
|
||||||
---@type evolved.duplicate?
|
|
||||||
local fragment_duplicate =
|
|
||||||
__evolved_get(fragment, __DUPLICATE)
|
|
||||||
|
|
||||||
local prefab_component_storage = prefab_component_storages[prefab_component_index]
|
|
||||||
local prefab_component = prefab_component_storage[prefab_place]
|
|
||||||
|
|
||||||
local new_component = prefab_component
|
|
||||||
|
|
||||||
if new_component ~= nil and fragment_duplicate then
|
|
||||||
new_component = fragment_duplicate(new_component)
|
|
||||||
end
|
|
||||||
|
|
||||||
if new_component == nil then
|
|
||||||
new_component = true
|
|
||||||
end
|
|
||||||
|
|
||||||
local component_index = chunk_component_indices[fragment]
|
local component_index = chunk_component_indices[fragment]
|
||||||
local component_storage = chunk_component_storages[component_index]
|
|
||||||
|
|
||||||
component_storage[place] = new_component
|
if component_index then
|
||||||
|
---@type evolved.duplicate?
|
||||||
|
local fragment_duplicate =
|
||||||
|
__evolved_get(fragment, __DUPLICATE)
|
||||||
|
|
||||||
|
local prefab_component_storage = prefab_component_storages[prefab_component_index]
|
||||||
|
local prefab_component = prefab_component_storage[prefab_place]
|
||||||
|
|
||||||
|
local new_component = prefab_component
|
||||||
|
|
||||||
|
if new_component ~= nil and fragment_duplicate then
|
||||||
|
new_component = fragment_duplicate(new_component)
|
||||||
|
end
|
||||||
|
|
||||||
|
if new_component == nil then
|
||||||
|
new_component = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local component_storage = chunk_component_storages[component_index]
|
||||||
|
|
||||||
|
component_storage[place] = new_component
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
for prefab_component_index = 1, prefab_component_count do
|
for prefab_component_index = 1, prefab_component_count do
|
||||||
local fragment = prefab_component_fragments[prefab_component_index]
|
local fragment = prefab_component_fragments[prefab_component_index]
|
||||||
|
|
||||||
local prefab_component_storage = prefab_component_storages[prefab_component_index]
|
|
||||||
local prefab_component = prefab_component_storage[prefab_place]
|
|
||||||
|
|
||||||
local new_component = prefab_component
|
|
||||||
|
|
||||||
if new_component == nil then
|
|
||||||
new_component = true
|
|
||||||
end
|
|
||||||
|
|
||||||
local component_index = chunk_component_indices[fragment]
|
local component_index = chunk_component_indices[fragment]
|
||||||
local component_storage = chunk_component_storages[component_index]
|
|
||||||
|
|
||||||
component_storage[place] = new_component
|
if component_index then
|
||||||
|
local prefab_component_storage = prefab_component_storages[prefab_component_index]
|
||||||
|
local prefab_component = prefab_component_storage[prefab_place]
|
||||||
|
|
||||||
|
local new_component = prefab_component
|
||||||
|
|
||||||
|
if new_component == nil then
|
||||||
|
new_component = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local component_storage = chunk_component_storages[component_index]
|
||||||
|
|
||||||
|
component_storage[place] = new_component
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user