Skip to content

Commit

Permalink
Migrated from npm to yarn. Worked on typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
NimbusFox committed Jan 4, 2021
1 parent a4d5b48 commit 076971d
Show file tree
Hide file tree
Showing 37 changed files with 863 additions and 94 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .gitmodules
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Binary file removed assets/raylib.png
Binary file not shown.
16 changes: 4 additions & 12 deletions examples/Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
ARGS = -s INITIAL_MEMORY=671088640 -fsanitize=address -s ALLOW_MEMORY_GROWTH=1 --emit-symbol-map --bind -g4 --no-entry -s USE_GLFW=3 -I../../raylib/src -I../../include -L../../raylib/src/ -lraylib --shell-file=../../raylib/src/shell.html ../../bin/raylibweb.bc

all: core models

core: dependency
cd core && emmake make ARGS="--source-map-base /example/core/ $(ARGS)"

models: dependency
cd models && emmake make ARGS="--source-map-base /example/models/ $(ARGS)"

dependency:
cd ../src/WebAssembly && emmake make static BUILD=DEBUG
all:
cd ../src/TypeScript && make examples
../node_modules/.bin/tsc -p ./core/BasicWindow/tsconfig.json
../node_modules/.bin/tsc -p ./models/MeshGeneration/tsconfig.json
22 changes: 10 additions & 12 deletions examples/core/BasicWindow/src.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import Raylib from "../../../bin/raylibWeb.js";
function loop() {

Module.BeginDrawing();

Module.ClearBackground({ r: 245, g: 245, b: 245, a: 255 });

Module.DrawText("Congrats! You created your first window!", 190, 200, 20, { r: 200, g: 200, b: 200, a: 255 })

Module.EndDrawing();
Raylib.raylibC.BeginDrawing();
Raylib.raylibC.ClearBackground({ r: 245, g: 245, b: 245, a: 255 });
Raylib.raylibC.DrawText("Congrats! You created your first window!", 190, 200, 20, { r: 200, g: 200, b: 200, a: 255 });
Raylib.raylibC.EndDrawing();
setTimeout(loop);
}

Module.onRuntimeInitialized = function () {
Module.SetLoop(loop);
Module.InitWindow(800, 450);
}
Raylib.raylibC.InitWindow(800, 450);
loop();
};
Raylib.init();
22 changes: 22 additions & 0 deletions examples/core/BasicWindow/src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Raylib from "../../../bin/raylibWeb.js";

declare let Module: any;

function loop() {
Raylib.raylibC.BeginDrawing();

Raylib.raylibC.ClearBackground({ r: 245, g: 245, b: 245, a: 255 });

(Raylib.raylibC as any).DrawText("Congrats! You created your first window!", 190, 200, 20, { r: 200, g: 200, b: 200, a: 255 })

Raylib.raylibC.EndDrawing();

setTimeout(loop);
}

Module.onRuntimeInitialized = function () {
Raylib.raylibC.InitWindow(800, 450);
loop();
}

Raylib.init();
13 changes: 13 additions & 0 deletions examples/core/BasicWindow/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "ES6",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"strict": true,
"target": "ES6",
"sourceMap": false
},
"include": ["./*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
5 changes: 0 additions & 5 deletions examples/core/Makefile

This file was deleted.

5 changes: 0 additions & 5 deletions examples/models/Makefile

This file was deleted.

49 changes: 15 additions & 34 deletions examples/models/MeshGeneration/src.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
"use strict";
var Module;
if (Module === undefined) {
Module = {};
}
let models = [];
let texture;

let camera = { position: { x: 5.0, y: 5.0, z: 5.0 }, target: { x: 0.0, y: 0.0, z: 0.0 }, up: { x: 0.0, y: 1.0, z: 0.0 }, rotation: 45.0, zoom: 0, fovy: 90, type: 0 };

let position = { x: 0.0, y: 0.0, z: 0.0 };

let current = 0;

Module.onRuntimeInitialized = function () {
Module.InitWindow(1920, 1080);

let checked = Module.GenImageChecked(2, 2, 1, 1, { r: 255, g: 0, b: 0, a: 255 }, { r: 0, g: 255, b: 0, a: 255 });

texture = Module.LoadTextureFromImage(checked);

Module.UnloadImage(checked);

models.push(Module.LoadModelFromMesh(Module.GenMeshPlane(2, 2, 5, 5)));
models.push(Module.LoadModelFromMesh(Module.GenMeshCube(2.0, 1.0, 2.0)));
models.push(Module.LoadModelFromMesh(Module.GenMeshSphere(2, 32, 32)));
Expand All @@ -24,52 +21,36 @@ Module.onRuntimeInitialized = function () {
models.push(Module.LoadModelFromMesh(Module.GenMeshTorus(0.25, 4.0, 16, 32)));
models.push(Module.LoadModelFromMesh(Module.GenMeshKnot(1.0, 2.0, 16, 128)));
models.push(Module.LoadModelFromMesh(Module.GenMeshPoly(5, 2.0)));

for (let i = 0; i < models.length; i++) {
for (let i = 0; i < models.length; i++) {
Module.SetModelTexture(models[i], 0, 0, texture);
}

Module.SetCameraMode(camera, 2);

loop();
}

};
function loop() {
camera = Module.UpdateCamera(camera);

if (Module.IsMouseButtonPressed(0)) {
current = (current + 1) % models.length;
}

if (Module.IsKeyPressed(262)) {
current++;

if (current >= models.length) {
current = 0;
}
} else if (Module.IsKeyPressed(263)) {
}
else if (Module.IsKeyPressed(263)) {
current--;

if (current < 0) {
current = models.length - 1;
}
}

Module.BeginDrawing();

Module.ClearBackground({ r: 245, g: 245, b: 245, a: 255 });

Module.BeginMode3D(camera);

Module.DrawModel(models[current], position, 1.0, {r: 255, g: 255, b: 255, a: 255});

Module.DrawGrid(10, 1.0);

Module.EndMode3D();

Module.DrawFPS(0, 0);

Module.ClearBackground({ r: 245, g: 245, b: 245, a: 255 });
Module.BeginMode3D(camera);
Module.DrawModel(models[current], position, 1.0, { r: 255, g: 255, b: 255, a: 255 });
Module.DrawGrid(10, 1.0);
Module.EndMode3D();
Module.DrawFPS(0, 0);
Module.EndDrawing();

setTimeout(loop);
}
79 changes: 79 additions & 0 deletions examples/models/MeshGeneration/src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
var Module: any;
if (Module === undefined) {
Module = {};
}
let models: any[] = [];
let texture;

let camera = { position: { x: 5.0, y: 5.0, z: 5.0 }, target: { x: 0.0, y: 0.0, z: 0.0 }, up: { x: 0.0, y: 1.0, z: 0.0 }, rotation: 45.0, zoom: 0, fovy: 90, type: 0 };

let position = { x: 0.0, y: 0.0, z: 0.0 };

let current = 0;

Module.onRuntimeInitialized = function () {
Module.InitWindow(1920, 1080);

let checked = Module.GenImageChecked(2, 2, 1, 1, { r: 255, g: 0, b: 0, a: 255 }, { r: 0, g: 255, b: 0, a: 255 });

texture = Module.LoadTextureFromImage(checked);

Module.UnloadImage(checked);

models.push(Module.LoadModelFromMesh(Module.GenMeshPlane(2, 2, 5, 5)));
models.push(Module.LoadModelFromMesh(Module.GenMeshCube(2.0, 1.0, 2.0)));
models.push(Module.LoadModelFromMesh(Module.GenMeshSphere(2, 32, 32)));
models.push(Module.LoadModelFromMesh(Module.GenMeshHemiSphere(2, 16, 16)));
models.push(Module.LoadModelFromMesh(Module.GenMeshCylinder(1, 2, 16)));
models.push(Module.LoadModelFromMesh(Module.GenMeshTorus(0.25, 4.0, 16, 32)));
models.push(Module.LoadModelFromMesh(Module.GenMeshKnot(1.0, 2.0, 16, 128)));
models.push(Module.LoadModelFromMesh(Module.GenMeshPoly(5, 2.0)));

for (let i = 0; i < models.length; i++) {
Module.SetModelTexture(models[i], 0, 0, texture);
}

Module.SetCameraMode(camera, 2);

loop();
}

function loop() {
camera = Module.UpdateCamera(camera);

if (Module.IsMouseButtonPressed(0)) {
current = (current + 1) % models.length;
}

if (Module.IsKeyPressed(262)) {
current++;

if (current >= models.length) {
current = 0;
}
} else if (Module.IsKeyPressed(263)) {
current--;

if (current < 0) {
current = models.length - 1;
}
}

Module.BeginDrawing();

Module.ClearBackground({ r: 245, g: 245, b: 245, a: 255 });

Module.BeginMode3D(camera);

Module.DrawModel(models[current], position, 1.0, {r: 255, g: 255, b: 255, a: 255});

Module.DrawGrid(10, 1.0);

Module.EndMode3D();

Module.DrawFPS(0, 0);

Module.EndDrawing();

setTimeout(loop);
}
13 changes: 13 additions & 0 deletions examples/models/MeshGeneration/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "ES6",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"strict": true,
"target": "ES6",
"sourceMap": false
},
"include": ["./*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
13 changes: 13 additions & 0 deletions examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "ES6",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"strict": true,
"target": "ES6",
"sourceMap": false
},
"include": ["./*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
Empty file modified include/JSAnimImage.h
100644 → 100755
Empty file.
Empty file modified include/JSCodepoint.h
100644 → 100755
Empty file.
Empty file modified include/cacheDatabase.h
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "raylib-js",
"version": "0.0.1",
"main": "index.js",
"repository": "[email protected]:NimbusFox/raylib-js.git",
"author": "NimbusFox <[email protected]>",
"license": "Zlib",
"dependencies": {
"typescript": "^4.1.3"
}
}
18 changes: 11 additions & 7 deletions src/TypeScript/Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
debug: copyDefinitions
tsc -p ./tsconfig.debug.json
debug: dependencies
../../node_modules/.bin/tsc -p ./tsconfig.debug.json

release: copyDefinitions
tsc -p ./tsconfig.release.json
./node_modules/.bin/browserify ../../bin/js/raylibWeb.js -o ../../bin/raylibWeb.js
release: dependencies ts_release

examples: ts_release
cd ../WebAssembly && emmake make examples MODULE=TRUE

copyDefinitions:
cp -r ./definitions/*.d.ts ../../bin/typescript
ts_release:
../../node_modules/.bin/tsc -p ./tsconfig.release.json

dependencies:
cd ../WebAssembly && emmake make build MODULE=TRUE
Loading

0 comments on commit 076971d

Please sign in to comment.