Overwatch Script To Workshop
repository·master·Indexed 42 days ago
https://github.com/itsdeltin/overwatch-script-to-workshopA toolchain and high-level programming language that allows developers to write custom scripts and convert them into Overwatch Workshop code. It features support for control flow, functions, classes, and an LSP implementation (OstwLangServer) providing syntax highlighting and autocompletion for .del, .ostw, and .workshop files.
What's inside OSTW
- Deltin's Script To Workshop is a tool designed to allow developers to write scripts that are subsequently converted into Overwatch Workshop code. This enables a more programmatic approach to creating Overwatch game modes compared to using the in-game Workshop editor directly.
Overview of OSTW features
masterOSTW is a high-level programming language designed for the Overwatch workshop. It provides several programming constructs and developer experience improvements, including:
- Control Flow:
if...elsestatements,switchcases, and loops (while,for,foreach). - Data & Logic: Easy string creation and easy operation trees.
- Abstraction: Support for
functionsandclasses. - IDE Support: Syntax highlighting and autocompletion.
- Control Flow:
Install Overwatch Script To Workshop (OSTW)
masterTo install OSTW, download the latest release from the GitHub releases page. After downloading, you must configure your environment by setting the
ostw.deltintegerPathsetting to point to the location of yourdeltinteger.exefile.Set ostw.deltintegerPath to <path_to_deltinteger.exe>Build TextMate grammars with tmlanguage-generator
masterThe
tmlanguage-generatorpackage provides a programmatic API to construct complex regular expression trees and convert them into TextMate language grammars. It uses a functional approach to composeRegexNodeobjects using logic, quantifiers, and symbols, which can then be used to generateTmLanguagestructures viacreateTextmateGrammar.import { createTextmateGrammar, Or, Digit, Whitespace, Match } from 'overwatch-script-to-workshop/tmlanguage-generator'; // Example of composing a regex pattern const pattern = Or(Digit(), Whitespace()); // The actual grammar generation is handled by createTextmateGrammar (exported from TextmateGenerator) // using the patterns defined via this API.Initialize the OstwLangServer
masterThe
OstwLangServerclass is the main entrypoint for the Language Server Protocol (LSP) implementation. It manages protocol handlers for various IDE features like completion, definition, hover, and more.To instantiate the server, you must provide a
ITomlDiagnosticReporter, anIDocumentEventhandler, and optionally a logger and a file getter factory. The server uses aLanguageServerBuilderto coordinate the internal components.// Example instantiation pattern var server = new OstwLangServer( tomlDiagnosticsReporter, documentEventHandler, langLogger, createFileGetterFunc, settingsProvider );Custom LSP Requests in OstwLangServer
masterThe
OstwLangServerimplements several custom LSP requests that extend standard functionality. These requests allow the client to interact with specialized features like pathmap editing and decompilation.Available Custom Requests
Request Name Parameter Type Return Type Description pathmapFromClipboardstringstringImports a pathmap from the system clipboard. Returns "success"or an error message.pathmapApplyJTokenJTokenSaves the current lastMapto a file path specified in the JSON object:{"path": "..."}.pathmapEditorPathmapDocumentPathmapEditorResultGenerates/edits a pathmap script. PathmapDocumentcontainsTextandFilefields.semanticTokensJTokenSemanticToken[]Returns semantic tokens for a specific file path provided in {"fsPath": "..."}.decompile.insertN/A DecompileResultDecompiles text from the clipboard and returns the result. decompile.fileDecompileFileArgsDecompileResultDecompiles workshop code and writes it to the file path provided in DecompileFileArgs.Data Structures
DecompileFileArgs
file(string): The target file path to write the decompiled code to.
PathmapDocument
Text(string): The content of the pathmap.File(string): The file path.
Compose regex patterns using logic and quantifiers
masterYou can build complex regular expressions by composing simple building blocks using the following functional API:
Logic
Or(...values: Regexable[]): Matches any of the provided patterns.And(...values: Regexable[]): Matches a sequence of the provided patterns (Chain).Group(options: GroupOptions): Creates a grouping node.Match(value: Regexable, tmName: TmName): Creates a capturing group associated with a TextMate scope name.NonCapturing(value: Regexable): Creates a non-capturing group.
Quantifiers
All quantifiers accept a
lazy: booleanparameter (defaults tofalse).Maybe(value: Regexable, lazy?: boolean): Zero or one.ZeroOrMore(value: Regexable, lazy?: boolean): Zero or more.OneOrMore(value: Regexable, lazy?: boolean): One or more.Exactly(value: Regexable, count: number, lazy?: boolean): Exactly N times.AtLeast(value: Regexable, count: number, lazy?: boolean): At least N times.Between(value: Regexable, from: number, to: number, lazy?: boolean): Between N and M times.
Lookarounds
PositiveLookahead(value: Regexable)PositiveLookbehind(value: Regexable)NegativeLookahead(value: Regexable)NegativeLookbehind(value: Regexable)
import { Or, OneOrMore, Digit, Match } from 'overwatch-script-to-workshop/tmlanguage-generator'; // Matches one or more digits and assigns a TextMate scope const myPattern = OneOrMore(Digit()); const scopedPattern = Match(myPattern, 'keyword.control.digit');Use the ostw export from the Deltinteger CLI
masterThe
ostwobject is the primary entry point for interacting with the Overwatch Script To Workshop logic via the JavaScript bridge. It is exported from the main module and provides access to the underlying .NET assembly's functionality through a JavaScript interface. To use it, you must ensure thedotnetframework is initialized and the assembly exports are loaded.Note: This module is designed to run in an environment where the
dotnetframework (provided by./_framework/dotnet.js) is available, typically a browser-based WebAssembly environment.import { ostw } from './Deltinteger/Deltinteger/main.js'; // Use ostw to interact with the workshop logic // ostw is an instance of OstwJavascript await ostw.someMethod();Access OstwLangServer Protocol Handlers
masterThe
OstwLangServerexposes several public properties that provide access to specific protocol handlers. These handlers manage the logic for standard LSP features:DocumentHandler: Manages document lifecycle and changes.CompletionHandler: Provides autocompletion.SignatureHandler: Provides parameter information for function calls.DefinitionHandler: Handles 'Go to Definition'.HoverHandler: Provides hover information.ReferenceHandler: Handles 'Find All References'.CodeLensHandler: Manages code lens information.RenameHandler: Handles symbol renaming.ColorHandler: Provides color information.SemanticTokenHandler: Manages semantic highlighting.DocumentSymbolHandler: Provides document symbols (outline).ConfigurationHandler: Manages server configuration.
Other useful properties:
Builder: TheLanguageServerBuilderinstance.ProjectUpdater: AnIProjectUpdaterfor managing project-wide compilation state.Workspace: TheServerWorkspaceinstance.
Use regex symbols and character classes
masterThe API provides shorthand functions for common regex symbols and character classes:
Symbols
Digit():\dNotDigit():\DWordCharacter():\wNotWordCharacter():\WWhitespace():\sNotWhitespace():\SAny():.
Anchors
StartOfLine():^EndOfLine():$WordBoundary():\bNotWordBoundary():\B
Character Classes and Literals
CharacterClass(text: string): Creates a character set (e.g.,[a-z]).Raw(value: string): Creates aTextNodewith the exact string provided.Literal(value: string): Creates aTextNodebut automatically escapes regex reserved characters (like.,*,?, etc.).
import { Digit, Whitespace, WordBoundary, Literal } from 'overwatch-script-to-workshop/tmlanguage-generator'; // Using shorthand symbols const pattern = Whitespace().ZeroOrMore().Digit(); // Using Literal to safely escape characters const safePattern = Literal('hello.world'); // results in 'hello\.world'Convert various types to RegexNode with GetRegexNode
masterThe
GetRegexNodefunction is a utility that normalizes different input types into a singleRegexNode. This allows you to pass a variety of types into the composition functions.Supported
Regexabletypes:string: Converted to aLiteralnode.RegExp: Converted to anExpressionGroupnode.RegexNode: Used directly.RegexNode[]: Flattened into aChainNode.Regexable[]: Recursively processed and flattened.
import { GetRegexNode } from 'overwatch-script-to-workshop/tmlanguage-generator'; // These all result in valid RegexNodes const node1 = GetRegexNode('abc'); const node2 = GetRegexNode(/abc/); const node3 = GetRegexNode(['abc', /def/]);Create a pattern repository with makeRepository
masterThe
makeRepositoryfunction provides a structured way to collect and name multiplePatternobjects into a single lookup object. It accepts a callback function that provides anaddmethod to register patterns.Note: When registering a name, any
#character is stripped from the resulting key in the repository object.import { makeRepository, Digit, OneOrMore } from 'overwatch-script-to-workshop/tmlanguage-generator'; const myRepo = makeRepository((add) => { add('number#pattern', OneOrMore(Digit())); add('simple_text', Digit()); }); // myRepo will be: { 'numberpattern': Pattern, 'simple_text': Pattern } console.log(myRepo['numberpattern']);