#37: platform back button, no Quit on phones, flat labels, camera
- Android back: application/config/quit_on_go_back=false; Main.go_back() (from NOTIFICATION_WM_GO_BACK_REQUEST, phones only) closes the shop or pouch panel or leaves build mode, else pauses; paused it closes the question, then settings, then resumes (shared with the pause action); at the main menu it closes the question or settings, else quits. - Phones hide the main menu's Quit and the pause menu's Quit the game. - ScreenLabels.ensure() makes the one ScreenLabels (ToonLook's on desktop; Main's on phones, which watch()es the tree for Label3Ds). Label sizes grow with the window's content_scale_factor (1 on desktop). - FollowCamera starts at PHONE_DISTANCE (12 m) on phones. - MobilePort.forced for tests; game/tests/mobile/platform_test.gd. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f0291133fd
commit
c47e67891e
10 changed files with 368 additions and 23 deletions
|
|
@ -3,7 +3,11 @@ class_name FollowCamera
|
||||||
extends Camera3D
|
extends Camera3D
|
||||||
## Angled top-down camera that trails a target. The framing comes entirely from pitch / yaw /
|
## Angled top-down camera that trails a target. The framing comes entirely from pitch / yaw /
|
||||||
## distance (the transform is overwritten every frame, also in the editor so the framing can be
|
## distance (the transform is overwritten every frame, also in the editor so the framing can be
|
||||||
## previewed). PlayerCharacter moves relative to this camera's yaw. Mouse wheel zooms.
|
## previewed). PlayerCharacter moves relative to this camera's yaw. Mouse wheel zooms. On a phone
|
||||||
|
## (MobilePort) it starts closer, at PHONE_DISTANCE.
|
||||||
|
|
||||||
|
## The phones' distance (the small screen), in place of distance's default when the game starts.
|
||||||
|
const PHONE_DISTANCE := 12.0
|
||||||
|
|
||||||
@export var target: Node3D
|
@export var target: Node3D
|
||||||
@export_range(5.0, 89.0) var pitch_deg := 50.0
|
@export_range(5.0, 89.0) var pitch_deg := 50.0
|
||||||
|
|
@ -22,6 +26,8 @@ var _focus := Vector3.ZERO
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF
|
physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF
|
||||||
|
if not Engine.is_editor_hint() and MobilePort.active():
|
||||||
|
distance = PHONE_DISTANCE
|
||||||
snap_to_target()
|
snap_to_target()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,10 @@ extends Node
|
||||||
## over GD-Sync (GDSyncLink), with voice chat. In co-op the menus don't pause the farm; the
|
## over GD-Sync (GDSyncLink), with voice chat. In co-op the menus don't pause the farm; the
|
||||||
## host's leaving ends the partner's game (back to this menu, which says why), the partner's
|
## host's leaving ends the partner's game (back to this menu, which says why), the partner's
|
||||||
## leaving leaves the host alone. [M] mutes the microphone.
|
## leaving leaves the host alone. [M] mutes the microphone.
|
||||||
## * On a phone (MobilePort): no ToonLook, no co-op, two thumbsticks (TouchSticks), and leaving
|
## * On a phone (MobilePort): no ToonLook (Main adds the ScreenLabels that draws the Label3Ds
|
||||||
## the app pauses. The iOS test build adds PerfTest (frame times and test buttons).
|
## flat), no co-op, no Quit buttons, two thumbsticks (TouchSticks), and leaving the app
|
||||||
|
## pauses. Android's back button (go_back) closes what's on top or pauses, and quits from the
|
||||||
|
## main menu. The iOS test build adds PerfTest (frame times and test buttons).
|
||||||
## Main processes while paused; the farm doesn't. Tests set save_path and settings_path
|
## Main processes while paused; the farm doesn't. Tests set save_path and settings_path
|
||||||
## before adding it to the tree.
|
## before adding it to the tree.
|
||||||
|
|
||||||
|
|
@ -63,6 +65,8 @@ func _ready() -> void:
|
||||||
var look := ToonLook.new() # toon shading and pixel outlines on the farm
|
var look := ToonLook.new() # toon shading and pixel outlines on the farm
|
||||||
look.name = "ToonLook"
|
look.name = "ToonLook"
|
||||||
add_child(look)
|
add_child(look)
|
||||||
|
else:
|
||||||
|
ScreenLabels.ensure(self).watch(get_tree().root) # ToonLook's label drawing, without the look
|
||||||
if MobilePort.perf_test():
|
if MobilePort.perf_test():
|
||||||
var perf := PerfTest.new()
|
var perf := PerfTest.new()
|
||||||
perf.name = "PerfTest"
|
perf.name = "PerfTest"
|
||||||
|
|
@ -267,6 +271,49 @@ func _notification(what: int) -> void:
|
||||||
quit_game()
|
quit_game()
|
||||||
elif what == NOTIFICATION_APPLICATION_PAUSED: # a phone app sent to the background
|
elif what == NOTIFICATION_APPLICATION_PAUSED: # a phone app sent to the background
|
||||||
pause()
|
pause()
|
||||||
|
elif what == NOTIFICATION_WM_GO_BACK_REQUEST and MobilePort.active(): # Android's back button
|
||||||
|
go_back()
|
||||||
|
|
||||||
|
|
||||||
|
## The phone's back button (application/config/quit_on_go_back is off, so it comes here): what's
|
||||||
|
## on top closes. Playing: the workbench's or the shed's panel, the pouch panel, or build mode,
|
||||||
|
## else it pauses (over a conversation, a sign, the intro, or the end panel too, as Escape does).
|
||||||
|
## Paused: the question, then settings, then it resumes. The main menu: the question, then
|
||||||
|
## settings, else it quits (as Quit: quit_requested).
|
||||||
|
func go_back() -> void:
|
||||||
|
if quitting:
|
||||||
|
return
|
||||||
|
match screen:
|
||||||
|
Screen.PLAYING:
|
||||||
|
if sim.upgrade_panel != null and sim.upgrade_panel.is_open:
|
||||||
|
sim.upgrade_panel.close()
|
||||||
|
elif sim.shed_panel != null and sim.shed_panel.is_open:
|
||||||
|
sim.shed_panel.close()
|
||||||
|
elif sim.resource_hud != null and sim.resource_hud.open:
|
||||||
|
sim.resource_hud.toggle()
|
||||||
|
elif sim.build != null and sim.build.active:
|
||||||
|
sim.build.set_active(false)
|
||||||
|
else:
|
||||||
|
pause()
|
||||||
|
Screen.PAUSED:
|
||||||
|
_back_in_pause()
|
||||||
|
Screen.MENU:
|
||||||
|
if confirm.is_open:
|
||||||
|
confirm.close()
|
||||||
|
elif settings_menu.is_open:
|
||||||
|
settings_menu.close()
|
||||||
|
elif main_menu.visible: # (not the co-op menu's screens: no co-op on phones)
|
||||||
|
main_menu.quit_requested.emit()
|
||||||
|
|
||||||
|
|
||||||
|
## Paused, the pause action or back: the question closes first, then settings, then it resumes.
|
||||||
|
func _back_in_pause() -> void:
|
||||||
|
if confirm.is_open:
|
||||||
|
confirm.close()
|
||||||
|
elif settings_menu.is_open:
|
||||||
|
settings_menu.close()
|
||||||
|
else:
|
||||||
|
resume()
|
||||||
|
|
||||||
|
|
||||||
func _play() -> void:
|
func _play() -> void:
|
||||||
|
|
@ -407,10 +454,5 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||||
pause()
|
pause()
|
||||||
get_viewport().set_input_as_handled()
|
get_viewport().set_input_as_handled()
|
||||||
Screen.PAUSED:
|
Screen.PAUSED:
|
||||||
if confirm.is_open:
|
_back_in_pause()
|
||||||
confirm.close()
|
|
||||||
elif settings_menu.is_open:
|
|
||||||
settings_menu.close()
|
|
||||||
else:
|
|
||||||
resume()
|
|
||||||
get_viewport().set_input_as_handled()
|
get_viewport().set_input_as_handled()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ class_name MainMenu
|
||||||
extends Control
|
extends Control
|
||||||
## The title screen over the farm (Main slowly circles a camera around it): the title, then
|
## The title screen over the farm (Main slowly circles a camera around it): the title, then
|
||||||
## Continue (with which morning it resumes at, or why the save can't be continued), New
|
## Continue (with which morning it resumes at, or why the save can't be continued), New
|
||||||
## vacation, Play with a friend (co-op, CoopMenu; not on phones), Settings, and Quit, and a notice line (e.g.
|
## vacation, Play with a friend (co-op, CoopMenu; not on phones), Settings, and Quit (not on
|
||||||
|
## phones either), and a notice line (e.g.
|
||||||
## why a co-op game ended). Mouse, keyboard, and gamepad work through focus.
|
## why a co-op game ended). Mouse, keyboard, and gamepad work through focus.
|
||||||
|
|
||||||
signal continue_requested
|
signal continue_requested
|
||||||
|
|
@ -62,6 +63,7 @@ func _ready() -> void:
|
||||||
settings_button.pressed.connect(func() -> void: settings_requested.emit())
|
settings_button.pressed.connect(func() -> void: settings_requested.emit())
|
||||||
quit_button = _button(box, "Quit")
|
quit_button = _button(box, "Quit")
|
||||||
quit_button.pressed.connect(func() -> void: quit_requested.emit())
|
quit_button.pressed.connect(func() -> void: quit_requested.emit())
|
||||||
|
quit_button.visible = not MobilePort.active() # phones: the system closes apps (Android's back here, Main)
|
||||||
notice = Label.new()
|
notice = Label.new()
|
||||||
notice.add_theme_font_size_override("font_size", 22)
|
notice.add_theme_font_size_override("font_size", 22)
|
||||||
notice.add_theme_color_override("font_color", Color(1.0, 0.75, 0.5))
|
notice.add_theme_color_override("font_color", Color(1.0, 0.75, 0.5))
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,13 @@ extends RefCounted
|
||||||
## on, to see the phone build without a phone (add --rendering-method mobile for its renderer).
|
## on, to see the phone build without a phone (add --rendering-method mobile for its renderer).
|
||||||
|
|
||||||
|
|
||||||
|
## Tests: -1 detects the platform, 0 forces desktop, 1 forces a phone.
|
||||||
|
static var forced := -1
|
||||||
|
|
||||||
|
|
||||||
static func active() -> bool:
|
static func active() -> bool:
|
||||||
|
if forced >= 0:
|
||||||
|
return forced == 1
|
||||||
return OS.has_feature("mobile") or "--mobile" in OS.get_cmdline_user_args()
|
return OS.has_feature("mobile") or "--mobile" in OS.get_cmdline_user_args()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ extends CenterContainer
|
||||||
## Escape / Start during play (Main pauses the tree), hand-drawn like the HUD's pouch panel
|
## Escape / Start during play (Main pauses the tree), hand-drawn like the HUD's pouch panel
|
||||||
## (UiTheme.sketch): where you are and what's left to protect
|
## (UiTheme.sketch): where you are and what's left to protect
|
||||||
## (crops, animals, supplies; asset_counts), then Resume, Restart the night, Settings, Save & quit
|
## (crops, animals, supplies; asset_counts), then Resume, Restart the night, Settings, Save & quit
|
||||||
## to the menu, and Quit the game, with a reminder of what Continue picks up (the vacation is
|
## to the menu, and Quit the game (not on phones, MobilePort), with a reminder of what Continue
|
||||||
## saved every morning).
|
## picks up (the vacation is saved every morning).
|
||||||
|
|
||||||
signal resume_requested
|
signal resume_requested
|
||||||
signal restart_requested
|
signal restart_requested
|
||||||
|
|
@ -65,6 +65,7 @@ func _ready() -> void:
|
||||||
menu_button.pressed.connect(func() -> void: menu_requested.emit())
|
menu_button.pressed.connect(func() -> void: menu_requested.emit())
|
||||||
quit_button = _button(box, "Quit the game")
|
quit_button = _button(box, "Quit the game")
|
||||||
quit_button.pressed.connect(func() -> void: quit_requested.emit())
|
quit_button.pressed.connect(func() -> void: quit_requested.emit())
|
||||||
|
quit_button.visible = not MobilePort.active() # phones: the system closes apps
|
||||||
_note = Label.new()
|
_note = Label.new()
|
||||||
_note.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
_note.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||||
_note.custom_minimum_size = Vector2(520.0, 0.0)
|
_note.custom_minimum_size = Vector2(520.0, 0.0)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
class_name ScreenLabels
|
class_name ScreenLabels
|
||||||
extends Control
|
extends Control
|
||||||
## Draws the farm's Label3Ds as flat text over the 3D view, so they stay sharp and readable when
|
## Draws the farm's Label3Ds as flat text over the 3D view, so they stay sharp and readable when
|
||||||
## the 3D view is pixelated (GameSettings.pixel_size). ToonLook tracks every Label3D; a tracked
|
## the 3D view is pixelated (GameSettings.pixel_size) and at a phone's interface scale. There's one
|
||||||
|
## per game (ensure()): ToonLook's on desktop, which tracks every Label3D, and on phones (no
|
||||||
|
## ToonLook, MobilePort) Main's, which watch()es the tree for them itself. A tracked
|
||||||
## label stops rendering in 3D (layers 0) and is drawn here instead, centered on where it projects,
|
## label stops rendering in 3D (layers 0) and is drawn here instead, centered on where it projects,
|
||||||
## with its text, colors, and outline (in the HUD's handwritten font, Sketch, unless it has its own
|
## with its text, colors, and outline (in the HUD's handwritten font, Sketch, unless it has its own
|
||||||
## font), at the size it would have on screen but never smaller than
|
## font), at the size it would have on screen (times the interface scale, the window's
|
||||||
|
## content_scale_factor: phones', MobilePort; 1 on desktop) but never smaller than
|
||||||
## MIN_SIZE (far-off ones, under HIDE_BELOW, aren't drawn at all). Labels that would overlap are
|
## MIN_SIZE (far-off ones, under HIDE_BELOW, aren't drawn at all). Labels that would overlap are
|
||||||
## nudged apart: the lowest on screen keeps its place and the ones over it move up clear of it.
|
## nudged apart: the lowest on screen keeps its place and the ones over it move up clear of it.
|
||||||
## The game's labels are all
|
## The game's labels are all
|
||||||
|
|
@ -15,11 +18,30 @@ extends Control
|
||||||
const MIN_SIZE := 16.0 # canvas pixels (1080 high): smaller labels are drawn at this size...
|
const MIN_SIZE := 16.0 # canvas pixels (1080 high): smaller labels are drawn at this size...
|
||||||
const HIDE_BELOW := 6.0 # ...unless they'd be this small on screen, when they're not drawn
|
const HIDE_BELOW := 6.0 # ...unless they'd be this small on screen, when they're not drawn
|
||||||
const GAP := 2.0 # canvas pixels between labels nudged apart
|
const GAP := 2.0 # canvas pixels between labels nudged apart
|
||||||
|
const GROUP := &"screen_labels"
|
||||||
|
|
||||||
var _labels: Array = [] # Label3D; untyped, so freed ones can be dropped
|
var _labels: Array = [] # Label3D; untyped, so freed ones can be dropped
|
||||||
|
|
||||||
|
|
||||||
|
## The game's ScreenLabels: the one in the tree already, else a new one under host (which must
|
||||||
|
## be in the tree) on its own CanvasLayer, "Labels", over the 3D view and under the HUD (1) and
|
||||||
|
## the menus (10). ToonLook and Main (on phones) both get theirs here, so there's never two.
|
||||||
|
static func ensure(host: Node) -> ScreenLabels:
|
||||||
|
for n in host.get_tree().get_nodes_in_group(GROUP):
|
||||||
|
if not n.is_queued_for_deletion():
|
||||||
|
return n as ScreenLabels
|
||||||
|
var layer := CanvasLayer.new()
|
||||||
|
layer.name = "Labels"
|
||||||
|
layer.layer = -1
|
||||||
|
var labels := ScreenLabels.new()
|
||||||
|
labels.name = "ScreenLabels"
|
||||||
|
layer.add_child(labels)
|
||||||
|
host.add_child(layer)
|
||||||
|
return labels
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
add_to_group(GROUP)
|
||||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||||
|
|
||||||
|
|
@ -31,6 +53,20 @@ func track(label: Label3D) -> void:
|
||||||
_labels.append(label)
|
_labels.append(label)
|
||||||
|
|
||||||
|
|
||||||
|
## Without ToonLook to hand them over (phones): tracks every Label3D under root, and from now on
|
||||||
|
## each one as it enters the tree.
|
||||||
|
func watch(root: Node) -> void:
|
||||||
|
for l in root.find_children("*", "Label3D", true, false):
|
||||||
|
track(l as Label3D)
|
||||||
|
if not get_tree().node_added.is_connected(_on_node_added):
|
||||||
|
get_tree().node_added.connect(_on_node_added)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_node_added(node: Node) -> void:
|
||||||
|
if node is Label3D:
|
||||||
|
track(node as Label3D)
|
||||||
|
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
queue_redraw()
|
queue_redraw()
|
||||||
|
|
||||||
|
|
@ -45,6 +81,7 @@ func entries() -> Array[Dictionary]:
|
||||||
if cam == null:
|
if cam == null:
|
||||||
return out
|
return out
|
||||||
var up := cam.global_basis.y
|
var up := cam.global_basis.y
|
||||||
|
var ui := get_window().content_scale_factor # the interface scale (phones; 1 on desktop): labels grow with the HUD
|
||||||
var fallback := Sketch.font()
|
var fallback := Sketch.font()
|
||||||
for l: Label3D in _labels:
|
for l: Label3D in _labels:
|
||||||
if l.text == "" or not l.is_visible_in_tree():
|
if l.text == "" or not l.is_visible_in_tree():
|
||||||
|
|
@ -53,7 +90,7 @@ func entries() -> Array[Dictionary]:
|
||||||
if cam.is_position_behind(world):
|
if cam.is_position_behind(world):
|
||||||
continue
|
continue
|
||||||
var at := cam.unproject_position(world) # already in canvas units (the stretched 1080-high view)
|
var at := cam.unproject_position(world) # already in canvas units (the stretched 1080-high view)
|
||||||
var tall := at.distance_to(cam.unproject_position(world + up * l.font_size * l.pixel_size))
|
var tall := at.distance_to(cam.unproject_position(world + up * l.font_size * l.pixel_size)) * ui
|
||||||
if tall < HIDE_BELOW:
|
if tall < HIDE_BELOW:
|
||||||
continue
|
continue
|
||||||
var scale := maxf(tall, MIN_SIZE) / l.font_size
|
var scale := maxf(tall, MIN_SIZE) / l.font_size
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ extends Node
|
||||||
## * A full-screen quad (pixel_outline.gdshader) darkens depth edges and lightens creases for
|
## * A full-screen quad (pixel_outline.gdshader) darkens depth edges and lightens creases for
|
||||||
## whatever camera is current. It needs the Forward+ renderer.
|
## whatever camera is current. It needs the Forward+ renderer.
|
||||||
## * Label3Ds aren't rendered in 3D (they'd be pixelated): ScreenLabels draws them as sharp text
|
## * Label3Ds aren't rendered in 3D (they'd be pixelated): ScreenLabels draws them as sharp text
|
||||||
## over the 3D view, under the HUD.
|
## over the 3D view, under the HUD. (Phones have no ToonLook; Main adds the ScreenLabels.)
|
||||||
## The pixel size (rendering the 3D view small and scaling it up with sharp pixels) is a display
|
## The pixel size (rendering the 3D view small and scaling it up with sharp pixels) is a display
|
||||||
## setting: GameSettings.pixel_size.
|
## setting: GameSettings.pixel_size.
|
||||||
|
|
||||||
|
|
@ -32,13 +32,7 @@ var _pending: Array = [] # untyped: a node may be freed before the flush
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
outline = make_outline()
|
outline = make_outline()
|
||||||
add_child(outline)
|
add_child(outline)
|
||||||
var layer := CanvasLayer.new()
|
labels = ScreenLabels.ensure(self) # its own Labels layer, under the HUD (or the one already there)
|
||||||
layer.name = "Labels"
|
|
||||||
layer.layer = -1 # over the 3D view, under the HUD (1) and the menus (10)
|
|
||||||
add_child(layer)
|
|
||||||
labels = ScreenLabels.new()
|
|
||||||
labels.name = "ScreenLabels"
|
|
||||||
layer.add_child(labels)
|
|
||||||
get_tree().node_added.connect(_on_node_added)
|
get_tree().node_added.connect(_on_node_added)
|
||||||
apply_to(get_tree().root)
|
apply_to(get_tree().root)
|
||||||
|
|
||||||
|
|
|
||||||
255
game/tests/mobile/platform_test.gd
Normal file
255
game/tests/mobile/platform_test.gd
Normal file
|
|
@ -0,0 +1,255 @@
|
||||||
|
extends RefCounted
|
||||||
|
## #37, the phone's platform details, through the entry scene (main.tscn, test save and settings
|
||||||
|
## paths) with MobilePort.forced:
|
||||||
|
## * Android's back button (NOTIFICATION_WM_GO_BACK_REQUEST; quit_on_go_back is off, so the app
|
||||||
|
## doesn't just close): playing, it pauses (over the intro and the morning sign too); paused,
|
||||||
|
## it closes the question, then settings, then resumes; it closes the workbench's and the
|
||||||
|
## shed's panels, the pouch panel, and build mode before pausing; at the main menu it closes the
|
||||||
|
## question and settings, then quits (intercepted here, so the runner lives).
|
||||||
|
## * No Quit buttons on phones (focus moves past where they were); ScreenLabels, only one (a
|
||||||
|
## ToonLook added anyway shares it), draws the Label3Ds flat without ToonLook, growing with
|
||||||
|
## the interface scale; the camera starts at 12 m.
|
||||||
|
## * Desktop (forced 0) as before: both Quit buttons, back ignored, Escape / Start pauses and
|
||||||
|
## resumes, ToonLook's ScreenLabels, the camera at 16 m.
|
||||||
|
|
||||||
|
const SAVE := "user://test_platform_save.json"
|
||||||
|
const SETTINGS := "user://test_platform_settings.cfg"
|
||||||
|
const DT := 1.0 / 60.0
|
||||||
|
|
||||||
|
var t: GameTestRunner
|
||||||
|
|
||||||
|
|
||||||
|
func run(p_t) -> void:
|
||||||
|
t = p_t
|
||||||
|
_clean()
|
||||||
|
t.check(ProjectSettings.get_setting("application/config/quit_on_go_back") == false and not t.quit_on_go_back,
|
||||||
|
"back doesn't close the app by itself (quit_on_go_back off): Main handles it")
|
||||||
|
MobilePort.forced = 1
|
||||||
|
var main := await _start()
|
||||||
|
_phone_quit(main)
|
||||||
|
await _phone_back(main)
|
||||||
|
_camera(main, FollowCamera.PHONE_DISTANCE, "phones")
|
||||||
|
await _phone_labels(main)
|
||||||
|
await _phone_back_at_menu(main)
|
||||||
|
await _stop(main)
|
||||||
|
_clean()
|
||||||
|
MobilePort.forced = 0
|
||||||
|
main = await _start()
|
||||||
|
await _desktop(main)
|
||||||
|
_camera(main, 16.0, "desktop")
|
||||||
|
await _stop(main)
|
||||||
|
MobilePort.forced = -1
|
||||||
|
_clean()
|
||||||
|
|
||||||
|
|
||||||
|
func _clean() -> void:
|
||||||
|
for p in [SAVE, SAVE + ".tmp", SETTINGS]:
|
||||||
|
if FileAccess.file_exists(p):
|
||||||
|
DirAccess.remove_absolute(ProjectSettings.globalize_path(p))
|
||||||
|
|
||||||
|
|
||||||
|
func _start() -> Main:
|
||||||
|
var main := (load("res://game/scenes/main.tscn") as PackedScene).instantiate() as Main
|
||||||
|
main.save_path = SAVE
|
||||||
|
main.settings_path = SETTINGS
|
||||||
|
t.root.add_child(main)
|
||||||
|
await t.process_frame
|
||||||
|
await t.physics_frame
|
||||||
|
return main
|
||||||
|
|
||||||
|
|
||||||
|
func _stop(main: Main) -> void:
|
||||||
|
main.queue_free()
|
||||||
|
t.paused = false
|
||||||
|
await t.process_frame
|
||||||
|
|
||||||
|
|
||||||
|
## The back button as the platform sends it: to every node from the root.
|
||||||
|
func _back() -> void:
|
||||||
|
t.root.propagate_notification(Node.NOTIFICATION_WM_GO_BACK_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
|
## The pause action as Escape / Start sends it.
|
||||||
|
func _press(action: String) -> void:
|
||||||
|
for pressed in [true, false]:
|
||||||
|
var e := InputEventAction.new()
|
||||||
|
e.action = StringName(action)
|
||||||
|
e.pressed = pressed
|
||||||
|
Input.parse_input_event(e)
|
||||||
|
await t.process_frame
|
||||||
|
await t.process_frame
|
||||||
|
|
||||||
|
|
||||||
|
func _skip_intro(sim: FarmSim) -> void:
|
||||||
|
sim.intro.skip()
|
||||||
|
var s := 0.0
|
||||||
|
while sim.intro.busy() and s < 10.0:
|
||||||
|
sim.intro.step(DT)
|
||||||
|
s += DT
|
||||||
|
|
||||||
|
|
||||||
|
func _screen_labels() -> Array:
|
||||||
|
return t.root.find_children("*", "ScreenLabels", true, false).filter(
|
||||||
|
func(n: Node) -> bool: return not n.is_queued_for_deletion())
|
||||||
|
|
||||||
|
|
||||||
|
func _paused_menu(main: Main) -> bool:
|
||||||
|
return main.screen == Main.Screen.PAUSED and t.paused and main.pause_menu.visible
|
||||||
|
|
||||||
|
|
||||||
|
func _playing(main: Main) -> bool:
|
||||||
|
return main.screen == Main.Screen.PLAYING and not t.paused and not main.pause_menu.visible
|
||||||
|
|
||||||
|
|
||||||
|
func _phone_quit(main: Main) -> void:
|
||||||
|
var mm := main.main_menu
|
||||||
|
var pm := main.pause_menu
|
||||||
|
t.check(not mm.quit_button.visible and not pm.quit_button.visible and mm.settings_button.visible and pm.menu_button.visible,
|
||||||
|
"phones: no Quit on the main menu or the pause menu (the rest are there)")
|
||||||
|
t.check(mm.settings_button.find_valid_focus_neighbor(SIDE_BOTTOM) != mm.quit_button
|
||||||
|
and mm.settings_button.find_next_valid_focus() != mm.quit_button
|
||||||
|
and pm.menu_button.find_valid_focus_neighbor(SIDE_BOTTOM) != pm.quit_button
|
||||||
|
and pm.menu_button.find_next_valid_focus() != pm.quit_button,
|
||||||
|
"and focus (arrows, Tab) never lands on the hidden ones")
|
||||||
|
|
||||||
|
|
||||||
|
func _phone_back(main: Main) -> void:
|
||||||
|
var sim := main.sim
|
||||||
|
var c := sim.campaign
|
||||||
|
main.main_menu.settings_button.pressed.emit()
|
||||||
|
t.check(main.settings_menu.is_open, "(settings open from the main menu)")
|
||||||
|
_back()
|
||||||
|
t.check(not main.settings_menu.is_open and main.screen == Main.Screen.MENU and main.main_menu.visible,
|
||||||
|
"back at the main menu's settings closes them, back to the menu")
|
||||||
|
main.main_menu.new_button.pressed.emit()
|
||||||
|
t.check(main.screen == Main.Screen.PLAYING and sim.intro.running, "(a new vacation, its intro playing)")
|
||||||
|
_back()
|
||||||
|
t.check(_paused_menu(main) and sim.intro.running, "back during the intro pauses (Restart the night skips it from there)")
|
||||||
|
_back()
|
||||||
|
t.check(_playing(main) and sim.intro.running, "and back again resumes it")
|
||||||
|
_skip_intro(sim)
|
||||||
|
t.check(c.state.phase == CampaignController.Phase.MORNING and sim.review_panel.visible, "(the first morning's sign)")
|
||||||
|
_back()
|
||||||
|
t.check(_paused_menu(main) and sim.review_panel.visible, "back over the morning sign pauses (the sign stays)")
|
||||||
|
main.pause_menu.settings_button.pressed.emit()
|
||||||
|
t.check(main.settings_menu.is_open and not main.pause_menu.visible, "(settings open from the pause menu)")
|
||||||
|
_back()
|
||||||
|
t.check(not main.settings_menu.is_open and _paused_menu(main), "back closes settings, back to the pause menu")
|
||||||
|
main.pause_menu.restart_button.pressed.emit()
|
||||||
|
t.check(main.confirm.is_open, "(Restart the night asks first)")
|
||||||
|
_back()
|
||||||
|
t.check(not main.confirm.is_open and _paused_menu(main) and c.state.phase == CampaignController.Phase.MORNING,
|
||||||
|
"back closes the question (nothing restarted), back to the pause menu")
|
||||||
|
_back()
|
||||||
|
t.check(_playing(main), "and back resumes")
|
||||||
|
|
||||||
|
c.begin_day()
|
||||||
|
await t.physics_frame
|
||||||
|
sim.upgrade_panel.open()
|
||||||
|
t.check(sim.upgrade_panel.is_open, "(the workbench's panel open)")
|
||||||
|
_back()
|
||||||
|
t.check(not sim.upgrade_panel.is_open and _playing(main), "back closes the workbench's panel and doesn't pause")
|
||||||
|
sim.shed_panel.open()
|
||||||
|
_back()
|
||||||
|
t.check(not sim.shed_panel.is_open and _playing(main), "and the shed's")
|
||||||
|
sim.resource_hud.toggle()
|
||||||
|
t.check(sim.resource_hud.open, "(the pouch panel open)")
|
||||||
|
_back()
|
||||||
|
t.check(not sim.resource_hud.open and _playing(main), "back closes the pouch panel")
|
||||||
|
sim.build.set_active(true)
|
||||||
|
_back()
|
||||||
|
t.check(not sim.build.active and _playing(main), "back leaves build mode")
|
||||||
|
_back()
|
||||||
|
t.check(_paused_menu(main), "and with nothing open, back pauses")
|
||||||
|
_back()
|
||||||
|
|
||||||
|
|
||||||
|
func _camera(main: Main, want: float, platform: String) -> void:
|
||||||
|
var cam := main.sim.camera as FollowCamera
|
||||||
|
t.check(cam != null and is_equal_approx(cam.distance, want), "%s: the camera starts %.0f m away (%.1f)" % [platform, want, cam.distance])
|
||||||
|
|
||||||
|
|
||||||
|
func _phone_labels(main: Main) -> void:
|
||||||
|
var sim := main.sim
|
||||||
|
var labels := _screen_labels()
|
||||||
|
t.check(main.get_node_or_null("ToonLook") == null and labels.size() == 1 and (labels[0] as Node).get_parent() is CanvasLayer
|
||||||
|
and ((labels[0] as Node).get_parent() as CanvasLayer).layer == -1,
|
||||||
|
"phones: no ToonLook, and one ScreenLabels on its layer under the HUD (%d)" % labels.size())
|
||||||
|
var drawer := labels[0] as ScreenLabels
|
||||||
|
var label3ds := main.farm.find_children("*", "Label3D", true, false)
|
||||||
|
t.check(label3ds.size() >= 5 and label3ds.all(func(l: Node) -> bool: return (l as Label3D).layers == 0),
|
||||||
|
"which draws the farm's %d Label3Ds flat (none render in 3D)" % label3ds.size())
|
||||||
|
var cam := t.root.get_camera_3d()
|
||||||
|
t.check(cam == sim.camera, "(playing: the follow camera)")
|
||||||
|
var sign := Label3D.new()
|
||||||
|
sign.text = "Gather"
|
||||||
|
sign.font_size = 40
|
||||||
|
sign.pixel_size = 0.0075
|
||||||
|
sign.outline_size = 10
|
||||||
|
main.farm.add_child(sign)
|
||||||
|
sign.global_position = cam.global_position - cam.global_basis.z * 10.0
|
||||||
|
sign.reset_physics_interpolation()
|
||||||
|
await t.process_frame
|
||||||
|
var drawn := drawer.entries().filter(func(e: Dictionary) -> bool: return e["label"] == sign)
|
||||||
|
t.check(sign.layers == 0 and drawn.size() == 1 and drawn[0]["text"] == "Gather"
|
||||||
|
and drawn[0]["font_size"] >= ScreenLabels.MIN_SIZE and t.root.get_visible_rect().encloses(drawn[0]["rect"]),
|
||||||
|
"and a label added later is drawn flat too, at a readable size (%s)" % [drawn[0]["font_size"] if drawn.size() == 1 else "not drawn"])
|
||||||
|
var was := t.root.content_scale_factor
|
||||||
|
t.root.content_scale_factor = 1.0
|
||||||
|
drawn = drawer.entries().filter(func(e: Dictionary) -> bool: return e["label"] == sign)
|
||||||
|
var at_1x: int = drawn[0]["font_size"] if drawn.size() == 1 else 0
|
||||||
|
t.root.content_scale_factor = 1.6 # the phone's interface scale (MobilePort.ui_scale, #35)
|
||||||
|
drawn = drawer.entries().filter(func(e: Dictionary) -> bool: return e["label"] == sign)
|
||||||
|
var at_16x: int = drawn[0]["font_size"] if drawn.size() == 1 else 0
|
||||||
|
t.root.content_scale_factor = was
|
||||||
|
t.check(at_1x > 0 and absi(at_16x - at_1x) <= 1,
|
||||||
|
"labels scale with the interface: at 1.6x the same canvas size (%d, was %d), so 1.6x as big on screen as in 3D" % [at_16x, at_1x])
|
||||||
|
sign.queue_free()
|
||||||
|
t.check(ScreenLabels.ensure(main) == drawer, "asking for ScreenLabels again gets the same one")
|
||||||
|
var look := ToonLook.new() # if both ever applied
|
||||||
|
main.add_child(look)
|
||||||
|
t.check(look.labels == drawer and _screen_labels().size() == 1, "a ToonLook added on a phone shares it: still one")
|
||||||
|
look.queue_free()
|
||||||
|
await t.process_frame
|
||||||
|
|
||||||
|
|
||||||
|
func _phone_back_at_menu(main: Main) -> void:
|
||||||
|
main.to_menu()
|
||||||
|
t.check(main.screen == Main.Screen.MENU and main.main_menu.visible, "(back at the main menu)")
|
||||||
|
main.main_menu.new_button.pressed.emit()
|
||||||
|
t.check(main.confirm.is_open, "(New vacation asks first: it would replace the save)")
|
||||||
|
_back()
|
||||||
|
t.check(not main.confirm.is_open and main.screen == Main.Screen.MENU and main.main_menu.visible,
|
||||||
|
"back at the main menu closes the question")
|
||||||
|
var quits := [0]
|
||||||
|
main.main_menu.quit_requested.disconnect(main.quit_game) # the runner must live
|
||||||
|
main.main_menu.quit_requested.connect(func() -> void: quits[0] += 1)
|
||||||
|
_back()
|
||||||
|
t.check(quits[0] == 1, "and back at the main menu itself quits (Android's way), as Quit would")
|
||||||
|
|
||||||
|
|
||||||
|
func _desktop(main: Main) -> void:
|
||||||
|
var mm := main.main_menu
|
||||||
|
var pm := main.pause_menu
|
||||||
|
t.check(mm.quit_button.visible and mm.quit_button.text == "Quit" and pm.quit_button.visible and pm.quit_button.text == "Quit the game",
|
||||||
|
"desktop: Quit on the main menu and Quit the game on the pause menu")
|
||||||
|
var look := main.get_node_or_null("ToonLook") as ToonLook
|
||||||
|
var labels := _screen_labels()
|
||||||
|
t.check(look != null and labels.size() == 1 and labels[0] == look.labels and look.labels.get_parent().get_parent() == look,
|
||||||
|
"desktop: ToonLook makes the one ScreenLabels, under itself (%d)" % labels.size())
|
||||||
|
var quits := [0]
|
||||||
|
mm.quit_requested.disconnect(main.quit_game)
|
||||||
|
mm.quit_requested.connect(func() -> void: quits[0] += 1)
|
||||||
|
_back()
|
||||||
|
t.check(quits[0] == 0 and main.screen == Main.Screen.MENU and mm.visible, "desktop: a back request does nothing at the main menu")
|
||||||
|
mm.new_button.pressed.emit()
|
||||||
|
_skip_intro(main.sim)
|
||||||
|
_back()
|
||||||
|
t.check(_playing(main), "or while playing")
|
||||||
|
await _press("pause")
|
||||||
|
t.check(_paused_menu(main), "desktop: Escape / Start still pauses")
|
||||||
|
pm.settings_button.pressed.emit()
|
||||||
|
await _press("pause")
|
||||||
|
t.check(not main.settings_menu.is_open and _paused_menu(main), "closes settings")
|
||||||
|
await _press("pause")
|
||||||
|
t.check(_playing(main), "and resumes")
|
||||||
1
game/tests/mobile/platform_test.gd.uid
Normal file
1
game/tests/mobile/platform_test.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bhmtct5ivpte6
|
||||||
|
|
@ -19,6 +19,7 @@ run/main_scene="res://game/scenes/main.tscn"
|
||||||
config/features=PackedStringArray("4.7", "Forward Plus")
|
config/features=PackedStringArray("4.7", "Forward Plus")
|
||||||
boot_splash/image="uid://dpociv7go51qj"
|
boot_splash/image="uid://dpociv7go51qj"
|
||||||
config/icon="res://assets/pictures/icons/app_icon.png"
|
config/icon="res://assets/pictures/icons/app_icon.png"
|
||||||
|
config/quit_on_go_back=false
|
||||||
|
|
||||||
[audio]
|
[audio]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue