Skip to content

Commit 5dfceab

Browse files
committed
uhh,,,, stuff, fixed some bugs mainly i think
1 parent 18a1dd5 commit 5dfceab

File tree

8 files changed

+67
-48
lines changed

8 files changed

+67
-48
lines changed

src/codingworkshops/store.js

Lines changed: 3 additions & 3 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

@@ -111,7 +111,7 @@ export default {
111111
},
112112

113113
async exportProject ({ commit, getters }) {
114-
const { slug } = await this.$methods.createCodeProject({
114+
const { slug } = await this.$methods.createProject({
115115
project: getters.projectData,
116116
})
117117
let nextPath = () => ({

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="this.$rest.project.language" :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: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,29 @@ export default {
2929
data: {
3030
name: '',
3131
language: 'Blocks',
32-
get code() {
32+
get code () {
33+
console.log('heyo', this.language)
3334
return {
34-
"Blocks": "[]",
35-
"Lisa": "(defunc draw ()\n (rect 1 1 10 10))\n",
36-
"Python": "def draw():\n rect(1, 1, 10, 10)\n"
35+
Blocks: JSON.stringify([
36+
{
37+
type: 'callMars',
38+
func: 'rect',
39+
params: [
40+
{ type: 'literal', value: 10 },
41+
{ type: 'literal', value: 10 },
42+
{ type: 'literal', value: 10 },
43+
{ type: 'literal', value: 10 },
44+
],
45+
},
46+
]),
47+
Lisa: '(defunc draw ()\n (rect 1 1 10 10))\n',
48+
Python: 'def draw():\n rect(1, 1, 10, 10)\n',
3749
}[this.language]
3850
},
39-
spritesheet: "[]",
40-
tilesheet: "[]",
41-
flags: "null",
42-
public: false
51+
spritesheet: '[]',
52+
tilesheet: '[]',
53+
flags: 'null',
54+
public: false,
4355
},
4456
}
4557
},
@@ -50,6 +62,7 @@ export default {
5062
},
5163
methods: {
5264
async createProject () {
65+
console.log(JSON.stringify(this.data))
5366
const { ok, errors, slug } = await this.$methods.createProject({
5467
project: this.data,
5568
})

src/nico/src/nico/App.vue

Lines changed: 12 additions & 6 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-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'")
@@ -49,8 +49,8 @@ export default {
4949
settings: false,
5050
}),
5151
},
52-
language: {
53-
type: String,
52+
projectData: {
53+
type: Object,
5454
required: true,
5555
},
5656
scriptBoilerplate: {
@@ -62,12 +62,18 @@ export default {
6262
computed: {
6363
...mapState('nico', ['view']),
6464
},
65-
mounted () {
66-
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)
6771
if (this.scriptBoilerplate) this.loadBoilerplate()
6872
},
6973
methods: {
70-
...mapMutations('nico', ['loadBoilerplate',]),
74+
...mapMutations('nico', ['loadBoilerplate', 'setCode']),
75+
...mapMutations('sprite/sprite', ['setSpritesheet']),
76+
...mapMutations('tile/sprite', ['setTilesheet']),
7177
...mapActions('nico', ['setLanguage']),
7278
},
7379
}

src/nico/src/nico/components/BlockEditor.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<script>
1818
import Block from './Block'
1919
import Expr from './Expr'
20-
import { mapMutations, mapState } from 'vuex';
20+
import { mapMutations, mapState } from 'vuex'
2121
2222
const makeLit = value => ({
2323
type: 'literal',
@@ -86,7 +86,7 @@ export default {
8686
type: 'callMars',
8787
func: 'tilemap',
8888
params: [],
89-
}
89+
},
9090
],
9191
vars: [
9292
{
@@ -99,11 +99,11 @@ export default {
9999
watch: {
100100
blocksRoot: {
101101
handler () {
102-
this.$emit("input", this.blocksRoot)
102+
this.$emit('input', this.blocksRoot)
103103
},
104104
deep: true,
105-
}
106-
}
105+
},
106+
},
107107
}
108108
</script>
109109

src/nico/src/nico/store.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export default {
77
namespaced: true,
88

99
state: {
10-
code: window.localStorage.getItem('code') || '',
10+
code: '',
1111
errors: [],
1212
warnings: [],
1313
view: window.localStorage.getItem('view') || 'game',
1414
paused: false,
1515
running: false,
1616
mainCtx: null,
1717
hasBeenRun: false,
18-
language: new languages.Python(),
18+
language: null,
1919
loading: false,
2020
langLoading: false,
2121
loadingTime: null,
@@ -66,11 +66,6 @@ export default {
6666
},
6767
setCode (state, code) {
6868
state.code = code
69-
window.localStorage.setItem('code', state.code)
70-
},
71-
setBlocks (state, blocks) {
72-
state.blocks = blocks
73-
window.localStorage.setItem('blocks', JSON.stringify(state.blocks))
7469
},
7570
setRunning (state, running) {
7671
state.running = running

src/nico/src/tile/store/index.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import { transformData } from '../../image-editor/helpers'
99
import { getCoordsFromIndex } from '../../image-editor/bucket-fill'
1010
import { GRID_NUMBER, GRID_SIZE, CANVAS_SIZE, SCALE } from '../../image-editor/constants'
1111

12-
export const history = historyPlugin(['tile', 'sprite'], (store) => {
12+
import generateSet from '@/generateSet'
13+
14+
export const history = historyPlugin(['tile', 'sprite'], store => {
1315
// hacky fix to save spritesheet without mutation
1416
window.localStorage.setItem('tilesheet', store.state.sprite.sprite.spritesheet)
1517
window.lastCoords = [null, null]
@@ -23,7 +25,7 @@ export function getStoredFlags () {
2325
} catch (e) {}
2426
}
2527
return _.range(GRID_NUMBER).map(() =>
26-
_.range(GRID_NUMBER).map(() => Array(FLAG_NUMBER).fill(false)),
28+
_.range(GRID_NUMBER).map(() => Array(FLAG_NUMBER).fill(false))
2729
)
2830
}
2931

@@ -35,20 +37,20 @@ export default _.merge(sprite('tile', CANVAS_SIZE), {
3537
const sprites = rootGetters['sprite/sprite/rawSprites']
3638
const tilemap = getters.tilemap()
3739

38-
return transformData(null, (ctx) => {
40+
return transformData(null, ctx => {
3941
tilemap.forEach((row, y) =>
4042
row.forEach((spriteI, x) => {
4143
if (spriteI !== null) {
4244
ctx.putImageData(sprites[spriteI], x * GRID_SIZE, y * GRID_SIZE)
4345
}
44-
}),
46+
})
4547
)
4648
})
4749
},
48-
tilemap: (state) => () => {
50+
tilemap: state => () => {
4951
const result = _.range(GRID_NUMBER).map(() => Array(GRID_NUMBER))
5052

51-
_.range(0, state.spritesheet.length, 4).forEach((i) => {
53+
_.range(0, state.spritesheet.length, 4).forEach(i => {
5254
const spriteX = state.spritesheet[i]
5355
const spriteY = state.spritesheet[i + 1]
5456
const [y, x] = getCoordsFromIndex(i)
@@ -63,6 +65,9 @@ export default _.merge(sprite('tile', CANVAS_SIZE), {
6365
return result
6466
},
6567
},
68+
mutations: {
69+
...generateSet(['tilesheet']),
70+
},
6671
},
6772
tileSelect,
6873
},
@@ -73,8 +78,8 @@ export default _.merge(sprite('tile', CANVAS_SIZE), {
7378
mutations: {
7479
setFlags (state, flags) {
7580
const newFlags = _.cloneDeep(state.flags)
76-
const [x, y] = state.tileSelect.selectStart.map((coord) =>
77-
Math.floor(coord / (GRID_SIZE * SCALE)),
81+
const [x, y] = state.tileSelect.selectStart.map(coord =>
82+
Math.floor(coord / (GRID_SIZE * SCALE))
7883
)
7984
newFlags[x][y] = flags
8085
state.flags = newFlags
@@ -89,8 +94,8 @@ export default _.merge(sprite('tile', CANVAS_SIZE), {
8994
},
9095
},
9196
getters: {
92-
getCoordsFromEvent: (state) => (event) => {
93-
return [event.offsetX, event.offsetY].map((coord) => Math.floor(coord / SCALE / GRID_SIZE))
97+
getCoordsFromEvent: state => event => {
98+
return [event.offsetX, event.offsetY].map(coord => Math.floor(coord / SCALE / GRID_SIZE))
9499
},
95100
currentFlags: (state, getters) => {
96101
const [x, y] = getters['tileSelect/selectStartCoords']

src/rest.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const generateReq = (root, defaultOptions) => (uri, options) => {
1616
'Accept': 'application/json',
1717
},
1818
},
19-
]),
19+
])
2020
)
2121
}
2222

@@ -51,7 +51,7 @@ const generateMethod = (req, name, method, path, prepareBody, processResult) =>
5151
return makeReq(toPath(pathParams), method, body)
5252
}
5353
} else {
54-
return (body) => {
54+
return body => {
5555
return makeReq(path, method, body)
5656
}
5757
}
@@ -72,8 +72,8 @@ export default function prepare ({
7272
(paths, method) =>
7373
paths
7474
|> mapValuesKey((path, name) =>
75-
generateMethod(req, name, method, path, prepareBody, processResult),
76-
),
75+
generateMethod(req, name, method, path, prepareBody, processResult)
76+
)
7777
)
7878
|> _.mergeAll
7979

@@ -122,15 +122,15 @@ function init () {
122122

123123
rest
124124
|> _.keys
125-
|> _.forEach((key) => {
125+
|> _.forEach(key => {
126126
this.$set(this.$rest, key, null)
127127
})
128128
this.$rest.loading = true
129129

130130
const reqOpts =
131131
rest
132132
|> _.values
133-
|> _.map((val) => {
133+
|> _.map(val => {
134134
if (_.isFunction(val)) val = val.call(this)
135135
if (_.isArray(val)) return { name: val[0], opts: val[1] }
136136
return { name: val }
@@ -142,7 +142,7 @@ function init () {
142142
if (!(name in this.$methods)) throw new Error(`Method ${name} is undefined`)
143143
return this.$methods[name](opts)
144144
})
145-
Promise.all(reqs).then((res) => {
145+
Promise.all(reqs).then(res => {
146146
res
147147
|> _.zip(rest |> _.keys)
148148
|> _.forEach(([key, result]) => {

0 commit comments

Comments
 (0)