Skip to content

Commit

Permalink
Use Raylean and Raylean.Type namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Sep 3, 2024
1 parent 0c09e10 commit ef188ef
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lean/Examples/Camera2DPlatformer.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ open Types

namespace Camera2DPlatformer

open Raylean
open Raylean.Types

def screenWidth : Nat := 800
def screenHeight : Nat := 450
def fps : Nat := 60
Expand Down
2 changes: 2 additions & 0 deletions lean/Examples/Camera2DPlatformer/Types.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Lens

namespace Types

open Raylean.Types

structure Player where
position : Vector2
speed : Float
Expand Down
3 changes: 3 additions & 0 deletions lean/Examples/Camera3D.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import «Raylean»

namespace Camera3D

open Raylean
open Raylean.Types

private def screenWidth : Nat := 1000
private def screenHeight : Nat := 600
private def fps : Nat := 120
Expand Down
3 changes: 3 additions & 0 deletions lean/Examples/InputKeys.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import «Raylean»

namespace InputKeys

open Raylean
open Raylean.Types

private def screenWidth : Nat := 800
private def screenHeight : Nat := 450

Expand Down
3 changes: 3 additions & 0 deletions lean/Examples/JessicaCantSwim.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import Examples.JessicaCantSwim.Game

namespace JessicaCantSwim

open Raylean
open Raylean.Types

def getKeys: IO (List Keys.Keys) := do
let mut keys := #[]
if (← isKeyDown Key.down)
Expand Down
3 changes: 3 additions & 0 deletions lean/Examples/Selector.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Examples.Elab

namespace Selector

open Raylean
open Raylean.Types

/-- Demos supported in the selector --/
inductive Demo where
| jessica
Expand Down
3 changes: 3 additions & 0 deletions lean/Examples/Window.lean
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import «Raylean»

namespace Window

open Raylean.Types
open Raylean

def screenWidth : Nat := 800
def screenHeight : Nat := 600

Expand Down
15 changes: 4 additions & 11 deletions lean/Raylean/Core.lean
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import «Raylean».Types

namespace Raylean

open Raylean.Types

/- Window-related functions -/

@[extern "initWindow"]
Expand Down Expand Up @@ -111,20 +115,9 @@ opaque drawCubeWires : (position : Vector3) → (width : Float) → (height : Fl
@[extern "drawGrid"]
opaque drawGrid : (slices : Nat) → (spacing : Float) → IO Unit

@[extern "image_width"]
opaque Image.width (image : @& Image) : Nat

@[extern "image_height"]
opaque Image.height (image : @& Image) : Nat
@[extern "loadImage"]
opaque loadImage : (resourceName : @& String) -> IO Image

@[extern "texture2d_width"]
opaque Texture2D.width (texture2d : @& Texture2D) : Nat

@[extern "texture2d_height"]
opaque Texture2D.height (texture2d : @& Texture2D) : Nat

@[extern "loadTextureFromImage"]
opaque loadTextureFromImage : (image : @& Image) -> IO Texture2D

Expand Down
4 changes: 4 additions & 0 deletions lean/Raylean/Frame.lean
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import «Raylean».Core

namespace Raylean

open Raylean.Types

def renderFrame [Monad m] [MonadLiftT IO m] (mkFrame : m Unit) : m Unit := do
beginDrawing
mkFrame
Expand Down
6 changes: 6 additions & 0 deletions lean/Raylean/Math.lean
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import Raylean.Types

namespace Raylean

namespace Math

namespace Vector2

open Raylean.Types

def add (v1 : Vector2) (v2 : Vector2) : Vector2 :=
{ x := v1.x + v2.x, y := v1.y + v1.y : Vector2 }

Expand Down
20 changes: 20 additions & 0 deletions lean/Raylean/Types.lean
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
namespace Raylean

namespace Types

structure Vector2 where
x : Float
y : Float
Expand Down Expand Up @@ -125,6 +129,22 @@ private opaque Texture2DP : NonemptyType
def Texture2D := Texture2DP.type
instance : Nonempty Texture2D := Texture2DP.property

-- fields of Texture2D defined directly using a namespace must be in the same
-- namespace as Texture2D
@[extern "texture2d_width"]
opaque Texture2D.width (texture2d : @& Texture2D) : Nat

@[extern "texture2d_height"]
opaque Texture2D.height (texture2d : @& Texture2D) : Nat

private opaque ImageP : NonemptyType
def Image := ImageP.type
instance : Nonempty Image := ImageP.property

-- fields of Image defined directly using a namespace must be in the same
-- namespace as Image
@[extern "image_width"]
opaque Image.width (image : @& Image) : Nat

@[extern "image_height"]
opaque Image.height (image : @& Image) : Nat

0 comments on commit ef188ef

Please sign in to comment.