Browse Source

Move Plasma Games to addon User Preferences

Plasma game installs are a per-user config item and should not be stored
in a blend file. Considering that we will be adding more per-user
configs, namely Python 2.[2|3|7] install directories, it seems like a
good move to go ahead and move the games over.
pull/128/head
Adam Johnson 6 years ago
parent
commit
4d7c1cb58b
Signed by: Hoikas
GPG Key ID: 0B6515D6FF6F271E
  1. 4
      korman/__init__.py
  2. 76
      korman/addon_prefs.py
  3. 3
      korman/operators/op_export.py
  4. 15
      korman/operators/op_ui.py
  5. 60
      korman/operators/op_world.py
  6. 2
      korman/properties/modifiers/gui.py
  7. 2
      korman/properties/modifiers/logic.py
  8. 18
      korman/properties/prop_world.py
  9. 36
      korman/ui/ui_world.py

4
korman/__init__.py

@ -14,6 +14,7 @@
# along with Korman. If not, see <http://www.gnu.org/licenses/>. # along with Korman. If not, see <http://www.gnu.org/licenses/>.
import bpy import bpy
from . import addon_prefs
from . import exporter, render from . import exporter, render
from . import properties, ui from . import properties, ui
from . import nodes from . import nodes
@ -26,8 +27,7 @@ bl_info = {
"location": "File > Import-Export", "location": "File > Import-Export",
"description": "Exporter for Cyan Worlds' Plasma Engine", "description": "Exporter for Cyan Worlds' Plasma Engine",
"warning": "beta", "warning": "beta",
"category": "System", # Eventually, we will hide some of the default "category": "System",
# Blender panels (think materials)
} }

76
korman/addon_prefs.py

@ -0,0 +1,76 @@
# This file is part of Korman.
#
# Korman is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Korman is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Korman. If not, see <http://www.gnu.org/licenses/>.
import bpy
from bpy.props import *
game_versions = [("pvPrime", "Ages Beyond Myst (63.11)", "Targets the original Uru (Live) game"),
("pvPots", "Path of the Shell (63.12)", "Targets the most recent offline expansion pack"),
("pvMoul", "Myst Online: Uru Live (70)", "Targets the most recent online game")]
class PlasmaGame(bpy.types.PropertyGroup):
name = StringProperty(name="Name",
description="Name of the Plasma Game",
options=set())
path = StringProperty(name="Path",
description="Path to this Plasma Game",
options=set())
version = EnumProperty(name="Version",
description="Plasma version of this game",
items=game_versions,
options=set())
class KormanAddonPreferences(bpy.types.AddonPreferences):
bl_idname = __package__
games = CollectionProperty(type=PlasmaGame)
active_game_index = IntProperty(options={"SKIP_SAVE"})
def draw(self, context):
layout = self.layout
layout.label("Plasma Games:")
row = layout.row()
row.template_list("PlasmaGameListRW", "games", self, "games", self,
"active_game_index", rows=2)
col = row.column(align=True)
col.operator("world.plasma_game_add", icon="ZOOMIN", text="")
col.operator("world.plasma_game_remove", icon="ZOOMOUT", text="")
col.operator("world.plasma_game_convert", icon="IMPORT", text="")
# Game Properties
active_game_index = self.active_game_index
if bool(self.games) and active_game_index < len(self.games):
active_game = self.games[active_game_index]
layout.separator()
box = layout.box()
box.prop(active_game, "path", emboss=False)
box.prop(active_game, "version")
box.separator()
row = box.row(align=True)
op = row.operator("world.plasma_game_add", icon="FILE_FOLDER", text="Change Path")
op.filepath = active_game.path
op.game_index = active_game_index
@classmethod
def register(cls):
# Register the old-timey per-world Plasma Games for use in the conversion
# operator. What fun. I guess....
from .properties.prop_world import PlasmaGames
PlasmaGames.games = CollectionProperty(type=PlasmaGame)

3
korman/operators/op_export.py

@ -19,9 +19,10 @@ import cProfile
from pathlib import Path from pathlib import Path
import pstats import pstats
from ..addon_prefs import game_versions
from .. import exporter from .. import exporter
from ..helpers import UiHelper from ..helpers import UiHelper
from ..properties.prop_world import PlasmaAge, game_versions from ..properties.prop_world import PlasmaAge
from ..korlib import ConsoleToggler from ..korlib import ConsoleToggler
class ExportOperator(bpy.types.Operator): class ExportOperator(bpy.types.Operator):

15
korman/operators/op_ui.py

@ -13,6 +13,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Korman. If not, see <http://www.gnu.org/licenses/>. # along with Korman. If not, see <http://www.gnu.org/licenses/>.
import addon_utils
import bpy import bpy
from bpy.props import * from bpy.props import *
@ -87,3 +88,17 @@ class CollectionRemoveOperator(UIOperator, bpy.types.Operator):
return {"FINISHED"} return {"FINISHED"}
else: else:
return {"CANCELLED"} return {"CANCELLED"}
class OpenAddonPrefs(UIOperator, bpy.types.Operator):
bl_idname = "ui.korman_open_prefs"
bl_label = "Open Korman Preferences"
bl_description = "Opens the Korman User Preferences"
def execute(self, context):
bpy.ops.screen.userpref_show("INVOKE_DEFAULT")
context.user_preferences.active_section = "ADDONS"
context.window_manager.addon_filter = "System"
korman_addon = addon_utils.addons_fake_modules["korman"]
addon_utils.module_bl_info(korman_addon)["show_expanded"] = True
return {"FINISHED"}

60
korman/operators/op_world.py

@ -32,8 +32,8 @@ class GameAddOperator(AgeOperator, bpy.types.Operator):
game_index = IntProperty(default=-1, options={"HIDDEN"}) game_index = IntProperty(default=-1, options={"HIDDEN"})
def execute(self, context): def execute(self, context):
w = context.world prefs = context.user_preferences.addons["korman"].preferences
if w:
# First, verify this is a valid Uru directory... # First, verify this is a valid Uru directory...
path = Path(self.filepath) path = Path(self.filepath)
@ -45,13 +45,12 @@ class GameAddOperator(AgeOperator, bpy.types.Operator):
return {"CANCELLED"} return {"CANCELLED"}
# New game? # New game?
games = w.plasma_games
new_game = self.game_index == -1 new_game = self.game_index == -1
if new_game: if new_game:
games.active_game_index = len(games.games) prefs.active_game_index = len(prefs.games)
game = games.games.add() game = prefs.games.add()
else: else:
game = games.games[self.game_index] game = prefs.games[self.game_index]
# Setup game... # Setup game...
game.path = str(path) game.path = str(path)
@ -62,8 +61,6 @@ class GameAddOperator(AgeOperator, bpy.types.Operator):
game.name = path.name game.name = path.name
return {"FINISHED"} return {"FINISHED"}
else:
return {"CANCELLED"}
def invoke(self, context, event): def invoke(self, context, event):
@ -71,20 +68,53 @@ class GameAddOperator(AgeOperator, bpy.types.Operator):
return {"RUNNING_MODAL"} return {"RUNNING_MODAL"}
class GameConvertOperator(AgeOperator, bpy.types.Operator):
bl_idname = "world.plasma_game_convert"
bl_label = "This will save your User Preferences file!"
bl_description = "Load old per-file Plasma Games into your user preferences"
def draw(self, context):
self.layout.label("test")
def execute(self, context):
prefs = context.user_preferences.addons["korman"].preferences
w = context.scene.world
for old_game in w.plasma_games.games:
# don't add dupe games
match = next((i for i in prefs.games if i.path == old_game.path), None)
if match is not None:
continue
new_game = prefs.games.add()
new_game.name = old_game.name
new_game.path = old_game.path
new_game.version = old_game.version
w.plasma_games.games.clear()
bpy.ops.wm.save_userpref()
return {"FINISHED"}
def invoke(self, context, event):
return context.window_manager.invoke_confirm(self, event)
@classmethod
def poll(cls, context):
return super().poll(context) and bool(context.scene.world.plasma_games.games)
class GameRemoveOperator(AgeOperator, bpy.types.Operator): class GameRemoveOperator(AgeOperator, bpy.types.Operator):
bl_idname = "world.plasma_game_remove" bl_idname = "world.plasma_game_remove"
bl_label = "Remove Plasma Game" bl_label = "Remove Plasma Game"
def execute(self, context): def execute(self, context):
w = context.world prefs = context.user_preferences.addons["korman"].preferences
if w:
games = w.plasma_games if prefs.active_game_index >= len(prefs.games):
if games.active_game_index >= len(games.games):
return {"CANCELLED"} return {"CANCELLED"}
games.games.remove(games.active_game_index) prefs.games.remove(prefs.active_game_index)
prefs.active_game_index = max(prefs.active_game_index - 1, -1)
return {"FINISHED"} return {"FINISHED"}
else:
return {"CANCELLED"}
class PageAddOperator(AgeOperator, bpy.types.Operator): class PageAddOperator(AgeOperator, bpy.types.Operator):

2
korman/properties/modifiers/gui.py

@ -20,8 +20,8 @@ import mathutils
from bpy.props import * from bpy.props import *
from PyHSPlasma import * from PyHSPlasma import *
from ...addon_prefs import game_versions
from .base import PlasmaModifierProperties, PlasmaModifierLogicWiz from .base import PlasmaModifierProperties, PlasmaModifierLogicWiz
from .logic import game_versions
from ... import idprops from ... import idprops

2
korman/properties/modifiers/logic.py

@ -17,8 +17,8 @@ import bpy
from bpy.props import * from bpy.props import *
from PyHSPlasma import * from PyHSPlasma import *
from ...addon_prefs import game_versions
from .base import PlasmaModifierProperties from .base import PlasmaModifierProperties
from ..prop_world import game_versions
from ...exporter import ExportError from ...exporter import ExportError
from ... import idprops from ... import idprops

18
korman/properties/prop_world.py

@ -17,9 +17,7 @@ import bpy
from bpy.props import * from bpy.props import *
from PyHSPlasma import * from PyHSPlasma import *
game_versions = [("pvPrime", "Ages Beyond Myst (63.11)", "Targets the original Uru (Live) game"), from ..addon_prefs import game_versions
("pvPots", "Path of the Shell (63.12)", "Targets the most recent offline expansion pack"),
("pvMoul", "Myst Online: Uru Live (70)", "Targets the most recent online game")]
class PlasmaFni(bpy.types.PropertyGroup): class PlasmaFni(bpy.types.PropertyGroup):
bl_idname = "world.plasma_fni" bl_idname = "world.plasma_fni"
@ -58,23 +56,9 @@ class PlasmaFni(bpy.types.PropertyGroup):
min=1) min=1)
class PlasmaGame(bpy.types.PropertyGroup):
name = StringProperty(name="Name",
description="Name of the Plasma Game",
options=set())
path = StringProperty(name="Path",
description="Path to this Plasma Game",
options=set())
version = EnumProperty(name="Version",
description="Plasma version of this game",
items=game_versions,
options=set())
class PlasmaGames(bpy.types.PropertyGroup): class PlasmaGames(bpy.types.PropertyGroup):
bl_idname = "world.plasma_games" bl_idname = "world.plasma_games"
games = CollectionProperty(type=PlasmaGame)
active_game_index = IntProperty(options={"HIDDEN"}) active_game_index = IntProperty(options={"HIDDEN"})
@property @property

36
korman/ui/ui_world.py

@ -34,41 +34,39 @@ class PlasmaGamePanel(AgeButtonsPanel, bpy.types.Panel):
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
prefs = context.user_preferences.addons["korman"].preferences
games = context.world.plasma_games games = context.world.plasma_games
age = context.world.plasma_age age = context.world.plasma_age
row = layout.row() row = layout.row()
row.template_list("PlasmaGameList", "games", games, "games", games, # Remember: game storage moved to addon preferences!
row.template_list("PlasmaGameListRO", "games", prefs, "games", games,
"active_game_index", rows=2) "active_game_index", rows=2)
col = row.column(align=True) row.operator("ui.korman_open_prefs", icon="PREFERENCES", text="")
col.operator("world.plasma_game_add", icon="ZOOMIN", text="")
col.operator("world.plasma_game_remove", icon="ZOOMOUT", text="")
# Game Properties # Game Tools
active_game_index = games.active_game_index active_game_index = games.active_game_index
if active_game_index < len(games.games): if active_game_index < len(prefs.games):
active_game = games.games[active_game_index] active_game = prefs.games[active_game_index]
else:
active_game = None
layout.separator() layout.separator()
box = layout.box() row = layout.row(align=True)
box.prop(active_game, "path", emboss=False)
box.prop(active_game, "version")
box.separator()
row = box.row(align=True)
op = row.operator("world.plasma_game_add", icon="FILE_FOLDER", text="Change Path")
op.filepath = active_game.path
op.game_index = active_game_index
row = row.row(align=True)
row.operator_context = "EXEC_DEFAULT" row.operator_context = "EXEC_DEFAULT"
row.enabled = bool(age.age_name.strip()) row.enabled = bool(age.age_name.strip()) and active_game is not None
op = row.operator("export.plasma_age", icon="EXPORT") op = row.operator("export.plasma_age", icon="EXPORT")
if active_game is not None:
op.filepath = str((Path(active_game.path) / "dat" / age.age_name).with_suffix(".age")) op.filepath = str((Path(active_game.path) / "dat" / age.age_name).with_suffix(".age"))
op.version = active_game.version op.version = active_game.version
class PlasmaGameList(bpy.types.UIList): class PlasmaGameListRO(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_property, index=0, flt_flag=0):
layout.label(item.name, icon="BOOKMARKS")
class PlasmaGameListRW(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_property, index=0, flt_flag=0): def draw_item(self, context, layout, data, item, icon, active_data, active_property, index=0, flt_flag=0):
layout.prop(item, "name", text="", emboss=False, icon="BOOKMARKS") layout.prop(item, "name", text="", emboss=False, icon="BOOKMARKS")

Loading…
Cancel
Save