Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
fix: time_calculatorの作成
Browse files Browse the repository at this point in the history
  • Loading branch information
PigeonsHouse committed Jan 4, 2024
1 parent aa2f049 commit 0ce04d4
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 37 deletions.
42 changes: 33 additions & 9 deletions src/style/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,54 @@

from utils import VSMLManager

from .types import GraphicUnit, GraphicValue
from .types import GraphicUnit, GraphicValue, TimeUnit, TimeValue


def time_calculator(
value: TimeValue,
parent_value: Optional[TimeValue] = None,
source_value: Optional[TimeValue] = None,
) -> TimeValue:
# FIT
output_value = TimeValue("fit")
match value.unit:
case TimeUnit.SECOND | TimeUnit.FRAME:
# SECOND, FRAME
output_value = value
case TimeUnit.PERCENT:
if parent_value is not None:
output_value.value = parent_value.value * value.value / 100
# SECOND, FRAME
output_value.unit = parent_value.unit
elif source_value is not None:
# SECOND
output_value = source_value
case TimeUnit.SOURCE:
if source_value is not None:
# SECOND
output_value = source_value
return output_value


def graphic_calculator(
value: GraphicValue,
parent_pixel: Optional[int] = None,
source_value: Optional[GraphicValue] = None,
) -> GraphicValue:
# AUTO
output_value = GraphicValue("auto")
match value.unit:
case GraphicUnit.PIXEL:
# PIXEL
output_value = value
case GraphicUnit.PERCENT:
if parent_pixel is None:
if source_value is None:
# AUTO
output_value.unit = GraphicUnit.AUTO
else:
# PIXEL
output_value = source_value
else:
if parent_pixel is not None:
output_value.value = int(parent_pixel * value.value / 100)
# PIXEL
output_value.unit = GraphicUnit.PIXEL
elif source_value is not None:
# PIXEL
output_value = source_value
case GraphicUnit.RESOLUTION_WIDTH:
output_value.value = int(
VSMLManager.get_root_resolution().width * value.value / 100
Expand Down
73 changes: 45 additions & 28 deletions src/style/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from utils import TagInfoTree, VSMLManager

from .calculator import graphic_calculator
from .calculator import graphic_calculator, time_calculator
from .styling_parser import (
audio_system_parser,
color_and_pixel_parser,
Expand All @@ -29,7 +29,6 @@
GraphicValue,
LayerMode,
Order,
TimeUnit,
TimeValue,
)

Expand Down Expand Up @@ -401,36 +400,54 @@ def __init__(
pass

# calculate param
if self.object_length.unit == TimeUnit.PERCENT:
parent_object_length = (
parent_param.object_length
if (
parent_param is not None
and parent_param.object_length is not None
and parent_param.object_length.has_specific_value()
):
self.object_length.value = (
parent_param.object_length.value
* self.object_length.value
/ 100
)
self.object_length.unit = parent_param.object_length.unit

parent_width = None
if parent_param is None:
parent_width = VSMLManager.get_root_resolution().width
elif (
parent_param.width is not None
and parent_param.width.has_specific_value()
):
parent_width = parent_param.width.value
parent_height = None
if parent_param is None:
parent_height = VSMLManager.get_root_resolution().height
elif (
parent_param.height is not None
and parent_param.height.has_specific_value()
):
parent_height = parent_param.height.value
)
else None
)
self.object_length = time_calculator(
self.object_length,
parent_object_length,
self.source_object_length,
)
self.time_margin_start = time_calculator(
self.time_margin_start,
parent_object_length,
)
self.time_margin_end = time_calculator(
self.time_margin_end,
parent_object_length,
)
self.time_padding_start = time_calculator(
self.time_padding_start,
parent_object_length,
)
self.time_padding_end = time_calculator(
self.time_padding_end,
parent_object_length,
)

parent_width = (
VSMLManager.get_root_resolution().width
if parent_param is None
else (
parent_param.width.value
if parent_param.width.has_specific_value()
else None
)
)
parent_height = (
VSMLManager.get_root_resolution().height
if parent_param is None
else (
parent_param.height.value
if parent_param.height.has_specific_value()
else None
)
)
self.width = graphic_calculator(
self.width, parent_width, self.source_width
)
Expand Down

0 comments on commit 0ce04d4

Please sign in to comment.