yyc12345
3396947115
- add ballance map sector info in scene to indicate the maximum sector count of this map. - this adding will prevent the bug that the exported ballance map do not have successive sector groups. because original implement will not create sector group if no component in corresponding sector and previous remedy still have bug. and if this happended, ballance will show spaceship in wrong sector. this adding is the final solution of this bug. - exlarge ballance map sector info when user adding component. the enlarged value will be calculated by user input sector. - auto enlarge ballance map sector info when importing. this will give user a fluent experience when modifying existing map. - exporting map will also use ballance map sector info to pre-create successive sector group as term 2 stated. - move sector name extractor from virtools file exporting module to naming convention module.
82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
import bpy
|
|
import typing
|
|
from . import UTIL_functions
|
|
|
|
class RawBallanceMapInfo():
|
|
cSectorCount: typing.ClassVar[int] = 1
|
|
|
|
mSectorCount: int
|
|
|
|
def __init__(self, **kwargs):
|
|
self.mSectorCount = kwargs.get("mSectorCount", RawBallanceMapInfo.cSectorCount)
|
|
|
|
def regulate(self):
|
|
self.mSectorCount = UTIL_functions.clamp_int(self.mSectorCount, 1, 999)
|
|
|
|
#region Prop Decl & Getter Setter
|
|
|
|
class BBP_PG_ballance_map_info(bpy.types.PropertyGroup):
|
|
sector_count: bpy.props.IntProperty(
|
|
name = "Sector",
|
|
description = "The sector count of this Ballance map which is used in exporting map and may be changed when importing map.",
|
|
default = 1,
|
|
max = 999, min = 1,
|
|
soft_max = 8, soft_min = 1,
|
|
step = 1
|
|
) # type: ignore
|
|
|
|
def get_ballance_map_info(scene: bpy.types.Scene) -> BBP_PG_ballance_map_info:
|
|
return scene.ballance_map_info
|
|
|
|
def get_raw_ballance_map_info(scene: bpy.types.Scene) -> RawBallanceMapInfo:
|
|
props: BBP_PG_ballance_map_info = get_ballance_map_info(scene)
|
|
rawdata: RawBallanceMapInfo = RawBallanceMapInfo()
|
|
|
|
rawdata.mSectorCount = props.sector_count
|
|
|
|
rawdata.regulate()
|
|
return rawdata
|
|
|
|
def set_raw_ballance_map_info(scene: bpy.types.Scene, rawdata: RawBallanceMapInfo) -> None:
|
|
props: BBP_PG_ballance_map_info = get_ballance_map_info(scene)
|
|
|
|
props.sector_count = rawdata.mSectorCount
|
|
|
|
#endregion
|
|
|
|
class BBP_PT_ballance_map_info(bpy.types.Panel):
|
|
"""Show Ballance Map Infos."""
|
|
bl_label = "Ballance Map"
|
|
bl_idname = "BBP_PT_ballance_map_info"
|
|
bl_space_type = 'PROPERTIES'
|
|
bl_region_type = 'WINDOW'
|
|
bl_context = "scene"
|
|
|
|
@classmethod
|
|
def poll(cls, context):
|
|
return context.scene is not None
|
|
|
|
def draw(self, context):
|
|
layout: bpy.types.UILayout = self.layout
|
|
target: bpy.types.Scene = context.scene
|
|
props: BBP_PG_ballance_map_info = get_ballance_map_info(target)
|
|
|
|
# show map sector count numberbox
|
|
layout.prop(props, 'sector_count')
|
|
|
|
def register() -> None:
|
|
# register
|
|
bpy.utils.register_class(BBP_PG_ballance_map_info)
|
|
bpy.utils.register_class(BBP_PT_ballance_map_info)
|
|
|
|
# add into scene metadata
|
|
bpy.types.Scene.ballance_map_info = bpy.props.PointerProperty(type = BBP_PG_ballance_map_info)
|
|
|
|
def unregister() -> None:
|
|
# del from scene metadata
|
|
del bpy.types.Scene.ballance_map_info
|
|
|
|
# unregister
|
|
bpy.utils.unregister_class(BBP_PG_ballance_map_info)
|
|
bpy.utils.unregister_class(BBP_PT_ballance_map_info)
|