Refactor luagenerator

- cleaned up the generation
- created special class to handle the serialization
- improved string escaping: Replace OS Path separator with normal slash and allow the usage of a single quote in unit names by changing the delimiter to double quote instead (1797)
- adjusted unit_name generation to prevent scripting errors with unescaped characters
This commit is contained in:
RndName
2021-06-27 17:46:39 +02:00
parent 8f16f242b1
commit 138e48dc2d
3 changed files with 224 additions and 197 deletions

View File

@@ -19,6 +19,7 @@ from game.layout import LAYOUTS
from game.layout.layout import TgoLayout, TgoLayoutGroup
from game.point_with_heading import PointWithHeading
from game.theater.theatergroup import TheaterGroup
from game.utils import escape_string_for_lua
if TYPE_CHECKING:
from game import Game
@@ -251,7 +252,10 @@ class ForceGroup:
# Assign UniqueID, name and align relative to ground_object
for unit in units:
unit.id = game.next_unit_id()
unit.name = unit.unit_type.name if unit.unit_type else unit.type.name
# Add unit name escaped so that we do not have scripting issues later
unit.name = escape_string_for_lua(
unit.unit_type.name if unit.unit_type else unit.type.name
)
unit.position = PointWithHeading.from_point(
ground_object.position + unit.position,
# Align heading to GroundObject defined by the campaign designer