Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Syntax highlighting, snippets and autocompletion for the Portal 2 TAS files, usi

## Release Notes

### 1.4.3

- Add support for version 8
- Add support for toggling tick type on multiple lines at once
- Add support for `autoaim` easing types
- Various bugfixes related to some arguments complaining when they shouldn't

### 1.4.2

- Add support for version 7
Expand Down
12 changes: 7 additions & 5 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,16 @@ export function activate(context: vscode.ExtensionContext) {
return;
};

const line = editor!.selection.active.line;
const oldLineText = editor!.document.lineAt(line).text;
const startLine = editor.selection.start.line;
const endLine = editor.selection.end.line;
const range = new vscode.Range(new vscode.Position(startLine, 0), new vscode.Position(endLine, editor.document.lineAt(endLine).text.length));

const newLineText: string = await client.sendRequest("p2tas/toggleLineTickType", [editor!.document.uri, line]);
if (newLineText === "" || newLineText === oldLineText) return;
const oldText = editor.document.getText(range);
const newText: string = await client.sendRequest("p2tas/toggleLineTickType", [editor.document.uri, startLine, endLine]);
if (newText === "" || newText === oldText) return;

editor.edit(editBuilder => {
editBuilder.replace(new vscode.Range(new vscode.Position(line, 0), new vscode.Position(line, oldLineText.length)), newLineText);
editBuilder.replace(range, newText);
});
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "p2tas",
"displayName": "Portal 2 TAS Tools",
"description": "Syntax highlighting, snippets, autocompletion for the Portal 2 TASing script language",
"version": "1.4.2",
"version": "1.4.3",
"publisher": "Portal2SpeedrunningHub",
"icon": "images/logo128.png",
"repository": {
Expand Down
91 changes: 56 additions & 35 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,51 +423,72 @@ connection.onRequest("p2tas/tickLine", (params: [any, number]) => {
});

/** Toggles the given line's tick type (absolute <=> relative) on request of the client. */
connection.onRequest("p2tas/toggleLineTickType", (params: [any, number]) => {
const [uri, lineNumber] = params;
connection.onRequest("p2tas/toggleLineTickType", (params: [any, number, number]) => {
const [uri, startLine, endLine] = params;

const script = documents.get(uri.external);
if (script === undefined) return "";
const line = script.lines.get(lineNumber);
if (line === undefined) return "";

if (line.type !== LineType.Framebulk && line.type != LineType.ToolBulk) return line.lineText;

if (!line.isRelative) {
// Switch from absolute to relative
let previousLine: ScriptLine | undefined = undefined;
let prevLineNumber = lineNumber;

const modifiedLines: string[] = [];

// Process each line in the range [startLine, endLine]
for (let lineNumber = startLine; lineNumber <= endLine; lineNumber++) {
const line = script.lines.get(lineNumber);
if (line === undefined) continue;

// If the line isn't a framebulk nor a tool bulk, add the line to the output, unchanged.
if (line.type !== LineType.Framebulk && line.type !== LineType.ToolBulk) {
modifiedLines.push(line.lineText);
continue;
}

// Find the previous line
while (previousLine === undefined) {
prevLineNumber--;
if (!line.isRelative) {
// Switch from absolute to relative
let previousLine: ScriptLine | undefined = undefined;
let prevLineNumber = lineNumber;

if (prevLineNumber < 0) return line.lineText;
// Find the previous line
while (previousLine === undefined && prevLineNumber > 0) {
prevLineNumber--;
previousLine = script.lines.get(prevLineNumber);
}

previousLine = script.lines.get(prevLineNumber)
}
// If there is no previous line, or it's a Start/Version line, keep original
if (!previousLine || previousLine.type === LineType.Start || previousLine.type === LineType.Version) {
modifiedLines.push(line.lineText);
continue;
}

// If there is no previous line, then the requested line was the first line in the file
if ((previousLine!.type === LineType.Start || previousLine!.type === LineType.Version)) return line.lineText;
// Invalid line format
if (line.tokens[0].type !== TokenType.Number) {
modifiedLines.push(line.lineText);
continue;
}

// Invalid line format
if (line.tokens[0].type !== TokenType.Number) return line.lineText;
// Reformat the line to use the new tick format
const newTickSection = `+${line.tick - previousLine.tick}`;
// everything before the number -|relative tick -|everything after the tick
const newLine = `${line.lineText.substring(0, line.tokens[0].start)}${newTickSection}${line.lineText.substring(line.tokens[0].end).replace(/\r|\n/, "")}`;
modifiedLines.push(newLine);
} else {
// Switch from relative to absolute
// Invalid line format
if (line.tokens[0].type !== TokenType.Plus || line.tokens[1].type !== TokenType.Number) {
modifiedLines.push(line.lineText);
continue;
}

// Reformat the line to use the new tick format
const newTickSection = `+${line.tick - previousLine.tick}`;
// everything before the number -|relative tick -|everything after the tick
return `${line.lineText.substring(0, line.tokens[0].start)}${newTickSection}${line.lineText.substring(line.tokens[0].end).replace(/\r|\n/, "")}`;
}
else {
// Switch from relative to absolute
// Invalid line format
if (line.tokens[0].type !== TokenType.Plus || line.tokens[1].type !== TokenType.Number) return line.lineText;

// We already have the absolute tick of every line parsed out, so we just need to reformat the line to use it
const newTickSection = `${line.tick}`;
// everything before the plus -|everything after the plus -|absolute tick -|everything after the tick (remove new line)
return `${line.lineText.substring(0, line.tokens[0].start)}${line.lineText.substring(line.tokens[0].end, line.tokens[1].start)}${newTickSection}${line.lineText.substring(line.tokens[1].end).replace(/\r|\n/, "")}`;
// Reformat the line to use absolute tick
// We already have the absolute tick of every line parsed out, so we just need to reformat the line to use it
const newTickSection = `${line.tick}`;
// everything before the plus -|everything after the plus -|absolute tick -|everything after the tick (remove new line)
const newLine = `${line.lineText.substring(0, line.tokens[0].start)}${line.lineText.substring(line.tokens[0].end, line.tokens[1].start)}${newTickSection}${line.lineText.substring(line.tokens[1].end).replace(/\r|\n/, "")}`;
modifiedLines.push(newLine);
}
}

// Return all modified lines as a string with newlines instead of array
return modifiedLines.join("\n");
});

// Make the text document manager listen on the connection for events
Expand Down
Loading
Loading