enable customization in {stauto} (and rewind) for art and strings; fixes #15
This commit is contained in:
Родитель
6ca8fb7fda
Коммит
a6f9a887e9
14
ast/diff.ts
14
ast/diff.ts
|
@ -9,6 +9,7 @@ module TDev.AST.Diff {
|
|||
tutorialMode?:boolean;
|
||||
preciseStrings?:StringMap<boolean>;
|
||||
useStableNames?:boolean;
|
||||
tutorialCustomizations?: TutorialCustomizations;
|
||||
}
|
||||
|
||||
class RandomIdSetter
|
||||
|
@ -877,10 +878,14 @@ module TDev.AST.Diff {
|
|||
if (a.nodeType() != b.nodeType()) return 3;
|
||||
|
||||
if (opts.approxNameMatching) {
|
||||
var cust = opts.tutorialCustomizations
|
||||
|
||||
var fa = a.getForwardedDecl()
|
||||
var fb = b.getForwardedDecl()
|
||||
if (isArt(fa) && isArt(fb) && fa.getKind() == fb.getKind())
|
||||
if (isArt(fa) && isArt(fb) && fa.getKind() == fb.getKind()) {
|
||||
cust.artMapping[fb.getName()] = fa.getName()
|
||||
return 0;
|
||||
}
|
||||
|
||||
var pa = a.getProperty()
|
||||
var pb = b.getProperty()
|
||||
|
@ -898,7 +903,12 @@ module TDev.AST.Diff {
|
|||
if (typeof da === "string" && typeof db === "string") {
|
||||
if (opts.preciseStrings && opts.preciseStrings[db])
|
||||
return (da == db) ? 0 : 3;
|
||||
if ((da == "") == (db == "")) return 0;
|
||||
if (da == "" && db == "") return 0;
|
||||
if (da != "" && db != "") {
|
||||
if (cust)
|
||||
cust.stringMapping[db] = da
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return a.getText() == b.getText() ? 0 : 3;
|
||||
|
|
|
@ -24,6 +24,12 @@ module TDev.AST
|
|||
manual?: boolean;
|
||||
}
|
||||
|
||||
export interface TutorialCustomizations
|
||||
{
|
||||
stringMapping: StringMap<string>;
|
||||
artMapping: StringMap<string>;
|
||||
}
|
||||
|
||||
class SyntacticMethodFinder
|
||||
extends NodeVisitor
|
||||
{
|
||||
|
@ -580,7 +586,7 @@ module TDev.AST
|
|||
return res;
|
||||
}
|
||||
|
||||
static reply(orig:App, app:App, steps:Step[])
|
||||
static reply(orig:App, app:App, steps:Step[], customizations:TutorialCustomizations)
|
||||
{
|
||||
var last:StringMap<Decl> = {}
|
||||
steps.forEach(s => {
|
||||
|
@ -603,10 +609,28 @@ module TDev.AST
|
|||
newApp.setName(orig.getName())
|
||||
newApp.comment = orig.comment
|
||||
|
||||
// TODO we could do a merge here
|
||||
|
||||
AST.TypeChecker.tcScript(newApp);
|
||||
|
||||
AST.visitExprHolders(newApp, (stmt, eh) => {
|
||||
eh.tokens = eh.tokens.map(t => {
|
||||
var sl = t.getStringLiteral()
|
||||
if (sl && customizations.stringMapping.hasOwnProperty(sl))
|
||||
return mkLit(customizations.stringMapping[sl])
|
||||
return t
|
||||
})
|
||||
})
|
||||
newApp.resources().forEach(r => {
|
||||
if (customizations.artMapping.hasOwnProperty(r.getName())) {
|
||||
var nn = customizations.artMapping[r.getName()]
|
||||
var other = orig.resources().filter(t => t.getName() == nn)[0]
|
||||
if (other && other.getKind() == r.getKind()) {
|
||||
r.setName(nn)
|
||||
r.url = other.url
|
||||
r.comment = other.comment
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
newApp.hasIds = true;
|
||||
new AST.InitIdVisitor(false).dispatch(newApp)
|
||||
|
||||
|
|
|
@ -145,7 +145,8 @@ module TDev
|
|||
approxNameMatching: true,
|
||||
placeholderOk: true,
|
||||
tutorialMode: true,
|
||||
preciseStrings: this.data.preciseStrings
|
||||
preciseStrings: this.data.preciseStrings,
|
||||
tutorialCustomizations: this.parent.customizations
|
||||
})
|
||||
|
||||
function lookupLocal(name:string)
|
||||
|
@ -626,6 +627,7 @@ module TDev
|
|||
public hasValidators = false;
|
||||
public hourOfCode = false;
|
||||
private translatedTutorial: TDev.AST.TranslatedTutorialInfo = undefined;
|
||||
public customizations:AST.TutorialCustomizations;
|
||||
|
||||
constructor(private app:AST.App, private topic:HelpTopic, firstTime: boolean, private guid:string)
|
||||
{
|
||||
|
@ -645,6 +647,8 @@ module TDev
|
|||
this.showInitialStep = firstTime;
|
||||
this.hourOfCode = /#hourOfCode/i.test(this.topic.json.text || "");
|
||||
|
||||
this.resetCustomizations()
|
||||
|
||||
var skipActions:StringMap<boolean> = {}
|
||||
|
||||
TheEditor.intelliProfile.loadFrom(app, true)
|
||||
|
@ -676,6 +680,11 @@ module TDev
|
|||
|
||||
}
|
||||
|
||||
private resetCustomizations()
|
||||
{
|
||||
this.customizations = { stringMapping: {}, artMapping: {} }
|
||||
}
|
||||
|
||||
public updateProfile(ip:AST.IntelliProfile)
|
||||
{
|
||||
if (this.steps.some(s => !!s.data.addDecl || s.data.addsAction))
|
||||
|
@ -1765,7 +1774,7 @@ module TDev
|
|||
|
||||
public reply(stepNo:number)
|
||||
{
|
||||
var scr = AST.Step.reply(Script, this.app, this.steps.slice(0, stepNo).map(s => s.data))
|
||||
var scr = AST.Step.reply(Script, this.app, this.steps.slice(0, stepNo).map(s => s.data), this.customizations)
|
||||
TheEditor.loadScriptTextAsync(ScriptEditorWorldInfo, scr, JSON.stringify(Script.editorState)).then(() => {
|
||||
if (this.replyModalDialog) {
|
||||
this.replyModalDialog.dismiss()
|
||||
|
|
Загрузка…
Ссылка в новой задаче