Comments (5)
There's already a Lua implementation. It's not SQL, and arguably more involved, but there's little reason to have two different scripting languages.
https://slade.readthedocs.io/en/latest/
You can use it to update stuff from a map, see these examples:
https://slade.readthedocs.io/en/latest/md/Examples/ChangeTextures.html
https://slade.readthedocs.io/en/latest/md/Examples/ArchvileMadness.html
from slade.
I'll leave this open in case someone else wants to have a go at implementing something like it, but as @Gaerzi said we already have lua scripting that can do the same thing (and more)
from slade.
I've written a simple parser concept in TypeScript
export const QUERY_ACTIONS = ['select', 'deselect', 'update', 'delete', 'count'] as const;
export type QueryAction = typeof QUERY_ACTIONS[number];
export type QueryConditions = Record<string, string | number>; // TODO: Add typings
export const QUERY_TYPES = ['things', 'lines', 'sectors', 'vertexes'] as const;
export type QueryType = typeof QUERY_TYPES[number];
class Query {
query: string;
action: QueryAction;
type: QueryType;
conditions: QueryConditions | null;
constructor(query: string) {
this.query = query;
this.action = this.parseQueryAction(query);
this.type = this.parseQueryType(query);
this.conditions = this.parseWhereSection(query);
}
private parseQueryAction(query: string): QueryAction {
const tokens = query.toLowerCase().split(' ');
if (QUERY_ACTIONS.includes(tokens[0] as QueryAction)) return (tokens[0] as QueryAction);
throw new Error('Unknown query action ' + tokens[0]);
}
private parseQueryType(query: string): QueryType {
const tokens = query.toLowerCase().split(' ');
if (QUERY_TYPES.includes(tokens[1] as QueryType)) return (tokens[1] as QueryType);
throw new Error('Unknown query type' + tokens[1]);
}
private parseWhereSection(query: string): QueryConditions | null {
const queryLower = query.toLowerCase();
if (!queryLower.includes('where')) return null;
const tokensLower = queryLower.split(' ');
const tokens = query.replaceAll(',', '').split(' ');
const whereTokens = tokens.slice(tokensLower.indexOf('where') + 1);
const conditions: QueryConditions = {};
for (const condition of whereTokens) {
if (!condition.includes('=')) continue;
const [key, value] = condition.split('=');
conditions[key] = Number(value) ?? value;
}
return conditions;
}
}
class SLQL {
query: Query;
constructor(query: string) {
console.log('Executing the query: ' + query);
this.query = new Query(query);
}
public exec() {
switch (this.query.action) {
case 'select': return this.execSelectQuery();
default:
throw new Error('Query action not implemented yet ' + this.query.action)
}
}
private execSelectQuery() {
console.log(`Change selection type to ${this.query.type}`);
console.log(`Go through ${this.query.type} and filter for such conditions: ${this.query.conditions && Object.entries(this.query.conditions)}`)
console.log(`${this.query.action} filtered ${this.query.type}`);
}
}
const query = new SLQL('SELECT things WHERE type=3');
query.exec();
As dasho suggested, I've used TypeScript-to-Lua transpiler to check it.
The transpiled code looks like it should work, but I don't know how to use SLADE API from it:
The playground link with Lua code (wait a few seconds to transpile)
If a way is found to conveniently use the SLADE API, I can write a full SLQL handler in TypeScript and it can be added to SLADE as a Lua script.
But in that case, it would still need to be made convenient to use it. For example, when you press F1, a popup window opens where you can enter the query text with some autosuggestions and examples. This will require changes on the C++ side.
from slade.
i can definitely see a gui being useful for arbitrary find/replace (and perhaps meshing with #1618 in some ways), but i'm not sure how SQL would be an improvement over that. also your parser doesn't seem to understand type = 3
?
from slade.
your parser doesn't seem to understand type = 3?
Yeah, it's a quick concept, not ready-to-use parser
from slade.
Related Issues (20)
- Crash when using USB docking station as graphics card
- Slade crashed on Windows shutdown
- Flac playback
- Start Page completely fails to render HOT 2
- linux crash HOT 2
- Segmentation fault when running slade on (arch) linux HOT 3
- Slade crashed when trying to start after installation on MacOS 10.15.7 HOT 4
- Crop window is blank
- Typo on "Draw Pixels" tool instead says "Drag Pixels" when highlighting the pencil icon.
- Sort tool doesn't sort first file if sorting images in a folder.
- SLADE still looks for .exe files on Linux HOT 3
- Chrash when opening new map HOT 1
- SLADE lost the ability to select multiple lumps in the lump list. HOT 5
- TEXTUREx Editor Crash on freedoom1.wad HOT 3
- TEXTURES editor resets the options controlled by checkboxes when closing and reopening (but not the checkboxes themselves)
- Sprites are invisible when viewing them HOT 1
- Extra command line arguments field for ACS compiler
- TEXTUREx editor multiple issues both on Linux and Windows HOT 8
- Feature Request : An option to disable/hide revert button above the text editor. HOT 2
- Outlaws .lab files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slade.