Skip to content

Commit

Permalink
Release - 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
simon50keda committed Jan 29, 2016
1 parent 97e5eae commit f7d5f1a
Show file tree
Hide file tree
Showing 13 changed files with 460 additions and 360 deletions.
6 changes: 3 additions & 3 deletions addon/io_scs_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"name": "SCS Tools",
"description": "Setup models, Import-Export SCS data format",
"author": "Simon Lusenc (50keda), Milos Zajic (4museman)",
"version": (1, 1, "e02402c"),
"version": (1, 2, "bfa9481"),
"blender": (2, 75, 0),
"location": "File > Import-Export",
"wiki_url": "https://github.com/SCSSoftware/BlenderTools/wiki",
Expand Down Expand Up @@ -180,8 +180,8 @@ def draw(self, context):
layout_box_row = layout_box_col.row(align=True)
layout_box_row.prop(self, "scs_project_path_mode", toggle=True, text="Set Current Dir as Project Base", icon='SAVE_COPY')

# Debug options
ui.shared.draw_debug_settings(layout)
# Common global settings
ui.shared.draw_common_settings(layout)


class ExportSCS(bpy.types.Operator, ExportHelper):
Expand Down
10 changes: 10 additions & 0 deletions addon/io_scs_tools/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"""

from enum import Enum
from zipfile import ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2


class ConnectionsStorage:
Expand Down Expand Up @@ -379,3 +380,12 @@ class PIF:
class Bones:
init_scale_key = "scs_init_scale"
"""Pose bone custom property dictionary key for saving initial bone scale on PIS import."""


class ConvHlpr:
"""Conversion helper constants
"""
NoZip = "No Archive"
StoredZip = str(ZIP_STORED)
DeflatedZip = str(ZIP_DEFLATED)
Bzip2Zip = str(ZIP_BZIP2)
8 changes: 6 additions & 2 deletions addon/io_scs_tools/exp/pit.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,12 @@ def export(root_object, filepath, used_materials, used_parts):

material_export_data.sections.append(texture_section)

else:
# DEFAULT MATERIAL
else: # when user made material presets were there, but there is no preset library at export for some reason

lprint("W Shader preset used on %r not found in Shader Presets Library (Did you set correct path?), "
"exporting default material instead!",
(material_name,))

material_name = str("_" + material_name + "_-_default_settings_")
material_export_data = _default_material(material_name)

Expand Down
592 changes: 306 additions & 286 deletions addon/io_scs_tools/internals/containers/config.py

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions addon/io_scs_tools/internals/containers/pix.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ def get_data_from_file(filepath, ind, print_info=False):
:rtype: list of SectionData
"""

if filepath is None:
lprint("D Aborting PIX file read, 'None' file!")
return None

# print(' filepath: "%s"\n' % filepath)
container, state = _pix_parser.read_data(filepath, ind, print_info)
if len(container) < 1:
Expand Down
36 changes: 28 additions & 8 deletions addon/io_scs_tools/operators/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import subprocess
import shutil
from bpy.props import StringProperty, CollectionProperty, EnumProperty, IntProperty, BoolProperty
from io_scs_tools.consts import ConvHlpr as _CONV_HLPR_consts
from io_scs_tools.utils import object as _object_utils
from io_scs_tools.utils import view3d as _view3d_utils
from io_scs_tools.utils import path as _path_utils
Expand Down Expand Up @@ -1091,17 +1092,36 @@ def execute(self, context):
if not mod_name.endswith(".zip"):
mod_filepath += ".zip"

from zipfile import ZipFile
# delete mod folder if previously no archive option was used
mod_filepath_as_dir = mod_filepath[:-4]
if os.path.isdir(mod_filepath_as_dir):
shutil.rmtree(mod_filepath_as_dir)

with ZipFile(mod_filepath, 'w') as myzip:
# make sure previous ZIP file is not present
if os.path.isfile(mod_filepath):
os.remove(mod_filepath)

for root, dirs, files in os.walk(rsrc_path):
# do copy or zipping
if scs_globals.conv_hlpr_mod_compression == _CONV_HLPR_consts.NoZip:

for file in files:
shutil.copytree(rsrc_path, mod_filepath_as_dir)

abs_file = os.path.join(root, file)
archive_file = abs_file.replace(rsrc_path, "")
myzip.write(abs_file, archive_file, compress_type=int(scs_globals.conv_hlpr_mod_compression))
self.report({'INFO'}, "Packing done, mod copied to: '%s'" % mod_filepath_as_dir)

else:

from zipfile import ZipFile

with ZipFile(mod_filepath, 'w') as myzip:

for root, dirs, files in os.walk(rsrc_path):

for file in files:

abs_file = os.path.join(root, file)
archive_file = abs_file.replace(rsrc_path, "")
myzip.write(abs_file, archive_file, compress_type=int(scs_globals.conv_hlpr_mod_compression))

self.report({'INFO'}, "Packing done, mod packed to: '%s'" % mod_filepath)

self.report({'INFO'}, "Packing done, mod copied to: '%s'" % mod_filepath)
return {'FINISHED'}
70 changes: 45 additions & 25 deletions addon/io_scs_tools/properties/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
CollectionProperty,
EnumProperty,
FloatVectorProperty)
from zipfile import ZIP_STORED, ZIP_DEFLATED, ZIP_BZIP2
from io_scs_tools.consts import ConvHlpr as _CONV_HLPR_consts
from io_scs_tools.internals import preview_models as _preview_models
from io_scs_tools.internals.containers import config as _config_container
from io_scs_tools.utils import material as _material_utils
Expand Down Expand Up @@ -786,11 +786,6 @@ def show_preview_models_update(self, context):
)

# IMPORT & EXPORT SETTINGS SAVED IN CONFIG
def dump_level_update(self, context):
# utils.update_item_in_config_file(utils.get_config_filepath(), 'Various.DumpLevel', self.dump_level)
_config_container.update_item_in_file('Header.DumpLevel', self.dump_level)
return None

def import_scale_update(self, context):
_config_container.update_item_in_file('Import.ImportScale', float(self.import_scale))
return None
Expand Down Expand Up @@ -927,20 +922,6 @@ def sign_export_update(self, context):
_config_container.update_item_in_file('Export.SignExport', int(self.sign_export))
return None

dump_level = EnumProperty(
name="Printouts",
items=(
('0', "0 - Errors Only", "Print only Errors to the console"),
('1', "1 - Errors and Warnings", "Print Errors and Warnings to the console"),
('2', "2 - Errors, Warnings, Info", "Print Errors, Warnings and Info to the console"),
('3', "3 - Errors, Warnings, Info, Debugs", "Print Errors, Warnings, Info and Debugs to the console"),
('4', "4 - Errors, Warnings, Info, Debugs, Specials", "Print Errors, Warnings, Info, Debugs and Specials to the console"),
('5', "5 - Test mode (DEVELOPER ONLY)", "Extra developer mode. (Don't use it if you don't know what you are doing!)"),
),
default='2',
update=dump_level_update,
)

# IMPORT OPTIONS
import_scale = FloatProperty(
name="Scale",
Expand Down Expand Up @@ -1167,6 +1148,44 @@ def sign_export_update(self, context):
update=sign_export_update,
)

# COMMON SETTINGS - SAVED IN CONFIG
def dump_level_update(self, context):
_config_container.update_item_in_file('Header.DumpLevel', self.dump_level)
return None

def config_storage_place_update(self, context):

_config_container.update_item_in_file('Header.ConfigStoragePlace', self.config_storage_place)

if self.config_storage_place == "ConfigFile":
_config_container.apply_settings()

return None

dump_level = EnumProperty(
name="Printouts",
items=(
('0', "0 - Errors Only", "Print only Errors to the console"),
('1', "1 - Errors and Warnings", "Print Errors and Warnings to the console"),
('2', "2 - Errors, Warnings, Info", "Print Errors, Warnings and Info to the console"),
('3', "3 - Errors, Warnings, Info, Debugs", "Print Errors, Warnings, Info and Debugs to the console"),
('4', "4 - Errors, Warnings, Info, Debugs, Specials", "Print Errors, Warnings, Info, Debugs and Specials to the console"),
('5', "5 - Test mode (DEVELOPER ONLY)", "Extra developer mode. (Don't use it if you don't know what you are doing!)"),
),
default='2',
update=dump_level_update,
)
config_storage_place = EnumProperty(
name="Use Global Settings",
description="Defines place for storage of Global Settings. By default Common Config File is used for globals to be stored per machine.",
items=(
('ConfigFile', 'From Common Config File', "Global settings stored per machine"),
('BlendFile', 'From Blend File', "Global settings stored per each blend file"),
),
default='ConfigFile',
update=config_storage_place_update,
)

# COMMON SETTINGS - NOT SAVED IN CONFIG
preview_export_selection = BoolProperty(
name="Preview selection",
Expand Down Expand Up @@ -1197,7 +1216,7 @@ def conv_hlpr_converters_path_update(self, context):

conv_hlpr_converters_path = StringProperty(
name="Converters Path",
description="Path to SCS conversion tools directory.",
description="Path to SCS conversion tools directory (needed only if you use Conversion Helper).",
subtype="DIR_PATH",
update=conv_hlpr_converters_path_update,
default="<Select Converters Path>"
Expand Down Expand Up @@ -1255,9 +1274,10 @@ def path_update(self, context):
conv_hlpr_mod_compression = EnumProperty(
description="Compression method for mod packing",
items=(
(str(ZIP_STORED), "No Compression", "No compression done to package"),
(str(ZIP_DEFLATED), "Deflated", "Use ZIP deflated compression method"),
(str(ZIP_BZIP2), "BZIP2", "Uses bzip2 compression method"),
(_CONV_HLPR_consts.NoZip, "No Archive", "Create mod folder package instead of ZIP"),
(_CONV_HLPR_consts.StoredZip, "No Compression", "No compression done to package"),
(_CONV_HLPR_consts.DeflatedZip, "Deflated", "Use ZIP deflated compression method"),
(_CONV_HLPR_consts.Bzip2Zip, "BZIP2", "Uses bzip2 compression method"),
),
default=str(ZIP_DEFLATED)
default=_CONV_HLPR_consts.DeflatedZip
)
8 changes: 7 additions & 1 deletion addon/io_scs_tools/ui/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _draw_shader_texture(layout, mat, split_perc, texture, read_only):
layout_box_row.alert = False
else:
layout_box_row.alert = True
texture_icon = 'ERROR'
texture_icon = 'NONE' # info operator will have icon, so texture path should use none

# MARK EMPTY SLOTS
if shader_texture == "":
Expand All @@ -308,6 +308,12 @@ def _draw_shader_texture(layout, mat, split_perc, texture, read_only):

layout_box_row = layout_box_row.row(align=True)
layout_box_row.prop(mat.scs_props, shader_texture_id, text='', icon=texture_icon)

if layout_box_row.alert: # add info operator when texture path is invalid
_shared.draw_warning_operator(layout_box_row,
title="Texture Not Found",
message="Texture with given path doesn't exists or SCS Project Base Path is not properly set!")

props = layout_box_row.operator('material.scs_select_shader_texture_filepath', text='', icon='FILESEL')
props.shader_texture = shader_texture_id # DYNAMIC ID SAVE (FOR FILE REQUESTER)

Expand Down
30 changes: 14 additions & 16 deletions addon/io_scs_tools/ui/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _draw_path_settings_panel(scene, layout, scs_globals):
emboss=False
)
layout_box_row.label('')
layout_box_col = layout_box.column()
layout_box_col = layout_box.column(align=True)

# SCS Project Path (DIR_PATH - absolute)
layout_box_col.label('SCS Project Base Path:', icon='FILE_FOLDER')
Expand All @@ -68,8 +68,8 @@ def _draw_path_settings_panel(scene, layout, scs_globals):

# Divide labels and sub paths to columns
sub_paths_layout = layout_box_col.row().split(percentage=0.3)
sub_paths_left_col = sub_paths_layout.column()
sub_paths_right_col = sub_paths_layout.column()
sub_paths_left_col = sub_paths_layout.column(align=True)
sub_paths_right_col = sub_paths_layout.column(align=True)

# Trigger Actions File (FILE_PATH - relative)
icon = 'SNAP_ON' if _get_scs_globals().trigger_actions_use_infixed else 'SNAP_OFF'
Expand Down Expand Up @@ -134,6 +134,16 @@ def _draw_path_settings_panel(scene, layout, scs_globals):
layout_box_row.prop(scs_globals, 'shader_presets_filepath', text='', icon='NONE')
layout_box_row.operator('scene.select_shader_presets_filepath', text='', icon='FILESEL')

# CONVERSION TOOLS PATH
layout_box_col.label("Conversion Tools Path:", icon="FILE_FOLDER")

layout_box_row = layout_box_col.row(align=True)
valid = (os.path.isdir(scs_globals.conv_hlpr_converters_path) and
os.path.isfile(os.path.join(scs_globals.conv_hlpr_converters_path, "extra_mount.txt")) and
os.path.isfile(os.path.join(scs_globals.conv_hlpr_converters_path, "convert.cmd")))
layout_box_row.alert = not valid
layout_box_row.prop(scs_globals, "conv_hlpr_converters_path", text="")

else:
layout_box_row = layout_box.row()
layout_box_row.prop(
Expand Down Expand Up @@ -256,7 +266,7 @@ def _draw_global_settings_panel(scene, layout, scs_globals):
# DISPLAY SETTINGS PANEL
_draw_display_settings_panel(scene, layout_box.row(), scs_globals)

_shared.draw_debug_settings(layout_box)
_shared.draw_common_settings(layout_box, draw_config_storage_place=True)

else:
layout_box_row = layout_box.row()
Expand Down Expand Up @@ -347,18 +357,6 @@ def _draw_conversion_panel(layout, scs_globals):

layout_box = layout_column.box() # body

# TOOLS PATH
layout_col = layout_box.column(align=True)
row = layout_col.row()
row.label("Conversion Tools Path:", icon="FILE_FOLDER")

row = layout_col.row()
valid = os.path.isdir(scs_globals.conv_hlpr_converters_path)
valid = valid and os.path.isfile(os.path.join(scs_globals.conv_hlpr_converters_path, "extra_mount.txt"))
valid = valid and os.path.isfile(os.path.join(scs_globals.conv_hlpr_converters_path, "convert.cmd"))
row.alert = not valid
row.prop(scs_globals, "conv_hlpr_converters_path", text="")

# CLEAN & CONVERT CURRENT
row = layout_box.row(align=True)
row.scale_y = 1.2
Expand Down
22 changes: 15 additions & 7 deletions addon/io_scs_tools/ui/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Copyright (C) 2013-2014: SCS Software

import bpy

from io_scs_tools.consts import Icons as _ICONS_consts
from io_scs_tools.utils import object as _object_utils
from io_scs_tools.utils import get_scs_globals as _get_scs_globals
Expand Down Expand Up @@ -160,12 +159,21 @@ def draw_export_panel(layout):
'''


def draw_debug_settings(layout):
box4 = layout.box()
row = box4.row()
row.label("Printout Settings:", icon='MOD_EXPLODE')
row = box4.row()
row.prop(_get_scs_globals(), 'dump_level', text="Dump Level")
def draw_common_settings(layout, draw_config_storage_place=False):
"""Draw common settings panel featuring log level and usage type of global settings if requested
:param layout: Blender UI layout to draw operator to
:type layout: UILayout
:param draw_config_storage_place: draw globals storage type property
:type draw_config_storage_place: bool
"""
box4 = layout.box().column()
row = box4.row(align=True)
row.prop(_get_scs_globals(), 'dump_level', text="Log Level", icon='MOD_EXPLODE')

if draw_config_storage_place:
row = box4.row(align=True)
row.prop(_get_scs_globals(), 'config_storage_place', icon='NONE')


def draw_warning_operator(layout, title, message, text="", icon="ERROR"):
Expand Down
6 changes: 5 additions & 1 deletion addon/io_scs_tools/utils/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def get_texture(texture_path, texture_type, report_invalid=False):
# CREATE ABSOLUTE FILEPATH
abs_texture_filepath = _path.get_abs_path(texture_path)

if abs_texture_filepath and abs_texture_filepath.endswith(".tobj"):
# return None on non-existing texture file path
if not abs_texture_filepath or not os.path.isfile(abs_texture_filepath):
return None

if abs_texture_filepath.endswith(".tobj"):
abs_texture_filepath = _path.get_texture_path_from_tobj(abs_texture_filepath)

# if not existing or none supported file
Expand Down
Loading

0 comments on commit f7d5f1a

Please sign in to comment.