Skip to content

Commit

Permalink
tested v0.8.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sneat committed Apr 4, 2021
1 parent a8060b3 commit 491092b
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 637 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.js]
quote_type = single
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ Go to Settings tab in Sidebar and **right click** on data **below** "General Inf
* Copy Environment (core, system and module versions) to clipboard
* Save Environment (including manifest links) as a JSON file
* Export game settings (both 'world' and 'client' scopes)
* Import game settings ('client' ones, and if you are GM also 'world' ones)
* Export player settings (such as player color and "dice" settings)
* Import player settings (you will be able to choose which ones you want to import)
* Import game settings ('client' ones, and if you are GM also 'world' ones - you will be able to choose which ones you want to import)

*Please note that importing 'world' scope settings en masse as GM might cause some issues to connected players. I advise players should logout before attempt to import World Settings*
*Please note that importing 'world' scope settings en masse as GM might cause some issues to connected players. I advise players should logout before attempting to import World Settings*

## Contact

Expand Down
7 changes: 6 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

### v2.0.2

* Tested 0.8.1 compatibility

### v2.0.1

* Merged world and player settings into a single json to simplify use.
* Added differential style selection for world settings import.
* Finished adding localization support.
Expand All @@ -22,4 +27,4 @@
* Tested and bumped compatible core version to 0.7.1

### v1.0.1
* Initial release
* Initial release
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"name": "forien-copy-environment",
"title": "Forien's Copy Environment",
"description": "Allows for copying TXT/JSON list of system/modules and versions, and gives ability to export/import game and player settings",
"version": "2.0.1",
"version": "2.0.2",
"library": "false",
"manifestPlusVersion": "1.0.0",
"minimumCoreVersion": "0.6.0",
"compatibleCoreVersion": "0.8.0",
"compatibleCoreVersion": "0.8.1",
"author": "Forien — Forien#2130",
"authors": [{
"name": "Forien",
Expand Down Expand Up @@ -35,7 +35,7 @@
}],
"url": "https://github.com/League-of-Foundry-Developers/foundryvtt-forien-copy-environment",
"manifest": "https://github.com/League-of-Foundry-Developers/foundryvtt-forien-copy-environment/releases/latest/download/module.json",
"download": "https://github.com/League-of-Foundry-Developers/foundryvtt-forien-copy-environment/releases/download/2.0.1/module.zip",
"download": "https://github.com/League-of-Foundry-Developers/foundryvtt-forien-copy-environment/releases/download/2.0.2/module.zip",
"bugs": "https://github.com/League-of-Foundry-Developers/foundryvtt-forien-copy-environment/issues",
"changelog": "https://github.com/League-of-Foundry-Developers/foundryvtt-forien-copy-environment/blob/master/changelog.md",
"allowBugReporter": true
Expand Down
45 changes: 23 additions & 22 deletions scripts/config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
export const name = "forien-copy-environment";

export const templates = {
settings: `modules/${name}/templates/settings.html`,
};

export function log(force, ...args) {
try {
if (typeof force !== "boolean") {
console.warn(
'Copy Environment | Invalid log usage. Expected "log(force, ...args)" as boolean but got',
force
);
}

const isDebugging = window.DEV?.getPackageDebugValue(name);

if (force || isDebugging) {
console.log("Copy Environment |", ...args);
}
} catch (e) {}
}
export const name = 'forien-copy-environment';

export const templates = {
settings: `modules/${name}/templates/settings.html`,
};

export function log(force, ...args) {
try {
if (typeof force !== "boolean") {
console.warn(
'Copy Environment | Invalid log usage. Expected "log(force, ...args)" as boolean but got',
force
);
}

const isDebugging = window.DEV?.getPackageDebugValue(name);

if (force || isDebugging) {
console.log("Copy Environment |", ...args);
}
} catch (e) {
}
}
102 changes: 49 additions & 53 deletions scripts/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { name, templates, log } from "./config.js";
import Setting from "./setting.js";
import {name, templates, log} from './config.js';
import Setting from './setting.js';

export default class Core extends FormApplication {
/**
Expand All @@ -16,7 +16,7 @@ export default class Core extends FormApplication {
this.notFoundPlayers = [];

if (settings && Array.isArray(settings)) {
log(false, "Parsing provided settings", settings);
log(false, 'Parsing provided settings', settings);

settings.forEach((data) => {
try {
Expand Down Expand Up @@ -45,19 +45,19 @@ export default class Core extends FormApplication {
}
}
} catch (e) {
log(false, "Error importing setting:", e, data);
log(false, 'Error importing setting:', e, data);
}
});
}

log(false, "Processing world settings", this.settings);
log(false, "Processing player settings", this.playerSettings);
log(false, 'Processing world settings', this.settings);
log(false, 'Processing player settings', this.playerSettings);
}

static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ["copy-environment-settings"],
height: "auto",
classes: ['copy-environment-settings'],
height: 'auto',
width: Math.ceil(window.innerWidth / 2),
id: `${name}-settings`,
title: `${name}.title`,
Expand All @@ -81,29 +81,29 @@ export default class Core extends FormApplication {
activateListeners(html) {
super.activateListeners(html);

html.on("click", ".close", () => {
html.on('click', '.close', () => {
this.close();
});

html.on("change", ".toggle-selections", (el) => {
$(el.target.closest("fieldset"))
.find("td input")
.prop("checked", el.target.checked);
html.on('change', '.toggle-selections', (el) => {
$(el.target.closest('fieldset'))
.find('td input')
.prop('checked', el.target.checked);
});

html.on("click", ".import", () => {
for (let field of this.form.getElementsByTagName("fieldset")) {
html.on('click', '.import', () => {
for (let field of this.form.getElementsByTagName('fieldset')) {
let targetType = field.dataset?.type;
if (!targetType) {
log(false, "Could not find fieldset target type");
log(false, 'Could not find fieldset target type');
continue;
}

switch (targetType) {
case "world":
case 'world':
this.importWorldSettings(field);
break;
case "player":
case 'player':
this.importPlayerSettings(field);
break;
}
Expand All @@ -122,17 +122,17 @@ export default class Core extends FormApplication {

let target = input.dataset?.for;
if (!this.settings[target]) {
log(false, "Import world settings: could not find target for", input);
log(false, 'Import world settings: could not find target for', input);
continue;
}

log(false, "Importing world setting", this.settings[target]);
log(false, 'Importing world setting', this.settings[target]);
changes.push(this.settings[target]);
}
if (changes.length) {
Core.processSettings(changes).then(() => {
ui.notifications.info(
game.i18n.localize("forien-copy-environment.updatedReloading"),
game.i18n.localize('forien-copy-environment.updatedReloading'),
{}
);
window.setTimeout(window.location.reload.bind(window.location), 5000);
Expand All @@ -152,48 +152,44 @@ export default class Core extends FormApplication {

let target = input.dataset?.for;
if (!this.playerSettings[target]) {
log(false, "Import player settings: could not find target for", input);
log(false, 'Import player settings: could not find target for', input);
continue;
}

let type = input.dataset?.type;
if (!type) {
log(false, "Import player settings: missing type (core or flag)");
log(false, 'Import player settings: missing type (core or flag)');
continue;
}

if (!targetUser) {
targetUser = game.users.getName(this.playerSettings[target].name);
}

if (type === "core") {
changes[input.name] = this.playerSettings[target].playerDifferences[
input.name
].newVal;
if (type === 'core') {
changes[input.name] = this.playerSettings[target].playerDifferences[input.name].newVal;
}

if (type === "flag") {
changes.flags[input.name] = this.playerSettings[
target
].playerFlagDifferences[input.name].newVal;
if (type === 'flag') {
changes.flags[input.name] = this.playerSettings[target].playerFlagDifferences[input.name].newVal;
}
}

if (!targetUser) {
log(false, "No targetUser found.");
log(false, 'No targetUser found.');
return;
}

if (Object.keys(changes).length === 1 && isObjectEmpty(changes.flags)) {
log(false, "No changes selected for", targetUser?.name);
log(false, 'No changes selected for', targetUser?.name);
return;
}

log(false, `Updating ${targetUser.name} with`, changes);
targetUser.update(changes);

ui.notifications.info(
game.i18n.format("forien-copy-environment.import.updatedPlayer", {
game.i18n.format('forien-copy-environment.import.updatedPlayer', {
name: targetUser.name,
}),
{}
Expand All @@ -202,21 +198,21 @@ export default class Core extends FormApplication {

static download(data, filename) {
if (!filename) {
log(false, "Missing filename on download request");
log(false, 'Missing filename on download request');
return;
}

let jsonStr = JSON.stringify(data, null, 2);

saveDataToFile(jsonStr, "application/json", filename);
saveDataToFile(jsonStr, 'application/json', filename);
}

static data() {
let modules = game.data.modules.filter((m) => m.active);
let system = game.data.system;
let core = game.data.version;

let message = game.i18n.localize("forien-copy-environment.message");
let message = game.i18n.localize('forien-copy-environment.message');

return {
message,
Expand Down Expand Up @@ -247,18 +243,18 @@ export default class Core extends FormApplication {
static copyAsText() {
let text = this.getText();

const el = document.createElement("textarea");
const el = document.createElement('textarea');
el.value = text;
el.setAttribute("readonly", "");
el.style.position = "absolute";
el.style.left = "-9999px";
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand("copy");
document.execCommand('copy');
document.body.removeChild(el);

ui.notifications.info(
game.i18n.localize("forien-copy-environment.copiedToClipboard"),
game.i18n.localize('forien-copy-environment.copiedToClipboard'),
{}
);
}
Expand All @@ -284,7 +280,7 @@ export default class Core extends FormApplication {
};
});

this.download(data, "foundry-environment.json");
this.download(data, 'foundry-environment.json');
}

static exportGameSettings() {
Expand All @@ -305,19 +301,19 @@ export default class Core extends FormApplication {
flags: u.data.flags,
}))
);
this.download(data, "foundry-settings-export.json");
this.download(data, 'foundry-settings-export.json');
}

static importGameSettingsQuick() {
const input = $('<input type="file">');
input.on("change", this.importGameSettings);
input.trigger("click");
input.on('change', this.importGameSettings);
input.trigger('click');
}

static importGameSettings() {
const file = this.files[0];
if (!file) {
log(false, "No file provided for game settings importer.");
log(false, 'No file provided for game settings importer.');
return;
}

Expand All @@ -327,22 +323,22 @@ export default class Core extends FormApplication {
let coreSettings = new Core(settings);
coreSettings.render(true);
} catch (e) {
log(false, "Could not parse import data.");
log(false, 'Could not parse import data.');
}
});
}

static async processSettings(settings) {
for (const setting of settings) {
const config = game.settings.settings.get(setting.key);
if (config?.scope === "client") {
if (config?.scope === 'client') {
const storage = game.settings.storage.get(config.scope);
storage.setItem(setting.key, setting.value);
} else if (game.user.isGM) {
try {
await SocketInterface.dispatch("modifyDocument", {
type: "Setting",
action: "update",
await SocketInterface.dispatch('modifyDocument', {
type: 'Setting',
action: 'update',
data: setting,
});
} catch (e) {
Expand Down
Loading

0 comments on commit 491092b

Please sign in to comment.