Skip to content

Commit

Permalink
0.1.0 rc-1
Browse files Browse the repository at this point in the history
  • Loading branch information
MetaverseUnknower committed Oct 12, 2023
1 parent d4322a0 commit 5442d0c
Show file tree
Hide file tree
Showing 14 changed files with 849 additions and 671 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "rollup -c",
"build": "cross-env NODE_ENV=production rollup -c",
"dev": "cross-env NODE_ENV=development rollup -c",
"link": "npm link && rollup --watch -c "
},
"typings": "./dist/index.d.ts",
Expand Down Expand Up @@ -44,6 +45,7 @@
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-typescript": "^8.5.0",
"@types/jest": "^27.4.1",
"cross-env": "^7.0.3",
"decentraland-ecs": "latest",
"jest": "^27.5.1",
"rollup": "^2.79.1",
Expand All @@ -59,4 +61,4 @@
"dependencies": {
"colyseus.js": "^0.15.14"
}
}
}
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import commonjs from "@rollup/plugin-commonjs";
import typescript from "@rollup/plugin-typescript";
import { terser } from "rollup-plugin-terser";
import packageJson from "./package.json";

const isProduction = process.env.NODE_ENV === 'production';
export default {
input: "src/index.ts",
context: "globalThis",
Expand Down Expand Up @@ -41,6 +41,6 @@ export default {
exclude: "node_modules",
ignoreGlobal: true,
}),
terser({ format: { comments: false } }),
],
isProduction && terser({ format: { comments: false } }),
].filter(Boolean), // This filters out the falsy values from the array
};
253 changes: 170 additions & 83 deletions src/components/VLMGiveaway.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { signedFetch } from "@decentraland/SignedFetch";
import { VLMEnvironment } from "../environment";
import messages from "../messages/giveaway";
import { VLMNotificationManager } from "../logic/VLMNotification.logic";
import { VLMNotification } from "./VLMNotification.component";
import { VLMSessionManager } from "../logic/VLMSession.logic";
import { VLMClaimEvent } from "./VLMSystemEvents.component";
import { VLMEventManager } from "../logic/VLMSystemEvents.logic";

export namespace VLMGiveaway {
export type ClaimResponse = {
Expand Down Expand Up @@ -32,37 +31,59 @@ export namespace VLMGiveaway {
CLAIM_IN_PROGRESS,
}

export const showMessage: CallableFunction = (response: any, messageOptions: VLMNotification.MessageOptions) => {
if (response.error) {
VLMNotificationManager.addMessage(messages.errorMessage, messageOptions);
} else if (response.reason === ClaimDeniedReason.BEFORE_EVENT) {
VLMNotificationManager.addMessage(messages.beforeEventTime, messageOptions);
} else if (response.reason === ClaimDeniedReason.AFTER_EVENT) {
VLMNotificationManager.addMessage(messages.afterEventTime, messageOptions);
} else if (response.reason === ClaimDeniedReason.EXISTING_CLAIM) {
VLMNotificationManager.addMessage(messages.existingClaim, messageOptions);
} else if (response.reason === ClaimDeniedReason.IP_LIMIT) {
VLMNotificationManager.addMessage(messages.ipLimitReached, messageOptions);
} else if (response.reason === ClaimDeniedReason.NO_SUPPLY) {
VLMNotificationManager.addMessage(messages.noSupply, messageOptions);
} else if (response.reason === ClaimDeniedReason.INAUTHENTIC) {
VLMNotificationManager.addMessage(messages.inauthenticConnection, messageOptions);
} else if (response.success) {
VLMNotificationManager.addMessage(messages.successfulClaim, messageOptions);
}
};

export class ClaimPoint {
sk?: string;
actionId: string;
itemId: string;
position: { x: number; y: number; z: number };
scale?: { x: number; y: number; z: number };
scale: { x: number; y: number; z: number };
glb?: string;
image?: string;
clickDistance?: number;
rotation?: number;
hoverText?: string;
messageOptions?: VLMNotification.MessageOptions;
messageColor?: string;
messageFontSize?: number;
requestInProgress: boolean;
requestInProgress: boolean = false;

constructor(config: ClaimPoint, messageOptions: VLMNotification.MessageOptions) {
constructor(config: Partial<ClaimPoint> | null, giveawayConfig: DCLConfig) {
const objThis = this;
this.actionId = config.actionId;
this.position = config.position;
this.scale = config.scale;
this.glb = config.glb;
this.image = config.image;
this.clickDistance = config.clickDistance;
this.rotation = config.rotation;
this.hoverText = config.hoverText;
this.messageColor = messageOptions.color;
this.messageFontSize = messageOptions.fontSize;
this.sk = giveawayConfig?.sk;
this.position = config?.position;
this.scale = config?.scale;
this.glb = config?.glb;
this.image = config?.image;
this.clickDistance = config?.clickDistance;
this.rotation = config?.rotation;
this.hoverText = config?.hoverText;
this.messageOptions = giveawayConfig?.messageOptions;
this.messageColor = this.messageOptions?.color;
this.messageFontSize = this.messageOptions?.fontSize;
this.requestInProgress = false;
const claimEntity = new Entity("Giveaway Trigger");
engine.addEntity(claimEntity);
if (this.glb) {
claimEntity.addComponent(new GLTFShape(this.glb || "../vlm-giveaway/VLM-Sign.glb"));
claimEntity.addComponent(new GLTFShape(this.glb || "../models/VLM-Sign.glb"));
} else if (this.image) {
const plane = new PlaneShape();
plane.uvs = [0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1];
Expand All @@ -76,19 +97,19 @@ export namespace VLMGiveaway {
claimImageMat.transparencyMode = TransparencyMode.ALPHA_TEST;
claimEntity.addComponentOrReplace(claimImageMat);
} else {
claimEntity.addComponent(new BoxShape());
this.generateSdkClaimPoint(this)
}

const claimEntityTransform = new Transform({
position: new Vector3(this.position.x || 8, this.position.y || 8, this.position.z || 8),
position: new Vector3(this.position?.x || 8, this.position?.y || 1, this.position?.z || 8),
rotation: Quaternion.Euler(0, this.rotation || 0, 0),
scale: new Vector3(this.scale?.x || 1, this.scale?.y || 1, this.scale?.z || 1),
});
claimEntity.addComponentOrReplace(claimEntityTransform);
claimEntity.addComponent(
new OnPointerDown(
async function () {
await objThis.claim(objThis.actionId);
await objThis.claim(objThis.sk, this.messageOptions);
},
{
button: ActionButton.POINTER,
Expand All @@ -99,85 +120,151 @@ export namespace VLMGiveaway {
);
}

claim: CallableFunction = async (claimAction: string, messageOptions: VLMNotification.MessageOptions) => {
// try {
generateSdkClaimPoint: CallableFunction = (config: ClaimPoint) => {
// make a tall cylinder on top of a thicker short cylinder
const objThis = this;
const parentEntity = new Entity("Giveaway Claim Point");
const domeEntity = new Entity("Claim Point Dome");
const baseEntity = new Entity("Claim Point Base");
const avatarEntity = new Entity("Claim Point Avatar");
engine.addEntity(parentEntity);
engine.addEntity(avatarEntity);
engine.addEntity(domeEntity);
engine.addEntity(baseEntity);
domeEntity.setParent(parentEntity);
domeEntity.addComponent(new CylinderShape());
domeEntity.addComponent(
new OnPointerDown(
async function () {
await objThis.claim(config.sk, this.messageOptions);
},
{
button: ActionButton.POINTER,
hoverText: config.hoverText || "Claim Item",
distance: config.clickDistance || 5,
}
)
);
const defaultWearables = [
"urn:decentraland:off-chain:base-avatars:black_top",
"urn:decentraland:off-chain:base-avatars:double_bun",
"urn:decentraland:off-chain:base-avatars:f_eyes_00",
"urn:decentraland:off-chain:base-avatars:f_eyebrows_00",
"urn:decentraland:off-chain:base-avatars:f_mouth_00",
];
// avatarEntity.setParent(parentEntity);
baseEntity.setParent(parentEntity);
const avatarShape = new AvatarShape();
avatarShape.bodyShape = "urn:decentraland:off-chain:base-avatars:BaseFemale";
avatarShape.wearables = defaultWearables;
avatarShape.skinColor = new Color4(1.1, 1.1, 1.1, 1);
avatarShape.hairColor = new Color4(1, 1, 1, 1);
avatarEntity.addComponent(avatarShape);
baseEntity.addComponent(new CylinderShape());
const domeMaterial = new Material();
domeMaterial.albedoColor = new Color4(1, 1, 1, 0.5)
// domeMaterial.albedoColor = Color4.Blue();
domeMaterial.emissiveIntensity = 1;
domeMaterial.transparencyMode = TransparencyMode.ALPHA_BLEND;
domeEntity.addComponentOrReplace(domeMaterial);
const baseMaterial = new Material();
baseMaterial.albedoColor = Color3.FromHexString("#fffff");
baseMaterial.emissiveColor = Color3.FromHexString("#aaaaff");
baseMaterial.emissiveIntensity = 1;
baseMaterial.transparencyMode = TransparencyMode.ALPHA_TEST;
baseEntity.addComponentOrReplace(baseMaterial);
parentEntity.addComponent(
new Transform({
position: new Vector3(config.position?.x || 8, config.position?.y || 0, config.position?.z || 8),
rotation: Quaternion.Euler(0, config.rotation || 0, 0),
scale: new Vector3(config.scale?.x || 1, config.scale?.y || 1, config.scale?.z || 1),
})
);
domeEntity.addComponent(
new Transform({
position: new Vector3(0, 0.75, 0),
scale: new Vector3(0.59, 1.5, 0.59),
})
);
baseEntity.addComponent(
new Transform({
position: new Vector3(0, 0, 0),
scale: new Vector3(0.6, 0.1, 0.6),
})
);
avatarEntity.addComponent(
new Transform({
position: new Vector3(8, 0.15, 8),
scale: new Vector3(1, 1, 1)
})
);
parentEntity.addComponent(
new OnPointerDown(
async function () {
await objThis.claim(config.sk, this.messageOptions);
},
{
button: ActionButton.POINTER,
hoverText: config.hoverText || "Claim Item",
distance: config.clickDistance || 5,
}
)
);
};

claim: CallableFunction = async (giveawayId: string, messageOptions: VLMNotification.MessageOptions) => {
if (VLMNotificationManager.running) {
VLMNotificationManager.init();
}
if (!VLMSessionManager.sessionUser.hasConnectedWeb3) {
VLMNotificationManager.addMessage(messages.noWallet);
return;
} else if (this.requestInProgress) {
VLMNotificationManager.addMessage(messages.claimInProgress);
return;
}
if (VLMNotificationManager.running) {
VLMNotificationManager.init();
VLMNotificationManager.addMessage(messages.claimInProgress, messageOptions);
this.requestInProgress = true;
VLMEventManager.events.fireEvent(new VLMClaimEvent({ action: "claim", giveawayId, messageOptions }));
};

claimSuccess: CallableFunction = async (response: ClaimResponse, messageOptions: VLMNotification.MessageOptions) => {
if (response.type === ClaimResponseType.CLAIM_ACCEPTED) {
VLMNotificationManager.addMessage(response.message || messages.successfulClaim, messageOptions);
} else if (response.type === ClaimResponseType.CLAIM_DENIED) {
showMessage(response, messageOptions);
} else if (response.type === ClaimResponseType.CLAIM_IN_PROGRESS) {
VLMNotificationManager.addMessage(response.message || messages.claimInProgress, messageOptions);
}
VLMSessionManager.events.fireEvent(new VLMClaimEvent({ action: "claim", claimAction, messageOptions }));
};

claimDenial: CallableFunction = async (response: ClaimDeniedReason, messageOptions: VLMNotification.MessageOptions) => {
showMessage(response, messageOptions);
};
}

export class DCLConfig {
sk: string;
claimAction: string;
giveawayId: string;
requestInProgress: boolean;
messageOptions: VLMNotification.MessageOptions;
messageOptions: VLMNotification.MessageOptions = { color: "#ffffff", fontSize: 16, delay: 5000 };
claimPoints: ClaimPoint[] = [];

constructor(claimAction: string, messageOptions: VLMNotification.MessageOptions) {
this.claimAction = claimAction;
this.messageOptions = messageOptions;
constructor(config: VLMConfig) {
this.sk = config.sk;
this.giveawayId = config.sk;
this.messageOptions = config.messageOptions;
this.requestInProgress = false;
}
this.claimPoints = config.claimPoints || this.claimPoints;

claim: CallableFunction = async () => {
try {
if (!VLMSessionManager.sessionUser.hasConnectedWeb3) {
VLMNotificationManager.addMessage(messages.noWallet);
return;
} else if (this.requestInProgress) {
return;
}

this.requestInProgress = true;
let response = await signedFetch(`${VLMEnvironment.apiUrl}/nft`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ claimAction: this.claimAction }),
});

let json;
if (!response.text) return;

json = JSON.parse(response.text);
this.showMessage(json, this.messageOptions);
return json;
} catch (error) {
let response = {
error: true,
message: error,
};
this.showMessage(response, this.messageOptions);
return response;
}
};
private showMessage: CallableFunction = (response: any, messageOptions: VLMNotification.MessageOptions) => {
if (response.error) {
VLMNotificationManager.addMessage(messages.errorMessage, messageOptions);
} else if (response.reason === ClaimDeniedReason.BEFORE_EVENT) {
VLMNotificationManager.addMessage(messages.beforeEventTime, messageOptions);
} else if (response.reason === ClaimDeniedReason.AFTER_EVENT) {
VLMNotificationManager.addMessage(messages.afterEventTime, messageOptions);
} else if (response.reason === ClaimDeniedReason.EXISTING_CLAIM) {
VLMNotificationManager.addMessage(messages.existingClaim, messageOptions);
} else if (response.reason === ClaimDeniedReason.IP_LIMIT) {
VLMNotificationManager.addMessage(messages.ipLimitReached, messageOptions);
} else if (response.reason === ClaimDeniedReason.NO_SUPPLY) {
VLMNotificationManager.addMessage(messages.noSupply, messageOptions);
} else if (response.reason === ClaimDeniedReason.INAUTHENTIC) {
VLMNotificationManager.addMessage(messages.inauthenticConnection, messageOptions);
} else if (response.success) {
VLMNotificationManager.addMessage(messages.successfulClaim, messageOptions);
}
};
this.claimPoints.forEach((claimPoint) => {
new ClaimPoint(claimPoint, this);
});

// if (VLMEnvironment.devMode) {
// new ClaimPoint(null, this);

}
}

export class VLMConfig extends DCLConfig { }
Expand Down
Loading

0 comments on commit 5442d0c

Please sign in to comment.