Skip to content
This repository was archived by the owner on Nov 17, 2024. It is now read-only.

Commit 43ffd20

Browse files
author
Cosmo Myzrail Gorynych
committed
✨ Add a button to template and behavior editors for Catnip projects to hide left column and enlarge the blocks, useful for displaying them on a big screen or screencasting
1 parent 420585a commit 43ffd20

File tree

8 files changed

+135
-54
lines changed

8 files changed

+135
-54
lines changed

src/icons/screen.svg

Lines changed: 3 additions & 0 deletions
Loading

src/node_requires/events/index.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ type EventMenu = {
8888
items: IEventMenuSubmenu[];
8989
};
9090

91+
92+
export const getFullKey = (scriptableEvt: IScriptableEvent) => `${scriptableEvt.lib}_${scriptableEvt.eventKey}`;
93+
94+
const getEventByLib = (event: string, libName: string): IEventDeclaration | undefined =>
95+
events[`${libName}_${event}`];
96+
9197
const localizeCategoryName = (categoryKey: string): string => {
9298
const i18nScriptables = getLanguageJSON().scriptables;
9399
const category = categories[categoryKey];
@@ -96,6 +102,22 @@ const localizeCategoryName = (categoryKey: string): string => {
96102
}
97103
return localizeField(category, 'name');
98104
};
105+
106+
export const getIsParametrized = (scriptableEvt: IScriptableEvent) => {
107+
const event = getEventByLib(scriptableEvt.eventKey, scriptableEvt.lib);
108+
if (!event) {
109+
throw new Error(`Event "${getFullKey(scriptableEvt)}" was not found.`);
110+
}
111+
return event.arguments && Object.keys(event.arguments).length;
112+
};
113+
export const getHasLocalVars = (scriptableEvt: IScriptableEvent) => {
114+
const event = getEventByLib(scriptableEvt.eventKey, scriptableEvt.lib);
115+
if (!event) {
116+
throw new Error(`Event "${getFullKey(scriptableEvt)}" was not found.`);
117+
}
118+
return event.locals && Object.keys(event.locals).length;
119+
};
120+
99121
const timerPattern = /^Timer(\d)$/;
100122
const propToCoreDictionary = {
101123
category: 'coreEventsCategories',
@@ -153,6 +175,13 @@ const localizeLocalVarDesc = (eventFullCode: string, local: string): string => {
153175
}
154176
return localizeField(event.locals![local], 'description');
155177
};
178+
export const localizeEventName = (scriptableEvt: IScriptableEvent) => {
179+
if (getIsParametrized(scriptableEvt)) {
180+
return localizeParametrized(getFullKey(scriptableEvt), scriptableEvt);
181+
}
182+
return localizeProp(getFullKey(scriptableEvt), 'name');
183+
};
184+
156185
const tryGetIcon = (eventFullCode: string, scriptedEvent: IScriptableEvent): string | false => {
157186
const event = events[eventFullCode];
158187
if (!event.useAssetThumbnail) {
@@ -239,9 +268,6 @@ const bakeCategories = function bakeCategories(
239268
return menu;
240269
};
241270

242-
const getEventByLib = (event: string, libName: string): IEventDeclaration | undefined =>
243-
events[`${libName}_${event}`];
244-
245271
const getArgumentsTypeScript = (event: IEventDeclaration): string => {
246272
let code = '';
247273
if (event.locals) {

src/riotTags/editors/behavior-editor.tag

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
behavior-editor.aPanel.aView.flexrow
2-
.behavior-editor-Properties.nml
1+
behavior-editor.aPanel.aView.flexrow(class="{opts.class} {demonstrationmode: demonstrationMode}")
2+
.behavior-editor-Properties.nml(if="{!demonstrationMode}")
33
.tall.flexfix.aPanel.pad
44
.flexfix-header
55
button.wide(onclick="{openFields}")
@@ -22,11 +22,22 @@ behavior-editor.aPanel.aView.flexrow
2222
svg.feather
2323
use(xlink:href="#check")
2424
span {vocGlob.apply}
25-
.behavior-editor-anEditorPanel
25+
.behavior-editor-aCodeEditor(class="{demonstrationmode: demonstrationMode}")
26+
.aDemonstrationTitle.center(if="{demonstrationMode}")
27+
svg.feather
28+
use(xlink:href="#behavior")
29+
|
30+
|
31+
| {asset.name}
32+
|
33+
|
34+
span(if="{currentSheet}") —
35+
|
36+
|
37+
span(if="{currentSheet}") {localizeName(currentSheet)}
2638
.tabwrap.tall(style="position: relative" if="{currentSheet !== 'fields'}")
27-
div
28-
.tabbed.noborder
29-
code-editor-scriptable(event="{currentSheet}" asset="{asset}")
39+
.tabbed.noborder
40+
code-editor-scriptable(event="{currentSheet}" asset="{asset}")
3041
.aPanel.tall.pad(if="{currentSheet === 'fields'}")
3142
h1 {voc.customFields}
3243
p {voc.customFieldsDescription}
@@ -36,6 +47,10 @@ behavior-editor.aPanel.aView.flexrow
3647
b {vocFull.scriptables.typedefs}
3748
hover-hint(text="{vocFull.scriptables.typedefsHint}")
3849
textarea.code.wide(style="min-height: 10rem;" value="{asset.extendTypes}" onchange="{wire('asset.extendTypes')}")
50+
.aButtonGroup.behavior-editor-PresentationButtons(if="{currentProject.language === 'catnip'}")
51+
button.square.tiny(onclick="{toggleDemonstration}")
52+
svg.feather
53+
use(xlink:href="#screen")
3954
script.
4055
this.namespace = 'behaviorEditor';
4156
this.mixin(require('src/node_requires/riotMixins/voc').default);
@@ -80,3 +95,12 @@ behavior-editor.aPanel.aView.flexrow
8095
this.on('unmount', () => {
8196
window.orders.off('forceCodeEditorLayout', update);
8297
});
98+
99+
this.demonstrationMode = false;
100+
this.toggleDemonstration = () => {
101+
this.demonstrationMode = !this.demonstrationMode;
102+
};
103+
const eventsAPI = require('src/node_requires/events');
104+
this.allEvents = eventsAPI.events;
105+
this.getEventByLib = eventsAPI.getEventByLib;
106+
this.localizeName = eventsAPI.localizeEventName;

src/riotTags/editors/template-editor.tag

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ mixin eventsList
229229
currentevent="{currentSheet}"
230230
).tall
231231

232-
template-editor.aPanel.aView.flexrow
233-
.template-editor-Properties.nml(class="{alt: localStorage.altTemplateLayout === 'on'}")
232+
template-editor.aPanel.aView.flexrow(class="{opts.class} {demonstrationmode: demonstrationMode}")
233+
.template-editor-Properties.nml(class="{alt: localStorage.altTemplateLayout === 'on'}" if="{!demonstrationMode}")
234234
.tall.flexfix.aPanel.pad
235235
.flexfix-header
236236
// Main linked asset of a template
@@ -295,24 +295,42 @@ template-editor.aPanel.aView.flexrow
295295
+eventsList()
296296
svg.feather.template-editor-aSlidingEventListIcon.unclickable
297297
use(xlink:href="#plus")
298-
.template-editor-aCodeEditor
298+
.template-editor-aCodeEditor(class="{demonstrationmode: demonstrationMode}")
299+
.aDemonstrationTitle.center(if="{demonstrationMode}")
300+
svg.feather
301+
use(xlink:href="#template")
302+
|
303+
|
304+
| {asset.name}
305+
|
306+
|
307+
span(if="{currentSheet}") —
308+
|
309+
|
310+
span(if="{currentSheet}") {localizeName(currentSheet)}
299311
.tabwrap.tall(style="position: relative")
300-
div
301-
.tabbed.noborder(show="{tab === 'javascript'}")
302-
code-editor-scriptable(
303-
event="{currentSheet}"
304-
entitytype="template"
305-
asset="{asset}"
306-
)
307-
.template-editor-Properties.nmr(if="{localStorage.altTemplateLayout !== 'on' && !minimizeProps}")
312+
.tabbed.noborder
313+
code-editor-scriptable(
314+
event="{currentSheet}"
315+
entitytype="template"
316+
asset="{asset}"
317+
)
318+
.template-editor-Properties.nmr(if="{localStorage.altTemplateLayout !== 'on' && !minimizeProps && !demonstrationMode}")
308319
.tall.aPanel.pad.npt
309320
+templateProperties()
310-
button.toright.template-editor-aPresentationButton.square.tiny(
311-
onclick="{toggleProps}"
312-
if="{localStorage.altTemplateLayout !== 'on'}"
313-
)
314-
svg.feather
315-
use(xlink:href="#{minimizeProps ? 'maximize-2' : 'minimize-2'}")
321+
.aButtonGroup.template-editor-PresentationButtons
322+
button.square.tiny(
323+
onclick="{toggleDemonstration}"
324+
if="{currentProject.language === 'catnip'}"
325+
)
326+
svg.feather
327+
use(xlink:href="#screen")
328+
button.square.tiny(
329+
onclick="{toggleProps}"
330+
if="{localStorage.altTemplateLayout !== 'on'}"
331+
)
332+
svg.feather
333+
use(xlink:href="#{minimizeProps ? 'maximize-2' : 'minimize-2'}")
316334
script.
317335
this.namespace = 'templateView';
318336
this.mixin(require('src/node_requires/riotMixins/voc').default);
@@ -325,7 +343,6 @@ template-editor.aPanel.aView.flexrow
325343

326344
this.getTextureRevision = template => resources.getById(template.texture).lastmod;
327345

328-
this.tab = 'javascript';
329346
[this.currentSheet] = this.asset.events; // can be undefined, this is ok
330347

331348
const {schemaToExtensions} = require('src/node_requires/resources/content');
@@ -371,9 +388,6 @@ template-editor.aPanel.aView.flexrow
371388
this.refs.baseClassMenu.toggle();
372389
};
373390

374-
this.changeTab = tab => () => {
375-
this.tab = tab;
376-
};
377391
this.applyTexture = id => {
378392
if (id === -1) {
379393
this.asset.texture = -1;
@@ -508,3 +522,12 @@ template-editor.aPanel.aView.flexrow
508522
localStorage.minimizeTemplatesProps = this.minimizeProps ? 'yes' : 'no';
509523
window.orders.trigger('forceCodeEditorLayout');
510524
};
525+
526+
this.demonstrationMode = false;
527+
this.toggleDemonstration = () => {
528+
this.demonstrationMode = !this.demonstrationMode;
529+
};
530+
const eventsAPI = require('src/node_requires/events');
531+
this.allEvents = eventsAPI.events;
532+
this.getEventByLib = eventsAPI.getEventByLib;
533+
this.localizeName = eventsAPI.localizeEventName;

src/riotTags/shared/scriptables/event-list-scriptable.tag

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,11 @@ event-list-scriptable.flexfix(class="{opts.class}")
119119
this.allEvents = eventsAPI.events;
120120
this.getEventByLib = eventsAPI.getEventByLib;
121121

122-
const getFullKey = scriptableEvt => `${scriptableEvt.lib}_${scriptableEvt.eventKey}`;
123-
124122
this.isValid = scriptableEvt =>
125123
this.getEventByLib(scriptableEvt.eventKey, scriptableEvt.lib);
126-
this.localizeName = scriptableEvt => {
127-
if (this.getIsParametrized(scriptableEvt)) {
128-
return eventsAPI.localizeParametrized(getFullKey(scriptableEvt), scriptableEvt);
129-
}
130-
return eventsAPI.localizeProp(getFullKey(scriptableEvt), 'name');
131-
};
132-
this.getIcon = scriptableEvt => eventsAPI.tryGetIcon(getFullKey(scriptableEvt), scriptableEvt);
124+
this.localizeName = eventsAPI.localizeEventName;
125+
this.getIcon = scriptableEvt =>
126+
eventsAPI.tryGetIcon(eventsAPI.getFullKey(scriptableEvt), scriptableEvt);
133127
this.isStatic = scriptableEvt => !eventsAPI
134128
.canBeDynamicBehavior(eventsAPI.getEventByLib(scriptableEvt.eventKey, scriptableEvt.lib));
135129
this.isRestricted = scriptableEvt => !eventsAPI
@@ -146,20 +140,14 @@ event-list-scriptable.flexfix(class="{opts.class}")
146140
this.namespace = 'scriptables';
147141
this.mixin(require('src/node_requires/riotMixins/voc').default);
148142

149-
this.getIsParametrized = scriptableEvt => {
150-
const event = this.getEventByLib(scriptableEvt.eventKey, scriptableEvt.lib);
151-
return event.arguments && Object.keys(event.arguments).length;
152-
};
153-
this.getHasLocalVars = scriptableEvt => {
154-
const event = this.getEventByLib(scriptableEvt.eventKey, scriptableEvt.lib);
155-
return event.locals && Object.keys(event.locals).length;
156-
};
143+
this.getIsParametrized = eventsAPI.getIsParametrized;
144+
this.getHasLocalVars = eventsAPI.getIsParametrized;
157145
this.getLocals = scriptableEvt => this.getEventByLib(
158146
scriptableEvt.eventKey,
159147
scriptableEvt.lib
160148
).locals;
161149
this.getLocalDescription = (varName, scriptableEvt) => eventsAPI.localizeLocalVarDesc(
162-
getFullKey(scriptableEvt),
150+
eventsAPI.getFullKey(scriptableEvt),
163151
varName
164152
);
165153

src/styl/tags/editors/template-editor.styl

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
template-editor, [data-is="template-editor"], behavior-editor, [data-is="behavior-editor"]
2+
&.demonstrationmode
3+
position fixed
4+
left 0
5+
right 0
6+
bottom 0
7+
top 0
28
.aNav
39
border-bottom-left-radius 0
410
border-bottom-right-radius 0
@@ -46,6 +52,13 @@ template-editor, behavior-editor
4652
flex 0 0 19rem
4753
.&-aCodeEditor
4854
flex 1 1 auto
55+
&.demonstrationmode
56+
display flex
57+
flex-flow column nowrap
58+
catnip-editor > catnip-block-list
59+
font-size 150%
60+
catnip-block-list > catnip-block-list
61+
font-size 100%
4962
.&-aSlidingEventListIcon
5063
position absolute
5164
left 0.87rem
@@ -86,13 +99,15 @@ template-editor, behavior-editor
8699
margin-right 0.8rem
87100
& > .flexfix-footer
88101
padding 1rem
89-
.&-aPresentationButton
102+
.aButtonGroup.&-PresentationButtons
90103
position absolute
91104
right 0
92105
top 0
93-
border-top-right-radius 0
94-
border-top-left-radius 0
95-
border-bottom-right-radius 0
106+
button
107+
border-top-left-radius 0
108+
:last-child
109+
border-top-right-radius 0
110+
border-bottom-right-radius 0
96111
margin 0
97112

98113
.template-editor-Properties, .behavior-editor-Properties, room-properties

src/styl/tags/shared/scriptables/catnip-block.styl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ catnip-block, .catnip-block
166166
border-color error
167167

168168
& & .catnip-block-aTextLabel
169-
font-size 15px
169+
font-size 1500%/16
170170
& & & .catnip-block-aTextLabel
171-
font-size 14px
171+
font-size 1400%/16
172172

173173
textarea
174174
width 100%

src/styl/tags/shared/scriptables/code-editor-scriptable.styl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ code-editor-scriptable, script-editor
1515
height 100%
1616
&.tall
1717
overflow hidden
18+
& > [ref="codebox"]
19+
overflow visible // fixes scrollbars popping up in monaco when using a non-integer zoom value

0 commit comments

Comments
 (0)