Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
|
ff393b9793 | |
|
341882c786 | |
|
019a69ace9 | |
|
2c707d28e7 | |
|
d6b9d88e87 | |
|
a75a83702b | |
|
33c181038c | |
|
6e6d22f9c8 |
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -4,6 +4,22 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [1.0.5] - 2023-02-03
|
||||
### Added
|
||||
- Meta deterministic generation for authoring components
|
||||
|
||||
## [1.0.4] - 2023-01-27
|
||||
### Added
|
||||
- Support for `bhl_native_class` token
|
||||
### Changed
|
||||
- `ecs_serializable` now `serializable`
|
||||
- Fields are not serializaed by default
|
||||
- `serializable` token now applicable to fields
|
||||
|
||||
## [1.0.1] - 2023-01-25
|
||||
### Fixed
|
||||
- Wrong type generation
|
||||
|
||||
## [1.0.0] - 2023-01-25
|
||||
Release
|
|
@ -4,9 +4,9 @@ This package is used for code generation of C# meta structs for LeoECS using Twi
|
|||
ecs.meta
|
||||
```
|
||||
struct TestComponent
|
||||
@bhl_ecs_component @ecs_gen_component @ecs_gen_authoring @ecs_serializable
|
||||
pos : Vector3
|
||||
fwd : Vector3
|
||||
@bhl_ecs_component @ecs_gen_component @ecs_gen_authoring @serializable
|
||||
pos : Vector3 @serializable
|
||||
fwd : Vector3 @serializable
|
||||
width : float
|
||||
length : float
|
||||
end
|
||||
|
@ -17,5 +17,5 @@ to be added on game object.
|
|||
# Tags:
|
||||
@ecs_gen_component - generates C# component
|
||||
@ecs_gen_authoring - generates authoring monobehaviour to be added on game object
|
||||
@ecs_serializable - makes component editable in inspector
|
||||
@serializable - makes component editable in inspector
|
||||
@ecs_tag - marks component tag
|
|
@ -7,7 +7,8 @@
|
|||
"twig/twig" : "v3.4.3",
|
||||
"bit/metagen" : "^v2.0.2",
|
||||
"bit/metagen_cs" : "^v1.0.5",
|
||||
"bit/taskman_helpers" : "^v1.0.6"
|
||||
"bit/taskman_helpers" : "^v1.0.6",
|
||||
"ramsey/uuid" : "^v3"
|
||||
},
|
||||
"autoload": {
|
||||
"files": [
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?php
|
||||
namespace metagen_cs_ecs;
|
||||
|
||||
use Ramsey\Uuid\Uuid;
|
||||
|
||||
function supported_tokens()
|
||||
{
|
||||
return [
|
||||
'ecs_serializable',
|
||||
'serializable',
|
||||
'ecs_gen_component',
|
||||
'ecs_gen_authoring',
|
||||
'ecs_tag',
|
||||
|
@ -16,35 +18,48 @@ function get_twig_inc()
|
|||
return __DIR__ ."/../tpl";
|
||||
}
|
||||
|
||||
function get_gen_root()
|
||||
{
|
||||
global $GAME_ROOT;
|
||||
return "$GAME_ROOT/unity/Assets/Scripts/autogen/ecs";
|
||||
}
|
||||
|
||||
function generate_ecs_components(\mtgMetaInfo $meta)
|
||||
{
|
||||
global $GAME_ROOT;
|
||||
|
||||
$twig = \metagen_cs\get_twig(array(get_twig_inc()));
|
||||
$twig->setCache($GAME_ROOT . "/build/twig/metagen_cs_ecs");
|
||||
$gen_root = get_gen_root();
|
||||
$gen_components = new \mtgMetaInfo();
|
||||
$lock_file = "$GAME_ROOT/unity/Packages/metagen_autogen/Runtime/code/ecs/ecs.lock";
|
||||
$gen_authorings = new \mtgMetaInfo();
|
||||
$lock_file = "$gen_root/ecs.lock";
|
||||
|
||||
foreach ($meta->getUnits() as $unit)
|
||||
{
|
||||
if(!$unit->object->hasToken('ecs_gen_component') || !($unit->object instanceof \mtgUserType))
|
||||
continue;
|
||||
$gen_components->addUnit($unit);
|
||||
}
|
||||
|
||||
if(!\taskman\need_to_regen($lock_file, get_meta_units_files($gen_components)))
|
||||
if(!\taskman\need_to_regen($lock_file, get_meta_units_files($meta)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
\taskman\rrmdir("$GAME_ROOT/unity/Packages/metagen_autogen/Runtime/code/ecs/");
|
||||
\taskman\ensure_rm($gen_root);
|
||||
\taskman\ensure_write($lock_file, "");
|
||||
touch($lock_file);
|
||||
|
||||
foreach ($meta->getUnits() as $unit)
|
||||
{
|
||||
if(!($unit->object instanceof \mtgUserType))
|
||||
continue;
|
||||
if($unit->object->hasToken('ecs_gen_component'))
|
||||
$gen_components->addUnit($unit);
|
||||
if($unit->object->hasToken('ecs_gen_authoring'))
|
||||
$gen_authorings->addUnit($unit);
|
||||
}
|
||||
|
||||
$twig = \metagen_cs\get_twig(array(get_twig_inc()));
|
||||
_add_twig_support($twig);
|
||||
$twig->setCache($GAME_ROOT . "/build/twig/metagen_cs_ecs");
|
||||
|
||||
foreach ($gen_components->getUnits() as $unit)
|
||||
{
|
||||
$unit_name = $unit->object->getName();
|
||||
$filePath = str_replace(".", "/", $unit_name);
|
||||
$file = "$GAME_ROOT/unity/Packages/metagen_autogen/Runtime/code/ecs/$filePath.cs";
|
||||
$file = "$gen_root/$filePath.cs";
|
||||
$name_components = explode('.', $unit_name);
|
||||
$class_name = end($name_components);
|
||||
if($class_name != $unit_name)
|
||||
|
@ -52,7 +67,7 @@ function generate_ecs_components(\mtgMetaInfo $meta)
|
|||
else
|
||||
$namespace = "";
|
||||
|
||||
// Костыль. Убрать, когда будет поддержка namespace в bhl_bind
|
||||
// TODO: Костыль. Убрать, когда будет поддержка namespace в bhl_bind
|
||||
if(empty($namespace))
|
||||
$namespace = "ecs";
|
||||
|
||||
|
@ -74,19 +89,42 @@ function generate_ecs_components(\mtgMetaInfo $meta)
|
|||
],
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
$file_authoring = "$GAME_ROOT/unity/Packages/metagen_autogen/Runtime/code/ecs/{$filePath}AuthoringComponent.cs";
|
||||
if($unit->object->hasToken('ecs_gen_authoring'))
|
||||
{
|
||||
\taskman\ensure_write_if_differs(
|
||||
$file_authoring,
|
||||
$twig->render('codegen_ecs_authoring.twig', [
|
||||
'namespace' => $namespace,
|
||||
'class_name' => $class_name,
|
||||
'obj' => $unit->object
|
||||
])
|
||||
);
|
||||
}
|
||||
foreach ($gen_authorings->getUnits() as $unit)
|
||||
{
|
||||
$unit_name = $unit->object->getName();
|
||||
$filePath = str_replace(".", "/", $unit_name);
|
||||
$file = "$gen_root/{$filePath}AuthoringComponent.cs";
|
||||
$fileMeta = "$gen_root/{$filePath}AuthoringComponent.cs.meta";
|
||||
$name_components = explode('.', $unit_name);
|
||||
$class_name = end($name_components);
|
||||
if($class_name != $unit_name)
|
||||
$namespace = str_replace(".$class_name", "", $unit_name);
|
||||
else
|
||||
$namespace = "";
|
||||
|
||||
// TODO: Костыль. Убрать, когда будет поддержка namespace в bhl_bind
|
||||
if(empty($namespace))
|
||||
$namespace = "ecs";
|
||||
|
||||
\taskman\ensure_write_if_differs(
|
||||
$file,
|
||||
$twig->render('codegen_ecs_authoring.twig', [
|
||||
'namespace' => $namespace,
|
||||
'class_name' => $class_name,
|
||||
'obj' => $unit->object
|
||||
])
|
||||
);
|
||||
|
||||
$uuid = Uuid::uuid3(Uuid::NAMESPACE_URL, $file);
|
||||
$guid = bin2hex($uuid->getBytes());
|
||||
\taskman\ensure_write_if_differs(
|
||||
$fileMeta,
|
||||
$twig->render('codegen_ecs_authoring_meta.twig', [
|
||||
'guid' => $guid,
|
||||
])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,4 +134,16 @@ function get_meta_units_files(\mtgMetaInfo $meta)
|
|||
foreach($meta->getUnits() as $u)
|
||||
$files[$u->file] = true;
|
||||
return array_keys($files);
|
||||
}
|
||||
|
||||
function _add_twig_support(\Twig\Environment $twig)
|
||||
{
|
||||
$twig->addFilter(new \Twig\TwigFilter('ecs_type',
|
||||
function($type)
|
||||
{
|
||||
if(($type instanceof \mtgUserType) && $type->hasToken("bhl_native_class"))
|
||||
return $type->getToken("bhl_native_class");
|
||||
return \metagen_cs\cs_type($type);
|
||||
}
|
||||
));
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: {{guid}}
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -8,7 +8,7 @@ using {{imp}};
|
|||
namespace {{namespace}}
|
||||
{
|
||||
{% endif %}
|
||||
{% if has_token(obj, 'ecs_serializable') %}
|
||||
{% if has_token(obj, 'serializable') %}
|
||||
[System.Serializable]
|
||||
{% endif %}
|
||||
{% apply trim('\n:, ', 'right') %}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
{%- macro ecs_component_field(obj, field) -%}
|
||||
public {{field.type}} {{field.name}};
|
||||
{%- if not has_token(field, 'serializable') -%}
|
||||
[System.NonSerialized]
|
||||
{%- endif -%}
|
||||
public {{field.type|ecs_type}} {{field.name}};
|
||||
{%- endmacro -%}
|
Loading…
Reference in New Issue