|
| 1 | +# This script modifies ProjectSettings.asset in order to connect the project to Services (like Relay). This is needed for Netcode related builds and can be probably skipped in other cases |
| 2 | +# As a Netcode team we usually use (during Playtesting) the following settings |
| 3 | + |
| 4 | +# Note that cloudProjectId, projectName and organizationId are defined as secrets |
| 5 | + |
| 6 | +# Notice that those parameters are included as defaults but in your yml file you can override them with your own values. |
| 7 | + |
| 8 | +import sys |
| 9 | +import re |
| 10 | +import argparse |
| 11 | +import os |
| 12 | + |
| 13 | +def parse_args(): |
| 14 | + global args |
| 15 | + parser = argparse.ArgumentParser(description='Update ProjectSettings.asset in order to properly connect to services.') |
| 16 | + parser.add_argument('--project-settings-path', required=True, help='The absolute path to the project ProjectSettings.asset file that contains all of the services settings.') |
| 17 | + parser.add_argument('--cloud-project-ID', default=os.getenv("CLOUDPROJECTID"), help='ID of a cloud project to which we want to connect to.') |
| 18 | + parser.add_argument('--organization-ID', default=os.getenv("ORGANIZATIONID"), help="ID of the organization to which the cloud project belongs.") |
| 19 | + parser.add_argument('--project-name', default=os.getenv("PROJECTNAME"), help='Name of the project to which we want to connect to.') |
| 20 | + args = parser.parse_args() |
| 21 | + |
| 22 | +def main(): |
| 23 | + """ |
| 24 | + Modifies ProjectSettings.asset in order to connect the project to Services |
| 25 | + """ |
| 26 | + parse_args() |
| 27 | + |
| 28 | + with open(args.project_settings_path, 'r') as f: |
| 29 | + content = f.read() |
| 30 | + |
| 31 | + # Use regex to replace the values. This is safer than simple string replacement. |
| 32 | + content = re.sub(r"cloudProjectId:.*", f"cloudProjectId: {args.cloud_project_ID}", content) |
| 33 | + content = re.sub(r"organizationId:.*", f"organizationId: {args.organization_ID}", content) |
| 34 | + content = re.sub(r"projectName:.*", f"projectName: {args.project_name}", content) |
| 35 | + # Ensure the project is marked as connected |
| 36 | + content = re.sub(r"cloudEnabled:.*", "cloudEnabled: 1", content) |
| 37 | + |
| 38 | + with open(args.project_settings_path, 'w') as f: |
| 39 | + f.write(content) |
| 40 | + |
| 41 | + print(f"[Linker] Successfully updated {args.project_settings_path} with Project ID: {args.cloud_project_ID}, Org ID: {args.organization_ID}, Project Name: {args.project_name}") |
| 42 | + |
| 43 | +if __name__ == "__main__": |
| 44 | + main() |
| 45 | + |
| 46 | + |
0 commit comments