Class: DXRubyEditor::Editor

Inherits:
RenderTarget
  • Object
show all
Defined in:
lib/dxruby_editor/editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width: 640, height: Window.height, theme: nil) ⇒ Editor

call once

Parameters:

  • size (Integer)

    エディターのサイズ

  • theme (Integer) (defaults to: nil)

    エディターのカラーテーマを設定します



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dxruby_editor/editor.rb', line 11

def initialize(width: 640, height: Window.height, theme: nil)
  Window.before_call[:editor_update] = method(:_update)
  Window.after_call[:editor_draw] = method(:_rendering)

  @width = width
  @height = height
  @theme = theme || Core::Theme.new
  super(width, height, @theme[:bg])

  @x = Window.width - @width
  @y = 0
  @context = nil

  self
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/dxruby_editor/editor.rb', line 3

def context
  @context
end

#heightObject (readonly)

Returns the value of attribute height.



3
4
5
# File 'lib/dxruby_editor/editor.rb', line 3

def height
  @height
end

#themeObject

Returns the value of attribute theme.



4
5
6
# File 'lib/dxruby_editor/editor.rb', line 4

def theme
  @theme
end

#widthObject (readonly)

Returns the value of attribute width.



3
4
5
# File 'lib/dxruby_editor/editor.rb', line 3

def width
  @width
end

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/dxruby_editor/editor.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/dxruby_editor/editor.rb', line 4

def y
  @y
end

Instance Method Details

#_updateObject

main loop



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dxruby_editor/editor.rb', line 55

def _update
  Core::KeyInput.update(@context)
  Core::MouseInput.update(@context)
  Core::Command.update(@context)

  @run_code = @context.str if Input.key_push?(K_F5)
  if @run_code
    puts "----------------------------"
    puts @run_code
  end
  begin
    eval(@run_code || '')
  rescue StandardError => e
    puts(e.message)
  end

  @context.tick += 1
end

#debugObject



50
# File 'lib/dxruby_editor/editor.rb', line 50

def debug; end

#new_file(text: '') ⇒ Object

Parameters:

  • text (String) (defaults to: '')

    最初に表示数テキスト



30
31
32
33
34
35
# File 'lib/dxruby_editor/editor.rb', line 30

def new_file(text: '')
  i = 1
  file_name = "untitled-#{i}.rb"
  file_name = "untitled-#{i += 1}.rb" while File.exist?(file_name)
  @context = EditorContext.new(file_name, text)
end

#open(file_name, size: 640, theme: nil) ⇒ Object

Parameters:

  • file_name (String)

    開くファイルの名前

  • size (Integer) (defaults to: 640)

    エディターのサイズ

  • theme (Integer) (defaults to: nil)

    エディターのカラーテーマを設定します



42
43
44
45
46
47
48
# File 'lib/dxruby_editor/editor.rb', line 42

def open(file_name, size: 640, theme: nil)
  file = File.open(File.join($LOAD_PATH[0], file_name), 'r')
  text = file.read
  file.close

  @context = EditorContext.new(file_name, text)
end

#productionObject



52
# File 'lib/dxruby_editor/editor.rb', line 52

def production; end