Skip to content

Commit

Permalink
Merge pull request #127 from moo-man/dev
Browse files Browse the repository at this point in the history
2.5.0
  • Loading branch information
moo-man authored Feb 13, 2023
2 parents d5bc473 + 680c0d0 commit 330372d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 48 deletions.
77 changes: 44 additions & 33 deletions ddimport.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Hooks.on("init", () => {
default: {
source: "data",
bucket: "",
region: "",
path: "worlds/" + game.world.id,
offset: 0.0,
fidelity: 3,
Expand Down Expand Up @@ -60,8 +59,8 @@ class DDImporter extends FormApplication {
}


getData() {
let data = super.getData();
async getData() {
let data = await super.getData();
let settings = game.settings.get("dd-import", "importSettings")

data.dataSources = {
Expand All @@ -71,7 +70,13 @@ class DDImporter extends FormApplication {
data.defaultSource = settings.source || "data";

data.s3Bucket = settings.bucket || "";
data.s3Region = settings.region || "";
try {
data.bucketOptions = (await FilePicker.browse("s3", "")).dirs;
}
catch (e)
{
console.log("No S3 buckets found")
}
data.path = settings.path || "";
data.offset = settings.offset || 0;
data.padding = settings.padding || 0.25
Expand Down Expand Up @@ -99,7 +104,6 @@ class DDImporter extends FormApplication {
let padding = parseFloat(formData["padding"])
let source = formData["source"]
let bucket = formData["bucket"]
let region = formData["region"]
let path = formData["path"]
let filecount = formData["filecount"]
let mode = formData["multi-mode"]
Expand All @@ -111,8 +115,8 @@ class DDImporter extends FormApplication {
let customPixelsPerGrid = formData["customGridPPI"] * 1
var firstFileName

if ((!bucket || !region) && source == "s3")
return ui.notifications.error("Bucket and Region required for S3 upload")
if ((!bucket) && source == "s3")
return ui.notifications.error("Bucket required for S3 upload")

let files = []
var fileName = 'combined'
Expand Down Expand Up @@ -227,27 +231,35 @@ class DDImporter extends FormApplication {
thecanvas.height = height;
let mycanvas = thecanvas.getContext("2d");
ui.notifications.notify("Processing Images")
for (var fidx = 0; fidx < files.length; fidx++) {
ui.notifications.notify("Processing " + (fidx + 1) + " out of " + files.length + "images")
let f = files[fidx];
image_type = DDImporter.getImageType(atob(f.image.substr(0, 8)));
await DDImporter.image2Canvas(mycanvas, f, image_type, size.x, size.y)
if (files.length > 1) {
for (var fidx = 0; fidx < files.length; fidx++) {
ui.notifications.notify("Processing " + (fidx + 1) + " out of " + files.length + "images")
let f = files[fidx];
image_type = DDImporter.getImageType(atob(f.image.substr(0, 8)));
await DDImporter.image2Canvas(mycanvas, f, image_type, size.x, size.y)
}
ui.notifications.notify("Uploading image ....")
if (toWebp) {
image_type = 'webp';
}

var p = new Promise(function (resolve) {
thecanvas.toBlob(function (blob) {
blob.arrayBuffer().then(bfr => {
DDImporter.uploadFile(blob, fileName, path, source, image_type, bucket)
.then(function () {
resolve()
})
}, "image/" + image_type);
})
})
}
ui.notifications.notify("Uploading image ....")
if (toWebp) {
image_type = 'webp';
else {
let bfr = DDImporter.DecodeImage(files[0]);
image_type = DDImporter.getImageType(atob(files[0].image.substr(0, 8)));
DDImporter.uploadFile(bfr, fileName, path, source, image_type, bucket);
}

var p = new Promise(function (resolve) {
thecanvas.toBlob(function (blob) {
blob.arrayBuffer().then(bfr => {
DDImporter.uploadFile(bfr, fileName, path, source, image_type, bucket)
.then(function () {
resolve()
})
})
}, "image/" + image_type);
})

// aggregate the walls and place them right
let aggregated = {
Expand Down Expand Up @@ -305,12 +317,11 @@ class DDImporter extends FormApplication {
ui.notifications.notify("upload still in progress, please wait")
await p
ui.notifications.notify("creating scene")
DDImporter.DDImport(aggregated, sceneName, fileName, path, fidelity, offset, padding, image_type, bucket, region, source, pixelsPerGrid)
DDImporter.DDImport(aggregated, sceneName, fileName, path, fidelity, offset, padding, image_type, bucket, game.data.files.s3.endpoint, source, pixelsPerGrid)

game.settings.set("dd-import", "importSettings", {
source: source,
bucket: bucket,
region: region,
path: path,
offset: offset,
padding: padding,
Expand Down Expand Up @@ -467,14 +478,14 @@ class DDImporter extends FormApplication {
await FilePicker.upload(source, path, uploadFile, { bucket: bucket })
}

static async DDImport(file, sceneName, fileName, path, fidelity, offset, padding, extension, bucket, region, source, pixelsPerGrid) {
static async DDImport(file, sceneName, fileName, path, fidelity, offset, padding, extension, bucket, endpoint, source, pixelsPerGrid) {
if (path && path[path.length - 1] != "/")
path = path + "/"
let imagePath = path + fileName + "." + extension;
if (source === "s3") {
if (imagePath[0] != "/")
imagePath = "/" + imagePath
imagePath = "https://" + bucket + ".s3." + region + ".amazonaws.com" + imagePath;
if (imagePath[0] == "/")
imagePath = imagePath.slice(1)
imagePath = endpoint.protocol + '//' + bucket + '.' + endpoint.host + endpoint.path + imagePath;
}
let newScene = new Scene({
name: sceneName,
Expand Down Expand Up @@ -736,8 +747,8 @@ class DDImporter extends FormApplication {
x: ((light.position.x - file.resolution.map_origin.x) * pixelsPerGrid) + offsetX,
y: ((light.position.y - file.resolution.map_origin.y) * pixelsPerGrid) + offsetY,
rotation: 0,
dim: light.range * 4,
bright: light.range * 2,
dim: light.range * (game.system.gridDistance || 1),
bright: (light.range * (game.system.gridDistance || 1)) / 2,
angle: 360,
tintColor: "#" + light.color.substring(2),
tintAlpha: (0.05 * light.intensity)
Expand Down
13 changes: 9 additions & 4 deletions importer.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ <h3>Advanced:</h3>
</div>
<div class="s3-section" style="display: none">
<div class="form-group import">
<label class="import-options">Bucket Name for S3 Storage</label><input type='text' name="bucket" value="{{s3Bucket}}" />
</div>
<div class="form-group import">
<label class="import-options">Region Name for S3 Storage</label><input type='text' name="region" value="{{s3Region}}" />
<label class="import-options">Bucket Name for S3 Storage</label>
<select name="bucket">
{{#select s3Bucket}}
<option value=""></option>
{{#each bucketOptions}}
<option value="{{this}}">{{this}}</option>
{{/each}}
{{/select}}
</select>
</div>
</div>
</div>
Expand Down
25 changes: 14 additions & 11 deletions module.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
{
"name": "dd-import",
"id": "dd-import",
"title": "Universal Battlemap Importer",
"description": "Imports scene elements from Universal VTT files generated by editors like DungeonFog and Dungeondraft",
"version": "2.4.0",
"author": "Moo Man, m42e, jacquie",
"version": "2.5.0",
"authors": [
{"name": "Moo Man", "id": "Moo Man", "discord": "Moo Man#7518"},
{"name": "m42e", "id": "m42e"},
{"name": "jacquie", "id": "jacquie"}
],
"scripts": [
"./ddimport.js"
"ddimport.js"
],
"styles": [],
"packs": [],
"minimumCoreVersion": 10,
"compatibility" : {
"minimum" : 10,
"verified" : 10,
"maximum" : 10
"minimumCoreVersion" : 10,
"compatibility": {
"minimum": "10",
"verified": "10",
"maximum": "11"
},
"manifest": "https://raw.githubusercontent.com/moo-man/FVTT-DD-Import/master/module.json",
"download": "https://github.com/moo-man/FVTT-DD-Import/releases/download/2.4.0/uvtt-import.zip"
"download": "https://github.com/moo-man/FVTT-DD-Import/releases/download/2.5.0/uvtt-import.zip"
}

0 comments on commit 330372d

Please sign in to comment.