Skip to content

Commit

Permalink
暂存编译规则
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Nov 22, 2024
1 parent 0a9cf10 commit 4bbf057
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ecaCompiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Exp {

make(formatter: Formatter): string {
if (this.kind === 'value') {
return formatter.formatValue(this.type, y3.lua.encode(this.value));
return formatter.formatValue(this.type, this.value);
} else {
return formatter.formatCall(this.name, this.args!.map((arg) => arg.make(formatter)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/ecaCompiler/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Rule {
continue;
}
const argIndex = this.argNames?.indexOf(argName);
if (argIndex && argIndex !== -1) {
if (argIndex !== undefined && argIndex !== -1) {
parts.push(argIndex + 1); // 参数索引从1开始
} else {
parts.push(match[0]);
Expand Down Expand Up @@ -114,7 +114,7 @@ export class Formatter {
return rule.format(args);
}

public formatValue(type: number, value: string | number | boolean) {
public formatValue(type: number, value: string | number | boolean | undefined) {
let name = '$' + String(type);
let rule = this.rules.get(name);
if (!rule) {
Expand Down
5 changes: 5 additions & 0 deletions src/ecaCompiler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import * as vscode from 'vscode';
import * as y3 from 'y3-helper';

function testConfig(formatter: Formatter) {
formatter.setValueRule(100006, 'y3.unit.get_by_res_id({})');

formatter.setCallRule('UNIT_ENTITY_POINT', '{}:get_point()');
formatter.setCallRule('ALL_PLAYER', 'y3.player_group.get_all_players()');
formatter.setCallRule('CREATE_HARM_TEXT_NEW', 'y3.ui.create_floating_text2({point}, {type}, {str}, {jump_word_track}, {player_group})', ['point', 'type', 'str', 'player_group', 'jump_word_track']);
}

export function init() {
Expand Down

0 comments on commit 4bbf057

Please sign in to comment.