Manifest Fetching
This commit is contained in:
3
buildmac.sh
Executable file
3
buildmac.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/zsh
|
||||
|
||||
/Applications/Blender.app/Contents/MacOS/Blender --command extension build --source-dir ./d2toolbox --output-dir ./build
|
||||
@@ -1,19 +1,11 @@
|
||||
bl_info = {
|
||||
"name": "D2Toolbox",
|
||||
"author": "DcruBro",
|
||||
"version": (0, 1, 0),
|
||||
"blender": (5, 1, 0),
|
||||
"location": "View3D > Sidebar > D2Toolbox",
|
||||
"description": "Tools for working with Destiny 2 models",
|
||||
"category": "Import-Export",
|
||||
}
|
||||
|
||||
if "bpy" in locals():
|
||||
import importlib
|
||||
importlib.reload(globals)
|
||||
importlib.reload(operators)
|
||||
importlib.reload(panels)
|
||||
importlib.reload(preferences)
|
||||
else:
|
||||
from . import globals
|
||||
from . import operators
|
||||
from . import panels
|
||||
from . import preferences
|
||||
@@ -30,6 +22,11 @@ def register():
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
||||
if globals.getManifest() is None and bpy.app.online_access:
|
||||
try:
|
||||
globals.fetchAndSaveManifest()
|
||||
except Exception as e:
|
||||
print(f"D2Toolbox: failed to fetch manifest on load: {e}")
|
||||
|
||||
def unregister():
|
||||
for cls in reversed(classes):
|
||||
|
||||
@@ -10,6 +10,9 @@ type = "add-on"
|
||||
website = "https://git.dcrubro.com/dcrubro/d2toolbox"
|
||||
|
||||
tags = ["Import-Export"]
|
||||
copyright = [
|
||||
"2026 Copyright (C) DcruBro",
|
||||
]
|
||||
|
||||
blender_version_min = "5.1.0"
|
||||
|
||||
|
||||
53
d2toolbox/globals.py
Normal file
53
d2toolbox/globals.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import bpy
|
||||
import json
|
||||
import os
|
||||
import urllib.request
|
||||
|
||||
manifest = None # Object JSON
|
||||
|
||||
def getManifestPath():
|
||||
manifestPath = bpy.utils.extension_path_user(__package__, create=True)
|
||||
return os.path.join(manifestPath, "manifest.json")
|
||||
|
||||
|
||||
def loadManifest():
|
||||
global manifest
|
||||
|
||||
manifestPath = getManifestPath()
|
||||
if os.path.exists(manifestPath):
|
||||
with open(manifestPath, "r") as f:
|
||||
manifest = json.load(f)
|
||||
return manifest
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def getManifest():
|
||||
global manifest
|
||||
|
||||
if manifest is None:
|
||||
manifest = loadManifest()
|
||||
return manifest
|
||||
|
||||
|
||||
def fetchAndSaveManifest():
|
||||
global manifest
|
||||
# Fetch from server: https://dcrubro.com/files/d2toolbox_manifest.json ; TODO: This is my personal server, and I should maybe allow people to use their own server.
|
||||
# Will hardcode for now
|
||||
# Blender extensions should be "self-contained", meaning that they shouldn't use non-default libraries. So, we will use urllib.request instead of requests.
|
||||
url = "https://dcrubro.com/files/d2toolbox_manifest.json"
|
||||
request = urllib.request.Request(url, headers={"User-Agent": "D2Toolbox (Blender add-on)"})
|
||||
with urllib.request.urlopen(request) as response:
|
||||
manifest = json.loads(response.read().decode())
|
||||
|
||||
if manifest is None:
|
||||
raise Exception("Failed to fetch manifest from server.")
|
||||
|
||||
if (manifest.get("version") is None) or (manifest.get("version") != 1):
|
||||
raise Exception("Invalid manifest version.")
|
||||
|
||||
manifestPath = getManifestPath()
|
||||
|
||||
with open(manifestPath, "w") as f:
|
||||
json.dump(manifest, f)
|
||||
return manifest
|
||||
@@ -1,4 +1,5 @@
|
||||
import bpy
|
||||
from . import globals
|
||||
|
||||
class D2TOOLBOX_OT_hello(bpy.types.Operator):
|
||||
"""Example operator - replace with real functionality"""
|
||||
@@ -10,6 +11,19 @@ class D2TOOLBOX_OT_hello(bpy.types.Operator):
|
||||
self.report({"INFO"}, "D2Toolbox says hello")
|
||||
return {"FINISHED"}
|
||||
|
||||
class D2TOOLBOX_OT_refetch_manifest(bpy.types.Operator):
|
||||
"""Refetch the Destiny 2 model manifest (run every once in a while to get the latest models)."""
|
||||
bl_idname = "d2toolbox.refetch_manifest"
|
||||
bl_label = "Refetch Manifest"
|
||||
bl_options = {"REGISTER"}
|
||||
|
||||
def execute(self, context):
|
||||
# Placeholder for manifest refresh logic
|
||||
globals.fetchAndSaveManifest()
|
||||
self.report({"INFO"}, "Manifest refreshed")
|
||||
return {"FINISHED"}
|
||||
|
||||
classes = (
|
||||
D2TOOLBOX_OT_hello,
|
||||
D2TOOLBOX_OT_refetch_manifest
|
||||
)
|
||||
|
||||
@@ -7,9 +7,18 @@ class D2TOOLBOX_PT_main(bpy.types.Panel):
|
||||
bl_region_type = "UI"
|
||||
bl_category = "D2Toolbox"
|
||||
|
||||
# Check if blender allows internet access
|
||||
allowsInternet = bpy.app.online_access
|
||||
|
||||
def draw(self, context):
|
||||
if not self.allowsInternet:
|
||||
self.layout.label(text="Online access is disabled in Blender preferences.")
|
||||
self.layout.label(text="D2Toolbox requires online access to fetch models and assets.")
|
||||
return
|
||||
|
||||
layout = self.layout
|
||||
layout.operator("d2toolbox.hello")
|
||||
layout.label(text="Miscellaneous")
|
||||
layout.operator("d2toolbox.refetch_manifest")
|
||||
|
||||
classes = (
|
||||
D2TOOLBOX_PT_main,
|
||||
|
||||
Reference in New Issue
Block a user