Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCprep 3.5 Rewritten Core #401

Merged
merged 47 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b8551ef
began the process of moving much of conf.py to a singleton class
Oct 16, 2022
da3e82c
Began transitioning the source code to reflect the new MCprepEnv class
Oct 16, 2022
0bcea54
Some more rewrites to use the new MCprepEnv class
Oct 16, 2022
27af908
Fixed some bugs and changed how dev_build and verbose are set
Oct 18, 2022
10b210b
Deprecated conf.log in favor for conf.ENV.log
Oct 18, 2022
f495fed
Added mcprep_venv to .gitignore
Dec 29, 2022
e97bdf6
Changed ENV to env as requested
Dec 29, 2022
7943613
Merge remote-tracking branch 'origin/dev' into internal-rewrites
Dec 29, 2022
e4876a2
Some more fixes to account for deprecations
Dec 29, 2022
1123aa6
Added venv to gitignore
Dec 29, 2022
a167470
Ported some more code to use conf.env
Dec 29, 2022
143ccd3
Merge branch 'dev' into internal-rewrites
StandingPadAnimations Mar 17, 2023
643fefd
Deprecated make_annotations
StandingPadAnimations Mar 17, 2023
a34b01a
Added type annotations and use of Path
StandingPadAnimations Mar 17, 2023
185ab5b
Added type annotations to default arguments
StandingPadAnimations Mar 17, 2023
17af009
Deprecated bv28
StandingPadAnimations Mar 17, 2023
6d4def0
Replaced old syntax for properties
StandingPadAnimations Mar 18, 2023
2e2bf0f
Removed Blender Internal code from materials
StandingPadAnimations Mar 18, 2023
79ec6d4
Removed bang for Python scripts
StandingPadAnimations Mar 18, 2023
0844c2f
Added a deprecation warning function
StandingPadAnimations Mar 19, 2023
a1cdb6b
Merge branch 'internal-rewrites' into mcprep-3_5-recore
StandingPadAnimations Mar 19, 2023
145d66f
Replaced deprecation warninging function
StandingPadAnimations Mar 19, 2023
8e9f124
Replaced arguments for matprep_cycles
StandingPadAnimations Mar 19, 2023
9e96c6d
Added check for dev_build in deprecation_warning
StandingPadAnimations Mar 19, 2023
7020eb5
Added check for dev_build in deprecation_warning
StandingPadAnimations Mar 19, 2023
7e5f894
Fixed version for deprecation warning
StandingPadAnimations Mar 19, 2023
c067dd2
Fixed the remaining uses of ENV with env
StandingPadAnimations Apr 20, 2023
40090bb
Removed use of conf.register() in load_modules
StandingPadAnimations Apr 20, 2023
73d4f43
Updated version for deprecation warning.
StandingPadAnimations Apr 20, 2023
3f5965b
Hopefully fixed the last remaining env bugs
StandingPadAnimations Apr 23, 2023
646f874
Added a check for mcprep_dev.txt
StandingPadAnimations Apr 23, 2023
d2bbe67
Added a log statement for dev builds
StandingPadAnimations Apr 23, 2023
5826aa1
Added the -d and -f options to compile.sh
StandingPadAnimations Apr 23, 2023
b9934de
Moved the dev build log statement
StandingPadAnimations Apr 23, 2023
71ef4f6
Brought internal-rewrites improvements to recore
StandingPadAnimations Apr 23, 2023
8293431
Converting remaining properties to annotations for MCprep 3.5
TheDuckCow May 3, 2023
1b805ac
Merge branch 'milestone-3-5-0' into mcprep-3_5-recore
TheDuckCow May 3, 2023
eda3596
Fix remaining references to conf in favor of env.
TheDuckCow May 3, 2023
6863a49
Fix remaining references to conf in favor of env.
TheDuckCow May 3, 2023
9fef31e
Fixing unnecessary annotations in non-class files to fix UI.
TheDuckCow May 3, 2023
8d75ac5
Added Poetry pyproject.toml
StandingPadAnimations May 5, 2023
d23216c
Fixed name in Poetry project file
StandingPadAnimations May 5, 2023
022d8cd
Removed bv28 calls in UI and MCModel
StandingPadAnimations May 5, 2023
7cf9eee
Fixed license in pyproject.toml
StandingPadAnimations May 5, 2023
fcf055d
Added Linux folder population for compile.sh
StandingPadAnimations May 9, 2023
eccda95
Fixed Shellcheck errors in compile.sh
StandingPadAnimations May 9, 2023
0fd88e9
Added warning in registration and simplified code
StandingPadAnimations May 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion MCprep_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@

import bpy


def register():
load_modules.register(bl_info)

Expand Down
8 changes: 6 additions & 2 deletions MCprep_addon/addon_updater_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ def check_for_update(self, now):
# Blender version utils
# -----------------------------------------------------------------------------
def make_annotations(cls):
"""Add annotation attribute to fields to avoid Blender 2.8+ warnings"""
"""Add annotation attribute to fields to avoid Blender 2.8+ warnings.
Deprecated operator as MCprep 3.5 moves to support 2.8+ only and using
native python annotations.
"""
if not hasattr(bpy.app, "version") or bpy.app.version < (2, 80):
return cls
if bpy.app.version < (2, 93, 0):
Expand Down Expand Up @@ -1357,7 +1361,7 @@ def select_link_function(self, tag):
def register(bl_info):
"""Registering the operators in this module"""
from . import conf
updater.verbose = conf.v
updater.verbose = conf.env.verbose

# safer failure in case of issue loading module
if updater.error != None:
Expand Down
187 changes: 160 additions & 27 deletions MCprep_addon/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# ##### END GPL LICENSE BLOCK #####

import os

from pathlib import Path
import bpy

# check if custom preview icons available
Expand All @@ -31,18 +31,148 @@
# ADDON GLOBAL VARIABLES AND INITIAL SETTINGS
# -----------------------------------------------------------------------------

class MCprepEnv:
def __init__(self):
self.data = None
self.json_data = None
self.json_path: Path = Path(os.path.dirname(__file__), "MCprep_resources", "mcprep_data.json")
self.json_path_update: Path = Path(os.path.dirname(__file__), "MCprep_resources", "mcprep_data_update.json")

self.dev_file: Path = Path(os.path.dirname(__file__), "mcprep_dev.txt")

# if new update file found from install, replace old one with new
if self.json_path_update.exists():
self.json_path_update.replace(self.json_path)

# Check to see if there's a text file for a dev build. If so,
if self.dev_file.exists():
self.dev_build = True
self.verbose = True
self.very_verbose = True
self.log("Dev Build!")

else:
self.dev_build = False
self.verbose = False
self.very_verbose = False

# lazy load json, ie only load it when needed (util function defined)

# -----------------------------------------------
# For preview icons
# -----------------------------------------------

self.use_icons: bool = True
self.preview_collections: dict = {}

# -----------------------------------------------
# For initializing the custom icons
# -----------------------------------------------
self.icons_init()

# -----------------------------------------------
# For cross-addon lists
# -----------------------------------------------

# To ensure shift-A starts drawing sub menus after pressing load all spawns
# as without this, if any one of the spawners loads nothing (invalid folder,
# no blend files etc), then it would continue to ask to reload spanwers.
self.loaded_all_spawners: bool = False

self.skin_list: list = [] # each is: [ basename, path ]
self.rig_categories: list = [] # simple list of directory names
self.entity_list: list = []

# -----------------------------------------------
# Matieral sync cahce, to avoid repeat lib reads
# -----------------------------------------------

# list of material names, each is a string. None by default to indicate
# that no reading has occurred. If lib not found, will update to [].
# If ever changing the resource pack, should also reset to None.
self.material_sync_cache = []

# -----------------------------------------------------------------------------
# ICONS INIT
# -----------------------------------------------------------------------------


def icons_init(self):
collection_sets = [
"main", "skins", "mobs", "entities", "blocks", "items", "effects", "materials"]

try:
for iconset in collection_sets:
self.preview_collections[iconset] = bpy.utils.previews.new()

script_path = bpy.path.abspath(os.path.dirname(__file__))
icons_dir = os.path.join(script_path, 'icons')
self.preview_collections["main"].load(
"crafting_icon",
os.path.join(icons_dir, "crafting_icon.png"),
'IMAGE')
self.preview_collections["main"].load(
"meshswap_icon",
os.path.join(icons_dir, "meshswap_icon.png"),
'IMAGE')
self.preview_collections["main"].load(
"spawner_icon",
os.path.join(icons_dir, "spawner_icon.png"),
'IMAGE')
self.preview_collections["main"].load(
"sword_icon",
os.path.join(icons_dir, "sword_icon.png"),
'IMAGE')
self.preview_collections["main"].load(
"effects_icon",
os.path.join(icons_dir, "effects_icon.png"),
'IMAGE')
self.preview_collections["main"].load(
"entity_icon",
os.path.join(icons_dir, "entity_icon.png"),
'IMAGE')
self.preview_collections["main"].load(
"model_icon",
os.path.join(icons_dir, "model_icon.png"),
'IMAGE')
except Exception as e:
self.log("Old verison of blender, no custom icons available")
self.log("\t" + str(e))
global use_icons
self.use_icons = False
for iconset in collection_sets:
self.preview_collections[iconset] = ""

def log(self, statement: str, vv_only: bool=False):
if self.verbose and vv_only and self.very_verbose:
print(statement)
elif self.verbose:
print(statement)

def deprecation_warning(self):
if self.dev_build:
import traceback
self.log("Deprecation Warning: This will be removed in MCprep 3.5.1!")
traceback.print_stack()

env = MCprepEnv()

# ! Deprecated as of MCprep 3.4.2
def init():

env.deprecation_warning()
# -----------------------------------------------
# Verbose, use as conf.v
# Verbose, use as env.verbose
# Used to print out extra information, set false with distribution
# -----------------------------------------------
# ! Deprecated as of MCprep 3.4.2
global dev
dev = True

# ! Deprecated as of MCprep 3.4.2
global v
v = True # $VERBOSE, UI setting

# ! Deprecated as of MCprep 3.4.2
global vv
vv = dev # $VERYVERBOSE

Expand All @@ -52,13 +182,16 @@ def init():

# shouldn't load here, just globalize any json data?

# ! Deprecated as of MCprep 3.4.2
global data
# import json

# ! Deprecated as of MCprep 3.4.2
global json_data # mcprep_data.json
json_data = None # later will load addon information etc

# if existing json_data_update exists, overwrite it
# ! Deprecated as of MCprep 3.4.2
global json_path
json_path = os.path.join(
os.path.dirname(__file__),
Expand All @@ -81,8 +214,10 @@ def init():
# For preview icons
# -----------------------------------------------

# ! Deprecated as of MCprep 3.4.2
global use_icons
use_icons = True
# ! Deprecated as of MCprep 3.4.2
global preview_collections
preview_collections = {}

Expand All @@ -98,15 +233,19 @@ def init():
# To ensure shift-A starts drawing sub menus after pressing load all spawns
# as without this, if any one of the spawners loads nothing (invalid folder,
# no blend files etc), then it would continue to ask to reload spanwers.
# ! Deprecated as of MCprep 3.4.2
global loaded_all_spawners
loaded_all_spawners = False

# ! Deprecated as of MCprep 3.4.2
global skin_list
skin_list = [] # each is: [ basename, path ]

# ! Deprecated as of MCprep 3.4.2
global rig_categories
rig_categories = [] # simple list of directory names

# ! Deprecated as of MCprep 3.4.2
global entity_list
entity_list = []

Expand All @@ -117,16 +256,18 @@ def init():
# list of material names, each is a string. None by default to indicate
# that no reading has occurred. If lib not found, will update to [].
# If ever changing the resource pack, should also reset to None.
# ! Deprecated as of MCprep 3.4.2
global material_sync_cache
material_sync_cache = None


# ! Deprecated as of MCprep 3.4.2
# -----------------------------------------------------------------------------
# ICONS INIT
# -----------------------------------------------------------------------------


def icons_init():
env.deprecation_warning()
# start with custom icons
# put into a try statement in case older blender version!
global preview_collections
Expand Down Expand Up @@ -177,17 +318,14 @@ def icons_init():
for iconset in collection_sets:
preview_collections[iconset] = ""


# ! Deprecated as of MCprep 3.4.2
def log(statement, vv_only=False):
"""General purpose simple logging function."""
global v
global vv
if v and vv_only and vv:
env.deprecation_warning()
if env.verbose and vv_only and env.very_verbose:
print(statement)
elif v:
elif env.verbose:
print(statement)


def updater_select_link_function(self, tag):
"""Indicates what zip file to use for updating from a tag structure.

Expand All @@ -205,29 +343,24 @@ def updater_select_link_function(self, tag):
# GLOBAL REGISTRATOR INIT
# -----------------------------------------------------------------------------


# ! Deprecated as of MCprep 3.4.2
def register():
env.deprecation_warning()
init()


def unregister():
global preview_collections
if use_icons:
for pcoll in preview_collections.values():
if env.use_icons:
for pcoll in env.preview_collections.values():
try:
bpy.utils.previews.remove(pcoll)
except:
log('Issue clearing preview set ' + str(pcoll))
preview_collections.clear()
env.log('Issue clearing preview set ' + str(pcoll))
env.preview_collections.clear()

global json_data
json_data = None # actively clearing out json data for next open
env.json_data = None # actively clearing out json data for next open

global loaded_all_spawners
loaded_all_spawners = False
global skin_list
skin_list = []
global rig_categories
rig_categories = []
global material_sync_cache
material_sync_cache = []
env.loaded_all_spawners = False
env.skin_list = []
env.rig_categories = []
env.material_sync_cache = []
Loading