From 388679092564a52a748c3669d96ccce7fa526f86 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Tue, 1 Aug 2023 13:13:29 +1000 Subject: [PATCH] Added some screenshot functionality on ctrl+p Also tidied up some vs code stuff --- 🕹️cube-tube.code-workspace | 8 ++++++++ 🕹️cube-tube/.vscode/launch.json | 2 +- 🕹️cube-tube/app/classes/scene_instance.rb | 25 +++++++++++++++++++++++- 🕹️cube-tube/app/keybindings.rb | 4 ++-- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 🕹️cube-tube.code-workspace diff --git a/🕹️cube-tube.code-workspace b/🕹️cube-tube.code-workspace new file mode 100644 index 0000000..96a7d5b --- /dev/null +++ b/🕹️cube-tube.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "🕹️cube-tube" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/🕹️cube-tube/.vscode/launch.json b/🕹️cube-tube/.vscode/launch.json index 1fa4f2b..f52dae3 100644 --- a/🕹️cube-tube/.vscode/launch.json +++ b/🕹️cube-tube/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Run Game", "type": "node-terminal", "request": "launch", - "command": "${workspaceRoot}/../.dragonruby/dragonruby ${workspaceRoot}", + "command": "\"${workspaceRoot}/../.dragonruby/dragonruby\" \"${workspaceRoot}\"", "windows": { "command": "${workspaceRoot}/../.dragonruby/dragonruby.exe ${workspaceRoot}", }, diff --git a/🕹️cube-tube/app/classes/scene_instance.rb b/🕹️cube-tube/app/classes/scene_instance.rb index bbd3ad7..da70fbe 100644 --- a/🕹️cube-tube/app/classes/scene_instance.rb +++ b/🕹️cube-tube/app/classes/scene_instance.rb @@ -10,8 +10,31 @@ class SceneInstance attr_reader :tick_in_background attr_accessor :reset_on_pop + def screenshot(args) + screenshot_path = "../marketing-assets/screenshots/#{args.gtk.platform}" + now = Time.new + now_s = "#{now.year}-#{"#{now.month}".rjust(2, "0")}-#{"#{now.day}".rjust(2, "0")} at #{"#{now.hour}".rjust(2, "0")}.#{"#{now.min}".rjust(2, "0")}.#{"#{now.sec}".rjust(2, "0")}" + base_filename = "#{screenshot_path}/Screenshot - #{args.gtk.platform} - #{now_s}" + filename = "#{base_filename}.png" + count = 0 + while !args.gtk.stat_file(filename).nil? + count += 1; + filename = "#{base_filename} (#{count}).png" + end + + args.outputs.screenshots << { + x: 0, y: 0, w: args.grid.w, h: args.grid.h, # Which portion of the screen should be captured + path: filename, # Output path of PNG file (inside game directory) + # r: 255, g: 255, b: 255, a: 0 # Optional chroma key + } + + args.gtk.notify!("Screenshot taken: '#{filename}'") + end + # called every tick of the game loop - def tick(args) end + def tick(args) + screenshot(args) if args.inputs.keyboard.ctrl_p + end # custom logic to reset this scene def reset(args) end diff --git a/🕹️cube-tube/app/keybindings.rb b/🕹️cube-tube/app/keybindings.rb index 36ff611..5c00b3c 100644 --- a/🕹️cube-tube/app/keybindings.rb +++ b/🕹️cube-tube/app/keybindings.rb @@ -5,7 +5,7 @@ module Input class << self PRIMARY_KEYS = [:j, :z, :space] SECONDARY_KEYS = [:k, :x, :backspace] - PAUSE_KEYS = [:escape, :p] + PAUSE_KEYS = [:escape] BINDINGS = { primary: { keyboard: %i[j z space], @@ -16,7 +16,7 @@ module Input controller_one: %i[b] }, pause: { - keyboard: %i[escape p], + keyboard: %i[escape], controller_one: %i[start] }, rotate_left: {