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

Guide to using JSON, hotkey chords, changes to project format & Git-related changes, reworked tilemap pages and other additions #114

Merged
merged 53 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
3f00236
[General]MAN-643: Add a "Guide to Using JSON" page to the manual unde…
YYBartT Mar 5, 2024
e1a58c0
[General]phy_collision_x/y is marked as real, but is an array
YYBartT Mar 5, 2024
533ad10
[General]phy_collision_x/y is marked as real, but is an array
YYBartT Mar 6, 2024
47a8f34
[General]Update the code example on the async Steam event page
YYBartT Mar 7, 2024
2a2e241
[General]Update the code example on the async Steam event page
YYBartT Mar 7, 2024
8671521
[General]Missing info on pr_trianglefan in docs
YYBartT Mar 11, 2024
6a36dfb
[General]Code Editor: array_contains_ext()'s "matchall" is optional i…
YYBartT Mar 13, 2024
7e0f77b
Merge branch 'develop' into develop.bart
YYBartT Mar 13, 2024
9fa24cb
Fixed typo, "functions" => "function"
YYBartT Mar 13, 2024
01020f5
[General]State explicitly in the manual that instance method static v…
YYBartT Mar 14, 2024
bae12d8
[General]
YYBartT Mar 19, 2024
be277dc
Revert "[General]"
YYBartT Mar 21, 2024
352b6dc
docs: update 'IsUnlisted' => 'IsListed' in shortcuts script
YYBartT Mar 22, 2024
b903b85
docs: updated shortcuts script
YYBartT Mar 25, 2024
8c60d8e
docs(feature): update script to include hotkey chords
YYBartT Mar 25, 2024
3aa66ae
docs(general): added vars for code editor names
YYBartT Mar 26, 2024
bfaffc2
docs(general): update shortcuts script to export hotkeys as RH vars
YYBartT Mar 27, 2024
9fb475c
docs(feature): Hotkey Chords
YYBartT Mar 27, 2024
938005e
docs(general): sqrt errors on small values
YYBartT Mar 28, 2024
5a9faed
docs(general): add mouse button icon+ alt text RH snippets
YYBartT Mar 28, 2024
2521d4c
docs(general): fixed link to toString function explanation
YYBartT Mar 28, 2024
5921506
docs(general): small update of ds_exists function page
YYBartT Apr 1, 2024
c08a076
docs(general): minor changes to ds_list_is_list & ds_list_is_map pages
YYBartT Apr 1, 2024
569ea2a
docs(general): various changes and improvements to data structures re…
YYBartT Apr 2, 2024
c8d9eba
docs(general): updated broken toString() Method links, added handle t…
YYBartT Apr 2, 2024
870600d
docs(general): Update to JSON manual pages
YYBartT Apr 5, 2024
e55f17d
docs(general): minor changes and fixes to Layer Types and Properties …
YYBartT Apr 5, 2024
8f322f8
docs(general): replaced note on instance transform vars in sequence w…
YYBartT Apr 8, 2024
655a513
docs(general): typo fix "read only" -> "read-only"
YYBartT Apr 9, 2024
499afd3
docs(general): typo fixes and replaced links with crossrefs
YYBartT Apr 9, 2024
e8c6298
docs(general): removed docs on tile inheritance tool
YYBartT Apr 10, 2024
e3b279d
docs(general): updated back/next links, split function description & …
YYBartT Apr 10, 2024
f0ffbb4
docs(general): updated tile_get_index & tile_set_index pages
YYBartT Apr 10, 2024
8f39747
docs(general): updated some function pages
YYBartT Apr 10, 2024
9c7bd7c
docs(general): tilemap_set_mask page is confusing with poor examples
YYBartT Apr 11, 2024
1e04be8
docs(general):tilemap_set_mask page is confusing with poor examples
YYBartT Apr 11, 2024
2080ca8
docs(general)!: json_parse filter function must return the original v…
YYBartT Apr 11, 2024
b170b01
docs(feature): changed names of Code Editor 1 and 2 in the variables
YYBartT Apr 11, 2024
637ff0c
docs(general): fixed absolute link on the json_stringify page
YYBartT Apr 11, 2024
361cd2a
docs(feature): updated links to release notes on The Help Menu page
YYBartT Apr 11, 2024
0ff6924
docs(feature): updated Release Notes links and screenshot on the Help…
YYBartT Apr 11, 2024
26bae11
docs(feature): Preferences: [Win IDE] Change "Paths" defaults to avoi…
YYBartT Apr 15, 2024
ac41478
docs(feature): Project Saving: Expand "unsafe directory" warning to c…
YYBartT Apr 15, 2024
ae90e8d
docs(feature): Start new projects with a seed .gitignore and .gitattr…
YYBartT Apr 16, 2024
042d0a6
docs(feature): Start new projects with a seed .gitignore and .gitattr…
YYBartT Apr 17, 2024
ecb188e
docs(feature): .gitignore and .gitattributes are also added to new pr…
YYBartT Apr 19, 2024
f0eb141
docs(general): a couple of tiny typo fixes
YYBartT Apr 24, 2024
652441c
docs(general): tiny change to shortcut script's export path example
YYBartT Apr 24, 2024
cc7a101
docs(feature): updated all shortcuts on the keyboard shortcuts page
YYBartT Apr 24, 2024
185cb62
docs(feature): replaced code editor 1 & 2 names with a variable
YYBartT Apr 24, 2024
447f037
docs(general): updated shortcut styles on the IDE Input page
YYBartT Apr 24, 2024
b1eba7a
docs(feature): Reviewed PR #114
gurpreetsinghmatharoo Apr 25, 2024
d678d26
Merge branch 'develop' into develop.bart
gurpreetsinghmatharoo Apr 25, 2024
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
134 changes: 123 additions & 11 deletions Manual/GenerateKeyboardShortcutTableFromJson.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@
###
### Provide the full directory path to the .json files as the command line argument.
### The output HTML file will also be placed there.
### For example: CMD > python GenerateKeyboardShortcutTableFromJson.py "C:/Users/Dev/Documents/Manual/" -name_as_desc
### For example: CMD > python GenerateKeyboardShortcutTableFromJson.py "C:/Users/Dev/Documents/GitHub/ameMaker-Manual/Manual/" -name_as_desc -env beta -update_rh_vars
###
### You can provide an optional argument:
### You can provide a few optional arguments:
###
### -name_as_desc: Add this to write the hotkey's name as the description.
### -env: Provide this, followed by the environment in which you want to look for the JSON files
### (one of: "dev", "lts", "beta", "prod")
### Note: only works on Windows!
### -update_rh_vars: Add this to update the RoboHelp variables
### A RH variable is written (or updated if exists) for every Win/Mac shortcut
### For example: Hotkey_Create_Asset_Win, Hotkey_Create_Asset_Mac
###
### Important: Technically, the JSON cannot contain trailing commas, this isn't supported
### using the built-in json module. Though it is supported through the yy_load function.
###

import sys
import os
import json
import re
from collections import OrderedDict

# Write to RoboHelp variables
import xml.etree.ElementTree as ET

# Unique modifier keys
mods = set()

def yy_load(file):
""" Load json from a file that possibly contains trailing commas """
# Do some tricky regex substitution
Expand All @@ -29,35 +42,75 @@ def yy_load(file):

# Utility functions
def get_combo_string(combo):
global mods
if not combo:
combo_string = ""
else:
modifier = [key for key in combo['Modifier'].split(", ") if key != "None"]
combo_string = " + ".join([*modifier, combo['Keys']])
mods.update(modifier)
if type(combo['Keys']) is list:
# This is a hotkey chord
mods = " + ".join([*modifier])
combo_string = " => ".join([mods + " + " + key for key in combo['Keys']])
else:
# This is a regular hotkey
combo_string = " + ".join([*modifier, combo['Keys']])
return combo_string

# Default names
fname_win_hotkeys = "default_hotkeys.json"
fname_mac_hotkeys = "mac_hotkeys.json"

# Whether to use the shortcut's name as the description
name_as_desc = False
install_dirs = {
"dev": "GameMaker-Dev",
"lts": "GameMaker-LTS",
"beta": "GameMaker-Beta",
"prod": "GameMaker"
}

# Handle parameters received from command line
if len(sys.argv) == 1:
print("ERROR - The input/output directory should be provided. Exiting...")
exit()
else:
fdir = sys.argv[1]
name_as_desc = (len(sys.argv) == 3 and sys.argv[2] == "-name_as_desc")
out_dir = sys.argv[1]
in_dir = out_dir

# Whether to use the shortcut's name as the description
name_as_desc = "-name_as_desc" in sys.argv

# Whether to create new and/or update existing RH hotkey variables
write_update_rh_vars = "-update_rh_vars" in sys.argv

# Use an existing GM installation to get the JSON files, if provided
env = "out_dir"
if "-env" in sys.argv:
ind = sys.argv.index("-env")
env = sys.argv[ind+1]
in_dir = os.environ['ProgramFiles'] + os.sep + install_dirs[env]
if not os.path.isdir(in_dir):
# Revert to out_dir if there's no such directory
in_dir = out_dir

# Check if directories exist
if not os.path.isdir(in_dir) or not os.path.isdir(out_dir):
print("ERROR - One or more directories don't exist. Exiting...")
exit()

# Check if files exist
fpath_win = in_dir + os.sep + fname_win_hotkeys
fpath_mac = in_dir + os.sep + fname_mac_hotkeys
if not os.path.isfile(fpath_win) or not os.path.isfile(fpath_mac):
print("ERROR - One or more files doesn't exist. Exiting...")
exit()

# Data structures
input = [] # input from file
shortcuts = dict() # maps shortcut name => shortcut data
shortcuts_per_location = OrderedDict() # stores shortcuts under locations

# First read the Windows defaults file
with open(fdir + "/" + fname_win_hotkeys, 'r', encoding="utf-8") as f:
with open(fpath_win, 'r', encoding="utf-8") as f:
# Load all the data
# input = json.load(f) # risk of errors if trailing commas are present
input = yy_load(f) # regex-replace variety that fixes things
Expand All @@ -68,7 +121,8 @@ def get_combo_string(combo):
name = shortcut['Name']

# Nothing to do for unlisted shortcuts?
if 'IsUnlisted' in shortcut:
#if 'IsUnlisted' in shortcut:
if 'IsListed' in shortcut and shortcut['IsListed'] == False:
continue

# Get this shortcut's combo(s)
Expand Down Expand Up @@ -98,7 +152,7 @@ def get_combo_string(combo):
shortcuts_per_location[location][name] = name

# Then add the combos in the macOS defaults file
with open(fdir + "/" + fname_mac_hotkeys, 'r') as f:
with open(fpath_mac, 'r') as f:
# Load all the data
input = yy_load(f)

Expand Down Expand Up @@ -139,5 +193,63 @@ def get_combo_string(combo):
html += "</table>"

# Write to file
with open(fdir + "/" + "shortcuts.htm", 'w') as f:
fpath_out = out_dir + "/" + "shortcuts.htm"
with open(fpath_out, 'w') as f:
f.write(html)

# Output unique keys
print("Shortcuts of environment " + str(env) + " written to file:")
print(fpath_out)

if not write_update_rh_vars:
print("Not writing RH variables. Exiting...")
exit()

# Optional: write to RH variables
fdir = os.getcwd() + os.sep + "variable"
fpath = fdir + os.sep + "Default.var"
tree = ET.parse(fpath)
root = tree.getroot()
vars = {}
for child in root:
# Skip title tag to avoid parsing issues
if child.tag == "title":
continue

# Reconstruct RH vars mapping
key = child.attrib["keys"]
val = child[0][0][0].text
vars[key] = val

# Update or append shortcuts
for sc in shortcuts:
readable_name = sc.replace("-", "")
readable_name = readable_name.replace("+", "And")

for platform in ["win", "mac"]:
suffix = "_" + platform.capitalize()
key_name = "Hotkey_" + readable_name.replace(" ", "_") + suffix
v = [tag for tag in root.findall('.//keydef[@keys]') if tag.attrib['keys'] == key_name]
sc_key_name = platform + '_combo'
text = ", ".join(shortcuts[sc][sc_key_name])

if v:
# The shortcut already exists!
# Update
e = v[0]
e[0][0][0].text = text
else:
# The shortcut is a new one for the RH variables.
# Create
e = ET.SubElement(root, "keydef", attrib = {"keys": key_name})
ec = ET.SubElement(e, "topicmeta")
ec2 = ET.SubElement(ec, "keywords")
ec3 = ET.SubElement(ec2, "keyword")
ec3.text = text

# Prettify XML to maintain line-by-line diffs
ET.indent(tree, space="\t")

tree.write(fpath, encoding='utf-8', xml_declaration=True)

print("RoboHelp variables updated.")
77 changes: 0 additions & 77 deletions Manual/GenerateKeyboardShortcutTableFromList.py

This file was deleted.

Loading
Loading