forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
113
leenkx/blender/lnx/logicnode/native/LN_get_date_time.py
Normal file
113
leenkx/blender/lnx/logicnode/native/LN_get_date_time.py
Normal file
@ -0,0 +1,113 @@
|
||||
from lnx.logicnode.lnx_nodes import *
|
||||
|
||||
class GetDateTimeNode(LnxLogicTreeNode):
|
||||
"""Returns the values of the current date and time."""
|
||||
bl_idname = 'LNGetDateTimeNode'
|
||||
bl_label = 'Get Date and Time'
|
||||
lnx_section = 'Native'
|
||||
lnx_version = 1
|
||||
|
||||
@staticmethod
|
||||
def get_enum_id_value(obj, prop_name, value):
|
||||
return obj.bl_rna.properties[prop_name].enum_items[value].identifier
|
||||
|
||||
@staticmethod
|
||||
def get_count_in(type_name):
|
||||
return {
|
||||
'now': 0,
|
||||
'timestamp': 1,
|
||||
'timeZoneOffSet': 2,
|
||||
'weekday': 3,
|
||||
'day': 4,
|
||||
'month': 5,
|
||||
'year': 6,
|
||||
'hours': 7,
|
||||
'minutes': 8,
|
||||
'seconds': 9,
|
||||
'all': 10,
|
||||
'formatted': 11,
|
||||
}.get(type_name, 10)
|
||||
|
||||
def get_enum(self):
|
||||
return self.get('property0', 10)
|
||||
|
||||
def set_enum(self, value):
|
||||
# Checking the selection of each type
|
||||
select_current = self.get_enum_id_value(self, 'property0', value)
|
||||
select_prev = self.property0
|
||||
|
||||
#Check if type changed
|
||||
if select_prev != select_current:
|
||||
|
||||
for i in self.inputs:
|
||||
self.inputs.remove(i)
|
||||
for i in self.outputs:
|
||||
self.outputs.remove(i)
|
||||
|
||||
if (self.get_count_in(select_current) == 0):
|
||||
self.add_output('LnxStringSocket', 'Date')
|
||||
elif (self.get_count_in(select_current) == 10):
|
||||
self.add_input('LnxNodeSocketAction', 'In')
|
||||
self.add_output('LnxNodeSocketAction', 'Out')
|
||||
self.add_output('LnxIntSocket', 'Timestamp')
|
||||
self.add_output('LnxIntSocket', 'Timezone Offset')
|
||||
self.add_output('LnxIntSocket', 'Weekday')
|
||||
self.add_output('LnxIntSocket', 'Day')
|
||||
self.add_output('LnxIntSocket', 'Month')
|
||||
self.add_output('LnxIntSocket', 'Year')
|
||||
self.add_output('LnxIntSocket', 'Hours')
|
||||
self.add_output('LnxIntSocket', 'Minutes')
|
||||
self.add_output('LnxIntSocket', 'Seconds')
|
||||
elif (self.get_count_in(select_current) == 11):
|
||||
self.add_input('LnxStringSocket', 'Format', default_value="%Y/%m/%d - %H:%M:%S")
|
||||
self.add_output('LnxStringSocket', 'Date')
|
||||
else:
|
||||
self.add_output('LnxIntSocket', 'Value')
|
||||
|
||||
self['property0'] = value
|
||||
|
||||
|
||||
property0: HaxeEnumProperty(
|
||||
'property0',
|
||||
items = [('now', 'Now', 'Returns a Date representing the current local time.'),
|
||||
('timestamp', 'Timestamp', 'Returns the timestamp (in milliseconds) of this date'),
|
||||
('timeZoneOffSet', 'Timezone Offset', 'Returns the time zone difference of this Date in the current locale to UTC, in minutes'),
|
||||
('weekday', 'Weekday', 'Returns the day of the week of this Date (0-6 range, where 0 is Sunday) in the local timezone.'),
|
||||
('day', 'Day', 'Returns the day of this Date (1-31 range) in the local timezone.'),
|
||||
('month', 'Month', 'Returns the month of this Date (0-11 range) in the local timezone. Note that the month number is zero-based.'),
|
||||
('year', 'Year', 'Returns the full year of this Date (4 digits) in the local timezone.'),
|
||||
('hours', 'Hours', 'Returns the hours of this Date (0-23 range) in the local timezone.'),
|
||||
('minutes', 'Minutes', 'Returns the minutes of this Date (0-59 range) in the local timezone.'),
|
||||
('seconds', 'Seconds', 'Returns the seconds of this Date (0-59 range) in the local timezone.'),
|
||||
('all', 'All', 'Get all of the individual separated date and time properties'),
|
||||
('formatted', 'Formatted', 'Format the current system date and time')],
|
||||
name='',
|
||||
default='all',
|
||||
set=set_enum,
|
||||
get=get_enum)
|
||||
|
||||
|
||||
|
||||
|
||||
def __init__(self):
|
||||
array_nodes[str(id(self))] = self
|
||||
|
||||
|
||||
def lnx_init(self, context):
|
||||
self.add_input('LnxNodeSocketAction', 'In')
|
||||
self.add_output('LnxNodeSocketAction', 'Out')
|
||||
self.add_output('LnxIntSocket', 'Timestamp')
|
||||
self.add_output('LnxIntSocket', 'Timezone Offset')
|
||||
self.add_output('LnxIntSocket', 'Weekday')
|
||||
self.add_output('LnxIntSocket', 'Day')
|
||||
self.add_output('LnxIntSocket', 'Month')
|
||||
self.add_output('LnxIntSocket', 'Year')
|
||||
self.add_output('LnxIntSocket', 'Hours')
|
||||
self.add_output('LnxIntSocket', 'Minutes')
|
||||
self.add_output('LnxIntSocket', 'Seconds')
|
||||
|
||||
|
||||
|
||||
def draw_buttons(self, context, layout):
|
||||
layout.prop(self, 'property0')
|
||||
|
Reference in New Issue
Block a user