From acdbddef2faf085a79ede1dce8f08d6901b7d4a4 Mon Sep 17 00:00:00 2001 From: Ronja Date: Fri, 8 Apr 2022 12:06:40 +0200 Subject: [PATCH] repro --- .gitignore | 10 ++++ .luxeignore | 1 + game.wren | 110 +++++++++++++++++++++++++++++++++++ outline/app.wren | 74 +++++++++++++++++++++++ outline/inputs.input.lx | 23 ++++++++ outline/renderer.wren | 51 ++++++++++++++++ outline/settings.settings.lx | 19 ++++++ project.luxe | 14 +++++ project.modules.lx | 3 + 9 files changed, 305 insertions(+) create mode 100644 .gitignore create mode 100644 .luxeignore create mode 100644 game.wren create mode 100644 outline/app.wren create mode 100644 outline/inputs.input.lx create mode 100644 outline/renderer.wren create mode 100644 outline/settings.settings.lx create mode 100644 project.luxe create mode 100644 project.modules.lx diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9ab400 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*/.DS_Store +.DS_Store +.DS_Store? +*/thumbs.db +thumbs.db +.thumbs.db? +.luxe/ +_luxe.data/ +_luxe.deploy/ +log*.txt \ No newline at end of file diff --git a/.luxeignore b/.luxeignore new file mode 100644 index 0000000..a3de5ef --- /dev/null +++ b/.luxeignore @@ -0,0 +1 @@ +preview.png \ No newline at end of file diff --git a/game.wren b/game.wren new file mode 100644 index 0000000..b5793ae --- /dev/null +++ b/game.wren @@ -0,0 +1,110 @@ +import "luxe: game" for Ready +import "luxe: assets" for Assets +import "luxe: input" for Input, Key, MouseButton +import "luxe: world" for World, Entity, Transform, Sprite, Values, Tags, Camera, UIEventData +import "luxe: math" for Math +import "luxe: draw" for Draw +import "luxe: io" for IO +import "luxe: ui" for UI, UIPanel, UILabel, Control, UIEvent +import "luxe: color" for Color + +import "outline/app" for App + +class Game is Ready { + + construct ready() { + + super("ready!") + + app = App.new() + app.color = Color.black + + System.print("render size: %(app.width) x %(app.height) @ %(app.scale)x") + + var ui = Entity.create(app.ui) + UI.create(ui, 0, 0, app.width, app.height, 0, app.ui_camera) + + { //cross-control events dont work properly + var event_reciever = UIPanel.create(ui) + UIPanel.set_color(event_reciever, [1, 0, 0, 1]) + Control.set_allow_input(event_reciever, true) + Control.set_pos(event_reciever, 100, 100) + Control.set_process(event_reciever){|control: Control, state: Any, event: UIEventData, x: Num, y: Num, w: Num, h: Num| + if(event.control != control) return //required + if(event.type == UIEvent.change){ + System.print("receive") + UIPanel.set_color(event_reciever, [0, 0, 1, 1]) + } + } + + var event_sender = UILabel.create(ui) + UILabel.set_text(event_sender, "click to change panel.") + Control.set_pos(event_sender, 200, 100) + Control.set_allow_input(event_sender, true) + Control.set_process(event_sender){|control: Control, state: Any, event: UIEventData, x: Num, y: Num, w: Num, h: Num| + if(event.control != control) return //required + if(event.type == UIEvent.press){ + System.print("send") + UI.events_emit(event_reciever, UIEvent.change) + } + } + } + + { //cross-control capture doesnt work properly (clicking left control should capture right, but actually captures left with wrong debug vis) + var captured = UIPanel.create(ui) + Control.set_id(captured, "captured") + UIPanel.set_color(captured, [1, 0, 0, 1]) + Control.set_allow_input(captured, true) + Control.set_pos(captured, 200, 200) + Control.set_process(captured){|control: Control, state: Any, event: UIEventData, x: Num, y: Num, w: Num, h: Num| + if(event.control != control) return //required + if(event.type == UIEvent.move){ + System.print("move") + var rel_pos = inv_lerp(y, y+h, event.y) + var col = Color.lerp([1, 0, 0, 1], [0, 0, 1, 1], rel_pos) + UIPanel.set_color(captured, col) + } + } + + var capturing = UIPanel.create(ui) + Control.set_id(capturing, "capturing") + UIPanel.set_color(capturing, [1, 0, 0, 1]) + Control.set_allow_input(capturing, true) + Control.set_pos(capturing, 100, 200) + Control.set_process(capturing){|control: Control, state: Any, event: UIEventData, x: Num, y: Num, w: Num, h: Num| + if(event.control != control) return //required + if(event.type == UIEvent.move){ + System.print("move") + var rel_pos = inv_lerp(y, y+h, event.y) + var col = Color.lerp([1, 0, 0, 1], [0, 0, 1, 1], rel_pos) + UIPanel.set_color(capturing, col) + } + if(event.type == UIEvent.press){ + System.print("capture other") + UI.capture(captured) + } + } + } + } //ready + + inv_lerp(from, to, x){ + return (x - from) / (to - from) + } + + tick(delta) { + if(Input.key_state_released(Key.escape)) { + IO.shutdown() + } + } //tick + + destroy() { + + System.print("unready!") + app.destroy() + + } //destroy + + app:App { _app } + app=(v) { _app=v } + +} //Game diff --git a/outline/app.wren b/outline/app.wren new file mode 100644 index 0000000..a0f1768 --- /dev/null +++ b/outline/app.wren @@ -0,0 +1,74 @@ +import "luxe: world" for World, Camera, Entity, Transform +import "luxe: render" for Render +import "luxe: game" for Frame + +class App { + + world { _world } + ui { _ui_world } + + camera { _camera } + ui_camera { _ui_camera } + + color { _color } + color=(v) { _color = v } + + width { Render.window_w() } + height { Render.window_h() } + scale { Render.drawable_ratio() } + + construct new() { + + _color = [1,1,1,1] + + //create worlds + + _world = World.create("game") + _ui_world = World.create("ui") + + //create cameras + + _camera = Entity.create(_world, "app.camera") + Transform.create(_camera) + Camera.create(_camera) + Camera.set_default(_world, _camera) + + _ui_camera = Entity.create(_ui_world, "app.ui_camera") + Transform.create(_ui_camera) + Camera.create(_ui_camera) + Camera.set_default(_ui_world, _ui_camera) + + //update our worlds + + Frame.on(Frame.sim) {|delta| + World.tick(_world, delta) + World.tick(_ui_world, delta) + } + + //render our worlds + + Frame.on(Frame.visual) {|delta| + World.render(_world, _camera, "game", {"clear_color":_color}) + World.render(_ui_world, _ui_camera, "ui") + } + + } //new + + destroy() { + + //destroy cameras + + Camera.destroy(_camera) + Camera.destroy(_ui_camera) + + Entity.destroy(_camera) + Entity.destroy(_ui_camera) + + //destroy worlds + + World.destroy(_ui_world) + World.destroy(_world) + + } //destroy + +} // diff --git a/outline/inputs.input.lx b/outline/inputs.input.lx new file mode 100644 index 0000000..dc45459 --- /dev/null +++ b/outline/inputs.input.lx @@ -0,0 +1,23 @@ +input = { + nodes = [ + { name = "ui" where = "front" channels = ["c01"] } + { name = "game" where = "after: ui" channels = ["c02"] } + ] + + map = { + left = { keys = ["key_a", "left"] } + right = { keys = ["key_d", "right"] } + up = { keys = ["key_w", "up"] } + down = { keys = ["key_s", "down"] } + jump = { + keys = ["key_x", "up", "key_w", "space"] + mouse = ["left"] + gamepad = [0] + } + + next = { + keys = ["key_x", "up", "key_w", "space", "enter", "escape"] + mouse = ["left", "right"] + } + } +} diff --git a/outline/renderer.wren b/outline/renderer.wren new file mode 100644 index 0000000..8c00ab4 --- /dev/null +++ b/outline/renderer.wren @@ -0,0 +1,51 @@ +import "luxe: render" for Render, RenderLayerDesc, PassLayerDesc, LoadAction +import "luxe: render" for SortType, ImageDesc, ImageType, PixelFormat + +class Renderer { + + construct new() { + + System.print("game / render / init / ok") + + } //new + + ready() { + + } + + tick(delta) { + + } + + render_path(ctx) { + + if(ctx.path == "game") { + game_render_path(ctx) + } else if(ctx.path == "ui") { + ui_render_path(ctx) + } + + } //render_path + + game_render_path(ctx) { + + var layer = RenderLayerDesc.new() + layer.dest.color[0].clear_color = ctx.get("clear_color", [1,1,1,1]) + layer.dest.color[0].load_action = LoadAction.clear + layer.dest.depth.load_action = LoadAction.clear + + ctx.layer_render("default", layer) + + } //game_render_path + + ui_render_path(ctx) { + + var layer = RenderLayerDesc.new() + layer.dest.color[0].load_action = LoadAction.dont_care + layer.dest.depth.load_action = LoadAction.clear + + ctx.layer_render("default", layer) + + } //ui_render_path + +} //Renderer diff --git a/outline/settings.settings.lx b/outline/settings.settings.lx new file mode 100644 index 0000000..e4523ff --- /dev/null +++ b/outline/settings.settings.lx @@ -0,0 +1,19 @@ +engine = { + input.entry = "outline/inputs" + runtime = { + window = { + width = 960 + height = 640 + resizable = false + fullscreen = false + } + } + + render = { + antialiasing = 2 + stencil = 8 + depth = 24 + } + + ui.debug_vis = true +} \ No newline at end of file diff --git a/project.luxe b/project.luxe new file mode 100644 index 0000000..8105e5d --- /dev/null +++ b/project.luxe @@ -0,0 +1,14 @@ +import "luxe: project" for Entry + +class Project is Entry { + + construct entry(target) { + + name = "game" + version = "0.0.0" + renderer = "outline/renderer" + settings = "outline/settings" + + } //new + +} //Project \ No newline at end of file diff --git a/project.modules.lx b/project.modules.lx new file mode 100644 index 0000000..c0fe79d --- /dev/null +++ b/project.modules.lx @@ -0,0 +1,3 @@ +modules = { + luxe = "2022.0.5" +} //modules