current state

This commit is contained in:
Ronja 2020-09-03 17:31:23 +02:00
parent 853d153fb6
commit 17f09faca5
11 changed files with 98 additions and 39 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 156 B

After

Width:  |  Height:  |  Size: 177 B

View file

@ -2,6 +2,8 @@ import "luxe: io" for IO
import "luxe: world" for World, Entity, Modifiers, ModifierSystem, Transform, Sprite
import "math/vector" for Vector
import "math/util" for Util
import "globals" for Globals
import "luxe: assets" for Strings
//User facing API
//This is what the user of your modifier will interact with
@ -59,22 +61,30 @@ class HumanSystem is ModifierSystem {
//called usually once every frame.
//called when the world that this modifier lives in, is ticked
each {|entity, data|
if(!data.active) return
var mouse = Globals["GameMouse"]
var over = Sprite.contains(entity,mouse.x, mouse.y)
if(over && _hoverEnt != entity){
_hoverEnt = entity
Globals["Tooltip"].set(Strings.get(data.name), entity)
}
if(!over && _hoverEnt == entity){
_hoverEnt = null
Globals["Tooltip"].clear(entity)
}
}
} //tick
update(){
var i = 0
var size = Vector.new(player_size)
var start = Vector.new(player_start) + size / 2
var pos = Vector.new(player_start) + size / 2
each {|entity, data|
if(!data.active){
Transform.destroy(entity)
Sprite.destroy(entity)
return
}
var pos = Vector.new(start)
pos.x = pos.x + size.x * i
if(!Transform.has(entity)){
Transform.create(entity)
}
@ -83,7 +93,7 @@ class HumanSystem is ModifierSystem {
Sprite.set_color(entity, data.color.r, data.color.g, data.color.b, 1)
}
Transform.set_pos(entity, pos.x, pos.y)
i = i + 1
pos.x = pos.x + size.x
}
}
} //HumanSystem

View file

@ -22,7 +22,6 @@ class Ui{
var ui_rect = Globals["UiRect"]
_ui_mode = Observable.new(Ui.Info)
System.print(_ui_mode)
_ui = Entity.create(app.ui, "UI Root")
@ -50,6 +49,7 @@ class Ui{
//list
var list = UIList.create(_ui)
Control.set_id(list, "info list")
Control.child_add(root, list)
//todo: make list horizontal?
Control.set_pos(list, 0, ui_rect.height-16)
@ -61,6 +61,7 @@ class Ui{
//plan adventure
button = list_button(0)
Control.set_id(button, "info button %(0)")
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Adventure!")
ImageButton.set_tile_uv(button, tiles, [1, 0])
@ -73,6 +74,7 @@ class Ui{
//info
button = list_button(1)
Control.set_id(button, "info button %(1)")
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Stats")
ImageButton.set_tile_uv(button, tiles, [2, 0])
@ -80,6 +82,7 @@ class Ui{
//read diary
button = list_button(2)
Control.set_id(button, "info button %(2)")
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Diary")
ImageButton.set_tile_uv(button, tiles, [1, 0])
@ -111,6 +114,7 @@ class Ui{
//back to info
button = list_button(list_id)
Control.set_id(button, "plan button %(list_id)")
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Info")
ImageButton.set_tile_uv(button, tiles, [1, 0])
@ -124,6 +128,7 @@ class Ui{
//abort
button = list_button(list_id)
Control.set_id(button, "plan button %(list_id)")
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Abort")
ImageButton.set_tile_uv(button, tiles, [0, 0])
@ -132,6 +137,7 @@ class Ui{
//people
button = list_button(list_id)
Control.set_id(button, "plan button %(list_id)")
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Adventurers")
ImageButton.set_tile_uv(button, tiles, [2, 0])
@ -140,6 +146,7 @@ class Ui{
//stuff
button = list_button(list_id)
Control.set_id(button, "plan button %(list_id)")
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Stuff")
ImageButton.set_tile_uv(button, tiles, [4, 0])
@ -148,6 +155,7 @@ class Ui{
//direction
button = list_button(list_id)
Control.set_id(button, "plan button %(list_id)")
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Direction")
ImageButton.set_tile_uv(button, tiles, [3, 0])
@ -156,6 +164,7 @@ class Ui{
//go
button = list_button(list_id)
Control.set_id(button, "plan button %(list_id)")
UIImage.set_image(button, adventureButtons)
ImageButton.set_tooltip(button, "Depart")
ImageButton.set_tile_uv(button, tiles, [5, 0])

View file

@ -16,8 +16,7 @@ class ImageButton{
Control.set_state_data(button, data)
Control.set_events(button) {|event|
var change = true
var data
var data = null
if(event.type == UIEvent.enter){
data = Control.get_state_data(button)
data["hover"] = true
@ -31,10 +30,9 @@ class ImageButton{
} else if(event.type == UIEvent.release) {
data = Control.get_state_data(button)
data["press"] = false
} else {
change = false
}
if(change){
if(data){
var func = data["state_change"]
if(func){
func.call(data, button)

View file

@ -20,9 +20,6 @@ import "blocks/human/human" for Human
class game is Game {
construct ready() {
//simple example... in theory (should print `0, 1, a` and `1, 2, b` cause thats the union)
//Util.for_all([[0, 1, 2], [1, 2], ["a", "b", "c", "d"]]){|a, b, c|System.print("%(a), %(b), %(c)")}
Globals["Game"] = this
app = App.new()
@ -38,10 +35,12 @@ class game is Game {
tick(delta) {
var mouse_pos = Vector.new(Input.mouse_x(), Input.mouse_y())
var game_mouse = [0, 0]//Globals["Renderer"].game_mouse(mouse_pos)
Globals["GameMouse"] = Camera.screen_point_to_world(app.camera, game_mouse.x, game_mouse.y)
var ui_mouse = [0, 0]//Globals["Renderer"].ui_mouse(mouse_pos)
Globals["UiMouse"] = Camera.screen_point_to_world(app.ui_camera, ui_mouse.x, ui_mouse.y)
var game_mouse = Globals["Renderer"].game_mouse(mouse_pos)
game_mouse = Camera.screen_point_to_world(app.camera, game_mouse.x, game_mouse.y)
Globals["GameMouse"] = game_mouse
var ui_mouse = Globals["Renderer"].ui_mouse(mouse_pos)
ui_mouse = Camera.screen_point_to_world(app.ui_camera, ui_mouse.x, ui_mouse.y)
Globals["UiMouse"] = ui_mouse
if(Input.key_state_released(Key.escape)) {
IO.shutdown()
@ -53,7 +52,9 @@ class game is Game {
_ui.test()
DrawDebug.rect(game_mouse.x, game_mouse.y, 1, 1)
DrawDebug.commit()
_tooltip.tick()
app.tick(delta)
@ -61,10 +62,8 @@ class game is Game {
} //tick
destroy() {
System.print("unready!")
app.destroy()
} //destroy
setup(){
@ -81,6 +80,8 @@ class game is Game {
create_human()
create_human()
create_human()
create_human()
create_human()
}
create_human(){

View file

@ -20,8 +20,8 @@ class M{
if(value is Num) value = RepVal.new(value)
var result = []
Util.for_all([from, to, value]) { |v|
result.add(lerp(v[0], v[1], v[2]))
Util.for_all([from, to, value]) { |from, to, value|
result.add(inv_lerp(from, to, value))
}
return result
}
@ -42,8 +42,8 @@ class M{
if(value is Num) value = RepVal.new(value)
var result = []
Util.for_all([from, to, value]) { |v|
result.add(lerp(v[0], v[1], v[2]))
Util.for_all([from, to, value]) { |from, to, value|
result.add(lerp(from, to, value))
}
return result
}

View file

@ -26,13 +26,40 @@ class Util{
var counter = (0...count)
var iterators = List.filled(count, null)
counter.each{|i| iterators[i] = sequences[i].iterate(iterators[i])}
while(iterators.all{|iter| iter}){
while(iterators.all{|iter| !!iter}){
var values = (0...count).map{|i| sequences[i].iteratorValue(iterators[i])}.toList
fn.call(values)
call_arg_list(fn, values)
counter.each{|i| iterators[i] = sequences[i].iterate(iterators[i])}
}
}
static call_arg_list(fn, args){
var l = args.count
if(l == 0){
fn.call()
} else if(l == 1) {
fn.call(args[0])
} else if(l == 2) {
fn.call(args[0], args[1])
} else if(l == 3) {
fn.call(args[0], args[1], args[2])
} else if(l == 4) {
fn.call(args[0], args[1], args[2], args[3])
} else if(l == 5) {
fn.call(args[0], args[1], args[2], args[3], args[4])
} else if(l == 6) {
fn.call(args[0], args[1], args[2], args[3], args[4], args[5])
} else if(l == 7) {
fn.call(args[0], args[1], args[2], args[3], args[4], args[5], args[6])
} else if(l == 8) {
fn.call(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7])
} else if(l == 9) {
fn.call(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8])
} else {
System.print("%(l) is too many arguments")
}
}
//hue value saturation to rgb colors. all values in 0-1 range
static hsv(h, s, v){
//hue to rgb

View file

@ -53,6 +53,10 @@ class Vector is Sequence{
return one.x > other.x || one.y > other.y
}
toString {
return "(%(x)|%(y))"
}
y0(){
_y = 0
return this
@ -64,12 +68,12 @@ class Vector is Sequence{
}
iterate(iter){
if(!iter) return 0
if(iter > 1) return false
if(iter == null) return 0
if(iter >= 1) return false
return iter + 1
}
iteratorValue(iter){[iter]}
iteratorValue(iter){this[iter]}
[index]{
if(index == 0){
@ -77,7 +81,7 @@ class Vector is Sequence{
} else if(index == 1){
return y
}
return null
return false
}
+(other){

View file

@ -64,20 +64,28 @@ class Renderer {
Image.redefine(_rt, _desc)
_gameRect = AABB.new((window - res*_pixel_size)/2, res * _pixel_size)
_texRect = AABB.new((window - _gameRes*_pixel_size)/2, _gameRes * _pixel_size)
events.emit(Renderer.on_change)
}
game_mouse(mouse_pos){
var window = AABB.new(0, 0, Render.window_w(), Render.window_h())
var screen = AABB.new(_gameRect.min_x, Render.window_h() - _gameRect.max_y, _gameRect.width, _gameRect.height) //Y- mouse positions are the bane of my existance
return M.remap(screen.min, screen.max, window.min, window.max, mouse_pos)
//this is super inflexible, help :(
var pixel_game_rect = Globals["GameRect"]
var game_rect = AABB.new(_texRect.min_x + pixel_game_rect.min_x * _pixel_size,
_texRect.min_y + pixel_game_rect.min_y * _pixel_size,
pixel_game_rect.width * _pixel_size, pixel_game_rect.width * _pixel_size)
var point = M.inv_lerp(game_rect.min, game_rect.max, mouse_pos)
//System.print(point)
return point
}
ui_mouse(mouse_pos){
//good chance this works by luck and is not exact
var window = AABB.new(0, 0, Render.window_w(), Render.window_h())
var screen = AABB.new(_gameRect.min_x, Render.window_h() - _gameRect.max_y, _gameRect.width, _gameRect.height) //Y- mouse positions are the bane of my existance
var screen = AABB.new(_texRect.min_x, Render.window_h() - _texRect.max_y, _texRect.width, _texRect.height) //Y- mouse positions are the bane of my existance
return M.remap(screen.min, screen.max, window.min, window.max, mouse_pos)
}
@ -136,7 +144,7 @@ class Renderer {
out_pass.targets = ["screen"]
out_pass.inputs = {
"pass.flipy" : true,
"pass.rect" : _gameRect.pos_size_list,
"pass.rect" : _texRect.pos_size_list,
"pass.image" : {
"image": target, //image resource name
"sampler": "nearest_clamp" //sampler state

View file

@ -13,4 +13,6 @@ engine = {
stencil = 0
depth = 0
}
ui.debug_vis = true
}