More work on porting to crystal-lang, stubbed a few files

This commit is contained in:
2022-06-27 11:23:28 -05:00
parent 4e0506e46d
commit ed727e478e
18 changed files with 295 additions and 6 deletions

View File

@@ -1,6 +1,21 @@
require "./../src/cyberarm_engine"
class Window < CyberarmEngine::Window
class State < CyberarmEngine::GameState
@options : Int32
def draw
Gosu.draw_rect(0, 0, window.width, window.height, 0xff_353535)
end
def needs_cursor?
true
end
end
def setup
push_state(State.new(3))
end
end
Window.new(width: 700, height: 700).show
Window.new.show

View File

@@ -1,7 +1,17 @@
require "gosu"
module CyberarmEngine
VERSION = "0.1.0"
require "./cyberarm_engine/version"
require "./cyberarm_engine/window"
require "./cyberarm_engine/common"
require "./cyberarm_engine/game_state"
require "./cyberarm_engine/game_object"
# TODO: Put your code here
end
require "./cyberarm_engine/ui/gui_state"
require "./cyberarm_engine/ui/dsl"
require "./cyberarm_engine/ui/event"
require "./cyberarm_engine/ui/style"
require "./cyberarm_engine/ui/theme"
require "./cyberarm_engine/ui/element"
require "./cyberarm_engine/ui/elements/container"
require "./cyberarm_engine/ui/elements/stack"
require "./cyberarm_engine/ui/elements/flow"

View File

@@ -0,0 +1,7 @@
module CyberarmEngine
module Common
def window
CyberarmEngine::Window.instance.not_nil!
end
end
end

View File

@@ -0,0 +1,15 @@
module CyberarmEngine
class GameObject
def draw
end
def update
end
def button_down(id)
end
def button_up(id)
end
end
end

View File

@@ -0,0 +1,82 @@
module CyberarmEngine
class GameState
include Common
property :options, :global_pause
getter :game_objects
@down_keys : Hash(UInt32, Bool)
def initialize(@options)
@game_objects = [] of GameObject
@global_pause = false
@down_keys = {} of UInt32 => Bool
end
def setup
end
def post_setup
end
def draw
@game_objects.each do |o|
o.draw
end
end
def update
@game_objects.each do |o|
o.update
end
end
def needs_cursor?
true
end
def needs_redraw?
true
end
def drop(filename)
end
def gamepad_connected(index)
end
def gamepad_disconnected(index)
end
def gain_focus
end
def lose_focus
end
def button_down(id)
@down_keys[id] = true
@game_objects.each do |o|
o.button_down(id)
end
end
def button_up(id)
@down_keys.delete(id)
@game_objects.each do |o|
o.button_up(id)
end
end
def close : Bool
CyberarmEngine::Window.instance.not_nil!.close!
end
def destroy
@game_objects.each(&:destroy)
@game_objects.clear
end
end
end

View File

@@ -0,0 +1,4 @@
module CyberarmEngine
class Image < Gosu::Image
end
end

View File

View File

View File

View File

@@ -0,0 +1,6 @@
module CyberarmEngine
class Element
class Container < Element
end
end
end

View File

@@ -0,0 +1,15 @@
module CyberarmEngine
class Element
class Flow < Container
def layout
@children.each do |child|
if fits_on_line?(child)
position_on_current_line(child)
else
position_on_next_line(child)
end
end
end
end
end
end

View File

@@ -0,0 +1,11 @@
module CyberarmEngine
class Element
class Stack < Container
def layout
@children.each do |child|
move_to_next_line(child)
end
end
end
end
end

View File

View File

@@ -0,0 +1,4 @@
module CyberarmEngine
class GuiState < GameState
end
end

View File

View File

View File

@@ -0,0 +1,4 @@
module CyberarmEngine
NAME = "InDev"
VERSION = "0.1.0"
end

View File

@@ -1,6 +1,122 @@
module CyberarmEngine
class Window < Gosu::Window
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
@@instance = nil : CyberarmEngine::Window?
def self.instance
@@instance
end
def self.instance=(klass : CyberarmEngine::Window)
@@instance = klass
end
@last_frame_time : UInt64
@current_frame_time : UInt64
def initialize(@width = 800, @height = 600, @fullscreen = false, @update_interval = 1000.0 / 60, @resizable = false, @borderless = false)
@has_focus = false
@last_frame_time = Gosu.milliseconds
@current_frame_time = Gosu.milliseconds
@states = [] of CyberarmEngine::GameState
@exit_on_opengl_error = false
super(@width, @height, @fullscreen, @update_interval, @resizable, @borderless)
self.caption = "CyberarmEngine.cr v#{CyberarmEngine::VERSION} #{Gosu.language}"
CyberarmEngine::Window.instance = self
setup
end
def setup
end
def draw
current_state.not_nil!.draw if current_state
end
def update
current_state.not_nil!.update if current_state
@last_frame_time = Gosu.milliseconds - @current_frame_time
@current_frame_time = Gosu.milliseconds
end
def needs_cursor?
current_state ? current_state.not_nil!.needs_cursor? : true
end
def needs_redraw?
current_state ? current_state.not_nil!.needs_redraw? : true
end
def drop(filename)
current_state.not_nil!.drop(filename) if current_state
end
def gamepad_connected(index)
current_state.not_nil!.gamepad_connected(index) if current_state
end
def gamepad_disconnected(index)
current_state.not_nil!.gamepad_disconnected(index) if current_state
end
def gain_focus
current_state.not_nil!.gain_focus if current_state
end
def lose_focus
current_state.not_nil!.lose_focus if current_state
end
def button_down(id)
current_state.not_nil!.button_down(id) if current_state
end
def button_up(id)
current_state.not_nil!.button_up(id) if current_state
end
def close
current_state ? current_state.not_nil!.close : super
end
def dt
@last_frame_time / 1000.0
end
def aspect_ratio
width / height.to_f
end
def exit_on_opengl_error?
@exit_on_opengl_error
end
def push_state(instance)
@states << instance
current_state.not_nil!.setup
current_state.not_nil!.post_setup
end
def current_state : CyberarmEngine::GameState?
@states.last?
end
def pop_state : CyberarmEngine::GameState?
@states.pop?
end
def shift_state : CyberarmEngine::GameState?
@states.shift?
end
def has_focus?
@has_focus
end
end
end