Merge branch 'PR-Branch' of https://github.com/libccy/noname into PR-Branch

This commit is contained in:
Spmario233 2023-09-30 11:11:08 +08:00
commit a62407f6bd
4 changed files with 164 additions and 193 deletions

View File

@ -10459,166 +10459,4 @@
CodeMirror.defineOption("hintOptions", null);
});
(function (mod) {
// Plain browser env
mod(CodeMirror);
})(function (CodeMirror) {
var Pos = CodeMirror.Pos;
function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}
function arrayContains(arr, item) {
if (!Array.prototype.indexOf) {
var i = arr.length;
while (i--) {
if (arr[i] === item) {
return true;
}
}
return false;
}
return arr.indexOf(item) != -1;
}
function scriptHint(editor, keywords, getToken, options) {
// Find the token at the cursor
var cur = editor.getCursor(), token = getToken(editor, cur);
if (/\b(?:string|comment)\b/.test(token.type)) return;
var innerMode = CodeMirror.innerMode(editor.getMode(), token.state);
if (innerMode.mode.helperType === "json") return;
token.state = innerMode.state;
// If it's not a 'word-style' token, ignore the token.
if (!/^[\w$_]*$/.test(token.string)) {
token = {
start: cur.ch, end: cur.ch, string: "", state: token.state,
type: token.string == "." ? "property" : null
};
} else if (token.end > cur.ch) {
token.end = cur.ch;
token.string = token.string.slice(0, cur.ch - token.start);
}
var tprop = token;
// If it is a property, find out what it is a property of.
while (tprop.type == "property") {
tprop = getToken(editor, Pos(cur.line, tprop.start));
if (tprop.string != ".") return;
tprop = getToken(editor, Pos(cur.line, tprop.start));
if (!context) var context = [];
context.push(tprop);
}
return {
list: getCompletions(token, context, keywords, options),
from: Pos(cur.line, token.start),
to: Pos(cur.line, token.end)
};
}
function javascriptHint(editor, options) {
return scriptHint(editor, javascriptKeywords,
function (e, cur) { return e.getTokenAt(cur); },
options);
};
CodeMirror.registerHelper("hint", "javascript", javascriptHint);
function getCoffeeScriptToken(editor, cur) {
// This getToken, it is for coffeescript, imitates the behavior of
// getTokenAt method in javascript.js, that is, returning "property"
// type and treat "." as independent token.
var token = editor.getTokenAt(cur);
if (cur.ch == token.start + 1 && token.string.charAt(0) == '.') {
token.end = token.start;
token.string = '.';
token.type = "property";
}
else if (/^\.[\w$_]*$/.test(token.string)) {
token.type = "property";
token.start++;
token.string = token.string.replace(/\./, '');
}
return token;
}
function coffeescriptHint(editor, options) {
return scriptHint(editor, coffeescriptKeywords, getCoffeeScriptToken, options);
}
CodeMirror.registerHelper("hint", "coffeescript", coffeescriptHint);
var stringProps = ("charAt charCodeAt indexOf lastIndexOf substring substr slice trim trimLeft trimRight " +
"toUpperCase toLowerCase split concat match replace search").split(" ");
var arrayProps = ("length concat join splice push pop shift unshift slice reverse sort indexOf " +
"lastIndexOf every some filter forEach map reduce reduceRight ").split(" ");
var funcProps = "prototype apply call bind".split(" ");
var javascriptKeywords = ("break case catch class const continue debugger default delete do else export extends from false finally for function " +
"if in import instanceof let new null return super switch this throw true try typeof var void while with yield").split(" ");
var coffeescriptKeywords = ("and break catch class continue delete do else extends false finally for " +
"if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
function forAllProps(obj, callback) {
if (!Object.getOwnPropertyNames || !Object.getPrototypeOf) {
for (var name in obj) callback(name)
} else {
for (var o = obj; o; o = Object.getPrototypeOf(o))
Object.getOwnPropertyNames(o).forEach(callback);
}
}
function getCompletions(token, context, keywords, options) {
var found = [], start = token.string, global = options && options.globalScope || window;
function maybeAdd(str) {
if (str.lastIndexOf(start, 0) == 0 && !arrayContains(found, str)) found.push(str);
}
function gatherCompletions(obj) {
if (typeof obj == "string") forEach(stringProps, maybeAdd);
else if (obj instanceof Array) forEach(arrayProps, maybeAdd);
else if (obj instanceof Function) forEach(funcProps, maybeAdd);
forAllProps(obj, maybeAdd)
}
if (context && context.length) {
// If this is a property, see if it belongs to some object we can
// find in the current environment.
var obj = context.pop(), base;
if (obj.type && obj.type.indexOf("variable") === 0) {
if (options && options.additionalContext)
base = options.additionalContext[obj.string];
if (!options || options.useGlobalScope !== false)
base = base || global[obj.string];
} else if (obj.type == "string") {
base = "";
} else if (obj.type == "atom") {
base = 1;
} else if (obj.type == "function") {
if (global.jQuery != null && (obj.string == '$' || obj.string == 'jQuery') &&
(typeof global.jQuery == 'function'))
base = global.jQuery();
else if (global._ != null && (obj.string == '_') && (typeof global._ == 'function'))
base = global._();
}
while (base != null && context.length)
base = base[context.pop().string];
if (base != null) gatherCompletions(base);
} else {
// If not, just look in the global object, any local scope, and optional additional-context
// (reading into JS mode internals to get at the local and global variables)
for (var v = token.state.localVars; v; v = v.next) maybeAdd(v.name);
for (var c = token.state.context; c; c = c.prev)
for (var v = c.vars; v; v = v.next) maybeAdd(v.name)
for (var v = token.state.globalVars; v; v = v.next) maybeAdd(v.name);
if (options && options.additionalContext != null)
for (var key in options.additionalContext)
maybeAdd(key);
/*if (!options || options.useGlobalScope !== false)
gatherCompletions(global);*/
forEach(keywords, maybeAdd);
forEach(coffeescriptKeywords, maybeAdd);
}
return found.sort(function (a, b) {
return (a + '').localeCompare(b + '');
});
}
});
})();

View File

@ -5,19 +5,19 @@
localStorage.setItem('gplv3_noname_alerted',true);
}
else{
var ua=navigator.userAgent.toLowerCase();
var ios=ua.indexOf('iphone')!=-1||ua.indexOf('ipad')!=-1||ua.indexOf('macintosh')!=-1;
const ua=navigator.userAgent.toLowerCase();
const ios=ua.indexOf('iphone')!=-1||ua.indexOf('ipad')!=-1||ua.indexOf('macintosh')!=-1;
//electron
if(typeof window.process=='object'&&typeof window.require=='function'){
var versions=window.process.versions;
var electronVersion=parseFloat(versions.electron);
var remote;
const versions=window.process.versions;
const electronVersion=parseFloat(versions.electron);
let remote;
if(electronVersion>=14){
remote=require('@electron/remote');
}else{
remote=require('electron').remote;
}
var thisWindow=remote.getCurrentWindow();
const thisWindow=remote.getCurrentWindow();
thisWindow.destroy();
window.process.exit();
}
@ -7490,10 +7490,25 @@
});
//防止每次输出字符都创建以下元素
const event=_status.event;
const trigger=_status.event;
const player=ui.create.player().init('sunce');
const target=player;
const targets=[player];
const source=player;
const card=game.createCard();
//覆盖原本的javascript提示
CodeMirror.registerHelper('hint','javascript',(editor,options)=>{
const cards=[card];
const result={bool:true};
function forEach(arr,f) {
Array.from(arr).forEach(v=>f(v));
}
function forAllProps(obj,callback){
if(!Object.getOwnPropertyNames||!Object.getPrototypeOf){
for(let name in obj) callback(name);
}else{
for(let o=obj;o;o=Object.getPrototypeOf(o)) Object.getOwnPropertyNames(o).forEach(callback);
}
}
function scriptHint(editor,keywords,getToken,options){
//Find the token at the cursor
let cur=editor.getCursor(),token=editor.getTokenAt(cur);
if(/\b(?:string|comment)\b/.test(token.type)) return;
@ -7523,37 +7538,132 @@
context.push(tprop);
}
const list=[];
let obj;
if(Array.isArray(context)){
try {
const code=context.length==1?context[0].string:context.reduceRight((pre,cur)=>(pre.string||pre)+'.'+cur.string);
const obj=eval(code);
obj=eval(code);
if(![null,undefined].includes(obj)){
const keys=Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertyNames(Object.getPrototypeOf(obj))).filter(key=>key.startsWith(token.string));
list.addArray(keys);
}
}catch(_){ return;}
}else if(token&&typeof token.string=='string'){
const javascriptKeywords=("break case catch class const continue debugger default delete do else export extends from false finally for function " +
"if in import instanceof let new null return super switch this throw true try typeof var void while with yield").split(" ");
const coffeescriptKeywords=("and break catch class continue delete do else extends false finally for " +
"if in instanceof isnt new no not null of off on or return switch then throw true try typeof until void while with yes").split(" ");
const keys=['player','card','lib','game','ui','get','ai','_status'].concat(javascriptKeywords).concat(coffeescriptKeywords).concat(Object.getOwnPropertyNames(window));
const start=token.string;
function maybeAdd(str){
if(str.lastIndexOf(start,0)==0&&!list.includes(str)) list.push(str);
//非开发者模式下,提示这些单词
list.addArray(['player','card','cards','result','trigger','source','target','targets','lib','game','ui','get','ai','_status']);
}
return {
list:[...new Set(getCompletions(token,context,keywords,options).concat(list))]
.filter(key=>key.startsWith(token.string))
.sort((a,b)=>(a+'').localeCompare(b+''))
.map(text=>{
return {
render(elt,data,cur) {
var icon=document.createElement("span");
var className="cm-completionIcon cm-completionIcon-";
if(obj){
const type=typeof obj[text];
if(type== 'function') {
className+='function';
}
else if(type== 'string') {
className+='text';
}
else if(type== 'boolean') {
className+='variable';
}
else{
className+='namespace';
}
}else{
if(javascriptKeywords.includes(text)){
className+='keyword';
}
else if(window[text]) {
const type=typeof window[text];
if(type=='function'){
className+='function';
}
else if(type=='string'){
className+='text';
}
else if(text=='window'||type=='boolean'){
className+='variable';
}
else{
className+='namespace';
}
}else{
className+='namespace';
}
}
icon.className=className;
elt.appendChild(icon);
elt.appendChild(document.createTextNode(text));
},
displayText: text,
text: text,
}
}),
from:CodeMirror.Pos(cur.line,token.start),
to:CodeMirror.Pos(cur.line,token.end)
};
}
function javascriptHint(editor,options){
return scriptHint(editor,javascriptKeywords,function(e,cur){return e.getTokenAt(cur);},options);
};
//覆盖原本的javascript提示
CodeMirror.registerHelper("hint","javascript",javascriptHint);
const stringProps=Object.getOwnPropertyNames(String.prototype);
const arrayProps=Object.getOwnPropertyNames(Array.prototype);
const funcProps=Object.getOwnPropertyNames(Array.prototype);
const javascriptKeywords=("break case catch class const continue debugger default delete do else export extends from false finally for function " +
"if in import instanceof let new null return super switch this throw true try typeof var void while with yield").split(" ");
function getCompletions(token,context,keywords,options){
let found=[],start=token.string,global=options&&options.globalScope||window;
function maybeAdd(str){
if(str.lastIndexOf(start,0)==0&&!found.includes(str)) found.push(str);
}
function gatherCompletions(obj){
if(typeof obj=="string") forEach(stringProps,maybeAdd);
else if(obj instanceof Array) forEach(arrayProps,maybeAdd);
else if(obj instanceof Function) forEach(funcProps,maybeAdd);
forAllProps(obj, maybeAdd);
}
if(context&&context.length){
//If this is a property, see if it belongs to some object we can
//find in the current environment.
let obj=context.pop(),base;
if (obj.type&&obj.type.indexOf("variable")=== 0){
if(options&&options.additionalContext)
base=options.additionalContext[obj.string];
if(!options||options.useGlobalScope!==false)
base=base||global[obj.string];
}else if(obj.type=="string"){
base="";
}else if(obj.type == "atom"){
base=1;
}else if(obj.type == "function"){
if(global.jQuery!=null&&(obj.string=='$'||obj.string=='jQuery')&&(typeof global.jQuery=='function'))
base=global.jQuery();
else if(global._!=null&&(obj.string=='_')&&(typeof global._=='function'))
base=global._();
}
while(base!=null&&context.length)
base=base[context.pop().string];
if (base!=null) gatherCompletions(base);
}else{
//If not, just look in the global object, any local scope, and optional additional-context
//(reading into JS mode internals to get at the local and global variables)
for(let v=token.state.localVars;v;v=v.next) maybeAdd(v.name);
for(let c=token.state.context;c;c=c.prev) for(let v=c.vars;v;v=v.next) maybeAdd(v.name)
for(let v=token.state.globalVars;v;v=v.next) maybeAdd(v.name);
if(options&&options.additionalContext!=null) for(let key in options.additionalContext) maybeAdd(key);
list.addArray(keys);
if(!options||options.useGlobalScope!==false) gatherCompletions(global);
forEach(keywords,maybeAdd);
}
return {
list:list.filter(key=>key.startsWith(token.string)).sort((a,b)=>(a+'').localeCompare(b+'')),
from:CodeMirror.Pos(cur.line,token.start),
to:CodeMirror.Pos(cur.line,token.end),
};
});
return found.sort((a,b)=>(a+'').localeCompare(b+''));
}
},
setIntro:function(node,func,left){
if(lib.config.touchscreen){
@ -41170,7 +41280,7 @@
const size=this.innerHTML;
container.style.fontSize=size.slice(0,-2)/game.documentZoom+'px';
Array.from(self.parentElement.children).map(v=>v.createMenu).filter(Boolean).forEach(v=>{v.style.fontSize=size.slice(0,-2)/game.documentZoom+'px'});
container.listenTransition(()=>container.editor.refresh());
setTimeout(()=>container.editor.refresh(),0);
game.saveConfig('codeMirror_fontSize',size);
closeMenu.call(self);
};

View File

@ -468,14 +468,9 @@ div.cm-s-mdn-like span.CodeMirror-matchingbracket { outline:1px solid grey; colo
display: block;
}
@media (max-width: 1000px) {
.CodeMirror-hints::-webkit-scrollbar {
width: 25px;
}
}
.CodeMirror-hints::-webkit-scrollbar-thumb {
background-color: rgb(218, 215, 215);
border-radius: 5px;
height: 50px;
}
@ -496,3 +491,28 @@ li.CodeMirror-hint-active {
background: #08f;
color: white;
}
.cm-completionIcon {
position: relative;
font-size: 90%;
font-family: monospace;
width: .8em;
display: inline-block;
text-align: center;
padding-right: .6em;
opacity: 0.6;
box-sizing: content-box;
}
.cm-completionIcon-function:after,
.cm-completionIcon-method:after {content: 'ƒ';}
.cm-completionIcon-class:after {content: '○';}
.cm-completionIcon-interface:after {content: '◌';}
.cm-completionIcon-variable:after {content: '𝑥';}
.cm-completionIcon-constant:after {content: '𝐶';}
.cm-completionIcon-type:after {content: '𝑡';}
.cm-completionIcon-enum:after {content: '';}
.cm-completionIcon-property:after {content: '□';}
.cm-completionIcon-keyword:after {content: '🔑︎';}
.cm-completionIcon-namespace:after {content: '▢';}
.cm-completionIcon-text:after {content: 'abc'; font-size: 50%; vertical-align: middle;}

View File

@ -1876,6 +1876,9 @@ input.fileinput::-webkit-file-upload-button {
margin-bottom: 3px;
}
div.popup-container.editor,div.popup-container.editor div{
transition: none;
}
.popup-container.editor>div {
width: 80%;
height: 90%;