2 Star 2 Fork 0

MingZeY / Screeps-ConsoleCRS

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MulanPSL-1.0

Screeps-ConsoleCRS

基础导航

介绍

ConsoleCRS是一个便于在控制台输出外部JS代码的插件,全称Console Cross Regino Scripting 控制台跨域脚本。 您可以用它轻而易举的修改Screeps客户端,例如导航栏颜色、Creep的样式,你的头像等等任何您能在Screeps客户端上看到的东西。 您也可以用CRS向Screeps客户端的DOM上添加新的元素或标签,来定制你的Screeps客户端。

还有更多功能等待你的发掘,本仓库目前只提供一个基本交互的插件,它让这个过程变得更加容易。


近期更新

Version 1.2

  • A新增VUE支持,前往ConsoleCRS文件中,修改Setting对象下CRSCore_Support_VUE字段为true
  • A新增ElementUI支持,,前往ConsoleCRS文件中,修改Setting对象下CRSCore_Support_ElementUI字段为true
  • U数据交互优化,现在向外部域传递数据请使用ConsoleCRS.data,外部域读取数据使用CRSCore.data,并且该对象不会被清空
  • A新增使用VUE+ElementUI输出对象树的DEMO

Version 1.1

  • U修复了在反序列化时,单双引号以及反斜杠造成的转义后语法错误问题。
  • A新增在外部域中的对象CRSCore,该对象用于挂载ConsoleCRS提供的快捷方法来操作Screeps的GUI,这样您就可以在内部域代码中直接使用。
  • A新增方法ConsoleCRS.reMount(),可以重新挂载在外部域下的CRSCore对象,并刷新您的ConsoleCRS配置。
  • A您现在可以通过复写ConsoleCRS.RunQueue.data对象来传递Screeps内部域产生的数据。
  • A现在您可以手动或通过修改ConsoleCRS.setting[settingName] = true/false 来配置ConsoleCRS的执行组件,以此来减少不必要的资源浪费。
  • A您可以打开或关闭ConsoleCRS.pushFinish的执行成功在控制台的提示。

安装教程

  1. 下载ConsoleCRS.js并将其放置在您的Screeps游戏代码目录
  2. 在游戏中开头部分,使用以下代码来引入ConsoleCRS并保存
require("ConsoleCRS");
  1. 如果不出意外,您应该发现您的Console的Nav标签变成了橙色的ConsoleCRS字样,这便代表ConsoleCRS已经生效

文档术语

为了您更好的阅读本文档,您需要了解下面作者主张定义的一些特殊术语。

内部域

指通过您的编写在Screeps的云端保存的JS代码的上下文,例如main.js中定义的对象都在内部域中。

外部域

指在网页或Steam客户端中,webview视图中运行的JS代码的上下文。

为了便于区分不同域的对象

  • 内部域使用的主要对象是ConsoleCRS
  • 外部域使用的主要对象是CRSCore

因此,ConsoleCRS的准确描述就是,一个能在外部域中执行写在内部域中代码的插件。由于外部域能够访问到webview(浏览器)的对象,因此ConsoleCRS结合了内部域的云端保存永久存在的特性以及外部域广阔的访问权限,使您能够在Screeps中实现更多天马行空的功能。


内部域API

ConsoleCRS.pushCode(fun)

描述:添加到运行队列

  • 使用pushCode向ConsoleCRS添加runCode运行队列,通过pushCode添加的代码会按照顺序依次执行
  • 注意:需要在最后一次push代码后添加ConsoleCRS.pushFinish()

使用方法:

ConsoleCRS.pushCode(function(){
    //TODO
})

ConsoleCRS.pushFinish(fun)

描述:用于执行pushCode后的运行队列,和pushCode配套使用

  • 注意:如果您不使用ConsoleCRS.pushFinish(),您的代码将不会且不可能被执行。
  • 注意:pushFinish允许跨tick触发,但有可能导致某个pushCode的代码在n个tick内被push n 次,相应的这个方法也会执行多次,编写时请注意跨Tick逻辑 使用方法:
ConsoleCRS.pushCode(function(){
    //TODO First
});

//Some other code of Screeps

ConsoleCRS.pushCode(function(){
    //TODO Second
})
ConsoleCRS.pushFinish();

ConsoleCRS.cleanOutput()

描述:清空控制台输出

  • 该方法简述了如何通过CRS来控制Screeps客户端的界面按钮,如下

  • ".console-controls .md-button:eq(1)"就是清除控制台输出按钮的 选择器路径

  • 您应该遵循这个方法体,外层使用setTimeout,内层选中您想要的按钮元素,最后使用trigger('click')触发

  • 如果您想获取其他按钮的 选择器路径,您可以前往WEB版的Screeps并启用开发者模式,通过检查元素操作获得

使用DEMO:

//每10tick清空控制台
if (Game.time % 10 == 0) {
    ConsoleCRS.cleanOutput(); 
}
ConsoleCRS.pushFinish();//该方法也需要使用pushFinish(),否则将不会有效果

ConsoleCRS.reMount()

描述:重置挂载到外部域上的CRSCore对象,一般用于打开游戏时可能ConsoleCRS并未执行并挂载注入CRSCore,此时在控制台使用该命令即可激活。并且在您手动配置Setting后使用该API可以刷新您的ConsoleCRS配置,使其生效。

  • 建议不要再内部域上下文使用该方法,可能会造成不必要的性能损失。

ConsoleCRS Setting

该对象在ConsoleCRS.Setting下,您可以配置该对象的字段来开启或关闭某些功能。 例如,开启CRSCore的网络API支持。 需要打开设置CRSCore_Support_Net为true(当然现在还不能支持网络请求,因为我没写)

ConsoleCRS.Setting = {
  CRSCore_Support_Net: true
  //其他更多的字段配置
}
  • 注意:不建议在代码中修改setting。正确的做法是到ConsoleCRS.js文件中找到预设的原代码直接修改该对象。

目前支持的字段

常规设置

PrintRunTip 是否开启命令执行提示,开启后,执行命令将在console输出执行提示

CRSCore_Support

CRSCore_Support_ScreepsNet !无效字段:还没实现! 开启后将存在一个CRSCore.Net对象来支持网络连接和访问,提供便捷的GET/POST方法来访问网络。

CRSCore_Support_ScreepsDOM 开启后将存在一个CRSCore.ScreepsDOM对象,利用其中的方法迅速拿到相应的DOM元素。

CRSCore_Support_VUE VUE支持

CRSCore_Support_ElementUI Element-UI支持

等待编辑

使用技巧

内部域与外部域的数据交互


内部域与外部域的数据交互

由于内部域和外部域的执行顺序存在不同,即在非多线程的情况下,总是内部域的代码先执行完毕,再执行外部域的代码,因此写在内部域的外部代码是不会立即执行,在进行数据交换时,也需要特别的方式。 下面将展示几个有关内部域向外部域传递数据的例子。

==错误的数据交互==

//下面是错误的例子
let a = 123;
ConsoleCRS.pushCode(function(){
  console.log(a);//这里并非预期的输出123,因为此时这个变量a属于外部域,访问的是外部域.a,而不是内部域.a
});
//错误的例子2
ConsoleCRS.pushCode(function(){
  a = 123;
});
console.log(a);//这里同理,即便外部域执行的代码声明的变量a是全局变量,但该变量任然无法让内部域的代码访问。

==正确的数据交互==

//使用该特殊对象进行数据传递
ConsoleCRS.RunQueue.data ={
  a:123
}
ConsoleCRS.pushCode(function(){
  console.log(CRSCore.data.a);//此时我们的外部域上下文中便可以访问到内部域中的数据了,您可以通过该方式将内部域的数据传出到外部域
});
  • 注意:复写的ConsoleCRS.RunQueue.data,会在每次执行ConsoleCRS.pushFinish()后被重置

其他技巧

  • 使用CRS运行的代码将在每个tick最后执行,其代码中的作用域与调用的位置在并无联系,这意味着他们的变量以及作用域与原生的Screeps代码不在同一个域中,而使用CRS运行的代码都在同一个域中,并且他们可以访问到window和document,请注意使用
  • CRS运行的代码结果不会直接显示到Screeps的控制台中,你可以前往浏览器的开发者工具查看返回值或运行结果,或者你也可用写出一个div并将执行结果返回到该容器中直接在Screeps客户端查看
  • 写在代码文档中并使用CRS提交(push)的代码每个tick都会执行,如需只执行一次请自行创建识别状态的变量,例如判断全window下是否存在该变量
  • 运行的代码不耗费CPU,只在本地运行,只有本插件在序列化和饭序列化时会耗费少量CPU
  • 使用CRS可以访问到浏览器的cookie和window,您可以在上面储存一些数据帮助您编写代码逻辑
  • 在开发中不免出现调用错误,这样可能会导致DOM树出现非预期的混乱,建议此时刷新页面或重新进入游戏来查看效果。

更多Demo

//在Screeps客户端中央生成一个显示当前时间的黄色DIV
ConsoleCRS.pushCode(function(){
        //判断是否存在该元素
        if(!window.myElement){
            //不存在创建
            window.myElement=document.createElement("div");
            document.body.appendChild(myElement);
        }else{
            let myElement = window.myElement;
            myElement.style.width = "100px";
            myElement.style.height = "100px";
            myElement.style.background = "#ffc107";
            myElement.style.position = "fixed";
            myElement.style.top = "50%";
            myElement.style.left = "50%";

            //获取时间
            let mytime=new Date().toLocaleTimeString();
            myElement.innerHTML = mytime;
        }
    });
    ConsoleCRS.pushFinish();
//使用ScreeosDom修改客户端配色
ConsoleCRS.pushCode(function(){
        let mainColor = "#795548";
        let secondColor = "#3e2723"
        
        let CDOM = CRSCore.ScreepsDom;
        //顶部栏元素处理
        CDOM.TopContent.self.style.background = mainColor;
        CDOM.TopContent.Profile.self.children[0].setAttribute('style', 'background: '+secondColor+' !important');
        //左侧按钮处理
        CDOM.LeftControls.self.children[0].style.background = mainColor;
        CDOM.LeftControls.self.children[1].style.background = mainColor;
        CDOM.LeftControls.self.children[2].style.background = mainColor;
        //缩放按钮处理
        CDOM.ZoomControls.self.children[0].style.background = mainColor;
        CDOM.ZoomControls.self.children[1].style.background = mainColor;
        //右侧栏处理
        CDOM.AsideContent.self.style.background = secondColor;
        CDOM.AsideContent.BottomGroup[0].children[0].style.background = mainColor;
        CDOM.AsideContent.BottomGroup[1].children[0].style.background = mainColor;
        CDOM.AsideContent.BottomGroup[2].children[0].style.background = mainColor;
        CDOM.AsideContent.BottomGroup[3].children[0].style.background = mainColor;
        //编辑栏处理
        CDOM.EditorPlane.NavTab.style.background = mainColor;

    });
    ConsoleCRS.pushFinish();
//使用VUE+ELEMENT输出树状对象图
    let mydata = [
        {
            la: "标题名称" + Game.time,
            ch: [{
                la: "二级标题",
                ch: [{
                    la: "1-1-1"
                }
                ]
            }
            ]
        },
    ];

    //由于ConsoleCRS挂载后自动载入了VUE和ElementUI,因此您可以直接输出
    //输出一个可以被识别为VUEAPP的DIV到Console,使用Game.time来设置不同id
    console.log("Data:<div id='vueapp" + Game.time + "'><el-tree :data=\"data\" :props=\"defaultProps\"></el-tree></div>")

    //内部域向外部域传递数据
    ConsoleCRS.data.Gametime = Game.time;
    ConsoleCRS.data.mydata = mydata;

    //使用代码修改这个VUEAPP
    ConsoleCRS.pushCode(function () {
        new Vue({
            el: "#vueapp" + CRSCore.data.Gametime,
            data: function () {
                return {
                    data: CRSCore.data.mydata,
                    defaultProps: { children: "ch", label: "la" }
                }
            }
        })
    });

已知问题

  • 暂时无法将CRS执行代码立即反馈到游戏中,但您仍然可以通过WEB浏览器的开发者工具查看报错信息,后期我将提供一个方法来快捷实现功能
  • 如果执行的代码中存在调用错误,会导致插入的JavaScript无法正确的被移除,代码会在每个Tick执行多次。
  • 如有新的问题欢迎联系 1552904342@qq.com

法律以及安全警告

  • 该插件提供了向浏览器植入JavaScript代码的快捷方式,该方式存在一定风险,可以窃取用户隐私数据,请勿随意运行他人提供的CRS代码,否则可能会造成无法预料的财产损失。
木兰宽松许可证, 第1版 木兰宽松许可证, 第1版 2019年8月 http://license.coscl.org.cn/MulanPSL 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第1版(“本许可证”)的如下条款的约束: 0. 定义 “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 “法人实体”是指提交贡献的机构及其“关联实体”。 “关联实体”是指,对“本许可证”下的一方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 1. 授予版权许可 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 2. 授予专利许可 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括仅因您或他人修改“贡献”或其他结合而将必然会侵犯到的专利权利要求。如您或您的“关联实体”直接或间接地(包括通过代理、专利被许可人或受让人),就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 3. 无商标许可 “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 4. 分发限制 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 5. 免责声明与责任限制 “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 条款结束。 如何将木兰宽松许可证,第1版,应用到您的软件 如果您希望将木兰宽松许可证,第1版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; 3, 请将如下声明文本放入每个源文件的头部注释中。 Copyright (c) [2019] [name of copyright holder] [Software Name] is licensed under the Mulan PSL v1. You can use this software according to the terms and conditions of the Mulan PSL v1. You may obtain a copy of Mulan PSL v1 at: http://license.coscl.org.cn/MulanPSL THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v1 for more details. Mulan Permissive Software License,Version 1 Mulan Permissive Software License,Version 1 (Mulan PSL v1) August 2019 http://license.coscl.org.cn/MulanPSL Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v1 (this License) with following terms and conditions: 0. Definition Software means the program and related documents which are comprised of those Contribution and licensed under this License. Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. Legal Entity means the entity making a Contribution and all its Affiliates. Affiliates means entities that control, or are controlled by, or are under common control with a party to this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. Contribution means the copyrightable work licensed by a particular Contributor under this License. 1. Grant of Copyright License Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. 2. Grant of Patent License Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed, excluding of any patent claims solely be infringed by your or others’ modification or other combinations. If you or your Affiliates directly or indirectly (including through an agent, patent licensee or assignee), institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. 3. No Trademark License No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4. 4. Distribution Restriction You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. 5. Disclaimer of Warranty and Limitation of Liability The Software and Contribution in it are provided without warranties of any kind, either express or implied. In no event shall any Contributor or copyright holder be liable to you for any damages, including, but not limited to any direct, or indirect, special or consequential damages arising from your use or inability to use the Software or the Contribution in it, no matter how it’s caused or based on which legal theory, even if advised of the possibility of such damages. End of the Terms and Conditions How to apply the Mulan Permissive Software License,Version 1 (Mulan PSL v1) to your software To apply the Mulan PSL v1 to your work, for easy identification by recipients, you are suggested to complete following three steps: i. Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; ii. Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; iii. Attach the statement to the appropriate annotated syntax at the beginning of each source file. Copyright (c) [2019] [name of copyright holder] [Software Name] is licensed under the Mulan PSL v1. You can use this software according to the terms and conditions of the Mulan PSL v1. You may obtain a copy of Mulan PSL v1 at: http://license.coscl.org.cn/MulanPSL THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v1 for more details.

简介

ConsoleCRS是一个便于在控制台输出外部JS代码的插件,全称Console Cross Regino Scripting 控制台跨域脚本。 展开 收起
JavaScript
MulanPSL-1.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/mingzey/screeps-console-crs.git
git@gitee.com:mingzey/screeps-console-crs.git
mingzey
screeps-console-crs
Screeps-ConsoleCRS
master

搜索帮助