rokojori-godot/rokojori-cpp-generator/source/cpp-creation/members/Member.ts

133 lines
2.7 KiB
TypeScript

import { GodotTypes } from "../GodotTypes";
import { MemberInitializer } from "../MemberInitializer";
import { MemberType } from "../MemberType";
import { Parameter } from "../Parameter";
export abstract class Member
{
memberType:MemberType;
name = "";
isMethod = false;
isVirtual = true;
isStatic = false;
isSignal = false;
type = "void";
initialValue:string = null;
parameters:Parameter[] = [];
accessModifier = "";
parametersDefinition = "";
constructor( memberType:MemberType, memberInitializer:MemberInitializer )
{
this.memberType = memberType;
this.accessModifier = memberInitializer.accessModifier;
this.name = memberInitializer.name;
this.type = memberInitializer.type || this.type;
this.isMethod = memberInitializer.isMethod;
this.isSignal = memberInitializer.isSignal;
this.isStatic = memberInitializer.isStatic;
this.isVirtual = memberInitializer.isVirtual;
}
info()
{
let methodBrackets = this.isMethod ? "()" : "";
if ( methodBrackets === "()" && this.parameters.length > 0 )
{
methodBrackets = "( " + this.parametersDefinition + " )";
}
if ( this.isSignal )
{
}
return `// ${this.isSignal? "[signal] ": "" }${this.name}${methodBrackets} : ${this.type}`;
}
setPublic()
{
this.accessModifier = "public";
return this;
}
setProtected()
{
this.accessModifier = "protected";
return this;
}
abstract parseBody( body:any ):void
parseMethodParameters( body:any )
{
if ( ! body )
{
return;
}
if ( typeof body === "string" )
{
this.type = body;
return;
}
for ( let it in body )
{
if ( ! body.hasOwnProperty( it ) )
{
continue;
}
let cppParameter = new Parameter();
cppParameter.name = it;
cppParameter.type = body[ it ];
this.parameters.push( cppParameter );
}
this.parametersDefinition = this.parameters.map( p => p.get() ).join( ", " );
}
abstract getBindings( className:string ):string
abstract getHeaderDefinition():string;
getParametersDefinition()
{
return this.parameters.map( p => p.type + " " + p.name ).join( ", " );
}
/*
getFieldDeclaration()
{
return `${this.type} ${this.name};`
}
getFieldImplementation( className:string )
{
let bindings = [];
bindings.push( `// ${this.name}: ${this.type}` );
bindings.push( `${this.type} ${className}::get_${this.name}() { return ${this.name}; }` );
bindings.push( `void ${className}::set_${this.name}( ${this.type} p_${this.name} ) { ${this.name} = p_${this.name}; }` );
bindings.push( ` ` );
return bindings.join( "\n" );
}
*/
}