Skip to content

Commit 72a8c5a

Browse files
committed
Merge branch 'block-editor'
2 parents e5be5fb + 695e356 commit 72a8c5a

30 files changed

+2290
-324
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
node_modules
33
/dist
4+
elm-stuff
45

56
# local env files
67
.env.local
@@ -19,3 +20,4 @@ yarn-error.log*
1920
*.njsproj
2021
*.sln
2122
*.sw*
23+

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@
88
"lint": "vue-cli-service lint"
99
},
1010
"dependencies": {
11+
"@chicode/lisa-vm": "^1.0.4",
1112
"bootstrap": "^4.1.3",
1213
"highlight.js": "^9.13.0",
1314
"lodash": "^4.17.11",
1415
"marked": "^0.5.0",
1516
"path-to-regexp": "^3.0.0",
16-
"rustpython_wasm": "^0.1.0-pre-alpha.1",
17+
"rustpython_wasm": "0.1.0-pre-alpha.1",
1718
"vue": "^2.5.17",
1819
"vue-codemirror": "^4.0.5",
20+
"vue-fragment": "^1.5.1",
1921
"vue-router": "^3.0.1",
2022
"vue-simplemde": "^0.4.9",
23+
"vuedraggable": "^2.20.0",
2124
"vuex": "^3.0.1",
2225
"vuex-router-sync": "^5.0.0"
2326
},
@@ -30,9 +33,11 @@
3033
"@vue/eslint-config-standard": "^3.0.1",
3134
"babel-loader": "^8.0.4",
3235
"babel-plugin-lodash": "^3.3.4",
36+
"elm-webpack-loader": "^5.0.0",
3337
"eslint-plugin-lodash": "^3.1.0",
3438
"eslint-plugin-lodash-fp": "^2.2.0-a1",
3539
"node-sass": "^4.9.4",
40+
"prettier-eslint-cli": "^4.7.1",
3641
"pug": "^2.0.3",
3742
"pug-loader": "^2.4.0",
3843
"pug-plain-loader": "^1.0.0",

src/codingworkshops/store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default {
3232
},
3333
routeContext: (_state, _getters, rootState) => (excludes = []) => {
3434
return ['user', 'workshop', 'lesson', 'slide']
35-
.filter((item) => !excludes.includes(item))
35+
.filter(item => !excludes.includes(item))
3636
.reduce((acc, val) => ({ ...acc, [val]: rootState.router.params[val] }), {})
3737
},
3838
projectData (_state, _getters, rootState) {
@@ -80,7 +80,7 @@ export default {
8080
setDirectionIndexFromStorage ({ getters, commit }) {
8181
commit(
8282
'setDirectionIndex',
83-
parseInt(getNamespacedVar('directionIndex', getters.routeContext())) || 0,
83+
parseInt(getNamespacedVar('directionIndex', getters.routeContext())) || 0
8484
)
8585
},
8686

src/codingworkshops/views/Project.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="pug">
22
.full.d-flex.flex-column.justify-content-between(v-if="!$rest.loading && $rest.project.ok")
3-
Nico.p-5(:show-greeting="false" language="Python" :script-boilerplate="false")
3+
Nico.p-5(:show-greeting="false" :projectData="this.$rest.project" :script-boilerplate="false")
44
div.p-4.d-flex.justify-content-between.border-light.bt-only(style="height: 70px;")
55
div
66
router-link.mr-green(:to="{ name: 'home' }")
@@ -48,7 +48,7 @@ export default {
4848
project: {
4949
public: true,
5050
},
51-
},
51+
}
5252
)
5353
},
5454
},

src/codingworkshops/views/User.vue

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@
88

99
div.mt-5
1010
div
11-
p.error(v-if="errors.name") {{ errors.name[0] }}
11+
p.error(v-if="errors && errors.name") {{ errors.name[0] }}
1212
input.input(v-model="data.name" placeholder="name")
13-
button.button.mt-1(@click="create"): div new project
13+
select(v-model="data.language")
14+
option Blocks
15+
option Lisa
16+
option Python
17+
button.button.mt-1(@click="createProject"): div new project
1418
</template>
1519

1620
<script>
@@ -24,6 +28,29 @@ export default {
2428
errors: {},
2529
data: {
2630
name: '',
31+
language: 'Blocks',
32+
get code () {
33+
return {
34+
Blocks: JSON.stringify([
35+
{
36+
type: 'callMars',
37+
func: 'rect',
38+
params: [
39+
{ type: 'literal', value: 1 },
40+
{ type: 'literal', value: 1 },
41+
{ type: 'literal', value: 10 },
42+
{ type: 'literal', value: 10 },
43+
],
44+
},
45+
]),
46+
Lisa: '(defunc draw ()\n (rect 1 1 10 10))\n',
47+
Python: 'def draw():\n rect(1, 1, 10, 10)\n',
48+
}[this.language]
49+
},
50+
spritesheet: '[]',
51+
tilesheet: '[]',
52+
flags: 'null',
53+
public: false,
2754
},
2855
}
2956
},
@@ -33,7 +60,7 @@ export default {
3360
},
3461
},
3562
methods: {
36-
async create () {
63+
async createProject () {
3764
const { ok, errors, slug } = await this.$methods.createProject({
3865
project: this.data,
3966
})

src/nico/src/nico/App.vue

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Header(:show-tabs='showTabs')
44

55
Game(v-if="showTabs.game" v-show="view === 'game'" :show-greeting="showGreeting")
6-
Editor(v-if="showTabs.editor" v-show="view === 'editor'" :language="language")
6+
Editor(v-show="view === 'editor'" :language="projectData.language")
77
Sprite(v-if="showTabs.sprite" v-show="view === 'sprite'")
88
Tile(v-if="showTabs.tile" v-show="view === 'tile'")
99
Settings(v-if="showTabs.settings" v-show="view === 'settings'")
@@ -14,6 +14,7 @@ import { mapState, mapMutations, mapActions } from 'vuex'
1414
1515
import Game from './components/Game'
1616
import Editor from './components/Editor'
17+
import BlockEditor from './components/BlockEditor'
1718
import Settings from './components/Settings'
1819
import Sprite from '../sprite/App'
1920
import Tile from '../tile/App'
@@ -29,6 +30,7 @@ export default {
2930
Sprite,
3031
Settings,
3132
Tile,
33+
BlockEditor,
3234
},
3335
props: {
3436
showGreeting: {
@@ -39,10 +41,16 @@ export default {
3941
showTabs: {
4042
type: Object,
4143
required: false,
42-
default: () => ({ game: true, editor: true, sprite: true, tile: true, settings: false }),
44+
default: () => ({
45+
game: true,
46+
editor: true,
47+
sprite: true,
48+
tile: true,
49+
settings: false,
50+
}),
4351
},
44-
language: {
45-
type: String,
52+
projectData: {
53+
type: Object,
4654
required: true,
4755
},
4856
scriptBoilerplate: {
@@ -54,12 +62,18 @@ export default {
5462
computed: {
5563
...mapState('nico', ['view']),
5664
},
57-
mounted () {
58-
this.setLanguage(this.language)
65+
beforeMount () {
66+
const { projectData } = this
67+
this.setLanguage(projectData.language)
68+
this.setCode(projectData.code)
69+
this.setSpritesheet(projectData.spritesheet)
70+
this.setTilesheet(projectData.tilesheet)
5971
if (this.scriptBoilerplate) this.loadBoilerplate()
6072
},
6173
methods: {
62-
...mapMutations('nico', ['loadBoilerplate']),
74+
...mapMutations('nico', ['loadBoilerplate', 'setCode']),
75+
...mapMutations('sprite/sprite', ['setSpritesheet']),
76+
...mapMutations('tile/sprite', ['setTilesheet']),
6377
...mapActions('nico', ['setLanguage']),
6478
},
6579
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<template lang="pug">
2+
draggable.my-3(
3+
:class="['dragArea', { clone }]"
4+
:list="children" :group="group" :clone="onClone" @add="onAdd" ghostClass="ghost" tag="ul"
5+
)
6+
li(v-for="child in children")
7+
div.if(v-if="child.type === 'if'")
8+
| if
9+
BlockParamEditor(v-model="child.condition" :type="{ name: 'condition', type: 'bool' }")
10+
Block.child(:children="child.children")
11+
div(v-if="child.type === 'while'")
12+
| while
13+
BlockParamEditor(v-model="child.condition" :type="{ name: 'condition', type: 'bool' }")
14+
Block.child(:children="child.children")
15+
div(v-if="child.type === 'callMars'")
16+
| {{ child.func }}
17+
BlockParamEditor(
18+
v-for="(param, i) in marsFuncs.find(func => child.func === func.name).parameters"
19+
v-model="child.params[i]"
20+
:type="param"
21+
)
22+
div(v-if="child.type === 'setVar'")
23+
| set
24+
input.var(v-model="child.varname")
25+
| =
26+
BlockParamEditor(
27+
:type="{name: 'var', type: 'str'}"
28+
v-model="child.expr"
29+
)
30+
</template>
31+
32+
<script>
33+
import draggable from 'vuedraggable'
34+
import BlockParamEditor from './BlockParamEditor'
35+
import { FUNCTIONS_ONLY } from '../constants'
36+
import _ from 'lodash'
37+
38+
export default {
39+
name: 'Block',
40+
components: {
41+
draggable,
42+
BlockParamEditor,
43+
},
44+
props: {
45+
children: {
46+
required: true,
47+
type: Array,
48+
},
49+
clone: {
50+
type: Boolean,
51+
default: false,
52+
},
53+
},
54+
computed: {
55+
group () {
56+
return this.clone ? { name: 'blocks', pull: 'clone' } : { name: 'blocks' }
57+
},
58+
marsFuncs: () => FUNCTIONS_ONLY,
59+
},
60+
methods: {
61+
onClone: _.cloneDeep,
62+
onAdd (evt) {
63+
if (this.clone) {
64+
// remove the new index from children, effectively not putting it there at all
65+
this.children.splice(evt.newIndex, 1)
66+
}
67+
},
68+
},
69+
}
70+
</script>
71+
72+
<style lang="scss" scoped>
73+
.child {
74+
margin-left: 20px;
75+
}
76+
.dragArea {
77+
outline: 1px dotted;
78+
min-height: 20px;
79+
padding: 10px;
80+
}
81+
.if {
82+
> .dragArea {
83+
min-height: 20px;
84+
}
85+
margin-bottom: 15px;
86+
padding-bottom: 0;
87+
}
88+
.dragArea.clone .ghost {
89+
display: none;
90+
}
91+
.var {
92+
max-width: 100px;
93+
outline: solid 1px;
94+
margin: 0 10px;
95+
}
96+
</style>

0 commit comments

Comments
 (0)