199 lines
5 KiB
Python
199 lines
5 KiB
Python
# Gplv3 or any later version
|
|
# (C) J.Y.Amihud 2024
|
|
|
|
import os
|
|
import json
|
|
|
|
# Those modules don't work everywhere
|
|
try:
|
|
import bge
|
|
import bpy
|
|
|
|
from Scripts import Main_update
|
|
from Scripts import Script
|
|
from Scripts import Money
|
|
from Scripts import Garage
|
|
from Scripts import Character_Controll
|
|
from Scripts import Vehicle
|
|
|
|
from Scripts.Common import *
|
|
except:
|
|
pass
|
|
|
|
def get_settings_folder():
|
|
|
|
game = "danisrace"
|
|
|
|
try:
|
|
data_dir = os.environ["XDG_DATA_HOME"] + "/" + game
|
|
except:
|
|
data_dir = os.path.expanduser("~/.local/share/"+game)
|
|
|
|
try:
|
|
os.makedirs(data_dir)
|
|
except:
|
|
pass
|
|
|
|
return data_dir
|
|
|
|
def load_settings():
|
|
|
|
folder = get_settings_folder()
|
|
f = folder+"/config.json"
|
|
|
|
try:
|
|
with open(f) as o:
|
|
return json.load(o)
|
|
except: return {}
|
|
|
|
def Execute():
|
|
|
|
|
|
# This function will execute the various settings inside of the game
|
|
|
|
data = load_settings()
|
|
if not data: return
|
|
|
|
scene = bge.logic.getCurrentScene()
|
|
|
|
# SHADOWS
|
|
|
|
for obj in scene.lights:
|
|
|
|
# Use Shadow
|
|
try: obj.blenderObject.data.use_shadow = data.get("shadows", True)
|
|
except: pass
|
|
|
|
# Use Contact Shadow
|
|
try: obj.blenderObject.use_contact_shadow = data.get("cntctshadows", True)
|
|
except: pass
|
|
|
|
# Softshadows
|
|
bpy.data.scenes["Scene"].eevee.use_soft_shadows = data.get("softshadows", True)
|
|
|
|
# Reflections
|
|
bpy.data.scenes["Scene"].eevee.use_ssr = data.get("reflections", True)
|
|
|
|
|
|
# Samples TODO figure it out
|
|
bpy.data.scenes["Scene"].eevee.taa_render_samples = data.get("samples", 1)
|
|
|
|
# Volume samples
|
|
bpy.data.scenes["Scene"].eevee.volumetric_samples = data.get("volumesamples", 32)
|
|
|
|
# Compositor
|
|
|
|
if data.get("compositor"):
|
|
bpy.context.space_data.shading.use_compositor = 'ALWAYS'
|
|
else:
|
|
bpy.context.space_data.shading.use_compositor = 'DISABLED'
|
|
|
|
# Skin samples
|
|
bpy.data.scenes["Scene"].eevee.sss_samples = data.get("skinsamples", 5)
|
|
|
|
# Volume shadows
|
|
bpy.data.scenes["Scene"].eevee.use_volumetric_shadows = data.get("volumeshadow", False)
|
|
|
|
# Volume lights
|
|
bpy.data.scenes["Scene"].eevee.use_volumetric_lights = data.get("volumelight", True)
|
|
|
|
# Volume shadows samp
|
|
bpy.data.scenes["Scene"].eevee.volumetric_shadow_samples = data.get("volshadsampl", 3)
|
|
|
|
# Cube Shadow res
|
|
bpy.data.scenes["Scene"].eevee.shadow_cube_size = data.get("shadowslamps", "512")
|
|
|
|
# Sun shadow res
|
|
bpy.data.scenes["Scene"].eevee.shadow_cascade_size = data.get("shadowssun", "1024")
|
|
|
|
# Logic Steps
|
|
#bge.logic.setMaxLogicFrame(100)
|
|
|
|
|
|
# Controlls
|
|
|
|
controlmap = {
|
|
"veh_forward" :"forward",
|
|
"veh_backward" :"backward",
|
|
"veh_left" :"left",
|
|
"veh_right" :"right",
|
|
"veh_drift" :"drift",
|
|
"veh_nitro" :"nitro",
|
|
"veh_resque" :"resque",
|
|
"veh_gear_up" :"gearup",
|
|
"veh_gear_down":"geardown",
|
|
"veh_auto_gear":"autogear",
|
|
"veh_dynamcam" :"dynamcam",
|
|
"veh_upload" :"unload",
|
|
"chr_forward" :"forward",
|
|
"chr_backward" :"backward",
|
|
"chr_left" :"left",
|
|
"chr_right" :"right",
|
|
"chr_jump" :"jump",
|
|
"chr_get_car" :"getcar",
|
|
"chr_swimdown" :"swimdown"
|
|
|
|
}
|
|
|
|
for control in controlmap:
|
|
if control.startswith("chr"): folder = bge.logic.globalDict["chr_controls"]
|
|
else: folder = bge.logic.globalDict["veh_controls"]
|
|
|
|
try: folder[controlmap[control]] = keycodes[data[control]]
|
|
except Exception as e:
|
|
print("Error assigning controls",e)
|
|
|
|
|
|
|
|
|
|
def SaveGame():
|
|
|
|
# Let's generate the data to save.
|
|
|
|
data = {
|
|
"currentEvent" : Script.Story["currentEvent"],
|
|
"passedEvents" : Script.Story["passed"]
|
|
}
|
|
|
|
data["cars"] = Garage.Encode()
|
|
data["money"] = Money.Get()
|
|
|
|
data["inventory"] = Garage.inventory
|
|
|
|
data["time"] = bge.logic.globalDict["time"]
|
|
|
|
folder = get_settings_folder()
|
|
f = folder+"/save.json"
|
|
|
|
try:
|
|
with open(f, "w") as save:
|
|
json.dump(data, save, indent=4, sort_keys=True)
|
|
print(clr["bold"]+clr["tdgr"]+"Game saved!"+clr["norm"], f)
|
|
except Exception as e:
|
|
print(clr["bold"]+clr["tdrd"]+"Failed to save game:"+clr["norm"], e)
|
|
|
|
def LoadGame():
|
|
|
|
# loading game
|
|
|
|
folder = get_settings_folder()
|
|
f = folder+"/save.json"
|
|
|
|
try:
|
|
with open(f) as o:
|
|
data = json.load(o)
|
|
except Exception as e:
|
|
print("Couldn't Load Game:", e)
|
|
return
|
|
|
|
bge.logic.globalDict["garage-saved"] = data.get("cars", [])
|
|
Script.Story["currentEvent"] = data.get("currentEvent", "01_Bring_Neonspeedster_To_Racetrack")
|
|
Script.Story["passed"] = data.get("passedEvents", [])
|
|
|
|
Money.Set(data.get("money", 0.0))
|
|
|
|
Garage.inventory = data.get("inventory", {})
|
|
Garage.UpdateShelfs()
|
|
|
|
bge.logic.globalDict["start-time"] = data.get("time")
|
|
|