rayjs/bindings/src/index.ts

252 lines
11 KiB
TypeScript
Raw Normal View History

2023-05-06 21:43:40 +00:00
import { readFileSync, writeFileSync } from "fs";
2023-05-10 21:26:53 +00:00
import { RayLibApi } from "./interfaces";
2023-05-06 21:43:40 +00:00
import { ApiDescription } from "./api";
2023-05-08 14:43:50 +00:00
import { RayLibHeader } from "./raylib-header";
2023-05-06 21:43:40 +00:00
function main(){
const api = <RayLibApi>JSON.parse(readFileSync("thirdparty/raylib/parser/output/raylib_api.json", 'utf8'))
const apiDesc = new ApiDescription(api)
2023-05-08 14:43:50 +00:00
const core_gen = new RayLibHeader("raylib_core", apiDesc)
2023-05-08 21:37:58 +00:00
core_gen.addApiStructByName("Color", {
properties: {
r: { get: true, set: true },
g: { get: true, set: true },
b: { get: true, set: true },
a: { get: true, set: true },
2023-05-09 21:25:28 +00:00
},
createConstructor: true
2023-05-08 21:37:58 +00:00
})
2023-05-11 20:10:40 +00:00
core_gen.addApiStructByName("Rectangle", {
properties: {
x: { get: true, set: true },
y: { get: true, set: true },
width: { get: true, set: true },
height: { get: true, set: true },
},
createConstructor: true
})
2023-05-10 21:26:53 +00:00
core_gen.addApiStructByName("Vector2", {
properties: {
x: { get: true, set: true },
y: { get: true, set: true },
},
createConstructor: true
})
2023-05-13 12:49:05 +00:00
core_gen.addApiStructByName("Vector3", {
properties: {
x: { get: true, set: true },
y: { get: true, set: true },
z: { get: true, set: true },
},
createConstructor: true
})
core_gen.addApiStructByName("Ray", {
properties: {
position: { get: false, set: true },
direction: { get: false, set: true },
},
createConstructor: true
})
core_gen.addApiStructByName("Camera2D",{
properties: {
offset: { get: false, set: true },
target: { get: false, set: true },
rotation: { get: true, set: true },
zoom: { get: true, set: true },
},
createConstructor: true
})
core_gen.addApiStructByName("Matrix",{
properties: {},
createConstructor: false
})
// Window-related functions
core_gen.addApiFunctionByName("InitWindow")
core_gen.addApiFunctionByName("WindowShouldClose")
core_gen.addApiFunctionByName("CloseWindow")
core_gen.addApiFunctionByName("IsWindowReady")
core_gen.addApiFunctionByName("IsWindowFullscreen")
core_gen.addApiFunctionByName("IsWindowHidden")
core_gen.addApiFunctionByName("IsWindowMinimized")
core_gen.addApiFunctionByName("IsWindowMaximized")
core_gen.addApiFunctionByName("IsWindowFocused")
core_gen.addApiFunctionByName("IsWindowResized")
core_gen.addApiFunctionByName("IsWindowState")
core_gen.addApiFunctionByName("SetWindowState")
core_gen.addApiFunctionByName("ClearWindowState")
core_gen.addApiFunctionByName("ToggleFullscreen")
core_gen.addApiFunctionByName("MaximizeWindow")
core_gen.addApiFunctionByName("MinimizeWindow")
core_gen.addApiFunctionByName("RestoreWindow")
// SetWindowIcon
// SetWindowIcons
2023-05-06 21:43:40 +00:00
core_gen.addApiFunctionByName("SetWindowTitle")
core_gen.addApiFunctionByName("SetWindowPosition")
2023-05-13 12:49:05 +00:00
core_gen.addApiFunctionByName("SetWindowMonitor")
core_gen.addApiFunctionByName("SetWindowMinSize")
core_gen.addApiFunctionByName("SetWindowSize")
core_gen.addApiFunctionByName("SetWindowOpacity")
// GetWindowHandle
core_gen.addApiFunctionByName("GetScreenWidth")
core_gen.addApiFunctionByName("GetScreenHeight")
core_gen.addApiFunctionByName("GetRenderWidth")
core_gen.addApiFunctionByName("GetRenderHeight")
core_gen.addApiFunctionByName("GetMonitorCount")
core_gen.addApiFunctionByName("GetCurrentMonitor")
core_gen.addApiFunctionByName("GetMonitorPosition")
core_gen.addApiFunctionByName("GetMonitorWidth")
core_gen.addApiFunctionByName("GetMonitorHeight")
core_gen.addApiFunctionByName("GetMonitorPhysicalWidth")
core_gen.addApiFunctionByName("GetMonitorPhysicalHeight")
core_gen.addApiFunctionByName("GetMonitorRefreshRate")
core_gen.addApiFunctionByName("GetWindowPosition")
core_gen.addApiFunctionByName("GetWindowScaleDPI")
core_gen.addApiFunctionByName("GetMonitorName")
core_gen.addApiFunctionByName("SetClipboardText")
core_gen.addApiFunctionByName("GetClipboardText")
core_gen.addApiFunctionByName("EnableEventWaiting")
core_gen.addApiFunctionByName("DisableEventWaiting")
// Custom frame control functions
// NOT SUPPORTED BECAUSE NEEDS COMPILER FLAG
// Cursor-related functions
core_gen.addApiFunctionByName("ShowCursor")
core_gen.addApiFunctionByName("HideCursor")
core_gen.addApiFunctionByName("IsCursorHidden")
core_gen.addApiFunctionByName("EnableCursor")
core_gen.addApiFunctionByName("DisableCursor")
core_gen.addApiFunctionByName("IsCursorOnScreen")
// Drawing related functions
core_gen.addApiFunctionByName("ClearBackground")
2023-05-06 21:43:40 +00:00
core_gen.addApiFunctionByName("BeginDrawing")
2023-05-11 20:10:40 +00:00
core_gen.addApiFunctionByName("EndDrawing", null, { before: fun => fun.call("app_update_quickjs", []) })
2023-05-13 12:49:05 +00:00
core_gen.addApiFunctionByName("BeginMode2D")
core_gen.addApiFunctionByName("EndMode2D")
//core_gen.addApiFunctionByName("BeginMode3D")
//core_gen.addApiFunctionByName("EndMode3D")
//core_gen.addApiFunctionByName("BeginTextureMode")
//core_gen.addApiFunctionByName("EndTextureMode")
//core_gen.addApiFunctionByName("BeginShaderMode")
//core_gen.addApiFunctionByName("EndShaderMode")
core_gen.addApiFunctionByName("BeginBlendMode")
core_gen.addApiFunctionByName("EndBlendMode")
core_gen.addApiFunctionByName("BeginScissorMode")
core_gen.addApiFunctionByName("EndScissorMode")
//core_gen.addApiFunctionByName("BeginVrStereoMode")
//core_gen.addApiFunctionByName("EndVrStereoMode")
// VR Stereo config options
//core_gen.addApiFunctionByName("LoadVrStereoConfig")
//core_gen.addApiFunctionByName("UnloadVrStereoConfig")
// Shader Management
// core_gen.addApiFunctionByName("LoadShader")
// core_gen.addApiFunctionByName("LoadShaderFromMemory")
// core_gen.addApiFunctionByName("IsShaderReady")
// core_gen.addApiFunctionByName("GetShaderLocation")
// core_gen.addApiFunctionByName("GetShaderLocationAttrib")
// core_gen.addApiFunctionByName("SetShaderValue")
// core_gen.addApiFunctionByName("SetShaderValueV")
// core_gen.addApiFunctionByName("SetShaderValueMatrix")
// core_gen.addApiFunctionByName("SetShaderValueTexture")
// // "UnloadShader" is destructor
// ScreenSpaceRelatedFunctions
//core_gen.addApiFunctionByName("GetMouseRay")
//core_gen.addApiFunctionByName("GetCameraMatrix")
core_gen.addApiFunctionByName("GetCameraMatrix2D")
//core_gen.addApiFunctionByName("GetWorldToScreen")
core_gen.addApiFunctionByName("GetScreenToWorld2D")
//core_gen.addApiFunctionByName("GetScreenToWorldEx")
core_gen.addApiFunctionByName("GetWorldToScreen2D")
// Timing related functions
2023-05-10 21:26:53 +00:00
core_gen.addApiFunctionByName("SetTargetFPS")
2023-05-13 12:49:05 +00:00
core_gen.addApiFunctionByName("GetFPS")
core_gen.addApiFunctionByName("GetFrameTime")
core_gen.addApiFunctionByName("GetTime")
// Misc functions
core_gen.addApiFunctionByName("GetRandomValue")
core_gen.addApiFunctionByName("SetRandomSeed")
core_gen.addApiFunctionByName("TakeScreenshot")
core_gen.addApiFunctionByName("SetConfigFlags")
const traceLog = apiDesc.getFunction("TraceLog")
if(!traceLog) throw new Error("TraceLog not found")
traceLog.params.pop()
core_gen.addApiFunction(traceLog)
core_gen.addApiFunctionByName("SetTraceLogLevel")
// Memory functions not supported on JS
core_gen.addApiFunctionByName("OpenURL")
// Callbacks not supported on JS
// Files management functions
//core_gen.addApiFunctionByName("LoadFileData")
//core_gen.addApiFunctionByName("UnloadLoadFileData")
//core_gen.addApiFunctionByName("SaveFileData")
// Export data as code not needed
core_gen.addApiFunctionByName("LoadFileText", null, { after: gen => gen.call("UnloadFileText", ["returnVal"]) })
core_gen.addApiFunctionByName("SaveFileText")
core_gen.addApiFunctionByName("FileExists")
core_gen.addApiFunctionByName("DirectoryExists")
core_gen.addApiFunctionByName("IsFileExtension")
// TODO: Who needs to clean memory here?
core_gen.addApiFunctionByName("GetFileLength")
core_gen.addApiFunctionByName("GetFileExtension")
core_gen.addApiFunctionByName("GetFileName")
core_gen.addApiFunctionByName("GetFileNameWithoutExt")
core_gen.addApiFunctionByName("GetDirectoryPath")
core_gen.addApiFunctionByName("GetPrevDirectoryPath")
core_gen.addApiFunctionByName("GetWorkingDirectory")
core_gen.addApiFunctionByName("GetApplicationDirectory")
core_gen.addApiFunctionByName("ChangeDirectory")
core_gen.addApiFunctionByName("IsPathFile")
//core_gen.addApiFunctionByName("LoadPathFiles")
//core_gen.addApiFunctionByName("LoadPathFilesEx")
// UnloadDirectoryFiles
core_gen.addApiFunctionByName("IsFileDropped")
//core_gen.addApiFunctionByName("LoadDroppedFiles")
// UnloadDroppedFiles
core_gen.addApiFunctionByName("GetFileModTime")
2023-05-09 21:25:28 +00:00
core_gen.addApiFunctionByName("DrawText")
2023-05-13 12:49:05 +00:00
core_gen.addApiFunctionByName("DrawLine")
2023-05-10 21:26:53 +00:00
core_gen.addApiFunctionByName("DrawCircleV")
core_gen.addApiFunctionByName("IsKeyDown")
2023-05-13 12:49:05 +00:00
core_gen.addApiFunctionByName("IsKeyPressed")
2023-05-11 20:10:40 +00:00
core_gen.addApiFunctionByName("GetMousePosition")
core_gen.addApiFunctionByName("IsMouseButtonPressed")
core_gen.addApiFunctionByName("GetMouseWheelMove")
core_gen.addApiFunctionByName("DrawRectangle")
2023-05-13 12:49:05 +00:00
core_gen.addApiFunctionByName("DrawRectangleRec")
core_gen.addApiFunctionByName("DrawRectangleLines")
core_gen.addApiFunctionByName("Fade")
2023-05-10 21:26:53 +00:00
api.defines.filter(x => x.type === "COLOR").map(x => ({ name: x.name, values: (x.value.match(/\{([^}]+)\}/) || "")[1].split(',').map(x => x.trim()) })).forEach(x => {
core_gen.exportGlobalStruct("Color", x.name, x.values)
})
2023-05-11 18:54:49 +00:00
api.enums.find(x => x.name === "KeyboardKey")?.values.forEach(x => core_gen.exportGlobalConstant(x.name))
2023-05-11 20:10:40 +00:00
api.enums.find(x => x.name === "MouseButton")?.values.forEach(x => core_gen.exportGlobalConstant(x.name))
2023-05-13 12:49:05 +00:00
api.enums.find(x => x.name === "ConfigFlags")?.values.forEach(x => core_gen.exportGlobalConstant(x.name))
api.enums.find(x => x.name === "BlendMode")?.values.forEach(x => core_gen.exportGlobalConstant(x.name))
api.enums.find(x => x.name === "TraceLogLevel")?.values.forEach(x => core_gen.exportGlobalConstant(x.name))
2023-05-08 14:43:50 +00:00
core_gen.writeTo("src/bindings/js_raylib_core.h")
2023-05-06 21:43:40 +00:00
2023-05-08 14:43:50 +00:00
const texture_gen = new RayLibHeader("raylib_texture", apiDesc)
2023-05-08 21:37:58 +00:00
texture_gen.addApiStructByName("Image", {
properties: {
width: { get: true },
height: { get: true }
},
destructor: "UnloadImage"
})
texture_gen.addApiFunctionByName("LoadImage")
2023-05-08 14:43:50 +00:00
texture_gen.writeTo("src/bindings/js_raylib_texture.h")
2023-05-06 21:43:40 +00:00
}
main()