Skip to content

Commit bd3d23c

Browse files
committed
Pull source files out of junctions
1 parent 782fa2e commit bd3d23c

19 files changed

Lines changed: 205 additions & 16 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ node_modules
22

33
/content/panorama/scripts/custom_game/**/*.js
44
/game/scripts/vscripts/**/*.lua
5-
!/game/scripts/vscripts/lib/timers.lua
65

76
# Dota 2 stuff
87
*.bin

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ A template for Dota 2 Custom Games built with modern technologies. It includes
1515

1616
After that you can press `Ctrl+Shift+B` in VSCode or run `npm run dev` command in terminal to compile your code and watch for changes.
1717

18+
## Contents:
19+
20+
* **[src/vscripts]:** TypeScript code Dota addon (Lua) scripts. Compiles lua to game/scripts/vscripts.
21+
* **[src/panorama]:** TypeScript code for panorama UI
22+
1823
## Continuous Integration
1924

2025
This template includes a [GitHub Actions](https://github.com/features/actions) [workflow](.github/workflows/ci.yml) that builds your custom game on every commit and fails when there are type errors.

content/panorama/scripts/custom_game/hud.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"build:panorama": "tsc --project content/panorama/scripts/custom_game/tsconfig.json",
99
"build:vscripts": "tstl --project game/scripts/vscripts/tsconfig.json",
1010
"dev": "run-p dev:*",
11-
"dev:panorama": "tsc --project content/panorama/scripts/custom_game/tsconfig.json --watch",
12-
"dev:vscripts": "tstl --project game/scripts/vscripts/tsconfig.json --watch"
11+
"dev:panorama": "tsc --project src/panorama/tsconfig.json --watch",
12+
"dev:vscripts": "tstl --project src/vscripts/tsconfig.json --watch"
1313
},
1414
"devDependencies": {
1515
"@moddota/dota-lua-types": "^4.11.0",

src/common/events.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* This file contains types for the events you want to send between the UI (Panorama)
3+
* and the server (VScripts).
4+
*
5+
* IMPORTANT:
6+
*
7+
* The dota engine will change the type of event data slightly when it is sent, so on the
8+
* Panorama side your event handlers will have to handle NetworkedData<EventType>, changes are:
9+
* - Booleans are turned to 0 | 1
10+
* - Arrays are automatically translated to objects when sending them as event. You have
11+
* to change them back into arrays yourself! See 'toArray()' in src/panorama/hud.ts
12+
*/
13+
14+
// To declare an event for use, add it to this table with the type of its data
15+
interface CustomGameEventDeclarations {
16+
example_event: ExampleEventData
17+
}
18+
19+
// Define the type of data sent by the example_event event
20+
interface ExampleEventData {
21+
myNumber: number;
22+
myBoolean: boolean;
23+
myString: string[];
24+
myArrayOfNumbers: number[]
25+
}

src/common/general.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* This file contains some general types related to your game that can be shared between
3+
* front-end (Panorama) and back-end (VScripts). Only put stuff in here you need to share.
4+
*/
5+
6+
interface Color {
7+
r: number,
8+
g: number,
9+
b: number
10+
}
11+
12+
interface UnitData {
13+
name: string,
14+
level: number
15+
}

src/panorama/hud.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
$.Msg("Hud panorama loaded");
2+
3+
GameEvents.Subscribe("my_custom_event", event => {
4+
$.Msg("Received custom event", event);
5+
});
6+
7+
GameEvents.SendCustomGameEventToServer<{}>("ui_loaded", {});
8+
9+
GameEvents.Subscribe("example_event", (data: NetworkedData<ExampleEventData>) => {
10+
const myNumber = data.myNumber;
11+
const myString = data.myString;
12+
13+
const myBoolean = data.myBoolean; // After sending to client this is now type 0 | 1!
14+
15+
const myArrayObject = data.myArrayOfNumbers; // After sending this is now an object!
16+
17+
const myArray = toArray(myArrayObject); // We can turn it back into an array ourselves.
18+
19+
});
20+
21+
/**
22+
* Turn a table object into an array.
23+
* @param obj The object to transform to an array.
24+
* @returns An array with items of the value type of the original object.
25+
*/
26+
function toArray<T>(obj: Record<number, T>): T[] {
27+
const result = [];
28+
29+
let key = 1;
30+
while (obj[key]) {
31+
result.push(obj[key]);
32+
key++;
33+
}
34+
35+
return result;
36+
}

content/panorama/scripts/custom_game/manifest.ts renamed to src/panorama/manifest.ts

File renamed without changes.

content/panorama/scripts/custom_game/tsconfig.json renamed to src/panorama/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"compilerOptions": {
33
"rootDir": ".",
4+
"outDir": "../../content/panorama/scripts/custom_game",
45
"target": "es2017",
56
"lib": ["es2017"],
67
"types": ["@moddota/panorama-types"],
78
"moduleResolution": "node",
89
"strict": true
9-
}
10+
},
11+
"include": ["**/*.ts", "../common/**/*.ts"]
1012
}
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { reloadable } from "./lib/tstl-utils";
2-
import "./modifiers/modifier_panic";
2+
import { modifier_panic } from "./modifiers/modifier_panic";
33

4-
const heroSelectionTime = 10;
4+
const heroSelectionTime = 20;
55

66
declare global {
77
interface CDOTAGamerules {
@@ -17,6 +17,7 @@ export class GameMode {
1717
}
1818

1919
public static Activate(this: void) {
20+
// When the addon activates, create a new instance of this GameMode class.
2021
GameRules.Addon = new GameMode();
2122
}
2223

@@ -44,8 +45,17 @@ export class GameMode {
4445
}
4546
}
4647

48+
if (state === DOTA_GameState.DOTA_GAMERULES_STATE_CUSTOM_GAME_SETUP) {
49+
// Automatically skip setup in tools
50+
if (IsInToolsMode()) {
51+
Timers.CreateTimer(3, () => {
52+
GameRules.FinishCustomGameSetup();
53+
});
54+
}
55+
}
56+
4757
// Start game once pregame hits
48-
if (state == DOTA_GameState.DOTA_GAMERULES_STATE_PRE_GAME) {
58+
if (state === DOTA_GameState.DOTA_GAMERULES_STATE_PRE_GAME) {
4959
Timers.CreateTimer(0.2, () => this.StartGame());
5060
}
5161
}
@@ -68,7 +78,7 @@ export class GameMode {
6878
const unit = EntIndexToHScript(event.entindex) as CDOTA_BaseNPC; // Cast to npc since this is the 'npc_spawned' event
6979
if (unit.IsRealHero()) {
7080
Timers.CreateTimer(1, () => {
71-
unit.AddNewModifier(unit, undefined, "modifier_panic", { duration: 8 });
81+
unit.AddNewModifier(unit, undefined, modifier_panic.name, { duration: 8 });
7282
});
7383

7484
if (!unit.HasAbility("meepo_earthbind_ts_example")) {

0 commit comments

Comments
 (0)