Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
theripper93 committed Jan 23, 2024
1 parent 1cd4535 commit 276333a
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 27 deletions.
97 changes: 97 additions & 0 deletions make_post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os
import json
import subprocess
import requests

def get_git_repo_info():
try:
# Get the remote URL of the Git repository
remote_url = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url']).decode('utf-8').strip()

# Extract the repository owner and name from the remote URL
repo_owner, repo_name = remote_url.split('/')[-2:]
repo_name = repo_name.rstrip('.git')

return repo_owner, repo_name
except subprocess.CalledProcessError:
print("Error: Not a Git repository or Git not installed.")
return None, None

def get_latest_release(repo_owner, repo_name, token):
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest'
headers = {'Authorization': f'Bearer {token}'}
response = requests.get(url, headers=headers)
data = response.json()
return data

def get_project_title_and_id():
with open('module.json', 'r', encoding='utf-8') as json_file:
data = json.load(json_file)
title = data.get('title', 'Project Title Not Found')
id = data.get('id', 'Project ID Not Found')
return title, id

def post_discord_webhook(webhook_url, embed_title, embed_description):
# Create the payload for the webhook
payload = {
'embeds': [
{
'title': embed_title,
'description': embed_description,
'color': 0x00ff00 # You can customize the color (hex) of the embed
}
]
}

# Make an HTTP POST request to the webhook URL
headers = {'Content-Type': 'application/json'}
response = requests.post(webhook_url, data=json.dumps(payload), headers=headers)

# Check if the request was successful
if response.status_code == 200 or response.status_code == 204:
print("Webhook posted successfully.")
else:
print(f"Failed to post webhook. Status code: {response.status_code}")

def load_secrets():
secrets_file_path = os.path.join(os.path.dirname(__file__), '..', 'SECRETS.json')

try:
with open(secrets_file_path, 'r') as secrets_file:
secrets = json.load(secrets_file)
return secrets
except FileNotFoundError:
print(f"SECRETS.json file not found at: {secrets_file_path}")
return {}
except json.JSONDecodeError:
print(f"Error decoding JSON in SECRETS.json file at: {secrets_file_path}")
return {}

if __name__ == "__main__":
# Get Git repository information
repo_owner, repo_name = get_git_repo_info()

if repo_owner and repo_name:
secrets = load_secrets()

# Get Discord webhook URL and GitHub token from secrets
discord_webhook_url = secrets.get('DISCORD_WEBHOOK_URL')
github_token = secrets.get('GITHUB_TOKEN')

# Get the latest release information from GitHub
latest_release = get_latest_release(repo_owner, repo_name, github_token)
version = latest_release.get('tag_name', 'Version Not Found')
description = latest_release.get('body', 'No description available for this release.')

project_title, id = get_project_title_and_id()
package_page_link = f"\n\n**Package Page**\n https://foundryvtt.com/packages/{id}"

description += package_page_link

# Get project title and id from module.json file


# Post Discord webhook with the embed
post_discord_webhook(discord_webhook_url, f'{project_title} - Version {version}', description)
else:
print("Unable to retrieve Git repository information.")
File renamed without changes.
2 changes: 1 addition & 1 deletion packs/levels-samples/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-001578
MANIFEST-001712
11 changes: 3 additions & 8 deletions packs/levels-samples/LOG
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
2023/12/30-15:04:04.754 9634 Recovering log #1577
2023/12/30-15:04:04.758 9634 Delete type=0 #1577
2023/12/30-15:04:04.758 9634 Delete type=3 #1576
2023/12/30-15:04:26.793 8900 Level-0 table #1581: started
2023/12/30-15:04:26.793 8900 Level-0 table #1581: 0 bytes OK
2023/12/30-15:04:26.794 8900 Delete type=0 #1579
2023/12/30-15:04:26.794 8900 Manual compaction at level-0 from '!scenes!fT64AORvwMUdHzwr' @ 72057594037927935 : 1 .. '!scenes.walls!w5eztsez7EhiFrmE.zlashxFbpTyjyOHo' @ 0 : 0; will stop at (end)
2023/12/30-15:04:26.794 8900 Manual compaction at level-1 from '!scenes!fT64AORvwMUdHzwr' @ 72057594037927935 : 1 .. '!scenes.walls!w5eztsez7EhiFrmE.zlashxFbpTyjyOHo' @ 0 : 0; will stop at (end)
2024/01/23-16:02:47.136 1028 Recovering log #1710
2024/01/23-16:02:47.140 1028 Delete type=0 #1710
2024/01/23-16:02:47.140 1028 Delete type=3 #1708
11 changes: 8 additions & 3 deletions packs/levels-samples/LOG.old
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2023/12/30-12:59:30.733 c0b4 Recovering log #1575
2023/12/30-12:59:30.737 c0b4 Delete type=0 #1575
2023/12/30-12:59:30.737 c0b4 Delete type=3 #1574
2024/01/23-01:40:15.189 c104 Recovering log #1707
2024/01/23-01:40:15.192 c104 Delete type=0 #1707
2024/01/23-01:40:15.192 c104 Delete type=3 #1706
2024/01/23-03:22:10.498 9e7c Level-0 table #1711: started
2024/01/23-03:22:10.498 9e7c Level-0 table #1711: 0 bytes OK
2024/01/23-03:22:10.499 9e7c Delete type=0 #1709
2024/01/23-03:22:10.499 9e7c Manual compaction at level-0 from '!scenes!fT64AORvwMUdHzwr' @ 72057594037927935 : 1 .. '!scenes.walls!w5eztsez7EhiFrmE.zlashxFbpTyjyOHo' @ 0 : 0; will stop at (end)
2024/01/23-03:22:10.499 9e7c Manual compaction at level-1 from '!scenes!fT64AORvwMUdHzwr' @ 72057594037927935 : 1 .. '!scenes.walls!w5eztsez7EhiFrmE.zlashxFbpTyjyOHo' @ 0 : 0; will stop at (end)
Binary file not shown.
File renamed without changes.
2 changes: 1 addition & 1 deletion packs/macros/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-001578
MANIFEST-001712
11 changes: 3 additions & 8 deletions packs/macros/LOG
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
2023/12/30-15:04:04.741 4384 Recovering log #1577
2023/12/30-15:04:04.745 4384 Delete type=0 #1577
2023/12/30-15:04:04.745 4384 Delete type=3 #1576
2023/12/30-15:04:26.788 8900 Level-0 table #1581: started
2023/12/30-15:04:26.788 8900 Level-0 table #1581: 0 bytes OK
2023/12/30-15:04:26.789 8900 Delete type=0 #1579
2023/12/30-15:04:26.789 8900 Manual compaction at level-0 from '!macros!2LfY4Ky5rRDkK7h8' @ 72057594037927935 : 1 .. '!macros!yx7Eb76rfzjh0LEO' @ 0 : 0; will stop at (end)
2023/12/30-15:04:26.789 8900 Manual compaction at level-1 from '!macros!2LfY4Ky5rRDkK7h8' @ 72057594037927935 : 1 .. '!macros!yx7Eb76rfzjh0LEO' @ 0 : 0; will stop at (end)
2024/01/23-16:02:47.123 78e8 Recovering log #1710
2024/01/23-16:02:47.127 78e8 Delete type=0 #1710
2024/01/23-16:02:47.127 78e8 Delete type=3 #1708
11 changes: 8 additions & 3 deletions packs/macros/LOG.old
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2023/12/30-12:59:30.726 2484 Recovering log #1575
2023/12/30-12:59:30.729 2484 Delete type=0 #1575
2023/12/30-12:59:30.729 2484 Delete type=3 #1574
2024/01/23-01:40:15.175 f54 Recovering log #1707
2024/01/23-01:40:15.179 f54 Delete type=0 #1707
2024/01/23-01:40:15.179 f54 Delete type=3 #1706
2024/01/23-03:22:10.493 9e7c Level-0 table #1711: started
2024/01/23-03:22:10.493 9e7c Level-0 table #1711: 0 bytes OK
2024/01/23-03:22:10.495 9e7c Delete type=0 #1709
2024/01/23-03:22:10.495 9e7c Manual compaction at level-0 from '!macros!2LfY4Ky5rRDkK7h8' @ 72057594037927935 : 1 .. '!macros!yx7Eb76rfzjh0LEO' @ 0 : 0; will stop at (end)
2024/01/23-03:22:10.495 9e7c Manual compaction at level-1 from '!macros!2LfY4Ky5rRDkK7h8' @ 72057594037927935 : 1 .. '!macros!yx7Eb76rfzjh0LEO' @ 0 : 0; will stop at (end)
Binary file removed packs/macros/MANIFEST-001578
Binary file not shown.
Binary file added packs/macros/MANIFEST-001712
Binary file not shown.
8 changes: 5 additions & 3 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ Hooks.on("controlToken", (token, controlled)=>{
CONFIG.Levels.handlers.RefreshHandler.refreshPlaceables();
})

Hooks.on("preUpdateToken", (token,updates) => {
Hooks.on("preUpdateToken", (token, updates) => {
if(token?.object?.controlled) CONFIG.Levels.handlers.DrawingHandler.executeStairs(updates, token);
if(token.object && "elevation" in updates && !CONFIG.Levels?.useCollision3D){
const elevDiff = token.object.document.elevation - updates.elevation;
const p0 = {x:token.object.x,y:token.object.y,z:updates.elevation}
const p1 = {x:token.object.x,y:token.object.y,z:token.object.losHeight-elevDiff+0.1}
const prevElevation = token.object.losHeight;
const newElevation = prevElevation - elevDiff;
const p0 = {x:token.object.x,y:token.object.y,z:prevElevation}
const p1 = {x:token.object.x,y:token.object.y,z:newElevation+0.1}
const collision = CONFIG.Levels.handlers.SightHandler.testCollision(p0, p1, "collision")
if(collision){
ui.notifications.error(game.i18n.localize("levels.err.collision"))
Expand Down
107 changes: 107 additions & 0 deletions scripts/migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
This is internal code not currently used for the future V11 -> V12 migration
For every document in the collection, we want to migrate "flags.levels.rangeBottom" to the new core "elevation" property.
*/

export class LevelsMigration {
constructor() {}

async migrateCompendiums() {
let migratedScenes = 0;
const compendiums = Array.from(game.packs).filter((p) => p.documentName === "Scene");
for (const compendium of compendiums) {
const scenes = await compendium.getDocuments();
for (const scene of scenes) {
const migrated = await this.migrateData(scene);
if (migrated) migratedScenes++;
}
}
if (migratedScenes > 0) {
ui.notifications.notify(`Levels - Migrated ${migratedScenes} scenes in compendiums to new elevation data structure.`);
console.log(`Levels - Migrated ${migratedScenes} scenes in compendiums to new elevation data structure.`);
} else {
ui.notifications.notify(`Levels - No scenes in compendiums to migrate.`);
console.log(`Levels - No scenes in compendiums to migrate.`);
}
return migratedScenes;
}

async migrateScenes() {
const scenes = Array.from(game.scenes);
let migratedScenes = 0;
ui.notifications.warn("Levels - Migrating all scenes, do not refresh the page!");
for (const scene of scenes) {
const migrated = await this.migrateData(scene);
if (migrated) migratedScenes++;
}
if (migratedScenes > 0) {
ui.notifications.notify(`Levels - Migrated ${migratedScenes} scenes to new elevation data structure.`);
console.log(`Levels - Migrated ${migratedScenes} scenes to new elevation data structure.`);
} else {
ui.notifications.notify(`Levels - No scenes to migrate.`);
console.log(`Levels - No scenes to migrate.`);
}
return migratedScenes;
}

async migrateAll() {
ui.notifications.warn("Levels - Migrating all scenes, do not refresh the page!");
await this.migrateScenes();
await this.migrateCompendiums();
ui.notifications.notify(`Wall Height - Migration Complete.`);
await game.settings.set("levels", "migrateOnStartup", false);
}

async migrateData(scene) {
if (!scene) scene = canvas.scene;

const collections = scene.collections;

for (const [collectionName, collection] of Object.entries(collections)) {
const documents = collection.contents;
const updates = [];
for (const document of documents) {
const oldBottom = document.flags?.levels?.rangeBottom;
let update = {};
if (Number.isNumeric(oldBottom)) {
update = {
_id: document.id,
elevation: oldBottom,
flags: {
"-=levels.rangeBottom": null,
},
};
updates.push(update);
}
}
if (updates.length <= 0) continue;
await collection.updateEmbeddedDocuments(documents[0].documentName, updates);
ui.notifications.notify("Levels - Migrated " + updates.length + " " + collectionName + "s to new elevation data structure in scene " + scene.name);
console.log("Levels - Migrated " + updates.length + " " + collectionName + "s to new elevation data structure in scene " + scene.name);
}
}

showManualMigrationDialog() {
//shows a dialog with buttons for migrating current scene, all scenes, or all scenes in compendiums
new Dialog({
title: "Levels - Migration",
content: `<p>Use this dialog to migrate your scenes to the new elevation data structure. This is required for Levels to function properly in V12.</p>
<p><b>WARNING:</b> This will modify your scene data. Please back up your world before proceeding.</p>`,
buttons: {
scene: {
label: "Migrate Current Scene",
callback: () => this.migrateData(),
},
all: {
label: "Migrate All Sidebar Scenes",
callback: () => this.migrateScenes(),
},
compendiums: {
label: "Migrate All Scenes in Compendiums",
callback: () => this.migrateCompendiums(),
},
},
default: "scene",
}).render(true);
}
}

0 comments on commit 276333a

Please sign in to comment.