背景
我写了一个简单的 WebGL 益智游戏,我想让人们设计和分享他们自己的关卡。
我的想法是将关卡数据存储在 URL 的查询字符串中。如果他们想让朋友尝试关卡,这将让人们简单地分享 URL。
将游戏数据存储在查询字符串中的好方法是什么?
我试过的
目前我通过
"penguins.html?data="+encodeURIComponent(JSON.stringify([X,P]));
这首先将数据转换为 JSON:
[[[[3,-1,0,0,0],[4,-1,0,0,0]]],[{"x":20,"y":20,"dx":0,"dy":0,"vy":2.9999999871229686,"vx":0.0002779607689814708,"thetaf":180,"speed":3,"type":0,"state":6,"steps":0,"numfish":0,"d":4,"size":8},{"x":60,"y":60,"dx":20,"dy":100,"vy":97.51615330485151,"vx":-78.06665276994102,"thetaf":0,"speed":3,"type":17,"state":0,"steps":0,"numfish":0,"d":15,"size":89.00000012433019}]]
然后将其转义为:
[[[[3%2C-1%2C0%2C0%2C0]%2C[4%2C-1%2C0%2C0%2C0]]]%2C[{%22x%22%3A20%2C%22y%22%3A20%2C%22dx%22%3A0%2C%22dy%22%3A0%2C%22vy%22%3A2.9999999871229686%2C%22vx%22%3A0.0002779607689814708%2C%22thetaf%22%3A180%2C%22speed%22%3A3%2C%22type%22%3A0%2C%22state%22%3A6%2C%22steps%22%3A0%2C%22numfish%22%3A0%2C%22d%22%3A4%2C%22size%22%3A8}%2C{%22x%22%3A60%2C%22y%22%3A60%2C%22dx%22%3A20%2C%22dy%22%3A100%2C%22vy%22%3A97.51615330485151%2C%22vx%22%3A-78.06665276994102%2C%22thetaf%22%3A0%2C%22speed%22%3A3%2C%22type%22%3A17%2C%22state%22%3A0%2C%22steps%22%3A0%2C%22numfish%22%3A0%2C%22d%22%3A15%2C%22size%22%3A89.00000012433019}]]
当前方法的缺点
这种方法适用于小级别,但对于更大的级别,我得到了错误:
414. That’s an error.
The requested URL /penguins.html... is too large to process.
看来我当前的主机(Google Appengine)对 URL 的长度有限制。
问题
Javascript 中是否有更好的方法来存储我的游戏数据(即会导致 URI 更短)?