From 542ef017c01fc2ec5fb5168a107ac979f35cc729 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Sat, 28 Apr 2018 16:17:13 +0800 Subject: [PATCH] add JsonAsset --- cocos2d/core/assets/CCJsonAsset.js | 51 ++++++++++++++++++++++++++++++ cocos2d/core/assets/index.js | 1 + 2 files changed, 52 insertions(+) create mode 100644 cocos2d/core/assets/CCJsonAsset.js diff --git a/cocos2d/core/assets/CCJsonAsset.js b/cocos2d/core/assets/CCJsonAsset.js new file mode 100644 index 0000000000..2a6eee3883 --- /dev/null +++ b/cocos2d/core/assets/CCJsonAsset.js @@ -0,0 +1,51 @@ +/**************************************************************************** + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +/** + * !#en + * Class for JSON file. When the JSON file is loaded, this object is returned. + * The parsed JSON object can be accessed through the `json` attribute in it.
+ * If you want to get the original JSON text, you should modify the extname to `.txt` + * so that it is loaded as a `TextAsset` instead of a `JsonAsset`. + * + * !#zh + * JSON 资源类。JSON 文件加载后,将会返回该对象。可以通过其中的 `json` 属性访问解析后的 JSON 对象。
+ * 如果你想要获得 JSON 的原始文本,那么应该修改源文件的后缀为 `.txt`,这样就会加载为一个 `TextAsset` 而不是 `JsonAsset`。 + * + * @class JsonAsset + * @extends Asset + */ +var JsonAsset = cc.Class({ + name: 'cc.JsonAsset', + extends: cc.Asset, + properties: { + /** + * @property {Object} json - The loaded JSON object. + */ + json: null, + }, +}); + +module.exports = cc.JsonAsset = JsonAsset; diff --git a/cocos2d/core/assets/index.js b/cocos2d/core/assets/index.js index 0f838982c5..1bae94c49e 100644 --- a/cocos2d/core/assets/index.js +++ b/cocos2d/core/assets/index.js @@ -38,3 +38,4 @@ require('./CCSpriteAtlas'); require('./CCBitmapFont'); require('./CCLabelAtlas'); require('./CCTextAsset'); +require('./CCJsonAsset');