mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-14 12:10:23 +07:00
rename destroy policy to destruction policy
This commit is contained in:
28
README.md
28
README.md
@@ -127,9 +127,9 @@ EXECUTE :: fragment
|
||||
PROLOGUE :: fragment
|
||||
EPILOGUE :: fragment
|
||||
|
||||
DESTROY_POLICY :: fragment
|
||||
DESTROY_POLICY_DESTROY_ENTITY :: id
|
||||
DESTROY_POLICY_REMOVE_FRAGMENT :: id
|
||||
DESTRUCTION_POLICY :: fragment
|
||||
DESTRUCTION_POLICY_DESTROY_ENTITY :: id
|
||||
DESTRUCTION_POLICY_REMOVE_FRAGMENT :: id
|
||||
```
|
||||
|
||||
### Functions
|
||||
@@ -244,7 +244,7 @@ builder_mt:execute :: {chunk, entity[], integer} -> builder
|
||||
builder_mt:prologue :: {} -> builder
|
||||
builder_mt:epilogue :: {} -> builder
|
||||
|
||||
builder_mt:destroy_policy :: id -> builder
|
||||
builder_mt:destruction_policy :: id -> builder
|
||||
```
|
||||
|
||||
## Overview
|
||||
@@ -1061,18 +1061,18 @@ evolved.destroy(world)
|
||||
assert(evolved.alive(entity) and not evolved.has(entity, world))
|
||||
```
|
||||
|
||||
The default behavior works well in most cases, but you can change it by using the [`evolved.DESTROY_POLICY`](#evolveddestroy_policy) fragment. This fragment expects one of the following predefined identifiers:
|
||||
The default behavior works well in most cases, but you can change it by using the [`evolved.DESTRUCTION_POLICY`](#evolveddestruction_policy) fragment. This fragment expects one of the following predefined identifiers:
|
||||
|
||||
- [`evolved.DESTROY_POLICY_DESTROY_ENTITY`](#evolveddestroy_policy_destroy_entity) will destroy any entity that has the destroyed fragment. This is useful for cases like the one above, where you want to destroy all entities when their world is destroyed.
|
||||
- [`evolved.DESTRUCTION_POLICY_DESTROY_ENTITY`](#evolveddestruction_policy_destroy_entity) will destroy any entity that has the destroyed fragment. This is useful for cases like the one above, where you want to destroy all entities when their world is destroyed.
|
||||
|
||||
- [`evolved.DESTROY_POLICY_REMOVE_FRAGMENT`](#evolveddestroy_policy_remove_fragment) will remove the destroyed fragment from all entities that have it. This is the default behavior, so you don't have to set it explicitly, but you can if you want.
|
||||
- [`evolved.DESTRUCTION_POLICY_REMOVE_FRAGMENT`](#evolveddestruction_policy_remove_fragment) will remove the destroyed fragment from all entities that have it. This is the default behavior, so you don't have to set it explicitly, but you can if you want.
|
||||
|
||||
```lua
|
||||
local evolved = require 'evolved'
|
||||
|
||||
local world = evolved.builder()
|
||||
:tag()
|
||||
:destroy_policy(evolved.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
:destruction_policy(evolved.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
:spawn()
|
||||
|
||||
local entity = evolved.builder()
|
||||
@@ -1128,11 +1128,11 @@ assert(not evolved.alive(entity))
|
||||
|
||||
### `evolved.EPILOGUE`
|
||||
|
||||
### `evolved.DESTROY_POLICY`
|
||||
### `evolved.DESTRUCTION_POLICY`
|
||||
|
||||
### `evolved.DESTROY_POLICY_DESTROY_ENTITY`
|
||||
### `evolved.DESTRUCTION_POLICY_DESTROY_ENTITY`
|
||||
|
||||
### `evolved.DESTROY_POLICY_REMOVE_FRAGMENT`
|
||||
### `evolved.DESTRUCTION_POLICY_REMOVE_FRAGMENT`
|
||||
|
||||
## Functions
|
||||
|
||||
@@ -1710,12 +1710,12 @@ function evolved.builder_mt:prologue(prologue) end
|
||||
function evolved.builder_mt:epilogue(epilogue) end
|
||||
```
|
||||
|
||||
#### `evolved.builder_mt:destroy_policy`
|
||||
#### `evolved.builder_mt:destruction_policy`
|
||||
|
||||
```lua
|
||||
---@param destroy_policy evolved.id
|
||||
---@param destruction_policy evolved.id
|
||||
---@return evolved.builder builder
|
||||
function evolved.builder_mt:destroy_policy(destroy_policy) end
|
||||
function evolved.builder_mt:destruction_policy(destruction_policy) end
|
||||
```
|
||||
|
||||
## [License (MIT)](./LICENSE.md)
|
||||
|
||||
@@ -33,11 +33,11 @@ for _, entity in ipairs(all_entity_list) do
|
||||
end
|
||||
|
||||
if math.random(1, 5) == 1 then
|
||||
evo.set(entity, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
evo.set(entity, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
end
|
||||
|
||||
if math.random(1, 5) == 1 then
|
||||
evo.set(entity, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(entity, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,10 +52,10 @@ local should_be_destroyed_entity_list = {} ---@type evolved.entity[]
|
||||
local should_be_destroyed_entity_count = 0 ---@type integer
|
||||
|
||||
local function collect_destroyed_entities_with(entity)
|
||||
local entity_destroy_policy = evo.get(entity, evo.DESTROY_POLICY)
|
||||
or evo.DESTROY_POLICY_REMOVE_FRAGMENT
|
||||
local entity_destruction_policy = evo.get(entity, evo.DESTRUCTION_POLICY)
|
||||
or evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT
|
||||
|
||||
if entity_destroy_policy == evo.DESTROY_POLICY_DESTROY_ENTITY then
|
||||
if entity_destruction_policy == evo.DESTRUCTION_POLICY_DESTROY_ENTITY then
|
||||
for _, other_entity in ipairs(all_entity_list) do
|
||||
if evo.has(other_entity, entity) and not should_be_destroyed_entity_set[other_entity] then
|
||||
should_be_destroyed_entity_count = should_be_destroyed_entity_count + 1
|
||||
|
||||
@@ -33,11 +33,11 @@ for _, entity in ipairs(all_entity_list) do
|
||||
end
|
||||
|
||||
if math.random(1, 5) == 1 then
|
||||
evo.set(entity, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
evo.set(entity, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
end
|
||||
|
||||
if math.random(1, 5) == 1 then
|
||||
evo.set(entity, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(entity, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,10 +52,10 @@ local should_be_destroyed_entity_list = {} ---@type evolved.entity[]
|
||||
local should_be_destroyed_entity_count = 0 ---@type integer
|
||||
|
||||
local function collect_destroyed_entities_with(entity)
|
||||
local entity_destroy_policy = evo.get(entity, evo.DESTROY_POLICY)
|
||||
or evo.DESTROY_POLICY_REMOVE_FRAGMENT
|
||||
local entity_destruction_policy = evo.get(entity, evo.DESTRUCTION_POLICY)
|
||||
or evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT
|
||||
|
||||
if entity_destroy_policy == evo.DESTROY_POLICY_DESTROY_ENTITY then
|
||||
if entity_destruction_policy == evo.DESTRUCTION_POLICY_DESTROY_ENTITY then
|
||||
for _, other_entity in ipairs(all_entity_list) do
|
||||
if evo.has(other_entity, entity) and not should_be_destroyed_entity_set[other_entity] then
|
||||
should_be_destroyed_entity_count = should_be_destroyed_entity_count + 1
|
||||
|
||||
@@ -3958,7 +3958,7 @@ do
|
||||
local c1 = assert(evo.chunk(f1))
|
||||
local c2 = assert(evo.chunk(f2))
|
||||
local c12 = assert(evo.chunk(f1, f2))
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(f1, f1)
|
||||
evo.set(f2, f1)
|
||||
evo.set(f2, f2)
|
||||
@@ -3992,7 +3992,7 @@ do
|
||||
local c1 = assert(evo.chunk(f1))
|
||||
local c2 = assert(evo.chunk(f2))
|
||||
local c12 = assert(evo.chunk(f1, f2))
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
evo.set(f1, f1)
|
||||
evo.set(f2, f1)
|
||||
evo.set(f2, f2)
|
||||
@@ -4050,7 +4050,7 @@ do
|
||||
local f1, f2, f3 = evo.id(3)
|
||||
local c1 = assert(evo.chunk(f1))
|
||||
local c2 = assert(evo.chunk(f2))
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(f2, f1)
|
||||
evo.set(f3, f2)
|
||||
do
|
||||
@@ -4077,7 +4077,7 @@ do
|
||||
local f1, f2, f3 = evo.id(3)
|
||||
local c1 = assert(evo.chunk(f1))
|
||||
local c2 = assert(evo.chunk(f2))
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
evo.set(f2, f1)
|
||||
evo.set(f3, f2)
|
||||
do
|
||||
@@ -4104,7 +4104,7 @@ do
|
||||
evo.set(f1, ft)
|
||||
evo.set(f2, ft)
|
||||
evo.set(f3, ft)
|
||||
evo.set(f3, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
evo.set(f3, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
local qt = evo.builder():include(ft):spawn()
|
||||
|
||||
local c4 = assert(evo.chunk(f4))
|
||||
@@ -4139,7 +4139,7 @@ end
|
||||
|
||||
do
|
||||
local f1 = evo.id()
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
evo.set(f1, f1, f1)
|
||||
|
||||
local remove_count = 0
|
||||
@@ -4165,7 +4165,7 @@ end
|
||||
|
||||
do
|
||||
local f1 = evo.id()
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(f1, f1, f1)
|
||||
|
||||
local remove_count = 0
|
||||
@@ -4248,7 +4248,7 @@ do
|
||||
local f1, f2 = evo.id(2)
|
||||
evo.set(f1, f1)
|
||||
evo.set(f2, f1)
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
evo.destroy(f1)
|
||||
assert(not evo.alive(f1))
|
||||
assert(not evo.alive(f2))
|
||||
@@ -4258,7 +4258,7 @@ do
|
||||
local f1, f2 = evo.id(2)
|
||||
evo.set(f1, f1)
|
||||
evo.set(f2, f1)
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
|
||||
evo.destroy(f1)
|
||||
assert(not evo.alive(f1))
|
||||
assert(evo.alive(f2) and evo.empty(f2))
|
||||
@@ -4268,7 +4268,7 @@ end
|
||||
do
|
||||
local f1, f2 = evo.id(2)
|
||||
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
|
||||
local e12a = evo.builder():set(f1, 1):set(f2, 2):spawn()
|
||||
local e12b = evo.builder():set(f1, 3):set(f2, 4):spawn()
|
||||
@@ -4302,7 +4302,7 @@ do
|
||||
evo.set(f1, evo.NAME, "f1")
|
||||
evo.set(f2, evo.NAME, "f2")
|
||||
|
||||
evo.set(f1, evo.DESTROY_POLICY, evo.DESTROY_POLICY_REMOVE_FRAGMENT)
|
||||
evo.set(f1, evo.DESTRUCTION_POLICY, evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
|
||||
|
||||
local e12a = evo.builder():set(f1, 1):set(f2, 2):spawn()
|
||||
local e12b = evo.builder():set(f1, 3):set(f2, 4):spawn()
|
||||
@@ -4333,12 +4333,12 @@ do
|
||||
local fb = evo.builder()
|
||||
|
||||
local f1 = fb:spawn()
|
||||
local f2 = fb:destroy_policy(evo.DESTROY_POLICY_DESTROY_ENTITY):spawn()
|
||||
local f3 = fb:destroy_policy(evo.DESTROY_POLICY_REMOVE_FRAGMENT):spawn()
|
||||
local f2 = fb:destruction_policy(evo.DESTRUCTION_POLICY_DESTROY_ENTITY):spawn()
|
||||
local f3 = fb:destruction_policy(evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT):spawn()
|
||||
|
||||
assert(evo.get(f1, evo.DESTROY_POLICY) == nil)
|
||||
assert(evo.get(f2, evo.DESTROY_POLICY) == evo.DESTROY_POLICY_DESTROY_ENTITY)
|
||||
assert(evo.get(f3, evo.DESTROY_POLICY) == evo.DESTROY_POLICY_REMOVE_FRAGMENT)
|
||||
assert(evo.get(f1, evo.DESTRUCTION_POLICY) == nil)
|
||||
assert(evo.get(f2, evo.DESTRUCTION_POLICY) == evo.DESTRUCTION_POLICY_DESTROY_ENTITY)
|
||||
assert(evo.get(f3, evo.DESTRUCTION_POLICY) == evo.DESTRUCTION_POLICY_REMOVE_FRAGMENT)
|
||||
end
|
||||
|
||||
do
|
||||
|
||||
36
evolved.lua
36
evolved.lua
@@ -715,9 +715,9 @@ local __EXECUTE = __acquire_id()
|
||||
local __PROLOGUE = __acquire_id()
|
||||
local __EPILOGUE = __acquire_id()
|
||||
|
||||
local __DESTROY_POLICY = __acquire_id()
|
||||
local __DESTROY_POLICY_DESTROY_ENTITY = __acquire_id()
|
||||
local __DESTROY_POLICY_REMOVE_FRAGMENT = __acquire_id()
|
||||
local __DESTRUCTION_POLICY = __acquire_id()
|
||||
local __DESTRUCTION_POLICY_DESTROY_ENTITY = __acquire_id()
|
||||
local __DESTRUCTION_POLICY_REMOVE_FRAGMENT = __acquire_id()
|
||||
|
||||
---
|
||||
---
|
||||
@@ -2182,10 +2182,10 @@ local function __destroy_fragment_list(fragment_list, fragment_count)
|
||||
releasing_fragment_count = releasing_fragment_count + 1
|
||||
releasing_fragment_list[releasing_fragment_count] = processing_fragment
|
||||
|
||||
local processing_fragment_destroy_policy = __evolved_get(processing_fragment, __DESTROY_POLICY)
|
||||
or __DESTROY_POLICY_REMOVE_FRAGMENT
|
||||
local processing_fragment_destruction_policy = __evolved_get(processing_fragment, __DESTRUCTION_POLICY)
|
||||
or __DESTRUCTION_POLICY_REMOVE_FRAGMENT
|
||||
|
||||
if processing_fragment_destroy_policy == __DESTROY_POLICY_DESTROY_ENTITY then
|
||||
if processing_fragment_destruction_policy == __DESTRUCTION_POLICY_DESTROY_ENTITY then
|
||||
destroy_entity_policy_fragment_count = destroy_entity_policy_fragment_count + 1
|
||||
destroy_entity_policy_fragment_list[destroy_entity_policy_fragment_count] = processing_fragment
|
||||
|
||||
@@ -2205,12 +2205,12 @@ local function __destroy_fragment_list(fragment_list, fragment_count)
|
||||
|
||||
processing_fragment_stack_size = processing_fragment_stack_size + minor_chunk_entity_count
|
||||
end
|
||||
elseif processing_fragment_destroy_policy == __DESTROY_POLICY_REMOVE_FRAGMENT then
|
||||
elseif processing_fragment_destruction_policy == __DESTRUCTION_POLICY_REMOVE_FRAGMENT then
|
||||
remove_fragment_policy_fragment_count = remove_fragment_policy_fragment_count + 1
|
||||
remove_fragment_policy_fragment_list[remove_fragment_policy_fragment_count] = processing_fragment
|
||||
else
|
||||
__error_fmt('unknown DESTROY_POLICY policy (%s) on (%s)',
|
||||
__id_name(processing_fragment_destroy_policy), __id_name(processing_fragment))
|
||||
__error_fmt('unknown DESTRUCTION_POLICY (%s) on (%s)',
|
||||
__id_name(processing_fragment_destruction_policy), __id_name(processing_fragment))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5192,10 +5192,10 @@ function __builder_mt:epilogue(epilogue)
|
||||
return self:set(__EPILOGUE, epilogue)
|
||||
end
|
||||
|
||||
---@param destroy_policy evolved.id
|
||||
---@param destruction_policy evolved.id
|
||||
---@return evolved.builder builder
|
||||
function __builder_mt:destroy_policy(destroy_policy)
|
||||
return self:set(__DESTROY_POLICY, destroy_policy)
|
||||
function __builder_mt:destruction_policy(destruction_policy)
|
||||
return self:set(__DESTRUCTION_POLICY, destruction_policy)
|
||||
end
|
||||
|
||||
---
|
||||
@@ -5269,9 +5269,9 @@ __evolved_set(__EXECUTE, __NAME, 'EXECUTE')
|
||||
__evolved_set(__PROLOGUE, __NAME, 'PROLOGUE')
|
||||
__evolved_set(__EPILOGUE, __NAME, 'EPILOGUE')
|
||||
|
||||
__evolved_set(__DESTROY_POLICY, __NAME, 'DESTROY_POLICY')
|
||||
__evolved_set(__DESTROY_POLICY_DESTROY_ENTITY, __NAME, 'DESTROY_POLICY_DESTROY_ENTITY')
|
||||
__evolved_set(__DESTROY_POLICY_REMOVE_FRAGMENT, __NAME, 'DESTROY_POLICY_REMOVE_FRAGMENT')
|
||||
__evolved_set(__DESTRUCTION_POLICY, __NAME, 'DESTRUCTION_POLICY')
|
||||
__evolved_set(__DESTRUCTION_POLICY_DESTROY_ENTITY, __NAME, 'DESTRUCTION_POLICY_DESTROY_ENTITY')
|
||||
__evolved_set(__DESTRUCTION_POLICY_REMOVE_FRAGMENT, __NAME, 'DESTRUCTION_POLICY_REMOVE_FRAGMENT')
|
||||
|
||||
---
|
||||
---
|
||||
@@ -5450,9 +5450,9 @@ evolved.EXECUTE = __EXECUTE
|
||||
evolved.PROLOGUE = __PROLOGUE
|
||||
evolved.EPILOGUE = __EPILOGUE
|
||||
|
||||
evolved.DESTROY_POLICY = __DESTROY_POLICY
|
||||
evolved.DESTROY_POLICY_DESTROY_ENTITY = __DESTROY_POLICY_DESTROY_ENTITY
|
||||
evolved.DESTROY_POLICY_REMOVE_FRAGMENT = __DESTROY_POLICY_REMOVE_FRAGMENT
|
||||
evolved.DESTRUCTION_POLICY = __DESTRUCTION_POLICY
|
||||
evolved.DESTRUCTION_POLICY_DESTROY_ENTITY = __DESTRUCTION_POLICY_DESTROY_ENTITY
|
||||
evolved.DESTRUCTION_POLICY_REMOVE_FRAGMENT = __DESTRUCTION_POLICY_REMOVE_FRAGMENT
|
||||
|
||||
evolved.id = __evolved_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user