def mixin_oop(oop_list: List[CompoundOOPData]): for data in each_oop_data_from_list_by_name(oop_list, ListType.SHARED, 'getColShapeSize'): data.method.signature.return_types.return_types = [ FunctionType(is_optional=False, names=[ 'number', 'Vector2', 'Vector3', ]) ] for data in each_oop_data_from_list_by_name(oop_list, ListType.SHARED, 'setColShapeSize'): data.method.signature.arguments.arguments = [[ FunctionArgument(default_value=None, argument_type=FunctionType(is_optional=False, names=[ 'number', 'Vector2', 'Vector3', ]), name='vectorized') ]] for data in each_oop_data_from_list_by_name(oop_list, ListType.SHARED, 'getElementBoundingBox'): data.method.signature.return_types.return_types = [ FunctionType(is_optional=False, names=[ 'Vector3', ]), FunctionType(is_optional=False, names=[ 'Vector3', ]) ] for data in each_oop_data_from_list_by_name(oop_list, ListType.SHARED, 'setElementBoundingBox'): data.method.signature.arguments.arguments = [ [ FunctionArgument(default_value=None, argument_type=FunctionType(is_optional=False, names=[ 'Vector3', ]), name='vectorized') ], ]
def vectorize_method_return_type(method: FunctionData, how: VectorizableType) -> None: method.signature.return_types.return_types = [ FunctionType( names=[how.value], is_optional=False, ) ]
def vectorize_method_args(method: FunctionData, how: VectorizableType) -> None: method.signature.arguments.arguments = [[ FunctionArgument( name='vectorized', argument_type=FunctionType( names=[how.value], is_optional=False, ), default_value=None, ) ], *method.signature.arguments.arguments[6 if how == VectorizableType. Matrix else 3:]]
def test_function_generate_arg_text(): arg = [ FunctionArgument( name='z', argument_type=FunctionType( names=['float'], is_optional=True, ), default_value=None, ), FunctionArgument( name='z_1', argument_type=FunctionType( names=['string'], is_optional=False, ), default_value='aasdasd', ), ] expected = 'z?: float | string' result = TypeScriptFunctionGenerator.function_arg_text(arg) assert result == expected
def generate_file_content(data_list: List[List[EventData]], side: str) -> str: result = ( FilterEventSaveDeclarations.FILE_STARTER + FilterFunctionSave.generate_imports( FilterEventSaveDeclarations.imports[side], '../structure')) # TODO: split declaration generator and file # composer into separated filter classes data_list = sorted(data_list, key=lambda x: x[0].name) for data_list in data_list: data = data_list[0] name = FilterEventSaveNames.normalize_enum_variable_name(data.name) arguments = deepcopy(data.arguments) # Add this:void argument arguments.arguments.insert( 0, [ FunctionArgument( name='this', argument_type=FunctionType( names=['void'], is_optional=False, ), default_value=None, ) ], ) function_type = TypeScriptFunctionGenerator.generate_arguments( arguments) function_type = function_type.replace('\n ', '\n ') result += f''' export interface {name} extends GenericEventHandler {{ name: EventNames.{name}; function: ( {function_type} ) => void; }} ''' return result
def test_function_generate_arguments_last_varargs_cut( function_generator_fixture: TypeScriptFunctionGenerator): function_generator_fixture.data.signature.arguments.arguments.append([ FunctionArgument( name='arguments', argument_type=FunctionType(names=['var'], is_optional=True), default_value=None, ) ]) expected = '''x: float, y: float, z: float | string, citiesonly?: bool, ...varargs: any[]''' result = function_generator_fixture.generate_arguments( function_generator_fixture.data.signature.arguments) assert result == expected
def get_returns(self) -> FunctionReturnTypes: """ Gets return types of the function """ return_types: List[FunctionType] = [] is_variable_length = False is_optional = False append_type = False for token in self.tokenized: # All return types was provided before the function name if token.type == self.TokenType.FUNCTION_NAME: break if token.type == self.TokenType.OPTIONAL_START: is_optional = True continue if token.type == self.TokenType.OPTIONAL_END: is_optional = False continue if token.type == self.TokenType.VARARGS_RETURN_SIGN: is_variable_length = True continue if token.type == self.TokenType.TYPE_UNION_SIGN: append_type = True continue if token.type == self.TokenType.RETURN_TYPE: if append_type: return_types[-1].names.append(token.value) append_type = False else: return_types.append(FunctionType(names=[token.value], is_optional=is_optional)) return FunctionReturnTypes(return_types=return_types, variable_length=is_variable_length)
FunctionReturnTypes, \ FunctionSignature, \ FunctionDoc, \ FunctionData, \ CompoundFunctionData DUMP_PARTIAL = [ CompoundFunctionData( server=[ FunctionData( signature=FunctionSignature( name='addBan', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['ban'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument( name='IP', argument_type=FunctionType( names=['string'], is_optional=True, ), default_value=None, ) ],
def function_generator_fixture() -> TypeScriptFunctionGenerator: data = FunctionData( signature=FunctionSignature( name='getZoneName', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['string', 'mixed'], is_optional=True, ), FunctionType( names=['int'], is_optional=False, ), ], variable_length=True, ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument( name='x', argument_type=FunctionType( names=['float'], is_optional=False, ), default_value=None, ) ], [ FunctionArgument( name='y', argument_type=FunctionType( names=['float'], is_optional=False, ), default_value=None, ) ], [ FunctionArgument( name='z', argument_type=FunctionType( names=['float'], is_optional=False, ), default_value=None, ), FunctionArgument( name='z_1', argument_type=FunctionType( names=['string'], is_optional=False, ), default_value=None, ), ], [ FunctionArgument( name='citiesonly', argument_type=FunctionType( names=['bool'], is_optional=True, ), default_value='false', ) ]], variable_length=True, ), ), url='getZoneName', docs=FunctionDoc( description="This function allows you to retrieve " "the zone name of a certain location. ", arguments={ "x": """The X axis position """, "y": """The Y axis position """, "z": """The Z axis position """, "citiesonly": (": An optional argument to choose if you want " "to return one of the following city names:\n" "** Tierra Robada\n" "** Bone County\n" "** Las Venturas\n" "** San Fierro\n" "** Red County\n" "** Whetstone\n" "** Flint County\n" "** Los Santos ") }, result="""returns the string of the zone name """, ), ) url = PageUrl( url="/wiki/GetZoneName", name="getZoneName", category="World functions", type=ListType.SERVER, ) return TypeScriptFunctionGenerator(data=data, url=url, host_name='https://example.com')
], ), CompoundOOPData( server=[], client=[ FunctionOOP( description=None, base_function_name="getLightColor", class_name='light', method=FunctionData( signature=FunctionSignature( name='getColor', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['int'], is_optional=False, ), FunctionType( names=['int'], is_optional=False, ), FunctionType( names=['int'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument(
name='onClientPickupHit', docs=FunctionDoc( description='This event triggers whenever a pickup is hit clientside.' , arguments={ "thePlayer": """the player that hit the pickup """, "matchingDimension": """true if thePlayer is in the same dimension as the pickup, false otherwise. """ }, result='' , ), arguments=FunctionArgumentValues( arguments=[ [ FunctionArgument( name='thePlayer', argument_type=FunctionType( names=['player'], is_optional=False, ), default_value=None, ) ], [ FunctionArgument( name='matchingDimension', argument_type=FunctionType( names=['bool'], is_optional=False, ), default_value=None, ) ] ],
def apply_actions(processor: FilterDumpProcessPost, function_name: str, functions: List[List[FunctionData]], side: ListType, actions: Dict[str, Any]): if 'properties' in actions: properties: Dict[str, Any] = actions['properties'] variable_length = properties.get('variableLength') if variable_length is not None: for function in functions: for declaration in function: declaration.signature.arguments.variable_length = False print( f' Applied variable_length =' f' \u001b[34m{variable_length}\u001b[0m' ) if 'addGeneric' in actions: generic_list: List[Dict[str, str]] = actions['addGeneric'] for generic in generic_list: name = generic['name'] extends = generic.get('extends') default = generic.get('default') processor.add_generic_type(functions, FunctionGeneric( name=name, extends=extends, default_value=default, )) print(' Add generic parameter:') print(f' Name: \u001b[34m{name}\u001b[0m') print(f' Extends: \u001b[34m{extends}\u001b[0m') print(f' Default: \u001b[34m{default}\u001b[0m') if 'replaceArgument' in actions: argument_list: List[Dict[str, Any]] = actions['replaceArgument'] for argument in argument_list: name = argument['name'] arguments = processor.get_signature_arguments_by_name(functions, name) if not arguments: raise FilterDumpProcessPostError( 'No arguments found.\n' f'Side: {side}, name: ' f'{function_name}, argument: {name}' ) argument_data = argument['newArgument'] for inner_argument in arguments: to_replace = inner_argument[0] arg_name = argument_data.get('name') if arg_name is not None: to_replace.name = arg_name arg_default = argument_data.get('default') if arg_default is not None: to_replace.default_value = arg_default arg_type: Dict[str, Any] = argument_data.get('type') if arg_type is not None: arg_type_names = arg_type['names'] arg_type_optional = arg_type.get('isOptional') to_replace.argument_type.names = arg_type_names to_replace.argument_type.is_optional = arg_type_optional print(f' Replaced parameter {name}:') print(f' Name: \u001b[34m{arg_name}\u001b[0m') print(f' Extends: \u001b[34m{arg_default}\u001b[0m') print(f' Type: \u001b[34m{arg_type}\u001b[0m') if 'addArgument' in actions: argument_list: List[Dict[str, Any]] = actions['addArgument'] for argument in argument_list: arg_name = argument.get('name') arg_default = argument.get('default') arg_type: Dict[str, Any] = argument.get('type', dict()) f_arg_type = FunctionType(names=['unknown'], is_optional=False) if arg_type is not None: arg_type_names = arg_type.get('names', []) arg_type_optional = arg_type.get('isOptional') f_arg_type = FunctionType(names=arg_type_names, is_optional=arg_type_optional) arg = FunctionArgument(name=arg_name, argument_type=f_arg_type, default_value=arg_default) processor.add_signature_argument(functions, [arg]) print(' Add argument:') print(f' Name: \u001b[34m{arg_name}\u001b[0m') print(f' Extends: \u001b[34m{arg_default}\u001b[0m') print(f' Type: \u001b[34m{arg_type}\u001b[0m') if 'removeArgument' in actions: argument_list: List[Dict[str, Any]] = actions['removeArgument'] for argument in argument_list: arg_name = argument.get('name') processor.remove_signature_argument(side, functions, arg_name) print(f' Removed argument \u001b[34m{arg_name}\u001b[0m') if 'replaceReturnType' in actions: return_types: List[str] = actions['replaceReturnType']['values'] for f_inner in functions: for f in f_inner: f.signature.return_types.return_types = [ FunctionType( is_optional=False, names=[value], ) for value in return_types ] print(' Replaced return types\u001b[0m')
def get_argument(self, index_from: int, argument_context: Dict[str, Any]) -> \ Tuple[List[FunctionArgument], int]: """ Parse a single argument :param index_from: Index to start :param argument_context: Context :return: Parsed argument and index to continue """ stop_token = { self.TokenType.ARGUMENT_END, self.TokenType.COMMA_SIGN, } result: List[FunctionArgument] = [] partial_name: Optional[str] = None partial_type: Optional[FunctionType] = None partial_default = None append = False index = index_from while index < len(self.tokenized): token = self.tokenized[index] if token.type in stop_token and partial_name is not None: # Add on stop and only if there was a name result.append(FunctionArgument(name=partial_name, argument_type=partial_type, default_value=partial_default)) break # Special tokens to update the context if token.type == self.TokenType.OPTIONAL_START: argument_context['optional_counter'] += 1 elif token.type == self.TokenType.OPTIONAL_END: argument_context['optional_counter'] -= 1 elif token.type == self.TokenType.VARARGS_SIGN: argument_context['is_variable_length'] = True elif token.type == self.TokenType.TYPE_UNION_SIGN: append = True elif token.type == self.TokenType.ARGUMENT_TYPE: if append: if partial_name is None: partial_type.names.append(token.value) index += 1 continue else: result.append(FunctionArgument( name=partial_name, argument_type=partial_type, default_value=partial_default) ) partial_name = None partial_default = None append = False partial_type = FunctionType( names=[token.value], is_optional=argument_context['optional_counter'] > 0 ) elif token.type == self.TokenType.ARGUMENT_NAME: partial_name = token.value elif token.type == self.TokenType.DEFAULT_VALUE: partial_default = token.value index += 1 return result, index
name='onClientCharacter', docs=FunctionDoc( description= 'This event triggers whenever the user presses an alphanumeric character on their keyboard. This also includes special characters, ie. / # % { }.', arguments={ "character": """: a string representing the pressed character. """ }, result='', ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument( name='character', argument_type=FunctionType( names=['string'], is_optional=False, ), default_value=None, ) ]], variable_length=False, ), ) ], ), CompoundEventData( server=[], client=[ EventData( name='onClientClick', docs=FunctionDoc(
def vectorize_field(field: FunctionOOPField, how: VectorizableType) -> \ None: field.types = [FunctionType( names=[how.value], is_optional=False, )]
client=[], ), CompoundOOPData( server=[], client=[ FunctionOOP( description=None, base_function_name="getProjectileCounter", class_name='projectile', method=FunctionData( signature=FunctionSignature( name='getCounter', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['int'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument( name='projectile', argument_type=FunctionType( names=['projectile'], is_optional=False, ), default_value=None, ) ]],
CompoundOOPData( server=[ ], client=[ FunctionOOP( description=None, base_function_name="engineApplyShaderToWorldTexture", class_name='shader', method=FunctionData( signature=FunctionSignature( name='applyToWorldTexture', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['bool'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[ [ FunctionArgument( name='shader', argument_type=FunctionType( names=['element'], is_optional=False, ), default_value=None, )
CompoundOOPData( server=[ ], client=[ FunctionOOP( description=None, base_function_name="getSearchLightEndPosition", class_name='Element/Searchlight|searchLight', method=FunctionData( signature=FunctionSignature( name='getEndPosition', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['float'], is_optional=False, ), FunctionType( names=['float'], is_optional=False, ), FunctionType( names=['float'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[ [
FunctionReturnTypes, \ FunctionSignature, \ FunctionDoc, \ FunctionData, \ CompoundFunctionData DUMP_PARTIAL = [ CompoundFunctionData( server=[ FunctionData( signature=FunctionSignature( name='getOriginalWeaponProperty', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['int'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument( name='weaponID', argument_type=FunctionType( names=['int'], is_optional=False, ), default_value=None, ), FunctionArgument(
client=[], ), CompoundOOPData( server=[ FunctionOOP( description= """This OOP syntax is for [[Element/Weapon|custom weapons]] only.""", base_function_name="getWeaponProperty", class_name='Element/Weapon|weapon', method=FunctionData( signature=FunctionSignature( name='getProperty', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['int'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument( name='weaponID', argument_type=FunctionType( names=['int'], is_optional=False, ), default_value=None, ), FunctionArgument(
FunctionType, \ FunctionArgument dx_create_texture_function: FunctionData = FunctionData( url='dxCreateTexture', docs=FunctionDoc( description='This function creates a texture ' 'element that can be used in the dxDraw functions', arguments={}, result='Returns a texture if successful, ' 'false if invalid arguments were passed to the function.'), signature=FunctionSignature( name='dxCreateTexture', return_types=FunctionReturnTypes( return_types=[ FunctionType(is_optional=False, names=['DxTexture']) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[ [ FunctionArgument( name='width', argument_type=FunctionType(is_optional=False, names=['number']), default_value=None, ) ], [ FunctionArgument(
server=[], client=[], ), CompoundOOPData( server=[ FunctionOOP( description=None, base_function_name="getTimerDetails", class_name='timer', method=FunctionData( signature=FunctionSignature( name='getDetails', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['int'], is_optional=False, ), FunctionType( names=['int'], is_optional=False, ), FunctionType( names=['int'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument(
server=[], client=[ EventData( name='onClientProjectileCreation', docs=FunctionDoc( description= 'This event is triggered when a projectile is created.', arguments={ "creator": """the element that created the projectile. """ }, result='', ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument( name='creator', argument_type=FunctionType( names=['element'], is_optional=False, ), default_value=None, ) ]], variable_length=False, ), ) ], ) ]
FunctionReturnTypes, \ FunctionSignature, \ FunctionDoc, \ FunctionData, \ CompoundFunctionData DUMP_PARTIAL = [ CompoundFunctionData( server=[ FunctionData( signature=FunctionSignature( name='getBodyPartName', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['string'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[ [ FunctionArgument( name='bodyPartID', argument_type=FunctionType( names=['int'], is_optional=False, ), default_value=None, )
FunctionReturnTypes, \ FunctionSignature, \ FunctionDoc, \ FunctionData, \ CompoundFunctionData DUMP_PARTIAL = [ CompoundFunctionData( server=[ FunctionData( signature=FunctionSignature( name='getLoadedModules', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['table'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[ ], variable_length=False, ), generic_types=[ ], ), docs=FunctionDoc(
arguments={ "text": """The text that was output to chatbox. """, "r": """The amount of red in the color of the text. """, "g": """The amount of green in the color of the text. """, "b": """The amount of blue in the color of the text. """, "messageType": """The type of message as a number. """ }, result='' , ), arguments=FunctionArgumentValues( arguments=[ [ FunctionArgument( name='text', argument_type=FunctionType( names=['string'], is_optional=False, ), default_value=None, ) ], [ FunctionArgument( name='r', argument_type=FunctionType( names=['int'], is_optional=False, ), default_value=None, ) ], [
FunctionReturnTypes, \ FunctionSignature, \ FunctionDoc, \ FunctionData, \ CompoundFunctionData DUMP_PARTIAL = [ CompoundFunctionData( server=[ FunctionData( signature=FunctionSignature( name='loadMapData', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['element'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument( name='node', argument_type=FunctionType( names=['xmlnode'], is_optional=False, ), default_value=None, ) ],
FunctionReturnTypes, \ FunctionSignature, \ FunctionDoc, \ FunctionData, \ CompoundFunctionData DUMP_PARTIAL = [ CompoundFunctionData( server=[ FunctionData( signature=FunctionSignature( name='createExplosion', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['bool'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[[ FunctionArgument( name='x', argument_type=FunctionType( names=['float'], is_optional=False, ), default_value=None, ) ],
], ), CompoundOOPData( server=[ FunctionOOP( description=None, base_function_name="dbExec", class_name='connection', method=FunctionData( signature=FunctionSignature( name='exec', return_types=FunctionReturnTypes( return_types=[ FunctionType( names=['bool'], is_optional=False, ) ], variable_length=False, ), arguments=FunctionArgumentValues( arguments=[ [ FunctionArgument( name='databaseConnection', argument_type=FunctionType( names=['element'], is_optional=False, ), default_value=None, )
description='' , arguments={ "fileResource": """Resource the file belongs to. """, "fileName": """Relative resource file path. """, "fileSize": """Size of the file in bytes. """, "state": """Possible values: <code>queued</code> or <code>finished</code> or <code>failed</code>. """ }, result='' , ), arguments=FunctionArgumentValues( arguments=[ [ FunctionArgument( name='fileResource', argument_type=FunctionType( names=['resource'], is_optional=False, ), default_value=None, ) ], [ FunctionArgument( name='fileName', argument_type=FunctionType( names=['string'], is_optional=False, ), default_value=None, ) ], [