Skip to content

Commit

Permalink
Addon runtime options(runtime path, workding directory) will be saved…
Browse files Browse the repository at this point in the history
… to Blender User Addon Preferences, not the cfg file.
  • Loading branch information
[email protected] committed Jun 8, 2014
1 parent 82709aa commit dc2079b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
Binary file added BlenderAddon/addon_game_gamekit.zip
Binary file not shown.
8 changes: 6 additions & 2 deletions BlenderAddon/game_gamekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
bl_info = {
'name': 'Gamekit Engine',
'author': 'Xavier Thomas (xat)',
'version': (0,0,601),
'version': (0,0,611),
'api': 35899,
'blender': (2, 5, 7),
'blender': (2, 6, 6),
'location': 'Info Window > Render Engine > Gamekit',
'description': 'Launch game using the fine gamekit engine',
'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Gamekit_Engine',
Expand All @@ -41,9 +41,11 @@
#if "operators" in locals():
imp.reload(operators)
imp.reload(ui)
imp.reload(config)
else:
from . import operators
from . import ui
from . import config


#init_data = True
Expand All @@ -55,6 +57,7 @@ def register():

bpy.utils.register_class(operators.GamekitExportStartupFileOperator)
bpy.utils.register_class(operators.GamekitStartGameOperator)
bpy.utils.register_class(config.GamekitAddonPreferences)

ui.addProperties()

Expand All @@ -63,6 +66,7 @@ def unregister():

bpy.utils.unregister_class(operators.GamekitExportStartupFileOperator)
bpy.utils.unregister_class(operators.GamekitStartGameOperator)
bpy.utils.unregister_class(config.GamekitAddonPreferences)

ui.remProperties()

Expand Down
22 changes: 22 additions & 0 deletions BlenderAddon/game_gamekit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,30 @@


import bpy
from bpy.types import Operator, AddonPreferences
from bpy.props import StringProperty, IntProperty, BoolProperty
import os, os.path

class GamekitAddonPreferences(AddonPreferences):
# this must match the addon name, use '__package__'
# when defining this in a submodule of a python package.
bl_idname = __package__

runtime_path = StringProperty(
name="Runtime File Path",
subtype='FILE_PATH',
)
working_dir = StringProperty(
name="Working Directory",
subtype='FILE_PATH',
)

def draw(self, context):
layout = self.layout
layout.label(text="Gamekit Runtime options")
layout.prop(self, "runtime_path")
layout.prop(self, "working_dir")

class GamekitConfig:
cfg = dict()

Expand Down
17 changes: 12 additions & 5 deletions BlenderAddon/game_gamekit/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ def execute(self, context):
gdata = context.scene.game_settings
gks = context.scene.gamekit
scene = context.scene

cfg = config.GamekitConfig()

cfg.set("runtime", gks.gk_runtime_exec_path)
cfg.set("workingdir", gks.gk_runtime_working_dir)
#cfg.set("runtime", gks.gk_runtime_exec_path)
#cfg.set("workingdir", gks.gk_runtime_working_dir)
cfg.set("rendersystem", gks.gk_render_system.lower())
cfg.set('log', gks.gk_log_file)
cfg.set('debugfps', str(gdata.show_framerate_profile))
Expand Down Expand Up @@ -135,7 +135,13 @@ def execute(self, context):
scene = context.scene
gks = scene.gamekit

execpath = bpy.path.abspath(gks.gk_runtime_exec_path)
user_preferences = context.user_preferences
addon_prefs = user_preferences.addons[__package__].preferences

execpath = bpy.path.abspath(addon_prefs.runtime_path)
working_dir = bpy.path.abspath(addon_prefs.working_dir)

#execpath = bpy.path.abspath(gks.gk_runtime_exec_path)
if execpath[0:2] in { "./", ".\\" }:
pwd = os.path.dirname(bpy.app.binary_path)
execpath = pwd + os.sep + execpath
Expand All @@ -144,7 +150,8 @@ def execute(self, context):
gamefile = tmpdir + "gamekit_tmp.blend"
cfgfile = tmpdir + "gamekit_startup.cfg"
cmdline = execpath + " -c " + cfgfile + " " + gamefile
workingdir = assure_temp_dir(bpy.path.abspath(gks.gk_runtime_working_dir))
#workingdir = assure_temp_dir(bpy.path.abspath(gks.gk_runtime_working_dir))
workingdir = assure_temp_dir(working_dir)

args = shlex.split(cmdline.replace(os.sep, '/'))

Expand Down
17 changes: 13 additions & 4 deletions BlenderAddon/game_gamekit/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ def draw(self, context):
col = layout.column()

col.prop(gks, "gk_window_title")
col.prop(gks, "gk_runtime_exec_path")
col.prop(gks, "gk_runtime_working_dir")
#col.prop(gks, "gk_runtime_exec_path")
#col.prop(gks, "gk_runtime_working_dir")
col.prop(gks, "gk_log_file")

# Main Gamekit panel
Expand Down Expand Up @@ -328,6 +328,14 @@ class GamekitRender(bpy.types.RenderEngine):

def remProperties():
# bpy.types.Scene.RemoveProperty("gamekit")
bpy.utils.unregister_class(WORLD_PT_world)
bpy.utils.unregister_class(WORLD_PT_mist)

bpy.utils.unregister_class(RENDER_PT_gamekit)
bpy.utils.unregister_class(RENDER_PT_gamekit_runtime)
bpy.utils.unregister_class(RENDER_PT_gamekit_performance)


bpy.utils.unregister_class(GamekitRender)
bpy.utils.unregister_class(GamekitSettings)

Expand All @@ -348,7 +356,8 @@ def addProperties():

cfg = config.GamekitConfig()
cfg.load_defaults()


"""
GamekitSettings.gk_runtime_exec_path = bpy.props.StringProperty(
name="Runtime",
description="Path of the gamekit executable",
Expand All @@ -363,7 +372,7 @@ def addProperties():
maxlen = 512,
default = cfg.get('workingdir'),
subtype='FILE_PATH')

"""
GamekitSettings.gk_render_system = bpy.props.EnumProperty(
name="Render system",
items=(('GL', 'OpenGL', 'gl'),
Expand Down

0 comments on commit dc2079b

Please sign in to comment.