kurohyou / roll20-snippets Goto Github PK
View Code? Open in Web Editor NEWA repository for storing and sharing useful snippets of code for use in Roll20 API scripts and Character Sheets
License: MIT License
A repository for storing and sharing useful snippets of code for use in Roll20 API scripts and Character Sheets
License: MIT License
The common object methods like Object.keys()
do not return useful information for the attributeProxy
. Methods should be added to the proxy to replicate these methods so that they return the attribute information stored in the proxy.
In this bit, the removed eventName ends up being removed:repeating_section
, which makes it search for fieldset_removed:repeating_section
, so along with removing clicked:
, removed:
also needs to be removed, and then things can properly listen to repeater items being removed.
let typePrefix = 'attr_';
if (eventName.startsWith('clicked:')) {
typePrefix = 'act_';
eventName = eventName.replace('clicked:', '');
} else if (event.removedInfo) {
typePrefix = 'fieldset_';
eventName = eventName.replace('remove:', '');
}
return casc[`${typePrefix}${eventName}`];
This delete is being parsed as PUG and generating <delete>
tags:
This is either due to a missing varObjects
prefix in
persistentTab
because the tab mixin was never calledThe pug Mixins are currently only split between two files (_htmlelements.pug
and _rolltemplate_mixins.pug
). These should be modularized more to make it easier to work on discrete sets of mixins.
Proposed mixin modules:
_attrHolders.pug
: to hold the basic input/textarea/select mixins_buttons.pug
: to hold the various button mixins_fieldsets.pug
: to hold the fieldset mixins_functions.pug
: to hold the helper functions_script.pug
: to hold the various script mixins_headedTextarea.pug
and _adaptive.pug
for the headed textarea construction and adaptiveInput/adaptiveTextarea mixins respectivelyIts a bit difficult to navigate the code on this repository because there are several different versions of the code, corresponding to the different blog posts. There are a few things that you could do keep them separate without creating so many redundancies:
You could give them separate branches. This would require users who wanted to get one or the other to understand how to checkout different branches. You would be able to push fixes to earlier versions and propogate those changes to later versions by rebasing (although that would be a bit of a hassle.
You could tag them at each release point. This would allow you to keep the history nice and do some development on them. It would be easy to share the links to each release as well.
You could compress the whole repository as a certain point and then upload it as Blog_Post_1_release.zip
or whatever. This would make it really easy for people to download the release that they want, but it would be impossible to maintain a specific release, unless you combined this strategy with one of the above.
Create SCSS files for some of the basic layouts that the more complex mixins are intended to work with.
When using the +roller
mixin, if the provided name
contains the string "roll"
somewhere, the roll button no longer works (it doesn't trigger the abilitiy).
"roll"
+roller({name:'testrl')
generated HTML
<button class="roller" name="roll_testrl" value="@{testrl_action}" title="%{testrl}" type="roll">
</button>
<button name="act_testrl-action" hidden="" type="action" title="%{testrl-action}">
</button>
<input name="attr_testrl_action" type="hidden" title="@{testrl_action}"/>
+roller({name:'testroll')
<button class="roller" name="roll_testroll" value="@{testaction}" title="%{testroll}" type="roll">
</button>
<button name="act_testaction" hidden="" type="action" title="%{testaction}">
</button>
<input name="attr_testaction" type="hidden" title="@{testaction}"/>
Based on the work done with the tabs construction, the select/options combination of mixins would become more easily readable if turned into a group of nested mixins. This should also then allow us to move the trigger for selects to the select itself instead of the options.
The call passes in event
to getAllAttrs
which doesn't take an event
value.
//accessSheet
const accessSheet = function(event){
debug({funcs:Object.keys(funcs)});
debug({event});
getAllAttrs({event,callback:(attributes,sections,casc)=>{
let trigger = attributes.getCascObj(event,casc);
attributes.processChange({event,trigger,attributes,sections,casc});
}});
};
//getAllAttrs
const getAllAttrs = function({props=baseGet,sectionDetails=repeatingSectionDetails,callback}){
getSections(sectionDetails,(repeats,sections)=>{
getAttrs([...props,...repeats],(values)=>{
const attributes = createAttrProxy(values);
orderSections(attributes,sections);
const casc = expandCascade(cascades,sections,attributes);
callback(attributes,sections,casc);
})
});
};
I've been reading the blog posts and combing through the code, working to build out my own sheet. It's been very challenging to understand what the pipelines are here, namely, how does the javascript actually get attached and to where. Roll20 seems to have a lot of poorly documented requirements (i.e. apparently all JS must be organized into on sheetworker, or something).
My biggest question is what are triggers and how do they work? It looks like there are a number of different types of triggers (affects, calculation, listeners, etc). Are those documented anywhere? There's some code in here that "registers" functions to kFuncs, although that's not listed in the README anywhere as a necessary step. Does the code that handles triggers look for those triggers in kFuncs? The return statement for kFuncs is in a different file from the initialization, which makes it very hard to read.
Here's my main pug file:
// system.pug
include scaffold/_kpug.pug
mixin spec-block(name)
.spec
// Displays modifier
+span({
name: `${name}_mod`,
title:`@{${name}_mod}`,
value: 0,
trigger: {calculation: "calculateSpecMod"}
})
// Base input
+number({
name,
class: "base-input",
value: 10,
trigger: {affects: [`${name}_mod`]}
})
main
.sheet
.specs
for spec in constants.specs
+spec-block(spec)
+kscript
include javascript/specs.js
and
// javascript/specs.js
function calculateSpecMod(spec) {
console.log("hello world")
return Math.floor((spec - 10) / 2)
}
I haven't been able to see any console output anywhere or values change based on updating anything. I've also been unable to see any of the hefty js that kscript generates show up in the actual character sheet sandbox, despite it being visible in the HTML files. It's like its being stripped from the file when its uploaded.
UPDATE: It appears that the kscript code is crashind that's likely the cause of the problem. I've downloaded the most recent scaffold code from week 4 (see issue #15). I put in a PR for a bug that seems to only exist in older versions of the code (#14 , and again #15), but I'm still seeing an error message in the console when loading the kscript:
SyntaxError: unexpected token: identifier
Currently, if a user puts their kscript
call at the start of their html (or anywhere but the end), much of the JS functionality of the scaffold is lost without any notice to the user that this is an issue.
kscript
mixin sets to true when it is invoked.The current scaffold assumes that attribute/fieldset/button names should be used as they are entered other than enforcing snake_case
. Some sheets however need the ability to set a prefix across a wide area.
Line 9 has attributes.sheet_version
and line 20 has attributes.version
. I think that likely no version updates will be applied due to this.
if(!attributes.sheet_version){
Object.entries(initialSetups).forEach(([funcName,handler])=>{
if(typeof funcs[funcName] === 'function'){
debug(`running ${funcName}`);
funcs[funcName]({attributes,sections,casc});
}else{
debug(`!!!Warning!!! no function named ${funcName} found. Initial sheet setup not performed.`);
}
});
}else{
Object.entries(updateHandlers).forEach(([ver,handler])=>{
if(attributes.version < +ver){
handler({attributes,sections,casc});
}
});
}
Setup the K-scaffold so that it can be installed via npm i k-scaffold
.
I propose to dedicate this repository to k-scaffold, by renaming it to k-scaffold
and changing the layout.
The current layout of the repo makes it harder-than-needed to install or add k-scaffold into a project. Other than k-scaffold, this repository containes two snippets parseRepeatName
and fill-left
elements, which are already part of k-scaffold.
Making this repo k-scaffold dedicated would make k-scaffold installation easy though a git clone --depth 1
or git submodule add
.
.
├── docs/ # documentation folder
├──tutorial/ # Folder holding the tutorial code and posts
├── src/ # source for k-scaffold
│ ├── buttons/ # a part of k-scaffold, isolated in a folder
│ │ └── _buttons.pug
│ ├── helpers/ # a part of k-scaffold that need .pug, .js and .scss to worl
│ │ ├── helpers.js
│ │ └── _helpers.pug
│ │ └── _helpers.scss
│ └── tabs/ # a part of k-scaffold that need .pug, .js and .scss to worl
│ ├── tabs.js
│ ├── _tabs.pug
│ └── _tabs.scss
├── _kpug.pug # root file to import in a project using k-scaffold
├── _k.scss # root file to import in a project using k-scaffold
├── LICENSE
├── README.md
└── template/ # template character sheet for creating new project
├── prepros.config
├── sheet.json
├── system.html
├── system.pug
└── translation.json
Installation would be achieved through
git submodule add <repo url>
and allow updating the underlying version of k-scaffold. Submodules also prevent staging k-scaffold files as part of the sheet's repo: git will go get the k-scaffold repo itself and put it in a folder.
EDIT: Added Tutorial folder to grid outline.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.