Scriptable environment setting

This commit is contained in:
Scott Wadden 2024-03-24 22:22:03 -03:00
parent cfe0b9c46e
commit 6995c6f0ad
11 changed files with 126 additions and 61 deletions

View File

@ -0,0 +1,29 @@
[gd_resource type="Environment" load_steps=3 format=2]
[ext_resource path="res://textures/planet_sky.png" type="Texture" id=1]
[sub_resource type="PanoramaSky" id=1]
panorama = ExtResource( 1 )
[resource]
background_mode = 2
background_sky = SubResource( 1 )
background_sky_orientation = Basis( -1, 1.52079e-08, -8.60899e-08, 0, 0.984753, 0.173958, 8.74228e-08, 0.173958, -0.984753 )
background_energy = 0.5
ambient_light_color = Color( 0.741176, 0.996078, 0.588235, 1 )
ambient_light_energy = 1.5
ambient_light_sky_contribution = 0.0
fog_enabled = true
fog_color = Color( 0, 0, 0, 1 )
fog_sun_color = Color( 0.211765, 0.211765, 0.211765, 1 )
fog_depth_begin = 150.0
fog_depth_end = 200.0
fog_height_max = 50.0
tonemap_mode = 3
tonemap_white = 0.13
dof_blur_far_distance = 200.0
dof_blur_far_transition = 20.0
dof_blur_far_quality = 0
glow_enabled = true
glow_bloom = 1.0
glow_high_quality = true

View File

@ -0,0 +1,30 @@
[gd_resource type="Environment" load_steps=3 format=2]
[ext_resource path="res://textures/planet_sky.png" type="Texture" id=1]
[sub_resource type="PanoramaSky" id=1]
panorama = ExtResource( 1 )
[resource]
background_mode = 2
background_sky = SubResource( 1 )
background_sky_orientation = Basis( -1, 1.52079e-08, -8.60899e-08, 0, 0.984753, 0.173958, 8.74228e-08, 0.173958, -0.984753 )
background_energy = 0.5
ambient_light_color = Color( 0.0509804, 0.858824, 0.843137, 1 )
ambient_light_energy = 11.36
fog_enabled = true
fog_color = Color( 0, 0, 0, 1 )
fog_sun_color = Color( 0.211765, 0.211765, 0.211765, 1 )
fog_depth_begin = 150.0
fog_depth_end = 200.0
fog_height_max = 50.0
tonemap_mode = 3
tonemap_white = 0.13
dof_blur_far_distance = 200.0
dof_blur_far_transition = 20.0
dof_blur_far_quality = 0
glow_enabled = true
glow_bloom = 1.0
glow_high_quality = true
adjustment_enabled = true
adjustment_saturation = 5.42

View File

@ -471,6 +471,15 @@ proc open_sign(self: Unit): Sign =
proc `open_sign=`(self: Unit, value: Sign) =
state.open_sign = value
# World bindings
proc environment(_: PNode): string =
state.config.environment
proc `environment=`(_: PNode, mode: string) =
state.config_value.value:
environment = mode
# Sign bindings
proc new_markdown_sign(
@ -583,4 +592,7 @@ proc bridge_to_vm*(worker: Worker) =
result.bridged_from_vm "players",
playing, `playing=`, god, `god=`, flying, `flying=`, tool, `tool=`, coding,
`coding=`, running, `running=`, open_sign, `open_sign=`
`coding=`, running, `running=`, open_sign, `open_sign=`, environment,
`environment=`
result.bridged_from_vm "worlds", environment, `environment=`

View File

@ -25,11 +25,12 @@ const savable_flags = {
ConsoleVisible, MouseCaptured, Flying, God, AltWalkSpeed, AltFlySpeed
}
const game_modes = [
const environment_names = [
"default", "blue", "bright", "bw", "bw2", "bw3", "noir", "strange",
"dream_mode"
"dream_mode", "opposite", "none", "wild_imagination"
]
var environments {.threadvar.}: Table[string, Environment]
var saved_transform {.threadvar.}: Transform
var saved_rotation {.threadvar.}: float
var saved_flags {.threadvar.}: set[LocalStateFlags]
@ -49,7 +50,6 @@ gdobj Game of Node:
force_quit_at = MonoTime.high
node_controller: NodeController
script_controller: ScriptController
game_mode: int
method process*(delta: float) =
Zen.thread_ctx.boop
@ -189,6 +189,7 @@ gdobj Game of Node:
mouse_sensitivity = uc.mouse_sensitivity ||= 5.0
gamepad_sensitivity = uc.gamepad_sensitivity ||= 2.5
invert_gamepad_y_axis = uc.invert_gamepad_y_axis ||= false
environment = "default"
state.set_flag(God, uc.god_mode ||= false)
@ -260,6 +261,22 @@ gdobj Game of Node:
self.stats = self.find_node("stats").as(Label)
self.stats.visible = state.config.show_stats
state.config_value.changes:
if removed and change.item.environment != state.config.environment:
let env =
state.nodes.game.find_node("Level").get_node("WorldEnvironment") as
WorldEnvironment
if state.config.environment notin environments:
let res = \"res://environments/{state.config.environment}.tres"
let environment = load(res) as Environment
if not ?environment:
logger("err", \"Environment {state.config.environment} not found")
return
environments[state.config.environment] = environment
env.environment = environments[state.config.environment]
logger("info", \"Changed game mode to {state.config.environment}")
state.player_value.changes:
if added and ?change.item and restarting:
change.item.transform = saved_transform
@ -420,17 +437,11 @@ gdobj Game of Node:
if host_os != "macosx":
state.push_flag Quitting
elif event.is_action_pressed("change_mode"):
self.game_mode += 1
if self.game_mode >= game_modes.len:
self.game_mode = 0
let env =
state.nodes.game.find_node("Level").get_node("WorldEnvironment") as
WorldEnvironment
let mode_scene =
load(\"res://environments/{game_modes[self.game_mode]}.tres") as
Environment
env.environment = mode_scene
logger("info", \"Changed game mode to {game_modes[self.game_mode]}")
var mode = state.config.environment
while (mode = environment_names.sample; mode == state.config.environment):
discard
state.config_value.value:
environment = mode
elif EditorVisible notin state.local_flags:
if event.is_action_pressed("toggle_mouse_captured"):
state.set_flag MouseCaptured, MouseCaptured notin state.local_flags

View File

@ -2,8 +2,8 @@
#proc bot_code_template(base64_code, file_name, imports: string): string =
import system except echo, quit
import std / [strutils]
import types, class_macros, players, state_machine, base_api, bots, builds,
signs, bots_private
import types, class_macros, worlds, players, state_machine, base_api, bots,
builds, signs, bots_private
let instance_global_by_default = true
var move_mode = 1

View File

@ -2,8 +2,8 @@
#proc build_code_template(base64_code, file_name, imports: string): string =
import system except echo, quit
import std / [strutils]
import types, class_macros, players, state_machine, base_api, bots, builds,
signs, builds_private
import types, class_macros, players, worlds, state_machine, base_api, bots,
builds, signs, builds_private
let instance_global_by_default = false
var move_mode = 1

View File

@ -196,6 +196,7 @@ type
dock_icon_size*: float
show_stats*: bool
mega_pixels*: float
environment*: string
world_dir*: string
level_dir*: string
data_dir*: string

View File

@ -307,7 +307,6 @@ proc lean*(self: Unit, degrees: float, move_mode: int) =
if degrees <= 180:
self.lean Directions.right, degrees, move_mode
else:
let d = 180 - (degrees - 180)
self.lean Directions.left, 180 - (degrees - 180), move_mode
template lean*(self: Unit, direction: Directions, degrees = 90.0) =

View File

@ -4,44 +4,17 @@ let player* = PlayerType()
register_active(player)
bridged_to_host:
proc tool*(self: PlayerType): Tools =
discard
proc `tool=`*(self: PlayerType, value: Tools) =
discard
proc playing*(self: PlayerType): bool =
discard
proc `playing=`*(self: PlayerType, value: bool) =
discard
proc flying*(self: PlayerType): bool =
discard
proc `flying=`*(self: PlayerType, value: bool) =
discard
proc running*(self: PlayerType): bool =
discard
proc `running=`*(self: PlayerType, value: bool) =
discard
proc god*(self: PlayerType): bool =
discard
proc `god=`*(self: PlayerType, value: bool) =
discard
proc coding*(self: PlayerType): Unit =
discard
proc `coding=`*(self: PlayerType, value: Unit) =
discard
proc open_sign*(self: PlayerType): Sign =
discard
proc `open_sign=`*(self: PlayerType, value: Sign) =
discard
proc tool*(self: PlayerType): Tools
proc `tool=`*(self: PlayerType, value: Tools)
proc playing*(self: PlayerType): bool
proc `playing=`*(self: PlayerType, value: bool)
proc flying*(self: PlayerType): bool
proc `flying=`*(self: PlayerType, value: bool)
proc running*(self: PlayerType): bool
proc `running=`*(self: PlayerType, value: bool)
proc god*(self: PlayerType): bool
proc `god=`*(self: PlayerType, value: bool)
proc coding*(self: PlayerType): Unit
proc `coding=`*(self: PlayerType, value: Unit)
proc open_sign*(self: PlayerType): Sign
proc `open_sign=`*(self: PlayerType, value: Sign)

View File

@ -30,6 +30,8 @@ type
seed: int
sign*: Sign
World* = ref object of RootObj
PositionOffset* = object
position*: Vector3
offset*: float

8
vmlib/enu/worlds.nim Normal file
View File

@ -0,0 +1,8 @@
import system except echo
import types, vm_bridge_utils
var world* = World()
bridged_to_host:
proc environment*(self: World): string
proc `environment=`*(self: World, value: string)