Skip to content

Commit

Permalink
✨ Events framework — more vanilla events and ability to add modded ones!
Browse files Browse the repository at this point in the history
Closes #215
  • Loading branch information
CosmoMyzrailGorynych committed Jul 1, 2022
1 parent ee5ac3f commit a6aeb08
Show file tree
Hide file tree
Showing 69 changed files with 2,611 additions and 816 deletions.
6 changes: 6 additions & 0 deletions app/data/ct.libs/place/events/collisionCGroup_thisOnStep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
const other = ct.place.occupied(this, /*%%group%%*/);
if (ct.templates.valid(other)) {
/*%%USER_CODE%%*/
}
}
6 changes: 6 additions & 0 deletions app/data/ct.libs/place/events/collisionTemplate_thisOnStep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
const other = ct.place.meet(this, /*%%template%%*/);
if (ct.templates.valid(other)) {
/*%%USER_CODE%%*/
}
}
60 changes: 59 additions & 1 deletion app/data/ct.libs/place/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,63 @@
"collect": true,
"collectScope": "place::cgroup",
"key": "cgroup"
}]
}],
"eventCategories": {
"collisions": {
"name": "Collisions",
"name_Ru": "Столкновения",
"icon": "copy"
}
},
"events": {
"collisionTemplate": {
"name": "Collision with a template",
"name_Ru": "Столкновение с шаблоном",
"parameterizedName": "Collides %%template%% template",
"parameterizedName_Ru": "Столкновение с шаблоном %%template%%",
"icon": "copy",
"useAssetThumbnail": true,
"applicable": ["template"],
"category": "collisions",
"arguments": {
"template": {
"name": "Template",
"name_Ru": "Шаблон",
"type": "template"
}
},
"codeTargets": ["thisOnStep"],
"locals": {
"other": {
"type": "Copy",
"description": "What collides with your copy",
"description_ru": "То, что столкнулось с копией"
}
}
},
"collisionCGroup": {
"name": "Collision with a group",
"name_Ru": "Столкновение с группой",
"parameterizedName": "Collides %%group%% group",
"parameterizedName_Ru": "Столкновение с группой %%group%%",
"icon": "copy",
"applicable": ["template"],
"category": "collisions",
"arguments": {
"group": {
"name": "Group",
"name_Ru": "Группа",
"type": "string"
}
},
"codeTargets": ["thisOnStep"],
"locals": {
"other": {
"type": "Copy | PIXI.Sprite",
"description": "What collides with your copy. PIXI.Sprite is a ct.js tile",
"description_ru": "То, что столкнулось с копией. PIXI.Sprite — это плитка тайлсета"
}
}
}
}
}
2 changes: 2 additions & 0 deletions app/data/ct.release/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ ct.u.ext(ct.u, {// make aliases
ct.inputs.updateActions();
ct.timer.updateTimers();
/*%beforeframe%*/
ct.rooms.rootRoomOnStep.apply(ct.room);
for (let i = 0, li = ct.stack.length; i < li; i++) {
ct.templates.beforeStep.apply(ct.stack[i]);
ct.stack[i].onStep.apply(ct.stack[i]);
Expand Down Expand Up @@ -590,6 +591,7 @@ ct.u.ext(ct.u, {// make aliases
item.onDraw.apply(item);
ct.rooms.afterDraw.apply(item);
}
ct.rooms.rootRoomOnDraw.apply(ct.room);
/*%afterframe%*/
if (ct.rooms.switching) {
ct.rooms.forceSwitch();
Expand Down
14 changes: 14 additions & 0 deletions app/data/ct.release/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ Room.roomId = 0;
roomName = nextRoom;
}
if (ct.room) {
ct.rooms.rootRoomOnLeave.apply(ct.room);
ct.room.onLeave();
ct.rooms.onLeave.apply(ct.room);
ct.room = void 0;
Expand All @@ -312,6 +313,7 @@ Room.roomId = 0;
ct.pixiApp.renderer.resize(template.width, template.height);
ct.rooms.current = ct.room = new Room(template);
ct.stage.addChild(ct.room);
ct.rooms.rootRoomOnCreate.apply(ct.room);
ct.room.onCreate();
ct.rooms.onCreate.apply(ct.room);
ct.rooms.list[roomName].push(ct.room);
Expand Down Expand Up @@ -351,6 +353,18 @@ ct.rooms.beforeDraw = function beforeDraw() {
ct.rooms.afterDraw = function afterDraw() {
/*%afterroomdraw%*/
};
ct.rooms.rootRoomOnCreate = function rootRoomOnCreate() {
/*@rootRoomOnCreate@*/
};
ct.rooms.rootRoomOnStep = function rootRoomOnStep() {
/*@rootRoomOnStep@*/
};
ct.rooms.rootRoomOnDraw = function rootRoomOnDraw() {
/*@rootRoomOnDraw@*/
};
ct.rooms.rootRoomOnLeave = function rootRoomOnLeave() {
/*@rootRoomOnLeave@*/
};

/*@rooms@*/
/*%rooms%*/
5 changes: 4 additions & 1 deletion app/data/ct.release/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const Copy = (function Copy() {
this.template = template;
this.parent = container;
this.blendMode = t.blendMode || PIXI.BLEND_MODES.NORMAL;
this.loop = t.loopAnimation;
if (t.playAnimationOnStart) {
this.play();
}
Expand Down Expand Up @@ -357,6 +358,7 @@ const Copy = (function Copy() {
return ct.templates.list[template].length > 0;
},
/*
* ⚠ Actual typings for this is in src\typedefs\ct.js\ct.templates.d.ts ⚠
* Checks whether a given object exists in game's world.
* Intended to be applied to copies, but may be used with other PIXI entities.
* @param {Copy|PIXI.DisplayObject|any} obj The copy which existence needs to be checked.
Expand All @@ -371,7 +373,8 @@ const Copy = (function Copy() {
}
return Boolean(obj);
},
/**
/*
* ⚠ Actual typings for this is in src\typedefs\ct.js\ct.templates.d.ts ⚠
* Checks whether a given object is a ct.js copy.
* @param {any} obj The object which needs to be checked.
* @returns {boolean} Returns `true` if the passed object is a copy; `false` otherwise.
Expand Down
64 changes: 64 additions & 0 deletions app/data/i18n/English.json
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@
"codeFont": "Font for code",
"codeLigatures": "Ligatures",
"codeDense": "Dense layout",
"altTemplateLayout": "Alternative layout for template editor",
"disableSounds": "Disable UI sounds",
"changeDataFolder": "Set data folder location",
"forceProductionForDebug": "Force production tasks for debug exports"
Expand Down Expand Up @@ -869,6 +870,68 @@
"licensePanel": {
"ctjsLicense": "Ct.js License (MIT)"
},
"scriptables": {
"addEvent": "Add an event",
"removeEvent": "Remove the event",
"removeEventConfirm": "Are you sure you want to remove this event? This can't be undone!",
"changeArguments": "Change arguments",
"eventAlreadyExists": "The same event already exists!",
"localEventVars": "Local variables",
"createEventHint": "Create your first event in the left column, and define your logic here",
"coreEventsCategories": {
"lifecycle": "Lifecycle",
"actions": "Actions",
"pointer": "Pointer events",
"misc": "Miscellaneous",
"animation": "Animation"
},
"coreEvents": {
"OnCreate": "Creation",
"OnRoomStart": "Room start",
"OnStep": "Frame start",
"OnDraw": "Frame end",
"OnDestroy": "Destruction",
"OnRoomEnd": "Room end",
"OnPointerClick": "Click",
"OnPointerSecondaryClick": "Secondary click",
"OnPointerEnter": "Pointer enter",
"OnPointerLeave": "Pointer leave",
"OnPointerDown": "Pointer down",
"OnPointerUp": "Pointer up",
"OnPointerUpOutside": "Pointer up (outside)",
"OnPointerWheel": "Wheel scroll",
"OnActionPress": "Action press",
"OnActionRelease": "Action release",
"OnActionDown": "Action down",
"OnFrameChange": "Frame change",
"OnAnimationLoop": "Animation loop",
"OnAnimationComplete": "Animation completed"
},
"coreParameterizedNames": {
"OnActionPress": "On %%action%% press",
"OnActionRelease": "On %%action%% release",
"OnActionDown": "On %%action%% down"
},
"coreEventsArguments": {
"action": "Action"
},
"coreEventsLocals": {
"OnActionDown_value": "Current action's value"
},
"coreEventsDescriptions": {
"OnCreate": "Triggers when your copy is created.",
"OnRoomStart": "Triggers when this room is created, either by switching to it or by adding it as a layer.",
"OnStep": "Happens at the beginning of every frame.",
"OnDraw": "Happens at the end of every frame. Good for animation updates.",
"OnDestroy": "Happens between \"frame start\" and \"frame end\" when this copy gets destroyed.",
"OnRoomEnd": "Triggers when you switch to another room, or when this room is removed after it was added as a layer.",
"OnActionPress": "Happens when an action's input becomes active — by pressing, clicking, flicking a joystick, etc.",
"OnActionRelease": "Happens when an action's input becomes inactive — by releasing buttons, resting joysticks, etc.",
"OnActionDown": "Runs every frame if an action's input is active.",
"OnAnimationLoop": "Fires every time an animation restarts.",
"OnAnimationComplete": "Fires once a non-looping animation finishes."
}
},
"templates": {
"create": "Create"
},
Expand All @@ -887,6 +950,7 @@
"opacity": "Opacity:",
"blendMode": "Blend mode:",
"playAnimationOnStart": "Play animation on start",
"loopAnimation": "Loop animation",
"blendModes": {
"normal": "Normal",
"add": "Add (burn)",
Expand Down
11 changes: 1 addition & 10 deletions app/data/typedefs/keywordWorkarounds.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
declare namespace ct {
namespace types {
/**
* Works like ct.types.each, but only for the specified Copy: it applies a given function to a copy (executes against it).
* @param {Copy} copy The Copy to apply a function to
* @param {function} func The function that needs to be applied
*/
var _with: function(Copy, function): void;
export {_with as with};
}
namespace rooms {
/**
* Switches to a room with a given name.
Expand All @@ -27,4 +18,4 @@ declare namespace ct {
var _new: function(string, object): void;
export {_new as new};
}
}
}
2 changes: 1 addition & 1 deletion docs
19 changes: 19 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"typescript": "^4.0.3"
},
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"eslint-plugin-pug": "^1.2.2",
"gulp-ext-replace": "^0.3.0"
},
Expand Down
Loading

0 comments on commit a6aeb08

Please sign in to comment.